Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update safe-string-coercion to handle additions of string literals #25286

Merged
merged 3 commits into from
Oct 4, 2022

Conversation

poteto
Copy link
Member

@poteto poteto commented Sep 16, 2022

Adding strings shouldn't trigger a lint violation of this rule, since adding strings are always safe.

@facebook-github-bot facebook-github-bot added the React Core Team Opened by a member of the React Core Team label Sep 16, 2022
@sizebot
Copy link

sizebot commented Sep 16, 2022

Comparing: aed33a4...4d32d44

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 135.46 kB 135.46 kB = 43.41 kB 43.41 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 147.72 kB 147.72 kB = 47.17 kB 47.17 kB
facebook-www/ReactDOM-prod.classic.js = 491.70 kB 491.70 kB = 87.49 kB 87.49 kB
facebook-www/ReactDOM-prod.modern.js = 477.00 kB 477.00 kB = 85.24 kB 85.24 kB
facebook-www/ReactDOMForked-prod.classic.js = 491.70 kB 491.70 kB = 87.49 kB 87.49 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 4d32d44

Copy link
Contributor

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need a check that the operator is +?

scripts/eslint-rules/safe-string-coercion.js Show resolved Hide resolved
@poteto poteto force-pushed the lt/safe-string-coercion branch 2 times, most recently from 11496fa to 13ecb57 Compare September 19, 2022 16:03
@poteto
Copy link
Member Author

poteto commented Sep 27, 2022

@acdlite would appreciate a review if you have time, not a big deal but solves a minor annoyance (typing 'my long message that spans ' + '' gives you an immediate red squiggly)

Copy link
Contributor

@sophiebits sophiebits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm, this is just annoying while typing in development right? There's no need to commit a + '' with a string literal.

Worth checking that the template literal doesn't have any substitutions?

@sophiebits
Copy link
Contributor

I guess even if the template literal has substitutions then the + '' is fine since it's already a string at that point. We might want to lint on the template literal itself but not the concatenation. However a tagged template literal could be a non-string I think.

@poteto
Copy link
Member Author

poteto commented Sep 30, 2022

@sophiebits Yeah this is really a mild annoyance at dev time when you're say, writing a long error message that spans multiple lines. Good point about tagged template literals returning non-strings though, I just tried it out and it looks like it is possible. I'll see if I can just match on non-tagged

@poteto
Copy link
Member Author

poteto commented Oct 4, 2022

Updated so we only treat untagged template literals as strings.

@poteto poteto merged commit af9afe9 into main Oct 4, 2022
@poteto poteto deleted the lt/safe-string-coercion branch October 4, 2022 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants