Skip to content

prefer-string-raw: Forbid unnecessary String.raw#2695

Merged
sindresorhus merged 18 commits into
sindresorhus:mainfrom
som-sm:feat/remove-unnecessary-string-raw-usage
Jun 5, 2026
Merged

prefer-string-raw: Forbid unnecessary String.raw#2695
sindresorhus merged 18 commits into
sindresorhus:mainfrom
som-sm:feat/remove-unnecessary-string-raw-usage

Conversation

@som-sm

@som-sm som-sm commented Jun 25, 2025

Copy link
Copy Markdown
Contributor

Closes #2652

This PR simply loops over all the quasis and checks if any of them contain a backslash. If none of them do, then the rule starts complaining.

Also, the suggestion is a template string(`) only if there are expressions or the string contains line breaks, otherwise, the suggestion is always a single quotes string (').

Comment thread test/prefer-string-raw.js
Comment thread rules/prefer-string-raw.js Outdated
Comment thread rules/prefer-string-raw.js
Comment thread rules/prefer-string-raw.js Outdated
@fisker fisker changed the title prefer-string-raw: Remove unnecessary usages prefer-string-raw: Forbid unnecessary String.raw Jun 26, 2025
Comment thread rules/prefer-string-raw.js
@som-sm som-sm requested a review from fisker June 26, 2025 17:24
Comment thread rules/prefer-string-raw.js Outdated
Comment thread rules/prefer-string-raw.js Outdated
Comment thread rules/prefer-string-raw.js Outdated
Comment thread test/prefer-string-raw.js
@som-sm som-sm force-pushed the feat/remove-unnecessary-string-raw-usage branch from 0c30a3c to ffcc738 Compare June 27, 2025 14:37
@som-sm som-sm requested a review from fisker June 27, 2025 14:52
Comment thread rules/prefer-string-raw.js
Comment thread rules/prefer-string-raw.js
@fisker

fisker commented Oct 16, 2025

Copy link
Copy Markdown
Collaborator

@som-sm Can you solve the conflicts?

@sindresorhus

Copy link
Copy Markdown
Owner

Bump :)

@som-sm

som-sm commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi, apologies! This slipped off my head. I'll try to update this sometime this week.

@som-sm som-sm force-pushed the feat/remove-unnecessary-string-raw-usage branch from 0cc9823 to 1aebc29 Compare February 11, 2026 07:07
@som-sm som-sm force-pushed the feat/remove-unnecessary-string-raw-usage branch from 528fef7 to 27be5c6 Compare February 11, 2026 08:15
@som-sm som-sm force-pushed the feat/remove-unnecessary-string-raw-usage branch from 27be5c6 to bf5619e Compare February 11, 2026 08:21
@som-sm som-sm requested a review from fisker February 11, 2026 09:07
@som-sm

som-sm commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

I had lost all context on this, but I've tried to update it and address all pending comments.

@sindresorhus

Copy link
Copy Markdown
Owner

The fixer handles multiline return/throw, but it does not handle multiline yield.

Input:

function* foo() {
	yield String.raw
		// comment
		`abc`;
}

Current fix:

function* foo() {
	yield
		// comment
		'abc';
}

This changes runtime behvaior because ASI inserts after yield.

And an extra tests worth adding, same multiline yield shape but with interpolation:

function* foo() {
	yield String.raw
		`a${value}`;
}

@sindresorhus sindresorhus force-pushed the main branch 4 times, most recently from 814b622 to 0e023e3 Compare April 2, 2026 12:41
@sindresorhus sindresorhus merged commit 1fdace0 into sindresorhus:main Jun 5, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rule proposal: opposite of prefer-string-raw

3 participants