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

Add --fix-type support #3165

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rules/boolean-prop-naming.js
Expand Up @@ -21,6 +21,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
category: 'Stylistic Issues',
description: 'Enforces consistent naming for boolean props',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/button-has-type.js
Expand Up @@ -30,6 +30,7 @@ const messages = {

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Forbid "button" element without an explicit "type" attribute',
category: 'Possible Errors',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/default-props-match-prop-types.js
Expand Up @@ -21,6 +21,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Enforce all defaultProps are defined and not "required" in propTypes.',
category: 'Best Practices',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/destructuring-assignment.js
Expand Up @@ -54,6 +54,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Enforce consistent usage of destructuring assignment of props, state, and context',
category: 'Stylistic Issues',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/display-name.js
Expand Up @@ -23,6 +23,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Prevent missing displayName in a React component definition',
category: 'Best Practices',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/forbid-component-props.js
Expand Up @@ -24,6 +24,7 @@ const messages = {

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Forbid certain props on components',
category: 'Best Practices',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/forbid-dom-props.js
Expand Up @@ -24,6 +24,7 @@ const messages = {

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Forbid certain props on DOM Nodes',
category: 'Best Practices',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/forbid-elements.js
Expand Up @@ -21,6 +21,7 @@ const messages = {

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Forbid certain elements',
category: 'Best Practices',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/forbid-foreign-prop-types.js
Expand Up @@ -15,6 +15,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Forbid using another component\'s propTypes',
category: 'Best Practices',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/forbid-prop-types.js
Expand Up @@ -27,6 +27,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Forbid certain propTypes',
category: 'Best Practices',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/function-component-definition.js
Expand Up @@ -100,6 +100,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Standardize the way function component get defined',
category: 'Stylistic Issues',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-boolean-value.js
Expand Up @@ -56,6 +56,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Enforce boolean attributes notation in JSX',
category: 'Stylistic Issues',
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-child-element-spacing.js
Expand Up @@ -46,13 +46,13 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Ensures inline tags are not rendered without spaces between them',
category: 'Stylistic Issues',
recommended: false,
url: docsUrl('jsx-child-element-spacing'),
},
fixable: null,

messages,

Expand Down
3 changes: 2 additions & 1 deletion lib/rules/jsx-closing-bracket-location.js
Expand Up @@ -19,13 +19,14 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Validate closing bracket location in JSX',
category: 'Stylistic Issues',
recommended: false,
url: docsUrl('jsx-closing-bracket-location'),
},
fixable: 'code',
fixable: 'whitespace',
Copy link
Member

Choose a reason for hiding this comment

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

why is this change correct?

(if it is correct, i'd like to land it separately, before this PR)

Copy link
Author

@sryze sryze Jan 4, 2022

Choose a reason for hiding this comment

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

it was part of the original PR

I'm not 100% sure what this property means because the documentation doesn't mention what is the difference between code and whitespace; possibly whitepsace means that a fix will only change whitespace characters

Copy link
Author

Choose a reason for hiding this comment

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

@ljharb I've reverted the changes to fixable and category in made by the previous PR author as they are not related to --fix-type (purpose of this PR); please have a look, thanks!

Copy link
Author

Choose a reason for hiding this comment

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

looks like this change was correct, because the fix changes only spacing before the bracket (indents + newline), see eslint/eslint#15489 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

@sryze can we make a separate PR that changes all the "code"s to "whitespace"s?


messages,

Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-closing-tag-location.js
Expand Up @@ -20,6 +20,7 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Validate closing tag location for multiline JSX',
category: 'Stylistic Issues',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-curly-brace-presence.js
Expand Up @@ -38,6 +38,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description:
'Disallow unnecessary JSX expressions when literals alone are sufficient '
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/jsx-curly-newline.js
Expand Up @@ -44,16 +44,13 @@ const messages = {
module.exports = {
meta: {
type: 'layout',

docs: {
description: 'Enforce consistent line breaks inside jsx curly',
category: 'Stylistic Issues',
recommended: false,
url: docsUrl('jsx-curly-newline'),
},

fixable: 'whitespace',

schema: [
{
oneOf: [
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/jsx-curly-spacing.js
Expand Up @@ -36,13 +36,14 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Enforce or disallow spaces inside of curly braces in JSX attributes',
category: 'Stylistic Issues',
recommended: false,
url: docsUrl('jsx-curly-spacing'),
},
fixable: 'code',
fixable: 'whitespace',
Copy link
Member

Choose a reason for hiding this comment

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

same here?


messages,

Expand Down
3 changes: 2 additions & 1 deletion lib/rules/jsx-equals-spacing.js
Expand Up @@ -21,13 +21,14 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Disallow or enforce spaces around equal signs in JSX attributes',
category: 'Stylistic Issues',
recommended: false,
url: docsUrl('jsx-equals-spacing'),
},
fixable: 'code',
fixable: 'whitespace',
Copy link
Member

Choose a reason for hiding this comment

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

and here?


messages,

Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-filename-extension.js
Expand Up @@ -29,6 +29,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Restrict file extensions that may contain JSX',
category: 'Stylistic Issues',
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/jsx-first-prop-new-line.js
Expand Up @@ -19,13 +19,14 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Ensure proper position of the first property in JSX',
category: 'Stylistic Issues',
recommended: false,
url: docsUrl('jsx-first-prop-new-line'),
},
fixable: 'code',
fixable: 'whitespace',
Copy link
Member

Choose a reason for hiding this comment

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

and here


messages,

Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-fragments.js
Expand Up @@ -29,6 +29,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Enforce shorthand or standard form for React fragments',
category: 'Stylistic Issues',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-handler-names.js
Expand Up @@ -19,6 +19,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Enforce event handler naming conventions in JSX',
category: 'Stylistic Issues',
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/jsx-indent-props.js
Expand Up @@ -44,13 +44,14 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Validate props indentation in JSX',
category: 'Stylistic Issues',
recommended: false,
url: docsUrl('jsx-indent-props'),
},
fixable: 'code',
fixable: 'whitespace',
Copy link
Member

Choose a reason for hiding this comment

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

and here


messages,

Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-indent.js
Expand Up @@ -46,6 +46,7 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Validate JSX indentation',
category: 'Stylistic Issues',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-key.js
Expand Up @@ -30,6 +30,7 @@ const messages = {

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Report missing `key` props in iterators/collection literals',
category: 'Possible Errors',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-max-depth.js
Expand Up @@ -22,6 +22,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Validate JSX maximum depth',
category: 'Stylistic Issues',
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/jsx-max-props-per-line.js
Expand Up @@ -25,13 +25,14 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Limit maximum of props on a single line in JSX',
category: 'Stylistic Issues',
recommended: false,
url: docsUrl('jsx-max-props-per-line'),
},
fixable: 'code',
fixable: 'whitespace',
Copy link
Member

Choose a reason for hiding this comment

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

and here


messages,

Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-newline.js
Expand Up @@ -20,6 +20,7 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Require or prevent a new line after jsx elements and expressions.',
category: 'Stylistic Issues',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-no-bind.js
Expand Up @@ -26,6 +26,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Prevents usage of Function.prototype.bind and arrow functions in React component props',
category: 'Best Practices',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-no-comment-textnodes.js
Expand Up @@ -35,6 +35,7 @@ function checkText(node, context) {

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Comments inside children section of tag should be placed inside braces',
category: 'Possible Errors',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-no-constructed-context-values.js
Expand Up @@ -130,6 +130,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Prevents JSX context provider values from taking values that will cause needless rerenders.',
category: 'Best Practices',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-no-duplicate-props.js
Expand Up @@ -19,6 +19,7 @@ const messages = {

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Enforce no duplicate props',
category: 'Possible Errors',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-no-literals.js
Expand Up @@ -26,6 +26,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Prevent using string literals in React component definition',
category: 'Stylistic Issues',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-no-script-url.js
Expand Up @@ -49,6 +49,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Forbid `javascript:` URLs',
category: 'Best Practices',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-no-target-blank.js
Expand Up @@ -103,6 +103,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
fixable: 'code',
docs: {
description: 'Forbid `target="_blank"` attribute without `rel="noreferrer"`',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-no-undef.js
Expand Up @@ -19,6 +19,7 @@ const messages = {

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Disallow undeclared variables in JSX',
category: 'Possible Errors',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-one-expression-per-line.js
Expand Up @@ -23,6 +23,7 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Limit to one expression per line in JSX',
category: 'Stylistic Issues',
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-pascal-case.js
Expand Up @@ -78,6 +78,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Enforce PascalCase for user-defined JSX components',
category: 'Stylistic Issues',
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/jsx-props-no-multi-spaces.js
Expand Up @@ -19,13 +19,14 @@ const messages = {

module.exports = {
meta: {
type: 'layout',
docs: {
description: 'Disallow multiple spaces between inline JSX props',
category: 'Stylistic Issues',
recommended: false,
url: docsUrl('jsx-props-no-multi-spaces'),
},
fixable: 'code',
fixable: 'whitespace',
Copy link
Member

Choose a reason for hiding this comment

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

and here


messages,

Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-props-no-spreading.js
Expand Up @@ -40,6 +40,7 @@ const messages = {

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Prevent JSX prop spreading',
category: 'Best Practices',
Expand Down