Skip to content

Commit

Permalink
feat(eslint): allow specifying eslint config file (#71)
Browse files Browse the repository at this point in the history
* feat: allow specifying eslint config file

Add configuration option to pass through to ESLint that will specify a custom
path for ESLint to find the configuration file to be used.

* Update config property name inline with ESLint naming.

* Revert, mistakenly used deprecated option
  • Loading branch information
elwynelwyn authored Oct 7, 2021
1 parent 96fc4b4 commit 60ab2d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ _coming soon._
| :--------- | -------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 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. |

## 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 @@ -30,9 +30,13 @@ const createDiagnostic: CreateDiagnostic<'eslint'> = (pluginConfig) => {
if (!pluginConfig.eslint) return

const extensions = pluginConfig.eslint.extensions ?? ['.js']
const overrideConfigFile = pluginConfig.eslint.configFile
? { overrideConfigFile: pluginConfig.eslint.configFile }
: {}
const eslint = new ESLint({
cwd: root,
extensions,
...overrideConfigFile,
})
invariant(pluginConfig.eslint, 'config.eslint should not be `false`')
invariant(
Expand Down Expand Up @@ -111,15 +115,19 @@ export class EslintChecker extends Checker<'eslint'> {
buildBin: (pluginConfig) => {
let ext = ['.js']
let files: string[] = []
let overrideConfigFile: string[] = []
if (pluginConfig.eslint) {
ext = pluginConfig.eslint.extensions ?? ext
files =
typeof pluginConfig.eslint.files === 'string'
? [pluginConfig.eslint.files]
: pluginConfig.eslint.files
overrideConfigFile = pluginConfig.eslint.configFile
? ['--config', pluginConfig.eslint.configFile]
: []
}

return ['eslint', ['--ext', ext.join(','), ...files]]
return ['eslint', ['--ext', ext.join(','), ...overrideConfigFile, ...files]]
},
},
createDiagnostic,
Expand Down
5 changes: 5 additions & 0 deletions packages/vite-plugin-checker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export type EslintConfig =
* @defaultValue: 300
*/
// watchDelay?: number
/**
* Specify path to ESLint config file, if you wish to override ESLint's default configuration discovery.
* Equivalent to ESLint's "--config" option.
*/
configFile?: string
}

/** checkers shared configuration */
Expand Down

0 comments on commit 60ab2d0

Please sign in to comment.