This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eslint: Refactor eslint-loader and eslintrc config generation (#1182)
* Adds option validation to `@neutrinojs/eslint`, so that it now throws when passed options that are not supported by eslint-loader. * The eslintrc conversion now correctly handles all supported options under `baseConfig` rather than silently ignoring some of them. * The eslintrc conversion no longer looks for settings in locations that are invalid for eslint-loader (such as top-level `settings`, `extends`, `root` or `overrides` options). * The eslintrc conversion now no longer errors if passed options that were previously missing from the `omit()` list, such as `ignore` and `reportUnusedDisableDirectives`. * The custom lint `merge()` function has been replaced with ESLint's own merging function, which correctly handles several cases that were broken before. * All non-loader related configuration has now been moved under the `baseConfig` key, since the options under it more closely relate to the options that users will have previously seen in `.eslintrc` files, thereby reducing user-confusion and making it possible to copy and paste the contents of the `baseConfig` section to a static `.eslintrc.*`. * Support has been added for projects that want to use their own non-generated `.eslintrc.*` file. They now only need to set `useEslintrc` to `true`, which will make the linting presets only set the loader-related options, preventing conflicts with the options set in their static `.eslintrc.*` file. * The `@neutrinojs/loader-merge` middleware has been removed, since its functionality was not sufficient for merging lint configuration correctly, and was not used for any other purpose. Fixes #1181. Fixes #382.
- Loading branch information
Showing
47 changed files
with
1,599 additions
and
682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
const lint = require('@neutrinojs/eslint'); | ||
const { merge: eslintMerge } = require('eslint/lib/config/config-ops'); | ||
const { rules: airbnbBaseStyle } = require('eslint-config-airbnb-base/rules/style'); | ||
const { rules: airbnbBaseBestPractices } = require('eslint-config-airbnb-base/rules/best-practices'); | ||
|
||
module.exports = (neutrino, opts = {}) => { | ||
neutrino.use(lint, lint.merge({ | ||
module.exports = (neutrino, { eslint = {}, ...opts } = {}) => { | ||
neutrino.use(lint, { | ||
...opts, | ||
eslint: { | ||
baseConfig: { | ||
extends: [require.resolve('eslint-config-airbnb-base')] | ||
}, | ||
rules: { | ||
// Disable rules for which there are eslint-plugin-babel replacements: | ||
// https://github.com/babel/eslint-plugin-babel#rules | ||
'new-cap': 'off', | ||
'no-invalid-this': 'off', | ||
'object-curly-spacing': 'off', | ||
'semi': 'off', | ||
'no-unused-expressions': 'off', | ||
// Ensure the replacement rules use the options set by airbnb-base rather than ESLint defaults. | ||
'babel/new-cap': airbnbBaseStyle['new-cap'], | ||
'babel/no-invalid-this': airbnbBaseBestPractices['no-invalid-this'], | ||
'babel/object-curly-spacing': airbnbBaseStyle['object-curly-spacing'], | ||
'babel/semi': airbnbBaseStyle.semi, | ||
'babel/no-unused-expressions': airbnbBaseBestPractices['no-unused-expressions'] | ||
} | ||
...eslint, | ||
baseConfig: eslintMerge( | ||
{ | ||
extends: [require.resolve('eslint-config-airbnb-base')], | ||
rules: { | ||
// Disable rules for which there are eslint-plugin-babel replacements: | ||
// https://github.com/babel/eslint-plugin-babel#rules | ||
'new-cap': 'off', | ||
'no-invalid-this': 'off', | ||
'object-curly-spacing': 'off', | ||
'semi': 'off', | ||
'no-unused-expressions': 'off', | ||
// Ensure the replacement rules use the options set by airbnb-base rather than ESLint defaults. | ||
'babel/new-cap': airbnbBaseStyle['new-cap'], | ||
'babel/no-invalid-this': airbnbBaseBestPractices['no-invalid-this'], | ||
'babel/object-curly-spacing': airbnbBaseStyle['object-curly-spacing'], | ||
'babel/semi': airbnbBaseStyle.semi, | ||
'babel/no-unused-expressions': airbnbBaseBestPractices['no-unused-expressions'] | ||
} | ||
}, | ||
eslint.baseConfig || {} | ||
) | ||
} | ||
}, | ||
opts)); | ||
}); | ||
}; |
Oops, something went wrong.