b81de000ab16a88aa24fa4062f7b49615766025a2fea7e1edf9b046fe2c0f22393a7dcd4c119329ea481d33e3f125c613ad6da83a154d14f211a453379455d 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # @vue/cli-plugin-eslint
  2. > eslint plugin for vue-cli
  3. ## Injected Commands
  4. - **`vue-cli-service lint`**
  5. ```
  6. Usage: vue-cli-service lint [options] [...files]
  7. Options:
  8. --format [formatter] specify formatter (default: codeframe)
  9. --no-fix do not fix errors
  10. --max-errors specify number of errors to make build failed (default: 0)
  11. --max-warnings specify number of warnings to make build failed (default: Infinity)
  12. ```
  13. Lints and fixes files. If no specific files are given, it lints all files in `src` and `tests`.
  14. Other [ESLint CLI options](https://eslint.org/docs/user-guide/command-line-interface#options) are also supported.
  15. ## Configuration
  16. ESLint can be configured via `.eslintrc` or the `eslintConfig` field in `package.json`. See the [ESLint configuration docs](https://eslint.org/docs/user-guide/configuring) for more detail.
  17. ::: tip
  18. The following option is under the section of [`vue.config.js`](https://cli.vuejs.org/config/#vue-config-js). It is respected only when `@vue/cli-plugin-eslint` is installed.
  19. :::
  20. Lint-on-save during development with `eslint-loader` is enabled by default. It can be disabled with the `lintOnSave` option in `vue.config.js`:
  21. ``` js
  22. module.exports = {
  23. lintOnSave: false
  24. }
  25. ```
  26. When set to `true`, `eslint-loader` will emit lint errors as warnings. By default, warnings are only logged to the terminal and does not fail the compilation.
  27. To make lint errors show up in the browser overlay, you can use `lintOnSave: 'error'`. This will force `eslint-loader` to always emit errors. this also means lint errors will now cause the compilation to fail.
  28. Alternatively, you can configure the overlay to display both warnings and errors:
  29. ``` js
  30. // vue.config.js
  31. module.exports = {
  32. devServer: {
  33. overlay: {
  34. warnings: true,
  35. errors: true
  36. }
  37. }
  38. }
  39. ```
  40. When `lintOnSave` is a truthy value, `eslint-loader` will be applied in both development and production. If you want to disable `eslint-loader` during production build, you can use the following config:
  41. ``` js
  42. // vue.config.js
  43. module.exports = {
  44. lintOnSave: process.env.NODE_ENV !== 'production'
  45. }
  46. ```
  47. ## Installing in an Already Created Project
  48. ``` sh
  49. vue add eslint
  50. ```
  51. ## Injected webpack-chain Rules
  52. - `config.module.rule('eslint')`
  53. - `config.module.rule('eslint').use('eslint-loader')`