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