繁体   English   中英

--fix 不使用 eslint 修复错误

[英]--fix doesn't fix the errors using eslint

我在可视化代码中使用 eslint 来格式化 js 文件,但每次运行它时都会出错,这是我运行它的命令行node ./node_modules/eslint/bin/eslint -- src --fix错误消息

E:\PATH\src\reducers\roote-reducer.js
  1:8   error  There should be no space after '{'                object-curly-spacing
  1:26  error  There should be no space before '}'               object-curly-spacing
  6:1   error  Expected indentation of 1 tab but found 2 spaces  indent
  7:1   error  Expected indentation of 1 tab but found 2 spaces  indent
  8:4   error  Newline required at end of file but not found     eol-last

E:\PATH\src\reducers\schedule-reducer.js
   1:8   error  There should be no space after '{'                  object-curly-spacing
   1:22  error  There should be no space before '}'                 object-curly-spacing
   4:1   error  Expected indentation of 1 tab but found 4 spaces    indent
   7:24  error  Missing space before function parentheses           space-before-function-paren
   7:54  error  Missing space before opening brace                  space-before-blocks
   8:1   error  Expected indentation of 1 tab but found 4 spaces    indent
   9:1   error  Expected indentation of 1 tab but found 4 spaces    indent

E:\PATH\src\register-service-worker.js
   12:1  error  Expected indentation of 1 tab but found 2 spaces    indent
   17:1  error  Expected indentation of 5 tabs but found 6 spaces   indent
   17:7  error  Use regex shorthands to improve readability         unicorn/regex-shorthand
   22:1  error  Expected indentation of 1 tab but found 2 spaces    indent

✖ 309 problems (309 errors, 0 warnings)
  309 errors, 0 warnings potentially fixable with the `--fix` option.

我怎样才能自动修复它们?

要使用--fix选项,您需要直接运行 eslint。

尝试这个

./node_modules/.bin/eslint src --fix

在 Windows 上:

.\node_modules\.bin\eslint src\** --fix

格式应为:

./node_modules/.bin/eslint --fix path/to/file.js

有关更多背景信息,请参阅此线程(和 aravind1078 的答案)。

在新终端中运行以下命令:

./node_modules/.bin/eslint --fix . --ext .js,.vue src

尝试运行

eslint --fix

你必须安装第一个 eslint

npm install -g eslint

在您的代码存在的目录中运行:

eslint --fix .

代替

eslint --fix 

因为该命令需要一个参数,该参数指示代码所在的目录或要对其应用 linting 的文件本身

使用命令行终端,在 Visual Studio Code 中运行以下命令。

确保为工作项目配置了 .eslintrc.yml 文件

修复文件中的 lint 问题

npx eslint file1.js --fix

修复文件夹中所有文件的 lint 问题

npx eslint ./folder_name --fix

如果没有

 extend(config, ctx) { // Run ESLint on save if (ctx.isDev && ctx.isClient) { config.module.rules.push({ enforce: 'pre', test: /\.(js|vue)$/, loader: 'eslint-loader', exclude: /(node_modules)/, options: { fix: true } }) } } You. You can use this on the first page const colors = require('vuetify/es5/util/colors').default const pkg = require('./package') require('dotenv').config() module.exports = { mode: 'universal', /* ** Headers of the page */ head: { titleTemplate: '%s - ' + process.env.npm_package_name, title: process.env.npm_package_name || '', meta: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' }, { hid: 'description', name: 'description', content: process.env.npm_package_description || '' } ], link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }] }, /* ** Customize the progress-bar color */ loading: { color: '#fff' }, /* ** Global CSS */ css: [], /* ** Plugins to load before mounting the App */ plugins: [], /* ** Nuxt.js dev-modules */ buildModules: [ // Doc: https://github.com/nuxt-community/eslint-module '@nuxtjs/eslint-module', '@nuxtjs/vuetify' ], /* ** Nuxt.js modules */ modules: [ // Doc: https://axios.nuxtjs.org/usage '@nuxtjs/axios', '@nuxtjs/pwa', // Doc: https://github.com/nuxt-community/dotenv-module '@nuxtjs/dotenv' ], /* ** Axios module configuration ** See https://axios.nuxtjs.org/options */ axios: {}, /* ** vuetify module configuration ** https://github.com/nuxt-community/vuetify-module */ /* ** Build configuration */ build: { extend(config, ctx) { // Run ESLint on save if (ctx.isDev && ctx.isClient) { config.module.rules.push({ enforce: 'pre', test: /\.(js|vue)$/, loader: 'eslint-loader', exclude: /(node_modules)/, options: { fix: true } }) } } } }

如果你还是不明白我。

如果您还没有安装 eslint,请先安装

npm install -g eslint

然后运行

eslint --fix path/to/file.extension


注意:每次更改该特定文件后,您都必须运行上述命令。

  • 当我在 Nuxt.js 项目中使用eslint-config-airbnb-base而不是@nuxtjs/eslint-module时,我在使用--fix时遇到了困难
  • 当时运行 eslint 直接对我有用:./node_modules/.bin/ ./node_modules/.bin/eslint --fix


但是,我更喜欢在package.json中再写两个脚本

"lint": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
"lint-fix": "npm run lint -- --fix"

并运行yarn lint-fixnpm run lint-fix

我刚刚遇到了同样的问题

eslint --fix fileName.extention

第一个安装包: npm install -g eslint

运行:eslint --fix

如果它没有用 '--fix' 标志修复任何错误,这意味着你的 ESlint 配置文件有错误。 请再次交叉检查文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM