-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Adds eslint config extends with only whitespace rules enabled #1749
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const baseConfig = require('.'); | ||
const entries = require('object.entries'); | ||
const { CLIEngine } = require('eslint'); | ||
|
||
function onlyErrorOnRules(rulesToError, config) { | ||
const errorsOnly = { ...config }; | ||
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); | ||
const baseRules = cli.getConfigForFile('./').rules; | ||
|
||
entries(baseRules).forEach(([key, value]) => { | ||
if (rulesToError.indexOf(key) === -1) { | ||
if (Array.isArray(value)) { | ||
errorsOnly.rules[key] = ['warn'].concat(value.slice(1)); | ||
} else if (typeof value === 'number') { | ||
errorsOnly.rules[key] = 1; | ||
} else { | ||
errorsOnly.rules[key] = 'warn'; | ||
} | ||
} | ||
}); | ||
|
||
return errorsOnly; | ||
} | ||
|
||
module.exports = onlyErrorOnRules([ | ||
'array-bracket-newline', | ||
'array-bracket-spacing', | ||
'array-element-newline', | ||
'arrow-spacing', | ||
'block-spacing', | ||
'comma-spacing', | ||
'computed-property-spacing', | ||
'dot-location', | ||
'eol-last', | ||
'func-call-spacing', | ||
'function-paren-newline', | ||
'generator-star-spacing', | ||
'implicit-arrow-linebreak', | ||
'indent', | ||
'key-spacing', | ||
'keyword-spacing', | ||
'line-comment-position', | ||
'linebreak-style', | ||
'multiline-ternary', | ||
'newline-per-chained-call', | ||
'no-irregular-whitespace', | ||
'no-mixed-spaces-and-tabs', | ||
'no-multi-spaces', | ||
'no-regex-spaces', | ||
'no-spaced-func', | ||
'no-trailing-spaces', | ||
'no-whitespace-before-property', | ||
'nonblock-statement-body-position', | ||
'object-curly-newline', | ||
'object-curly-spacing', | ||
'object-property-newline', | ||
'one-var-declaration-per-line', | ||
'operator-linebreak', | ||
'padded-blocks', | ||
'padding-line-between-statements', | ||
'rest-spread-spacing', | ||
'semi-spacing', | ||
'semi-style', | ||
'space-before-blocks', | ||
'space-before-function-paren', | ||
'space-in-parens', | ||
'space-infix-ops', | ||
'space-unary-ops', | ||
'spaced-comment', | ||
'switch-colon-spacing', | ||
'template-tag-spacing', | ||
'import/newline-after-import', | ||
], baseConfig); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const baseConfig = require('.'); | ||
const entries = require('object.entries'); | ||
const { CLIEngine } = require('eslint'); | ||
|
||
function onlyErrorOnRules(rulesToError, config) { | ||
const errorsOnly = { ...config }; | ||
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); | ||
const baseRules = cli.getConfigForFile('./').rules; | ||
|
||
entries(baseRules).forEach(([key, value]) => { | ||
if (rulesToError.indexOf(key) === -1) { | ||
if (Array.isArray(value)) { | ||
errorsOnly.rules[key] = ['warn'].concat(value.slice(1)); | ||
} else if (typeof value === 'number') { | ||
errorsOnly.rules[key] = 1; | ||
} else { | ||
errorsOnly.rules[key] = 'warn'; | ||
} | ||
} | ||
}); | ||
|
||
return errorsOnly; | ||
} | ||
|
||
module.exports = onlyErrorOnRules([ | ||
'array-bracket-newline', | ||
'array-bracket-spacing', | ||
'array-element-newline', | ||
'arrow-spacing', | ||
'block-spacing', | ||
'comma-spacing', | ||
'computed-property-spacing', | ||
'dot-location', | ||
'eol-last', | ||
'func-call-spacing', | ||
'function-paren-newline', | ||
'generator-star-spacing', | ||
'implicit-arrow-linebreak', | ||
'indent', | ||
'key-spacing', | ||
'keyword-spacing', | ||
'line-comment-position', | ||
'linebreak-style', | ||
'multiline-ternary', | ||
'newline-per-chained-call', | ||
'no-irregular-whitespace', | ||
'no-mixed-spaces-and-tabs', | ||
'no-multi-spaces', | ||
'no-regex-spaces', | ||
'no-spaced-func', | ||
'no-trailing-spaces', | ||
'no-whitespace-before-property', | ||
'nonblock-statement-body-position', | ||
'object-curly-newline', | ||
'object-curly-spacing', | ||
'object-property-newline', | ||
'one-var-declaration-per-line', | ||
'operator-linebreak', | ||
'padded-blocks', | ||
'padding-line-between-statements', | ||
'rest-spread-spacing', | ||
'semi-spacing', | ||
'semi-style', | ||
'space-before-blocks', | ||
'space-before-function-paren', | ||
'space-in-parens', | ||
'space-infix-ops', | ||
'space-unary-ops', | ||
'spaced-comment', | ||
'switch-colon-spacing', | ||
'template-tag-spacing', | ||
'import/newline-after-import', | ||
// eslint-plugin-react rules | ||
'react/jsx-child-element-spacing', | ||
'react/jsx-closing-bracket-location', | ||
'react/jsx-closing-tag-location', | ||
'react/jsx-curly-spacing', | ||
'react/jsx-equals-spacing', | ||
'react/jsx-first-prop-newline', | ||
'react/jsx-indent', | ||
'react/jsx-indent-props', | ||
'react/jsx-max-props-per-line', | ||
'react/jsx-one-expression-per-line', | ||
'react/jsx-space-before-closing', | ||
'react/jsx-tag-spacing', | ||
'react/jsx-wrap-multilines', | ||
], baseConfig); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This object spread property in nodejs is introduced at version 8+. If this file is meant to be run with nodejs 8+, then we don't need to depend on more lib e.g.
object.entries
,Object.entries
already exists there.I can make a PR to clean this. What do you think, @ljharb?
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.
Even if we convert this file to be compatible with nodejs 4 which is declared in package.json, we still don't need this extra dependency, since eslint already depends on lodash, then we can add it too and use _.forEach.
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.
Whoops, this should use
object.assign
instead of spread.There’s no cost to an extra dev dep, and I’d prefer not to use lodash.
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.
I see, then we need to change array destructuring at line 10 too.
I'll make a PR, ok?
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.
Sure.