Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Correctly merge eslint rules, fix hardcoded formatter #694

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions packages/airbnb-base/index.js
Original file line number Diff line number Diff line change
@@ -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));
};
1 change: 0 additions & 1 deletion packages/airbnb-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
37 changes: 17 additions & 20 deletions packages/airbnb/index.js
Original file line number Diff line number Diff line change
@@ -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));
};
1 change: 0 additions & 1 deletion packages/airbnb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
87 changes: 52 additions & 35 deletions packages/eslint/index.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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) {
Expand All @@ -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;
39 changes: 18 additions & 21 deletions packages/standardjs/index.js
Original file line number Diff line number Diff line change
@@ -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));
};
1 change: 0 additions & 1 deletion packages/standardjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down