Skip to content

Commit

Permalink
[eslint config] [base] [refactor] make a single source of truth for w…
Browse files Browse the repository at this point in the history
…hitespace rule names
  • Loading branch information
ljharb committed Nov 22, 2021
1 parent 91cab81 commit 31c6f21
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 98 deletions.
51 changes: 2 additions & 49 deletions packages/eslint-config-airbnb-base/whitespace-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const entries = require('object.entries');
const { ESLint } = require('eslint');

const baseConfig = require('.');
const whitespaceRules = require('./whitespaceRules');

const severities = ['off', 'warn', 'error'];

Expand Down Expand Up @@ -45,52 +46,4 @@ async function onlyErrorOnRules(rulesToError, config) {
return errorsOnly;
}

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).then((config) => console.log(JSON.stringify(config)));
onlyErrorOnRules(whitespaceRules, baseConfig).then((config) => console.log(JSON.stringify(config)));
51 changes: 2 additions & 49 deletions packages/eslint-config-airbnb-base/whitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (CLIEngine) {
/* eslint no-inner-declarations: 0 */
const assign = require('object.assign');
const entries = require('object.entries');
const whitespaceRules = require('./whitespaceRules');

const baseConfig = require('.');

Expand Down Expand Up @@ -45,55 +46,7 @@ if (CLIEngine) {
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);
module.exports = onlyErrorOnRules(whitespaceRules, baseConfig);
} else {
const path = require('path');
const { execSync } = require('child_process');
Expand Down
49 changes: 49 additions & 0 deletions packages/eslint-config-airbnb-base/whitespaceRules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = [
'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'
];

0 comments on commit 31c6f21

Please sign in to comment.