-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[New] jsx-no-literals
: add noAttributeStrings
option
#2782
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
Conversation
Co-authored-by: TaLea Carpenter <[email protected]> Co-authored-by: tanmoyopenroot <[email protected]> Fixes #jsx-eslint#2486
lib/rules/jsx-no-literals.js
Outdated
} | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, altho if it helps readability it'd be fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line removed.
docs/rules/jsx-no-literals.md
Outdated
|
||
* `noStrings` (default: `false`) - Enforces no string literals used as children, wrapped or unwrapped. | ||
* `allowedStrings` - An array of unique string values that would otherwise warn, but will be ignored. | ||
* `ignoreProps` (default: `false`) - When `true` the rule ignores literals used in props, wrapped or unwrapped. | ||
* `noAttributeStrings` (default: `false` ) - Enforces no string literals used in attributes when set to `true`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `noAttributeStrings` (default: `false` ) - Enforces no string literals used in attributes when set to `true`. | |
* `noAttributeStrings` (default: `false`) - Enforces no string literals used in attributes when set to `true`. |
lib/rules/jsx-no-literals.js
Outdated
additionalProperties: false | ||
}] | ||
}, | ||
|
||
create(context) { | ||
const defaults = {noStrings: false, allowedStrings: [], ignoreProps: false}; | ||
const defaults = { | ||
noStrings: false, allowedStrings: [], ignoreProps: false, noAttributeStrings: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noStrings: false, allowedStrings: [], ignoreProps: false, noAttributeStrings: false | |
noStrings: false, | |
allowedStrings: [], | |
ignoreProps: false, | |
noAttributeStrings: false |
when the entire object doesn't fit on one line, each property should be on its own line.
lib/rules/jsx-no-literals.js
Outdated
function defaultMessage() { | ||
switch (true) { | ||
case config.noAttributeStrings: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use an if with early returns here instead of a switch.
lib/rules/jsx-no-literals.js
Outdated
|
||
context.report({ | ||
node, | ||
message: `${errorMessage}: “${context.getSourceCode().getText(node).trim()}”` | ||
message: `${errorMessage}: "${context.getSourceCode().getText(node).trim()}"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the curly quotes here are quite intentional; straight quotes are never appropriate in prose. please revert this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending comments
docs/rules/jsx-no-literals.md
Outdated
@@ -26,16 +26,17 @@ var Hello = <div> | |||
|
|||
## Rule Options | |||
|
|||
There are two options: | |||
There are three options: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a good idea to remove the count, to avoid having to update this in the future (also you're changing it to "three" but i think there's 4 now?):
There are three options: | |
The supported options are: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, the wording has been changed.
lib/rules/jsx-no-literals.js
Outdated
} | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, altho if it helps readability it'd be fine
lib/rules/jsx-no-literals.js
Outdated
&& parent.type !== 'JSXAttribute'; | ||
|
||
function isParentNodeStandard() { | ||
if (!/^[\s]+$/.test(node.value) && typeof node.value === 'string' && parent.type.indexOf('JSX') !== -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!/^[\s]+$/.test(node.value) && typeof node.value === 'string' && parent.type.indexOf('JSX') !== -1) { | |
if (!/^[\s]+$/.test(node.value) && typeof node.value === 'string' && parent.type.includes('JSX')) { |
jsx-no-literals
: add noAttributeStrings
option
Closes #2496. Fixes #2486.