You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.6 KiB
53 lines
1.6 KiB
8 years ago
|
const merge = require('deepmerge');
|
||
|
const clone = require('lodash.clonedeep');
|
||
|
const { join } = require('path');
|
||
|
|
||
|
const IF_NOT_DEV = process.env.NODE_ENV !== 'development';
|
||
|
const MODULES = join(__dirname, 'node_modules');
|
||
|
|
||
|
module.exports = options => (config, neutrino) => {
|
||
|
config.resolve.modules.add(MODULES);
|
||
|
config.resolveLoader.modules.add(MODULES);
|
||
|
config.module
|
||
|
.rule('lint')
|
||
|
.test(options.test || /\.(js|jsx)$/)
|
||
|
.pre()
|
||
|
.include(options.include)
|
||
|
.loader('eslint', require.resolve('eslint-loader'), merge({
|
||
|
failOnError: IF_NOT_DEV,
|
||
|
emitWarning: IF_NOT_DEV,
|
||
|
emitError: IF_NOT_DEV,
|
||
|
cwd: process.cwd(),
|
||
|
useEslintrc: false,
|
||
|
root: true,
|
||
|
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 || {}));
|
||
|
|
||
|
neutrino.eslintrc = () => {
|
||
|
const options = clone(config.module.rule('lint').loaders.get('eslint').options);
|
||
|
|
||
|
options.extends = options.baseConfig.extends;
|
||
|
options.useEslintrc = true;
|
||
|
options.env = options.envs.reduce((env, key) => Object.assign(env, { [key]: true }), {});
|
||
|
options.globals = options.globals.reduce((globals, key) => Object.assign(globals, { [key]: true }), {});
|
||
|
['envs', 'baseConfig', 'failOnError', 'emitWarning', 'emitError'].map(method => delete options[method]);
|
||
|
|
||
|
return options;
|
||
|
};
|
||
|
};
|