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

Commit

Permalink
docs: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Dec 4, 2019
1 parent 2dd8b43 commit 2346ff8
Showing 1 changed file with 39 additions and 61 deletions.
100 changes: 39 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ module.exports = {
};
```

When using with transpiling loaders (like `babel-loader`), make sure they are in correct order
(bottom to top). Otherwise files will be checked after being processed by `babel-loader`:
When using with transpiling loaders (like `babel-loader`), make sure they are in correct order (bottom to top). Otherwise files will be checked after being processed by `babel-loader`:

```js
module.exports = {
Expand All @@ -69,8 +68,7 @@ module.exports = {
};
```

To be safe, you can use `enforce: 'pre'` section to check source files, not modified
by other loaders (like `babel-loader`):
To be safe, you can use `enforce: 'pre'` section to check source files, not modified by other loaders (like `babel-loader`):

```js
module.exports = {
Expand All @@ -96,25 +94,20 @@ module.exports = {

## 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).
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).

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.
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.

### `cache`

- 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.
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.

This can either be a `boolean` value or the cache directory path(ex: `'./.eslint-loader-cache'`).

If `cache: true` is used, the cache file is written to the `./node_modules/.cache` directory.
This is the recommended usage.
If `cache: true` is used, the cache file is written to the `./node_modules/.cache` directory. This is the recommended usage.

```js
module.exports = {
Expand All @@ -139,9 +132,7 @@ module.exports = {
- 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`.
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`.

```js
module.exports = {
Expand All @@ -161,14 +152,14 @@ module.exports = {
};
```

### `formatter`
### `fix`

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

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/).
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 @@ -180,39 +171,20 @@ module.exports = {
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
// several examples !

// default value
formatter: 'stylish',

// community formatter
formatter: require('eslint-friendly-formatter'),

// custom formatter
formatter: function(results) {
// `results` format is available here
// http://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles()

// you should return a string
// DO NOT USE console.*() directly !
return 'OUTPUT';
},
fix: true,
},
},
],
},
};
```

### `fix`
### `formatter`

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

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.**
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/).

```js
module.exports = {
Expand All @@ -224,7 +196,23 @@ module.exports = {
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
fix: true,
// several examples !

// default value
formatter: 'stylish',

// community formatter
formatter: require('eslint-friendly-formatter'),

// custom formatter
formatter: function(results) {
// `results` format is available here
// http://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles()

// you should return a string
// DO NOT USE console.*() directly !
return 'OUTPUT';
},
},
},
],
Expand All @@ -234,9 +222,7 @@ module.exports = {

### 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:
**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`

Expand Down Expand Up @@ -370,9 +356,7 @@ module.exports = {

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,
if none is passed in the default/configured formatter will be used.
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
module.exports = {
Expand All @@ -399,17 +383,11 @@ module.exports = {

### NoEmitOnErrorsPlugin

`NoEmitOnErrorsPlugin` is now automatically enabled in webpack 4, when mode is either unset,
or set to production. So even ESLint warnings will fail the build.
No matter what error settings are used for `eslint-loader`, except if `emitWarning` enabled.
`NoEmitOnErrorsPlugin` is now automatically enabled in webpack 4, when mode is either unset, or set to production. So even ESLint warnings will fail the build. No matter what error settings are used for `eslint-loader`, except if `emitWarning` enabled.

### Defining `configFile` or using `eslint -c path/.eslintrc`

Bear in mind that when you define `configFile`, `eslint` doesn't automatically look for
`.eslintrc` files in the directory of the file to be linted.
More information is available in official eslint documentation in section
[_Using Configuration Files_](http://eslint.org/docs/user-guide/configuring#using-configuration-files).
See [#129](https://github.com/webpack-contrib/eslint-loader/issues/129).
Bear in mind that when you define `configFile`, `eslint` doesn't automatically look for `.eslintrc` files in the directory of the file to be linted. More information is available in official eslint documentation in section [_Using Configuration Files_](http://eslint.org/docs/user-guide/configuring#using-configuration-files). See [#129](https://github.com/webpack-contrib/eslint-loader/issues/129).

## Changelog

Expand Down

0 comments on commit 2346ff8

Please sign in to comment.