committed by
GitHub
10 changed files with 1314 additions and 1075 deletions
@ -0,0 +1,179 @@ |
|||
# Neutrino Lint Base |
|||
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
|||
|
|||
`neutrino-lint-base` is an abstract Neutrino preset base that makes creating ESLint-based presets simpler. By creating |
|||
a linting preset that extends from `neutrino-lint-base`, the development overhead and dependencies needed can be |
|||
significantly reduced. Use it as a baseline to create your own linting presets easier and more quickly. |
|||
|
|||
## Features |
|||
|
|||
- Quickly and easily create your own Neutrino linting presets |
|||
- Modern Babel knowledge supporting ES modules, JSX (when used with React preset), Web and Node.js apps |
|||
- Highly visible during development, fails compilation when building for production |
|||
- Easily extensible to customize your project as needed |
|||
|
|||
## Development Requirements |
|||
|
|||
- Node.js v6.9+ |
|||
- Yarn or npm client |
|||
- Neutrino v4 |
|||
|
|||
## Installation |
|||
|
|||
`neutrino-lint-base` can be installed via the Yarn or npm clients. |
|||
|
|||
#### Yarn |
|||
|
|||
```bash |
|||
❯ yarn add neutrino-lint-base |
|||
``` |
|||
|
|||
#### npm |
|||
|
|||
```bash |
|||
❯ npm install --save neutrino-lint-base |
|||
``` |
|||
|
|||
Your project should also install any dependencies needed to operate based on options passed to `eslint-loader` or |
|||
ESLint's CLIEngine. |
|||
|
|||
## Project Layout |
|||
|
|||
`neutrino-lint-base` follows the standard [project layout](/project-layout.md) specified by Neutrino. This |
|||
means that by default all project source code should live in a directory named `src` in the root of the |
|||
project. The `.js` or `.jsx` files in this directory are the ones that will be linted by your preset. |
|||
|
|||
## Creating the preset |
|||
|
|||
Your preset will follow the same guidelines for normally creating Neutrino presets, with your preset extending |
|||
`neutrino-lint-base`. This starts out by having your package module export a function which accepts a Neutrino instance: |
|||
|
|||
```js |
|||
module.exports = neutrino => { |
|||
// ... |
|||
}; |
|||
``` |
|||
|
|||
The next step is to `require`, or `import` if your package supports it, `neutrino-lint-base` and execute it with |
|||
Neutrino. This will add the lint base's configuration to Neutrino for your preset to extend further: |
|||
|
|||
```js |
|||
const lint = require('neutrino-lint-base'); |
|||
|
|||
module.exports = neutrino => { |
|||
lint(neutrino); |
|||
// ... |
|||
}; |
|||
``` |
|||
|
|||
Now comes the core of your own preset. By extending from `neutrino-lint-base`'s "lint" rule and "eslint" loader, you |
|||
can manipulate the options as you desire. Consider using a package such as |
|||
[`deepmerge`](https://www.npmjs.com/package/deepmerge) to make extending these options easier: |
|||
|
|||
_Example: Create a preset that shuts off semicolons from being required by ESLint._ |
|||
|
|||
```js |
|||
const lint = require('neutrino-lint-base'); |
|||
const merge = require('deepmerge'); |
|||
|
|||
module.exports = neutrino => { |
|||
lint(neutrino); |
|||
neutrino.config |
|||
.rule('lint') |
|||
.loader('eslint', props => merge(props, { |
|||
options: { |
|||
rules: { |
|||
semi: 'off' |
|||
} |
|||
} |
|||
})); |
|||
}; |
|||
``` |
|||
|
|||
_Example: Create a preset that lints a project using the Airbnb base ESLint rules._ |
|||
|
|||
```js |
|||
const lint = require('neutrino-lint-base'); |
|||
const merge = require('deepmerge'); |
|||
|
|||
module.exports = neutrino => { |
|||
lint(neutrino); |
|||
neutrino.config |
|||
.rule('lint') |
|||
.loader('eslint', props => merge(props, { |
|||
options: { |
|||
baseConfig: { |
|||
extends: ['airbnb-base'] |
|||
} |
|||
} |
|||
})); |
|||
}; |
|||
``` |
|||
|
|||
Visit the [creating presets](/creating-presets.md) documentation for more detailed information on creating your own |
|||
custom preset. |
|||
|
|||
## Customization |
|||
|
|||
`neutrino-lint-base` creates some conventions to make overriding the configuration easier once you are ready to |
|||
make changes. |
|||
|
|||
### Rules |
|||
|
|||
The following is a list of rules and their identifiers which can be overridden: |
|||
|
|||
- `lint`: Lints JS and JSX files from the `src` directory using ESLint. Contains a single loader named `eslint`. |
|||
|
|||
## Information |
|||
|
|||
The lint base will show errors and warnings in the console during development, and will cause a failure when |
|||
creating a build bundle. |
|||
|
|||
--- |
|||
|
|||
If you want your preset to also extend from another ESLint configuration that you have made a dependency, you must use |
|||
`baseConfig.extends` rather than just `extends`. This is a limitation of ESLint, not this lint base. |
|||
|
|||
```js |
|||
const lint = require('neutrino-lint-base'); |
|||
const merge = require('deepmerge'); |
|||
|
|||
module.exports = neutrino => { |
|||
lint(neutrino); |
|||
neutrino.config |
|||
.rule('lint') |
|||
.loader('eslint', props => merge(props, { |
|||
options: { |
|||
baseConfig: { |
|||
extends: [ |
|||
'YOUR_ESLINT_CONFIGURATION_BASE_A', |
|||
'YOUR_ESLINT_CONFIGURATION_BASE_B' |
|||
] |
|||
} |
|||
} |
|||
})); |
|||
}; |
|||
``` |
|||
|
|||
--- |
|||
|
|||
The linting base only configures a target environment for `es6`, leaving other build presets free to add their own |
|||
target environments. If your preset puts restrictions on which environments it is capable of running, please document |
|||
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). |
|||
|
|||
--- |
|||
|
|||
## Contributing |
|||
|
|||
This preset is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo |
|||
containing all resources for developing Neutrino and its core presets. Follow the |
|||
[contributing guide](/contributing/README.md) for details. |
|||
|
|||
[npm-image]: https://img.shields.io/npm/v/neutrino-lint-base.svg |
|||
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-lint-base.svg |
|||
[npm-url]: https://npmjs.org/package/neutrino-lint-base |
|||
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
|||
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,17 @@ |
|||
# Neutrino Lint Base |
|||
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Join Slack][slack-image]][slack-url] |
|||
|
|||
`neutrino-lint-base` is an abstract Neutrino preset base that makes creating ESLint-based presets simpler. By creating |
|||
a linting preset that extends from `neutrino-lint-base`, the development overhead and dependencies needed can be |
|||
significantly reduced. Use it as a baseline to create your own linting presets easier and more quickly. |
|||
|
|||
## Documentation |
|||
|
|||
See the [Neutrino docs](https://neutrino.js.org/presets/neutrino-lint-base/) |
|||
for details on installation, getting started, usage, and customizing. |
|||
|
|||
[npm-image]: https://img.shields.io/npm/v/neutrino-lint-base.svg |
|||
[npm-downloads]: https://img.shields.io/npm/dt/neutrino-lint-base.svg |
|||
[npm-url]: https://npmjs.org/package/neutrino-lint-base |
|||
[slack-image]: https://neutrino-slack.herokuapp.com/badge.svg |
|||
[slack-url]: https://neutrino-slack.herokuapp.com/ |
@ -0,0 +1,26 @@ |
|||
{ |
|||
"name": "neutrino-lint-base", |
|||
"version": "4.0.1", |
|||
"description": "Neutrino preset starter for adding building ESLint-based presets", |
|||
"main": "src/index.js", |
|||
"keywords": [ |
|||
"neutrino", |
|||
"neutrino-preset", |
|||
"eslint" |
|||
], |
|||
"author": "Eli Perelman <eli@eliperelman.com>", |
|||
"license": "MPL-2.0", |
|||
"repository": "mozilla-neutrino/neutrino-dev", |
|||
"dependencies": { |
|||
"babel-eslint": "^7.1.1", |
|||
"eslint": "^3.14.1", |
|||
"eslint-loader": "^1.6.1", |
|||
"eslint-plugin-babel": "^4.0.1", |
|||
"eslint-plugin-import": "^2.2.0" |
|||
}, |
|||
"peerDependencies": { |
|||
"neutrino": "^4.0.0" |
|||
}, |
|||
"homepage": "https://neutrino.js.org", |
|||
"bugs": "https://github.com/mozilla-neutrino/neutrino-dev/issues" |
|||
} |
@ -0,0 +1,40 @@ |
|||
const path = require('path'); |
|||
|
|||
const MODULES = path.join(__dirname, '../node_modules'); |
|||
const IF_NOT_DEV = process.env.NODE_ENV !== 'development'; |
|||
|
|||
module.exports = ({ config }) => { |
|||
config |
|||
.module |
|||
.rule('lint') |
|||
.test(/\.(js|jsx)$/) |
|||
.pre() |
|||
.include(path.join(process.cwd(), 'src')) |
|||
.loader('eslint', require.resolve('eslint-loader'), { |
|||
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: {} |
|||
}); |
|||
|
|||
config.resolve.modules.add(MODULES); |
|||
config.resolveLoader.modules.add(MODULES); |
|||
}; |
File diff suppressed because it is too large
@ -1,58 +1,31 @@ |
|||
'use strict'; |
|||
|
|||
const path = require('path'); |
|||
|
|||
const MODULES = path.join(__dirname, '../node_modules'); |
|||
|
|||
module.exports = ({ config }) => { |
|||
config |
|||
.module |
|||
.rule('lint') |
|||
.test(/\.(js|jsx)$/) |
|||
.pre() |
|||
.include(path.join(process.cwd(), 'src')) |
|||
.loader('eslint', require.resolve('eslint-loader'), { |
|||
failOnError: process.env.NODE_ENV !== 'development', |
|||
emitWarning: process.env.NODE_ENV !== 'development', |
|||
emitError: process.env.NODE_ENV !== 'development', |
|||
cwd: process.cwd(), |
|||
useEslintrc: false, |
|||
root: true, |
|||
plugins: ['babel'], |
|||
baseConfig: { |
|||
extends: ['airbnb-base'] |
|||
}, |
|||
envs: ['es6'], |
|||
parser: 'babel-eslint', |
|||
parserOptions: { |
|||
ecmaVersion: 2017, |
|||
sourceType: 'module', |
|||
ecmaFeatures: { |
|||
objectLiteralDuplicateProperties: false, |
|||
generators: true, |
|||
impliedStrict: true |
|||
} |
|||
}, |
|||
settings: {}, |
|||
globals: ['process'], |
|||
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'], |
|||
|
|||
// guard against awaiting async functions inside of a loop
|
|||
'babel/no-await-in-loop': 'error' |
|||
} |
|||
}); |
|||
|
|||
config.resolve.modules.add(MODULES); |
|||
config.resolveLoader.modules.add(MODULES); |
|||
const lint = require('neutrino-lint-base'); |
|||
const merge = require('deepmerge'); |
|||
|
|||
module.exports = neutrino => { |
|||
lint(neutrino); |
|||
neutrino.config.module |
|||
.rule('lint') |
|||
.loader('eslint', props => merge(props, { |
|||
options: { |
|||
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'], |
|||
|
|||
// guard against awaiting async functions inside of a loop
|
|||
'babel/no-await-in-loop': 'error' |
|||
} |
|||
} |
|||
})); |
|||
}; |
|||
|
File diff suppressed because it is too large
Loading…
Reference in new issue