Skip to content

Commit

Permalink
fix: options
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Mar 8, 2023
1 parent 2a84a08 commit c3de9d2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 53 deletions.
67 changes: 30 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ npm install -D eslint
With `pnpm`

```bash
pnpm add @nuxtjs/eslint-module
pnpm add -D @nuxtjs/eslint-module
```

Or, with `yarn`

```bash
yarn add @nuxtjs/eslint-module
yarn add -D @nuxtjs/eslint-module
```

Or, with `npm`

```bash
npm install @nuxtjs/eslint-module
npm install -D @nuxtjs/eslint-module
```

2. Add `@nuxtjs/eslint-module` to the `modules` section of `nuxt.config.js`
Expand Down Expand Up @@ -96,19 +96,19 @@ See the [eslint docs](https://eslint.org/docs/latest/integrate/nodejs-api#-new-e

**Note**: The cache is enabled by default to decrease execution time.

### `exclude`
### `include`

- Type: `Array[String]`
- Default: `['**/node_modules/**']]`
- Type: `String|Array[String]`
- Default: `[nuxt.options.srcDir.'/**/*.{js,jsx,ts,tsx,vue}']`

Specify the files and/or directories to exclude.
Specify directories, files, or globs.

### `extensions`
### `exclude`

- Type: `String|Array[String]`
- Default: `['js', 'jsx', 'ts', 'tsx', 'vue']`
- Type: `Array[String]`
- Default: `['**/node_modules/**', nuxt.options.buildDir]`

Specify extensions that should be checked.
Specify the files and/or directories to exclude.

### `eslintPath`

Expand All @@ -117,56 +117,49 @@ Specify extensions that should be checked.

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

#### `emitError`
### `formatter`

- Type: `Boolean`
- Default: `true`
- Type: `String|Function`
- Default: `'stylish'`

The errors found will be printed.
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/).

#### `emitWarning`
### `lintOnStart`

- Type: `Boolean`
- Default: `true`

The warnings found will be printed.
Check all matching files on project startup, too slow, turn on discreetly.

#### `failOnWarning`
### `emitWarning`

- Type: `Boolean`
- Default: `false`
- Default: `true`

Will cause the module build to fail if there are any warnings, based on `emitWarning`.
The warnings found will be printed.

#### `failOnError`
### `emitError`

- Type: `Boolean`
- Default: `false`
- Default: `true`

Will cause the module build to fail if there are any errors, based on `emitError`.
The errors found will be printed.

### `fix`
### `failOnWarning`

- Type: `Boolean`
- Default: `false`

Auto fix source code.

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

### `formatter`

- Type: `String|Function`
- Default: `'stylish'`

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/).
Will cause the module build to fail if there are any warnings, based on `emitWarning`.

### `lintOnStart`
### `failOnError`

- Type: `Boolean`
- Default: `true`
- Default: `false`

Check all matching files on project startup, too slow, turn on discreetly.
Will cause the module build to fail if there are any errors, based on `emitError`.

## Contributing

Expand Down
27 changes: 11 additions & 16 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import vitePluginEslint from 'vite-plugin-eslint'
import EslintWebpackPlugin from 'eslint-webpack-plugin'
import { name, version } from '../package.json'

export type ModuleOptions = VitePlugin & WebpackPlugin & {
extensions: string[]
}
export type ModuleOptions = VitePlugin & WebpackPlugin

export default defineNuxtModule<ModuleOptions>({
meta: {
Expand All @@ -18,19 +16,18 @@ export default defineNuxtModule<ModuleOptions>({
bridge: true
}
},
defaults: {
defaults: nuxt => ({
cache: true,
exclude: ['**/node_modules/**'],
extensions: ['js', 'jsx', 'ts', 'tsx', 'vue'],
include: [`${nuxt.options.srcDir}/**/*.{js,jsx,ts,tsx,vue}`],
exclude: ['**/node_modules/**', nuxt.options.buildDir],
eslintPath: 'eslint',
emitError: true,
formatter: 'stylish',
lintOnStart: true,
emitWarning: true,
failOnError: false,
emitError: true,
failOnWarning: false,
fix: false,
formatter: 'stylish',
lintOnStart: true
},
failOnError: false
}),
setup (options, nuxt) {
if (!nuxt.options.dev) {
return
Expand All @@ -51,14 +48,12 @@ export default defineNuxtModule<ModuleOptions>({
}
})

addVitePlugin(vitePluginEslint({
...options,
include: options.extensions.map(ext => `**/*.${ext}`)
}), { server: false })
addVitePlugin(vitePluginEslint(options), { server: false })

addWebpackPlugin(new EslintWebpackPlugin({
...options,
context: nuxt.options.srcDir,
files: options.include,
lintDirtyModulesOnly: !options.lintOnStart
}), { server: false })
}
Expand Down

0 comments on commit c3de9d2

Please sign in to comment.