簡體   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