diff --git a/.neutrinorc.js b/.neutrinorc.js index 90b8b570b..55115a94b 100644 --- a/.neutrinorc.js +++ b/.neutrinorc.js @@ -8,7 +8,6 @@ module.exports = { 'packages/neutrino/bin/*' ], eslint: { - node: true, envs: ['browser', 'commonjs', 'node'], plugins: ['eslint-plugin-prettier'], rules: { diff --git a/.travis.yml b/.travis.yml index 9d954ea72..6962c4dab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,5 +19,6 @@ install: before_script: - yarn bootstrap --frozen-lockfile script: +- yarn validate:eslintrc - yarn lint - yarn test diff --git a/package.json b/package.json index 3443ef3b6..1bf24f7b9 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,10 @@ "bugs": "https://github.com/mozilla-neutrino/neutrino-dev/issues", "repository": "mozilla-neutrino/neutrino-dev", "scripts": { + "validate:eslintrc:root": "eslint --no-eslintrc --print-config . -c ./.eslintrc.js > /dev/null", + "validate:eslintrc:eslint": "eslint --no-eslintrc --print-config . -c ./packages/neutrino-middleware-eslint/eslintrc.js > /dev/null", + "validate:eslintrc:airbnb-base": "eslint --no-eslintrc --print-config . -c ./packages/neutrino-preset-airbnb-base/eslintrc.js > /dev/null", + "validate:eslintrc": "yarn validate:eslintrc:eslint && yarn validate:eslintrc:airbnb-base && yarn validate:eslintrc:root", "lint": "node packages/neutrino/bin/neutrino lint", "bootstrap": "oao bootstrap --no-parallel", "changelog": "changelog mozilla-neutrino/neutrino-dev all --markdown > CHANGELOG.md", @@ -51,7 +55,11 @@ }, "lint-staged": { "*.js": [ - "packages/neutrino/bin/neutrino lint --fix", + "yarn lint --fix", + "git add" + ], + "packages/neutrino/bin/neutrino": [ + "yarn lint --fix", "git add" ] } diff --git a/packages/neutrino-middleware-eslint/eslintrc.js b/packages/neutrino-middleware-eslint/eslintrc.js new file mode 100644 index 000000000..64afc11f7 --- /dev/null +++ b/packages/neutrino-middleware-eslint/eslintrc.js @@ -0,0 +1,6 @@ +const { Neutrino } = require('../neutrino'); + +const api = Neutrino({ cwd: __dirname }); + +// eslint-disable-next-line global-require +module.exports = api.call('eslintrc', [require('.')]); diff --git a/packages/neutrino-middleware-eslint/index.js b/packages/neutrino-middleware-eslint/index.js index f3e925171..dfc257c43 100644 --- a/packages/neutrino-middleware-eslint/index.js +++ b/packages/neutrino-middleware-eslint/index.js @@ -15,8 +15,13 @@ const reduceToTrueKeys = reduce((acc, key) => assoc(key, true, acc), {}); const getEslintRcConfig = pipe( getEslintOptions, clone, - assoc('useEslintrc', true), - omit(['failOnError', 'emitWarning', 'emitError']), + // We remove these keys since they are needed when running the lint command but + // not the eslintrc command. The lint command uses ESLint's CLIEngine, but the + // ESLint RC format does not match the CLIEngine format exactly. We must remove + // anything we add that does not comply with ESLint's schemas. + // https://github.com/eslint/eslint/blob/9d1df92628dd4dd1e70fbb19454008e146387435/conf/config-schema.js + // https://github.com/eslint/eslint/blob/9d1df92628dd4dd1e70fbb19454008e146387435/lib/config/config-validator.js#L167 + omit(['failOnError', 'emitWarning', 'emitError', 'cwd', 'useEslintrc', 'fix', 'extensions']), renameKeys({ envs: 'env', baseConfig: 'extends' }), evolve({ extends: prop('extends'), diff --git a/packages/neutrino-preset-airbnb-base/eslintrc.js b/packages/neutrino-preset-airbnb-base/eslintrc.js new file mode 100644 index 000000000..64afc11f7 --- /dev/null +++ b/packages/neutrino-preset-airbnb-base/eslintrc.js @@ -0,0 +1,6 @@ +const { Neutrino } = require('../neutrino'); + +const api = Neutrino({ cwd: __dirname }); + +// eslint-disable-next-line global-require +module.exports = api.call('eslintrc', [require('.')]);