Skip to content

Commit 3a21afd

Browse files
feat!: use eslint-webpack-plugin (#40)
* perf: `cache` enabled by default BREAKING CHANGE: Use `eslint-webpack-plugin` instead of `eslint-loader` deprecated. * fix: docs and default values
1 parent 8e64f1d commit 3a21afd

File tree

4 files changed

+150
-62
lines changed

4 files changed

+150
-62
lines changed

README.md

+47-21
Original file line numberDiff line numberDiff line change
@@ -57,89 +57,113 @@ export default {
5757

5858
## Options
5959

60-
You can pass [eslint options](http://eslint.org/docs/developer-guide/nodejs-api#cliengine).
60+
You can pass [eslint options](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions).
6161

62-
**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.
62+
Note that the config option you provide will be passed to the `ESLint` class.
63+
This is a different set of options than what you'd specify in `package.json` or `.eslintrc`.
64+
See the [eslint docs](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions) for more details.
6365

64-
### `cache`
66+
**Warning**: In eslint-webpack-plugin version 1 the options were passed to the now deprecated [CLIEngine](https://eslint.org/docs/developer-guide/nodejs-api#cliengine).
6567

66-
- Type: `Boolean|String`
67-
- Default: `false`
68+
### `cache``
69+
70+
- Type: `Boolean`
71+
- Default: `true`
6872

69-
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.
73+
**Note**: The cache is enabled by default to decrease execution time.
7074

71-
This can either be a `boolean` value or the cache directory path(ex: `'./.eslint-loader-cache'`).
75+
### `context`
7276

73-
If `cache: true` is used, the cache is written to the `./node_modules/.cache/eslint-loader` directory. This is the recommended usage.
77+
- Type: `String`
78+
- Default: `srcDir`
79+
80+
A string indicating the root of your files.
7481

7582
### `eslintPath`
7683

7784
- Type: `String`
7885
- Default: `eslint`
7986

80-
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`.
87+
Path to `eslint` instance that will be used for linting.
88+
89+
### `files`
90+
91+
- Type: `String|Array[String]`
92+
- Default: `'.'`
93+
94+
Specify directories, files, or globs. Must be relative to `options.context`.
95+
Directories are traversed recursively looking for files matching `options.extensions`.
96+
File and glob patterns ignore `options.extensions`.
8197

8298
### `extensions`
8399

84-
- Type: `Array[String]`
100+
- Type: `String|Array[String]`
85101
- Default: `['ts', 'js', 'vue']`
86102

87-
Extensions that will be used by the loader.
103+
Specify extensions that should be checked.
88104

89105
### `fix`
90106

91107
- Type: `Boolean`
92108
- Default: `false`
93109

94-
This option will enable [ESLint autofix feature](http://eslint.org/docs/user-guide/command-line-interface#fix).
110+
Will enable [ESLint autofix feature](https://eslint.org/docs/developer-guide/nodejs-api#cliengineoutputfixes).
95111

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

98114
### `formatter`
99115

100116
- Type: `String|Function`
101-
- Default: `stylish`
117+
- Default: `'stylish'`
118+
119+
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/).
120+
121+
### `lintDirtyModulesOnly`
122+
123+
- Type: `Boolean`
124+
- Default: `true`
102125

103-
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/).
126+
Lint only changed files, skip lint on start.
104127

105128
### Errors and Warning
106129

107-
**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:
130+
**By default the plugin will auto adjust error reporting depending on eslint errors/warnings counts.**
131+
You can still force this behavior by using `emitError` **or** `emitWarning` options:
108132

109133
#### `emitError`
110134

111135
- Type: `Boolean`
112136
- Default: `false`
113137

114-
Will always return errors, if this option is set to `true`.
138+
Will always return errors, if set to `true`.
115139

116140
#### `emitWarning`
117141

118142
- Type: `Boolean`
119143
- Default: `false`
120144

121-
Will always return warnings, if option is set to `true`.
145+
Will always return warnings, if set to `true`.
122146

123147
#### `failOnError`
124148

125149
- Type: `Boolean`
126150
- Default: `false`
127151

128-
Will cause the module build to fail if there are any errors, if option is set to `true`.
152+
Will cause the module build to fail if there are any errors, if set to `true`.
129153

130154
#### `failOnWarning`
131155

132156
- Type: `Boolean`
133157
- Default: `false`
134158

135-
Will cause the module build to fail if there are any warnings, if option is set to `true`.
159+
Will cause the module build to fail if there are any warnings, if set to `true`.
136160

137161
#### `quiet`
138162

139163
- Type: `Boolean`
140164
- Default: `false`
141165

142-
Will process and report errors only and ignore warnings, if this option is set to `true`.
166+
Will process and report errors only and ignore warnings, if set to `true`.
143167

144168
#### `outputReport`
145169

@@ -148,7 +172,9 @@ Will process and report errors only and ignore warnings, if this option is set t
148172

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

151-
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.
175+
The `filePath` is an absolute path or relative to the webpack config: `output.path`.
176+
You can pass in a different `formatter` for the output file,
177+
if none is passed in the default/configured formatter will be used.
152178

153179
## Development
154180

lib/module.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ const logger = require('./logger')
33
const { moduleExists } = require('./utils')
44

55
module.exports = function (moduleOptions) {
6-
if (!moduleExists('eslint')) {
7-
logger.warn(
8-
'The dependency `eslint` not found.',
9-
'Please run `yarn add eslint --dev` or `npm install eslint --save-dev`'
10-
)
11-
return
12-
}
13-
146
const options = {
7+
context: this.options.srcDir,
8+
eslintPath: 'eslint',
159
extensions: ['ts', 'js', 'vue'],
10+
cache: true,
11+
lintDirtyModulesOnly: true,
1612
...this.options.eslint,
1713
...moduleOptions
1814
}
1915

16+
if (!moduleExists(options.eslintPath)) {
17+
logger.warn(
18+
`The dependency \`${options.eslintPath}\` not found.`,
19+
'Please run `yarn add eslint --dev` or `npm install eslint --save-dev`'
20+
)
21+
return
22+
}
23+
2024
const filesToWatch = [
2125
'.eslintrc',
2226
'.eslintrc.json',
@@ -31,13 +35,9 @@ module.exports = function (moduleOptions) {
3135

3236
this.extendBuild((config, { isDev, isClient }) => {
3337
if (isDev && isClient) {
34-
config.module.rules.push({
35-
enforce: 'pre',
36-
test: RegExp(`\\.(${options.extensions.join('|')})$`),
37-
loader: 'eslint-loader',
38-
exclude: /(node_modules)/,
39-
options
40-
})
38+
const EslintPlugin = require('eslint-webpack-plugin')
39+
40+
config.plugins.push(new EslintPlugin(options))
4141
}
4242
})
4343
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"dependencies": {
2121
"consola": "^2.15.0",
22-
"eslint-loader": "^4.0.2"
22+
"eslint-webpack-plugin": "^2.1.0"
2323
},
2424
"devDependencies": {
2525
"@commitlint/cli": "latest",

0 commit comments

Comments
 (0)