Skip to content

Commit 6048e77

Browse files
Adds eslint config extends with only whitespace rules enabled
Adds a change to pull in the eslint config from the project root, turn off all rules except the whitespace rules explicitly listed in the array.
1 parent c82500d commit 6048e77

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

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);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('../eslint-config-airbnb-base/whitespace');

0 commit comments

Comments
 (0)