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

[Fix] jsx-no-literals: trim whitespace for allowedStrings check #2436

Merged
merged 1 commit into from Oct 16, 2019
Merged

[Fix] jsx-no-literals: trim whitespace for allowedStrings check #2436

merged 1 commit into from Oct 16, 2019

Conversation

cainlevy
Copy link
Contributor

@cainlevy cainlevy commented Oct 2, 2019

The allowedStrings option for jsx-no-literals is checked against an untrimmed string containing potential spaces and newlines. This is at odds with the error message shown and substantially increases the difficulty of managing the allowedStrings list.

I propose trimming strings before checking inclusion in allowedStrings.

related:

const isNoStrings = context.options[0] ? context.options[0].noStrings : false;
const allowedStrings = context.options[0] ? new Set(context.options[0].allowedStrings) : false;
const allowedStrings = context.options[0] ?
new Set((context.options[0].allowedStrings || []).map(trimIfString)) :
Copy link
Member

Choose a reason for hiding this comment

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

why the ternary? just making this unconditionally be a Set simplifies the check below

}
}
`,
options: [{noStrings: true, allowedStrings: [' ']}]
Copy link
Member

Choose a reason for hiding this comment

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

could we add a few more tests, one with leading and trailing spaces on allowedStrings, and a different one with them on the rendered text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

apologies, i'm not sure how to action this request. could you say it another way?

for context, we happen to have a pre-existing test with spaces in allowedStrings that would fail if allowedStrings were not trimmed. here are all the combinations of spaces and not spaces with test coverage:

tested spaces in allowedStrings spaces in rendered text
🚫
🚫 🚫
🚫 🚫

is that the test gap you'd like me to fix?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, exactly right :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it!

Copy link
Member

Choose a reason for hiding this comment

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

I'd also like a test with noStrings false, and an allowedStrings value :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ I've made noStrings: false explicit in the existing test case

@ljharb ljharb merged commit 7fa31df into jsx-eslint:master Oct 16, 2019
@cainlevy cainlevy deleted the jsx-no-literals-trim branch October 16, 2019 15:38
@cainlevy
Copy link
Contributor Author

possible to get this in a release soon?

thanks for all the work you put into maintaining this plugin! 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants