Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
docs: formatting (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Sep 25, 2019
1 parent 0821e14 commit c6b7c12
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 43 deletions.
147 changes: 115 additions & 32 deletions README.md
Expand Up @@ -94,7 +94,7 @@ module.exports = {
};
```

### Options
## Options

You can pass [eslint options](http://eslint.org/docs/developer-guide/nodejs-api#cliengine)
using standard webpack [loader options](https://webpack.js.org/configuration/module/#useentry).
Expand All @@ -103,14 +103,10 @@ Note that the config option you provide will be passed to the `CLIEngine`.
This is a different set of options than what you'd specify in `package.json` or `.eslintrc`.
See the [eslint docs](http://eslint.org/docs/developer-guide/nodejs-api#cliengine) for more detail.

#### `fix` (default: false)
### `cache`

This option will enable
[ESLint autofix feature](http://eslint.org/docs/user-guide/command-line-interface#fix).

**Be careful: this option will change source files.**

#### `cache` (default: false)
- Type: `Boolean|String`
- Default: `false`

This option will enable caching of the linting results into a file.
This is particularly useful in reducing linting time when doing a full build.
Expand All @@ -120,9 +116,57 @@ This can either be a `boolean` value or the cache directory path(ex: `'./.eslint
If `cache: true` is used, the cache file is written to the `./node_modules/.cache` directory.
This is the recommended usage.

#### `formatter` (default: 'stylish')
```js
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
cache: true,
},
},
],
},
};
```

### `eslintPath`

- Type: `String`
- Default: `eslint`

Path to `eslint` instance that will be used for linting.
If the `eslintPath` is a folder like a official eslint, or specify a `formatter` option.
now you dont have to install `eslint`.

Loader accepts a function that will have one argument: an array of eslint messages (object).
```js
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
eslintPath: path.join(__dirname, 'reusable-eslint'),
},
},
],
},
};
```

### `formatter`

- Type: `String|Function`
- Default: `stylish`

This option accepts a function that will have one argument: an array of eslint messages (object).
The function must return the output as a string.
You can use official [eslint formatters](https://eslint.org/docs/user-guide/formatters/).

Expand Down Expand Up @@ -160,11 +204,15 @@ module.exports = {
};
```

#### `eslintPath` (default: 'eslint')
### `fix`

Path to `eslint` instance that will be used for linting.
If the `eslintPath` is a folder like a official eslint, or specify a `formatter` option.
now you dont have to install `eslint`.
- Type: `Boolean`
- Default: `false`

This option will enable
[ESLint autofix feature](http://eslint.org/docs/user-guide/command-line-interface#fix).

**Be careful: this option will change source files.**

```js
module.exports = {
Expand All @@ -176,23 +224,26 @@ module.exports = {
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
eslintPath: path.join(__dirname, 'reusable-eslint'),
fix: true,
},
},
],
},
};
```

#### Errors and Warning
### Errors and Warning

**By default the loader will auto adjust error reporting depending
on eslint errors/warnings counts.**
You can still force this behavior by using `emitError` **or** `emitWarning` options:

##### `emitError` (default: `false`)
#### `emitError`

Loader will always return errors if this option is set to `true`.
- Type: `Boolean`
- Default: `false`

Will always return errors, if this option is set to `true`.

```js
module.exports = {
Expand All @@ -212,14 +263,37 @@ module.exports = {
};
```

##### `emitWarning` (default: `false`)
#### `emitWarning`

Loader will always return warnings if option is set to `true`. If you're using hot module replacement,
you may wish to enable this in development, or else updates will be skipped when there's an eslint error.
- Type: `Boolean`
- Default: `false`

##### `quiet` (default: `false`)
Will always return warnings, if option is set to `true`. **If you're using hot module replacement, you may wish to enable this in development, or else updates will be skipped when there's an eslint error.**

Loader will process and report errors only and ignore warnings if this option is set to true
```js
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
emitWarning: true,
},
},
],
},
};
```

#### `failOnError`

- Type: `Boolean`
- Default: `false`

Will cause the module build to fail if there are any errors, if option is set to `true`.

```js
module.exports = {
Expand All @@ -231,17 +305,20 @@ module.exports = {
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
quiet: true,
failOnError: true,
},
},
],
},
};
```

##### `failOnWarning` (default: `false`)
#### `failOnWarning`

Loader will cause the module build to fail if there are any eslint warnings.
- Type: `Boolean`
- Default: `false`

Will cause the module build to fail if there are any warnings, if option is set to `true`.

```js
module.exports = {
Expand All @@ -261,9 +338,12 @@ module.exports = {
};
```

##### `failOnError` (default: `false`)
#### `quiet`

- Type: `Boolean`
- Default: `false`

Loader will cause the module build to fail if there are any eslint errors.
Will process and report errors only and ignore warnings, if this option is set to `true`.

```js
module.exports = {
Expand All @@ -275,20 +355,23 @@ module.exports = {
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
failOnError: true,
quiet: true,
},
},
],
},
};
```

##### `outputReport` (default: `null`)
#### `outputReport`

- Type: `Boolean|Object`
- Default: `false`

Write the output of the errors to a file, for example a checkstyle xml file for use for reporting on Jenkins CI

The `filePath` is an absolute path or relative to the webpack config: output.path
You can pass in a different formatter for the output file,
The `filePath` is an absolute path or relative to the webpack config: `output.path`
You can pass in a different `formatter` for the output file,
if none is passed in the default/configured formatter will be used

```js
Expand Down
22 changes: 11 additions & 11 deletions src/options.json
Expand Up @@ -2,21 +2,21 @@
"type": "object",
"additionalProperties": true,
"properties": {
"fix": {
"description": "This option will enable ESLint autofix feature",
"type": "boolean"
},
"cache": {
"description": "This option will enable caching of the linting results into a file. This is particularly useful in reducing linting time when doing a full build.",
"anyOf": [{ "type": "boolean" }, { "type": "string" }]
},
"eslintPath": {
"description": "Path to `eslint` instance that will be used for linting. If the `eslintPath` is a folder like a official eslint, or specify a `formatter` option. now you dont have to install `eslint` .",
"type": "string"
},
"formatter": {
"description": "Loader accepts a function that will have one argument: an array of eslint messages (object). The function must return the output as a string.",
"anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
},
"eslintPath": {
"description": "Path to `eslint` instance that will be used for linting. If the `eslintPath` is a folder like a official eslint, or specify a `formatter` option. now you dont have to install `eslint` .",
"type": "string"
"fix": {
"description": "This option will enable ESLint autofix feature",
"type": "boolean"
},
"emitError": {
"description": "Loader will always return errors if this option is set to `true`.",
Expand All @@ -26,16 +26,16 @@
"description": "Loader will always return warnings if option is set to `true`. If you're using hot module replacement, you may wish to enable this in development, or else updates will be skipped when there's an eslint error.",
"type": "boolean"
},
"quiet": {
"description": "Loader will process and report errors only and ignore warnings if this option is set to true",
"failOnError": {
"description": "Loader will cause the module build to fail if there are any eslint errors.",
"type": "boolean"
},
"failOnWarning": {
"description": "Loader will cause the module build to fail if there are any eslint warnings.",
"type": "boolean"
},
"failOnError": {
"description": "Loader will cause the module build to fail if there are any eslint errors.",
"quiet": {
"description": "Loader will process and report errors only and ignore warnings if this option is set to true",
"type": "boolean"
},
"outputReport": {
Expand Down

0 comments on commit c6b7c12

Please sign in to comment.