Skip to content

Commit

Permalink
feat: add eslintPath option to customize eslint instance
Browse files Browse the repository at this point in the history
fix #23
  • Loading branch information
gxmari007 committed Aug 6, 2022
1 parent 906ed1d commit 128fc9a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ Decrease execution time, `Beta` Cache now correctly recognizes file changes, you

Auto fix source code.

### `eslintPath`

- Type: `string`
- Default: `eslint`

Path to `eslint` instance that will be used for linting.

### `include`

- Type: `string | RegExp | ReadonlyArray<string | RegExp>`
Expand Down
29 changes: 15 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,27 @@ export default function eslintPlugin(rawOptions: Options = {}): Plugin {
},
rawOptions
)
const eslintOptions = pickESLintOptions(options)

filter = createFilter(options.include, options.exclude)
// eslint = new ESLint(eslintOptions)

// switch (typeof options.formatter) {
// case 'string':
// formatter = (await eslint.loadFormatter(options.formatter)).format
// break
// case 'function':
// formatter = options.formatter
// default:
// break
// }
},
async buildStart() {
const [error, module] = await to(import(options.eslintPath ?? 'eslint'))

if (error) {
this.error('Failed to import ESLint, do you install or configure eslintPath?')
} else {
const eslintOptions = pickESLintOptions(options)

eslint = new module.ESLint(eslintOptions)
filter = createFilter(options.include, options.exclude)

switch (typeof options.formatter) {
case 'string':
formatter = (await eslint.loadFormatter(options.formatter)).format
break
case 'function':
formatter = options.formatter
default:
break
}
}
},
async transform(_, id) {
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export function parseRequest(id: string) {

export function pickESLintOptions(options: Options): ESLint.Options {
const {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
eslintPath,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
include,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down

0 comments on commit 128fc9a

Please sign in to comment.