diff --git a/packages/airbnb-base/index.js b/packages/airbnb-base/index.js index 228daea4a..448828bc0 100644 --- a/packages/airbnb-base/index.js +++ b/packages/airbnb-base/index.js @@ -1,25 +1,22 @@ const lint = require('@neutrinojs/eslint'); -const merge = require('deepmerge'); module.exports = (neutrino, opts = {}) => { - neutrino.use(lint, merge.all([ - { - eslint: { - baseConfig: { - extends: ['airbnb-base'] - }, - rules: { - // handled by babel rules - 'new-cap': 'off', - // handled by babel rules - 'object-curly-spacing': 'off', - // require a capital letter for constructors - 'babel/new-cap': ['error', { newIsCap: true }], - // require padding inside curly braces - 'babel/object-curly-spacing': ['error', 'always'] - } + neutrino.use(lint, lint.merge({ + eslint: { + baseConfig: { + extends: ['airbnb-base'] + }, + rules: { + // handled by babel rules + 'new-cap': 'off', + // handled by babel rules + 'object-curly-spacing': 'off', + // require a capital letter for constructors + 'babel/new-cap': ['error', { newIsCap: true }], + // require padding inside curly braces + 'babel/object-curly-spacing': ['error', 'always'] } - }, - opts - ])); + } + }, + opts)); }; diff --git a/packages/airbnb-base/package.json b/packages/airbnb-base/package.json index 4d7434be0..35d163937 100644 --- a/packages/airbnb-base/package.json +++ b/packages/airbnb-base/package.json @@ -24,7 +24,6 @@ }, "dependencies": { "@neutrinojs/eslint": "^8.0.18", - "deepmerge": "^1.5.2", "eslint-config-airbnb-base": "^12.0.1", "eslint-plugin-import": "^2.7.0" }, diff --git a/packages/airbnb/index.js b/packages/airbnb/index.js index ac71f8039..931953086 100644 --- a/packages/airbnb/index.js +++ b/packages/airbnb/index.js @@ -1,25 +1,22 @@ const lint = require('@neutrinojs/eslint'); -const merge = require('deepmerge'); module.exports = (neutrino, opts = {}) => { - neutrino.use(lint, merge.all([ - { - eslint: { - baseConfig: { - extends: ['airbnb'] - }, - rules: { - // handled by babel rules - 'new-cap': 'off', - // handled by babel rules - 'object-curly-spacing': 'off', - // require a capital letter for constructors - 'babel/new-cap': ['error', { newIsCap: true }], - // require padding inside curly braces - 'babel/object-curly-spacing': ['error', 'always'] - } + neutrino.use(lint, lint.merge({ + eslint: { + baseConfig: { + extends: ['airbnb'] + }, + rules: { + // handled by babel rules + 'new-cap': 'off', + // handled by babel rules + 'object-curly-spacing': 'off', + // require a capital letter for constructors + 'babel/new-cap': ['error', { newIsCap: true }], + // require padding inside curly braces + 'babel/object-curly-spacing': ['error', 'always'] } - }, - opts - ])); + } + }, + opts)); }; diff --git a/packages/airbnb/package.json b/packages/airbnb/package.json index 82e297b31..d26366cc2 100644 --- a/packages/airbnb/package.json +++ b/packages/airbnb/package.json @@ -24,7 +24,6 @@ }, "dependencies": { "@neutrinojs/eslint": "^8.0.18", - "deepmerge": "^1.5.2", "eslint-config-airbnb": "^16.1.0", "eslint-plugin-import": "^2.7.0", "eslint-plugin-jsx-a11y": "^6.0.2" diff --git a/packages/eslint/index.js b/packages/eslint/index.js index 9b62b6924..127e7223f 100644 --- a/packages/eslint/index.js +++ b/packages/eslint/index.js @@ -1,10 +1,9 @@ const Future = require('fluture'); -const merge = require('deepmerge'); +const deepmerge = require('deepmerge'); const clone = require('lodash.clonedeep'); const { CLIEngine } = require('eslint'); -const codeframe = require('eslint/lib/formatters/codeframe'); const { - assoc, curry, evolve, keys, omit, pipe, prop, reduce + assoc, curry, evolve, keys, omit, pathOr, pipe, prop, reduce } = require('ramda'); const { basename, join } = require('path'); @@ -40,11 +39,52 @@ const getEslintRcConfig = pipe( }) ); +const merge = (source, destination) => { + const sourceRules = pathOr({}, ['eslint', 'rules'], source); + const destinationRules = pathOr({}, ['eslint', 'rules'], destination); + const rules = deepmerge(sourceRules, destinationRules, { + arrayMerge(source, destination) { + return destination; + } + }); + const options = deepmerge(source, destination); + + Object.assign(options.eslint, { rules }); + + return options; +}; + module.exports = (neutrino, opts = {}) => { - const options = merge.all([ - opts, - !opts.include ? { include: [neutrino.options.source] } : {} - ]); + const defaults = { + include: !opts.include ? [neutrino.options.source] : undefined, + eslint: { + failOnError: neutrino.options.command !== 'start', + cwd: neutrino.options.root, + useEslintrc: false, + root: true, + formatter: 'codeframe', + // eslint-loader uses executeOnText(), which ignores the `extensions` setting. + // However it's still needed for the lint command, as it uses executeOnFiles(). + extensions: neutrino.options.extensions, + plugins: ['babel'], + baseConfig: {}, + envs: ['es6'], + parser: 'babel-eslint', + parserOptions: { + ecmaVersion: 2017, + sourceType: 'module', + ecmaFeatures: { + objectLiteralDuplicateProperties: false, + generators: true, + impliedStrict: true + } + }, + settings: {}, + globals: ['process'], + rules: {} + } + }; + const options = merge(defaults, opts); neutrino.config .resolve @@ -65,32 +105,7 @@ module.exports = (neutrino, opts = {}) => { .when(options.exclude, rule => rule.exclude.merge(options.exclude)) .use('eslint') .loader(require.resolve('eslint-loader')) - .options(merge({ - failOnError: neutrino.options.command !== 'start', - cwd: neutrino.options.root, - useEslintrc: false, - root: true, - formatter: codeframe, - // eslint-loader uses executeOnText(), which ignores the `extensions` setting. - // However it's still needed for the lint command, as it uses executeOnFiles(). - extensions: neutrino.options.extensions, - plugins: ['babel'], - baseConfig: {}, - envs: ['es6'], - parser: 'babel-eslint', - parserOptions: { - ecmaVersion: 2017, - sourceType: 'module', - ecmaFeatures: { - objectLiteralDuplicateProperties: false, - generators: true, - impliedStrict: true - } - }, - settings: {}, - globals: ['process'], - rules: {} - }, options.eslint || {})); + .options(options.eslint); neutrino.register( 'eslintrc', @@ -108,14 +123,14 @@ module.exports = (neutrino, opts = {}) => { basename(exclude), '**/*' )); - const eslintConfig = merge(getEslintOptions(neutrino.config), { ignorePattern, fix }); + const eslintConfig = deepmerge(getEslintOptions(neutrino.config), { ignorePattern, fix }); return Future .of(eslintConfig) .map(options => new CLIEngine(options)) .chain(cli => Future.both( Future.of(cli.executeOnFiles(options.include)), - Future.of(cli.getFormatter('codeframe')) + Future.of(cli.getFormatter(options.eslint.formatter)) )) .map(([report, formatter]) => { if (fix) { @@ -134,3 +149,5 @@ module.exports = (neutrino, opts = {}) => { 'Perform a one-time lint using ESLint. Apply available automatic fixes with --fix' ); }; + +module.exports.merge = merge; diff --git a/packages/standardjs/index.js b/packages/standardjs/index.js index dd15a0737..1ed3eecd4 100644 --- a/packages/standardjs/index.js +++ b/packages/standardjs/index.js @@ -1,26 +1,23 @@ const lint = require('@neutrinojs/eslint'); -const merge = require('deepmerge'); module.exports = (neutrino, opts = {}) => { - neutrino.use(lint, merge.all([ - { - eslint: { - baseConfig: { - extends: ['standard', 'standard-jsx'] - }, - plugins: ['standard'], - rules: { - // handled by babel rules - 'new-cap': 'off', - // handled by babel rules - 'object-curly-spacing': 'off', - // require a capital letter for constructors - 'babel/new-cap': ['error', { newIsCap: true }], - // require padding inside curly braces - 'babel/object-curly-spacing': ['error', 'always'] - } + neutrino.use(lint, lint.merge({ + eslint: { + baseConfig: { + extends: ['standard', 'standard-jsx'] + }, + plugins: ['standard'], + rules: { + // handled by babel rules + 'new-cap': 'off', + // handled by babel rules + 'object-curly-spacing': 'off', + // require a capital letter for constructors + 'babel/new-cap': ['error', { newIsCap: true }], + // require padding inside curly braces + 'babel/object-curly-spacing': ['error', 'always'] } - }, - opts - ])); + } + }, + opts)); }; diff --git a/packages/standardjs/package.json b/packages/standardjs/package.json index 4692f0b10..71b58d171 100644 --- a/packages/standardjs/package.json +++ b/packages/standardjs/package.json @@ -25,7 +25,6 @@ }, "dependencies": { "@neutrinojs/eslint": "^8.0.18", - "deepmerge": "^1.5.2", "eslint-config-standard": "^10.2.1", "eslint-config-standard-jsx": "^4.0.2", "eslint-plugin-import": "^2.8.0",