Skip to content

Commit 8e6363c

Browse files
authored
[eslint config] [*] [new] add whitespace entry point
Adds eslint config extends with only whitespace rules enabled Merge pull request airbnb#1749 from airbnb/whitespace-rules
2 parents c82500d + 6373dab commit 8e6363c

File tree

6 files changed

+172
-2
lines changed

6 files changed

+172
-2
lines changed

packages/eslint-config-airbnb-base/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ Lints ES5 and below. Requires `eslint` and `eslint-plugin-import`.
8484

8585
See [Airbnb's overarching ESLint config](https://npmjs.com/eslint-config-airbnb), [Airbnb's Javascript styleguide](https://github.com/airbnb/javascript), and the [ESlint config docs](https://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information.
8686

87+
### eslint-config-airbnb-base/whitespace
88+
89+
This entry point that only warns on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/whitespace.js).
90+
8791
## Improving this config
8892

8993
Consider adding test cases if you're making complicated rules changes, like anything involving regexes. Perhaps in a distant future, we could use literate programming to structure our README as test cases for our .eslintrc?

packages/eslint-config-airbnb-base/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"node": ">= 4"
6767
},
6868
"dependencies": {
69-
"eslint-restricted-globals": "^0.1.1"
69+
"eslint-restricted-globals": "^0.1.1",
70+
"object.entries": "^1.0.4"
7071
}
7172
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const baseConfig = require('.');
2+
const entries = require('object.entries');
3+
const { CLIEngine } = require('eslint');
4+
5+
function onlyErrorOnRules(rulesToError, config) {
6+
const errorsOnly = { ...config };
7+
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false });
8+
const baseRules = cli.getConfigForFile('./').rules;
9+
10+
entries(baseRules).forEach(([key, value]) => {
11+
if (rulesToError.indexOf(key) === -1) {
12+
if (Array.isArray(value)) {
13+
errorsOnly.rules[key] = ['warn'].concat(value.slice(1));
14+
} else if (typeof value === 'number') {
15+
errorsOnly.rules[key] = 1;
16+
} else {
17+
errorsOnly.rules[key] = 'warn';
18+
}
19+
}
20+
});
21+
22+
return errorsOnly;
23+
}
24+
25+
module.exports = onlyErrorOnRules([
26+
'array-bracket-newline',
27+
'array-bracket-spacing',
28+
'array-element-newline',
29+
'arrow-spacing',
30+
'block-spacing',
31+
'comma-spacing',
32+
'computed-property-spacing',
33+
'dot-location',
34+
'eol-last',
35+
'func-call-spacing',
36+
'function-paren-newline',
37+
'generator-star-spacing',
38+
'implicit-arrow-linebreak',
39+
'indent',
40+
'key-spacing',
41+
'keyword-spacing',
42+
'line-comment-position',
43+
'linebreak-style',
44+
'multiline-ternary',
45+
'newline-per-chained-call',
46+
'no-irregular-whitespace',
47+
'no-mixed-spaces-and-tabs',
48+
'no-multi-spaces',
49+
'no-regex-spaces',
50+
'no-spaced-func',
51+
'no-trailing-spaces',
52+
'no-whitespace-before-property',
53+
'nonblock-statement-body-position',
54+
'object-curly-newline',
55+
'object-curly-spacing',
56+
'object-property-newline',
57+
'one-var-declaration-per-line',
58+
'operator-linebreak',
59+
'padded-blocks',
60+
'padding-line-between-statements',
61+
'rest-spread-spacing',
62+
'semi-spacing',
63+
'semi-style',
64+
'space-before-blocks',
65+
'space-before-function-paren',
66+
'space-in-parens',
67+
'space-infix-ops',
68+
'space-unary-ops',
69+
'spaced-comment',
70+
'switch-colon-spacing',
71+
'template-tag-spacing',
72+
'import/newline-after-import',
73+
], baseConfig);

packages/eslint-config-airbnb/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ If you use yarn, run `npm info "eslint-config-airbnb@latest" peerDependencies` t
5555

5656
2. Add `"extends": "airbnb"` to your .eslintrc
5757

58+
### eslint-config-airbnb/whitespace
59+
60+
This entry point that only warns on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/whitespace.js).
61+
5862
### eslint-config-airbnb/base
5963

6064
This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).

packages/eslint-config-airbnb/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
},
4949
"homepage": "https://github.com/airbnb/javascript",
5050
"dependencies": {
51-
"eslint-config-airbnb-base": "^12.1.0"
51+
"eslint-config-airbnb-base": "^12.1.0",
52+
"object.entries": "^1.0.4"
5253
},
5354
"devDependencies": {
5455
"babel-preset-airbnb": "^2.4.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const baseConfig = require('.');
2+
const entries = require('object.entries');
3+
const { CLIEngine } = require('eslint');
4+
5+
function onlyErrorOnRules(rulesToError, config) {
6+
const errorsOnly = { ...config };
7+
const cli = new CLIEngine({ baseConfig: config, useEslintrc: false });
8+
const baseRules = cli.getConfigForFile('./').rules;
9+
10+
entries(baseRules).forEach(([key, value]) => {
11+
if (rulesToError.indexOf(key) === -1) {
12+
if (Array.isArray(value)) {
13+
errorsOnly.rules[key] = ['warn'].concat(value.slice(1));
14+
} else if (typeof value === 'number') {
15+
errorsOnly.rules[key] = 1;
16+
} else {
17+
errorsOnly.rules[key] = 'warn';
18+
}
19+
}
20+
});
21+
22+
return errorsOnly;
23+
}
24+
25+
module.exports = onlyErrorOnRules([
26+
'array-bracket-newline',
27+
'array-bracket-spacing',
28+
'array-element-newline',
29+
'arrow-spacing',
30+
'block-spacing',
31+
'comma-spacing',
32+
'computed-property-spacing',
33+
'dot-location',
34+
'eol-last',
35+
'func-call-spacing',
36+
'function-paren-newline',
37+
'generator-star-spacing',
38+
'implicit-arrow-linebreak',
39+
'indent',
40+
'key-spacing',
41+
'keyword-spacing',
42+
'line-comment-position',
43+
'linebreak-style',
44+
'multiline-ternary',
45+
'newline-per-chained-call',
46+
'no-irregular-whitespace',
47+
'no-mixed-spaces-and-tabs',
48+
'no-multi-spaces',
49+
'no-regex-spaces',
50+
'no-spaced-func',
51+
'no-trailing-spaces',
52+
'no-whitespace-before-property',
53+
'nonblock-statement-body-position',
54+
'object-curly-newline',
55+
'object-curly-spacing',
56+
'object-property-newline',
57+
'one-var-declaration-per-line',
58+
'operator-linebreak',
59+
'padded-blocks',
60+
'padding-line-between-statements',
61+
'rest-spread-spacing',
62+
'semi-spacing',
63+
'semi-style',
64+
'space-before-blocks',
65+
'space-before-function-paren',
66+
'space-in-parens',
67+
'space-infix-ops',
68+
'space-unary-ops',
69+
'spaced-comment',
70+
'switch-colon-spacing',
71+
'template-tag-spacing',
72+
'import/newline-after-import',
73+
// eslint-plugin-react rules
74+
'react/jsx-child-element-spacing',
75+
'react/jsx-closing-bracket-location',
76+
'react/jsx-closing-tag-location',
77+
'react/jsx-curly-spacing',
78+
'react/jsx-equals-spacing',
79+
'react/jsx-first-prop-newline',
80+
'react/jsx-indent',
81+
'react/jsx-indent-props',
82+
'react/jsx-max-props-per-line',
83+
'react/jsx-one-expression-per-line',
84+
'react/jsx-space-before-closing',
85+
'react/jsx-tag-spacing',
86+
'react/jsx-wrap-multilines',
87+
], baseConfig);

0 commit comments

Comments
 (0)