Browse Source

Add custom method for generating an eslintrc config (#63)

v5.0.0-beta
Eli Perelman 8 years ago
committed by GitHub
parent
commit
68606b43e6
  1. 21
      docs/presets/neutrino-lint-base/README.md
  2. 21
      docs/presets/neutrino-preset-airbnb-base/README.md
  3. 3
      packages/neutrino-lint-base/package.json
  4. 17
      packages/neutrino-lint-base/src/index.js
  5. 4
      packages/neutrino-lint-base/yarn.lock

21
docs/presets/neutrino-lint-base/README.md

@ -164,6 +164,27 @@ that clearly in your preset.
For specifics on what options are configured when using this linting base, please
[view the source](https://github.com/mozilla-neutrino/neutrino-dev/blob/master/packages/neutrino-lint-base/src/index.js).
## eslintrc Config
`neutrino-lint-base` also provides a method for getting the ESLint configuration suitable for use in an eslintrc file.
Typically this is used for providing hints or fix solutions to the development environment, e.g. IDEs and text editors.
Doing this requires [creating an instance of the Neutrino API](/api/README.md) and providing the presets uses. If you
keep this information in `config.presets` in package.json, this should be relatively straightforward. By providing
all the presets used to Neutrino, you can ensure all the linting options used across all those preset will be merged
together for your development environment, without the need for copying, duplication, or loss of organization and
separation.
_Example: Create a .eslintrc.js file in the root of the project._
```js
// .eslintrc.js
const Neutrino = require('neutrino');
const pkg = require('./package.json');
const api = new Neutrino(pkg.config.presets);
module.exports = api.custom.eslintrc();
```
---
## Contributing

21
docs/presets/neutrino-preset-airbnb-base/README.md

@ -199,6 +199,27 @@ module.exports = neutrino => {
};
```
## eslintrc Config
`neutrino-lint-airbnb-base` also provides a method for getting the ESLint configuration suitable for use in an eslintrc
file. Typically this is used for providing hints or fix solutions to the development environment, e.g. IDEs and text
editors. Doing this requires [creating an instance of the Neutrino API](/api/README.md) and providing the presets uses.
If you keep this information in `config.presets` in package.json, this should be relatively straightforward. By
providing all the presets used to Neutrino, you can ensure all the linting options used across all those preset will be
merged together for your development environment, without the need for copying, duplication, or loss of organization and
separation.
_Example: Create a .eslintrc.js file in the root of the project._
```js
// .eslintrc.js
const Neutrino = require('neutrino');
const pkg = require('./package.json');
const api = new Neutrino(pkg.config.presets);
module.exports = api.custom.eslintrc();
```
## Contributing
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo

3
packages/neutrino-lint-base/package.json

@ -16,7 +16,8 @@
"eslint": "^3.16.1",
"eslint-loader": "^1.6.1",
"eslint-plugin-babel": "^4.0.1",
"eslint-plugin-import": "^2.2.0"
"eslint-plugin-import": "^2.2.0",
"lodash.clonedeep": "^4.5.0"
},
"peerDependencies": {
"neutrino": "^4.0.0"

17
packages/neutrino-lint-base/src/index.js

@ -1,9 +1,12 @@
const clone = require('lodash.clonedeep');
const path = require('path');
const MODULES = path.join(__dirname, '../node_modules');
const IF_NOT_DEV = process.env.NODE_ENV !== 'development';
module.exports = ({ config }) => {
module.exports = neutrino => {
const { config } = neutrino;
config
.module
.rule('lint')
@ -37,4 +40,16 @@ module.exports = ({ config }) => {
config.resolve.modules.add(MODULES);
config.resolveLoader.modules.add(MODULES);
neutrino.custom.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(env, { [key]: true }, {}));
['envs', 'baseConfig', 'failOnError', 'emitWarning', 'emitError'].map(method => delete options[method]);
return options;
};
};

4
packages/neutrino-lint-base/yarn.lock

@ -685,6 +685,10 @@ loader-utils@^1.0.2:
emojis-list "^2.0.0"
json5 "^0.5.0"
lodash.clonedeep@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
lodash.cond@^4.3.0:
version "4.5.2"
resolved "https://registry.yarnpkg.com/lodash.cond/-/lodash.cond-4.5.2.tgz#f471a1da486be60f6ab955d17115523dd1d255d5"

Loading…
Cancel
Save