|
1 | | -const assign = require('object.assign'); |
2 | | -const entries = require('object.entries'); |
| 1 | +/* eslint global-require: 0 */ |
| 2 | + |
3 | 3 | const { CLIEngine } = require('eslint'); |
4 | 4 |
|
5 | | -const baseConfig = require('.'); |
| 5 | +if (CLIEngine) { |
| 6 | + /* eslint no-inner-declarations: 0 */ |
| 7 | + const assign = require('object.assign'); |
| 8 | + const entries = require('object.entries'); |
| 9 | + const whitespaceRules = require('./whitespaceRules'); |
6 | 10 |
|
7 | | -const severities = ['off', 'warn', 'error']; |
| 11 | + const baseConfig = require('.'); |
8 | 12 |
|
9 | | -function getSeverity(ruleConfig) { |
10 | | - if (Array.isArray(ruleConfig)) { |
11 | | - return getSeverity(ruleConfig[0]); |
12 | | - } |
13 | | - if (typeof ruleConfig === 'number') { |
14 | | - return severities[ruleConfig]; |
| 13 | + const severities = ['off', 'warn', 'error']; |
| 14 | + |
| 15 | + function getSeverity(ruleConfig) { |
| 16 | + if (Array.isArray(ruleConfig)) { |
| 17 | + return getSeverity(ruleConfig[0]); |
| 18 | + } |
| 19 | + if (typeof ruleConfig === 'number') { |
| 20 | + return severities[ruleConfig]; |
| 21 | + } |
| 22 | + return ruleConfig; |
15 | 23 | } |
16 | | - return ruleConfig; |
17 | | -} |
18 | 24 |
|
19 | | -function onlyErrorOnRules(rulesToError, config) { |
20 | | - const errorsOnly = assign({}, config); |
21 | | - const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); |
22 | | - const baseRules = cli.getConfigForFile(require.resolve('./')).rules; |
| 25 | + function onlyErrorOnRules(rulesToError, config) { |
| 26 | + const errorsOnly = assign({}, config); |
| 27 | + const cli = new CLIEngine({ baseConfig: config, useEslintrc: false }); |
| 28 | + const baseRules = cli.getConfigForFile(require.resolve('./')).rules; |
| 29 | + |
| 30 | + entries(baseRules).forEach((rule) => { |
| 31 | + const ruleName = rule[0]; |
| 32 | + const ruleConfig = rule[1]; |
| 33 | + const severity = getSeverity(ruleConfig); |
| 34 | + |
| 35 | + if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') { |
| 36 | + if (Array.isArray(ruleConfig)) { |
| 37 | + errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1)); |
| 38 | + } else if (typeof ruleConfig === 'number') { |
| 39 | + errorsOnly.rules[ruleName] = 1; |
| 40 | + } else { |
| 41 | + errorsOnly.rules[ruleName] = 'warn'; |
| 42 | + } |
| 43 | + } |
| 44 | + }); |
23 | 45 |
|
24 | | - entries(baseRules).forEach((rule) => { |
25 | | - const ruleName = rule[0]; |
26 | | - const ruleConfig = rule[1]; |
27 | | - const severity = getSeverity(ruleConfig); |
| 46 | + return errorsOnly; |
| 47 | + } |
28 | 48 |
|
29 | | - if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') { |
30 | | - if (Array.isArray(ruleConfig)) { |
31 | | - errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1)); |
32 | | - } else if (typeof ruleConfig === 'number') { |
33 | | - errorsOnly.rules[ruleName] = 1; |
34 | | - } else { |
35 | | - errorsOnly.rules[ruleName] = 'warn'; |
36 | | - } |
37 | | - } |
38 | | - }); |
| 49 | + module.exports = onlyErrorOnRules(whitespaceRules, baseConfig); |
| 50 | +} else { |
| 51 | + const path = require('path'); |
| 52 | + const { execSync } = require('child_process'); |
39 | 53 |
|
40 | | - return errorsOnly; |
| 54 | + module.exports = JSON.parse(String(execSync(path.join(__dirname, 'whitespace-async.js')))); |
41 | 55 | } |
42 | | - |
43 | | -module.exports = onlyErrorOnRules([ |
44 | | - 'array-bracket-newline', |
45 | | - 'array-bracket-spacing', |
46 | | - 'array-element-newline', |
47 | | - 'arrow-spacing', |
48 | | - 'block-spacing', |
49 | | - 'comma-spacing', |
50 | | - 'computed-property-spacing', |
51 | | - 'dot-location', |
52 | | - 'eol-last', |
53 | | - 'func-call-spacing', |
54 | | - 'function-paren-newline', |
55 | | - 'generator-star-spacing', |
56 | | - 'implicit-arrow-linebreak', |
57 | | - 'indent', |
58 | | - 'key-spacing', |
59 | | - 'keyword-spacing', |
60 | | - 'line-comment-position', |
61 | | - 'linebreak-style', |
62 | | - 'multiline-ternary', |
63 | | - 'newline-per-chained-call', |
64 | | - 'no-irregular-whitespace', |
65 | | - 'no-mixed-spaces-and-tabs', |
66 | | - 'no-multi-spaces', |
67 | | - 'no-regex-spaces', |
68 | | - 'no-spaced-func', |
69 | | - 'no-trailing-spaces', |
70 | | - 'no-whitespace-before-property', |
71 | | - 'nonblock-statement-body-position', |
72 | | - 'object-curly-newline', |
73 | | - 'object-curly-spacing', |
74 | | - 'object-property-newline', |
75 | | - 'one-var-declaration-per-line', |
76 | | - 'operator-linebreak', |
77 | | - 'padded-blocks', |
78 | | - 'padding-line-between-statements', |
79 | | - 'rest-spread-spacing', |
80 | | - 'semi-spacing', |
81 | | - 'semi-style', |
82 | | - 'space-before-blocks', |
83 | | - 'space-before-function-paren', |
84 | | - 'space-in-parens', |
85 | | - 'space-infix-ops', |
86 | | - 'space-unary-ops', |
87 | | - 'spaced-comment', |
88 | | - 'switch-colon-spacing', |
89 | | - 'template-tag-spacing', |
90 | | - 'import/newline-after-import', |
91 | | - // eslint-plugin-react rules |
92 | | - 'react/jsx-child-element-spacing', |
93 | | - 'react/jsx-closing-bracket-location', |
94 | | - 'react/jsx-closing-tag-location', |
95 | | - 'react/jsx-curly-spacing', |
96 | | - 'react/jsx-equals-spacing', |
97 | | - 'react/jsx-first-prop-newline', |
98 | | - 'react/jsx-indent', |
99 | | - 'react/jsx-indent-props', |
100 | | - 'react/jsx-max-props-per-line', |
101 | | - 'react/jsx-one-expression-per-line', |
102 | | - 'react/jsx-space-before-closing', |
103 | | - 'react/jsx-tag-spacing', |
104 | | - 'react/jsx-wrap-multilines', |
105 | | -], baseConfig); |
0 commit comments