Skip to content

Commit

Permalink
feat: add maxWarnings option to eslint (#69)
Browse files Browse the repository at this point in the history
* add maxWarnings option to eslint

* docs: update README

Co-authored-by: fi3ework <fi3ework@gmail.com>
  • Loading branch information
mikew and fi3ework authored Oct 7, 2021
1 parent 60ab2d0 commit 8fc5d7f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ _coming soon._

### config.eslint

| field | Type | Default value | Description |
| :--------- | -------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| files | `string \| string[]` | This value is required | The lint target files. This can contain any of file paths, directory paths, and glob patterns. ([Details](https://eslint.org/docs/developer-guide/nodejs-api#parameters-1)). |
| extensions | `string[]` | `['.js']` | Specify linted file extensions, 'extensions' must be an array of non-empty strings, e.g. `['.jsx', '.js']`. ([Details](https://eslint.org/docs/developer-guide/nodejs-api#parameters)). |
| configFile | `string` | | Specify path to ESLint config file, if you wish to override ESLint's default configuration discovery. Equivalent to ESLint's "--config" option. |
| field | Type | Default value | Description |
| :---------- | -------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| files | `string \| string[]` | This value is required | The lint target files. This can contain any of file paths, directory paths, and glob patterns. ([Details](https://eslint.org/docs/developer-guide/nodejs-api#parameters-1)). |
| extensions | `string[]` | `['.js']` | Specify linted file extensions, 'extensions' must be an array of non-empty strings, e.g. `['.jsx', '.js']`. ([Details](https://eslint.org/docs/developer-guide/nodejs-api#parameters)). |
| configFile | `string` | `undefined` | Specify path to ESLint config file, if you wish to override ESLint's default configuration discovery. Equivalent to ESLint's "--config" option. |
| maxWarnings | `number` | `undefined` | Fail a build if there are more than this many warnings. |

## Playground

Expand Down
10 changes: 9 additions & 1 deletion packages/vite-plugin-checker/src/checkers/eslint/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ export class EslintChecker extends Checker<'eslint'> {
let ext = ['.js']
let files: string[] = []
let overrideConfigFile: string[] = []
let maxWarnings = ''

if (pluginConfig.eslint) {
ext = pluginConfig.eslint.extensions ?? ext
if (pluginConfig.eslint.maxWarnings !== undefined) {
maxWarnings = `--max-warnings=${pluginConfig.eslint.maxWarnings}`
}
files =
typeof pluginConfig.eslint.files === 'string'
? [pluginConfig.eslint.files]
Expand All @@ -127,7 +132,10 @@ export class EslintChecker extends Checker<'eslint'> {
: []
}

return ['eslint', ['--ext', ext.join(','), ...overrideConfigFile, ...files]]
return [
'eslint',
['--ext', ext.join(','), maxWarnings, ...overrideConfigFile, ...files].filter(Boolean),
]
},
},
createDiagnostic,
Expand Down
4 changes: 4 additions & 0 deletions packages/vite-plugin-checker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export type EslintConfig =
* Equivalent to ESLint's "--config" option.
*/
configFile?: string
/*
* Fail a build if there are more than this many warnings.
*/
maxWarnings?: number
}

/** checkers shared configuration */
Expand Down

0 comments on commit 8fc5d7f

Please sign in to comment.