![](/img/trans.png)
[英]'Fix all auto-fixable problems' doesn't fix as many issues as possible vscode-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 . --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
注意:每次更改该特定文件后,您都必须运行上述命令。
--fix
时遇到了困难./node_modules/.bin/eslint --fix
但是,我更喜欢在package.json中再写两个脚本
"lint": "eslint --ext \".js,.vue\" --ignore-path .gitignore .", "lint-fix": "npm run lint -- --fix"
并运行yarn lint-fix
或npm run lint-fix
我刚刚遇到了同样的问题
eslint --fix fileName.extention
第一个安装包: npm install -g eslint
和
运行:eslint --fix
如果它没有用 '--fix' 标志修复任何错误,这意味着你的 ESlint 配置文件有错误。 请再次交叉检查文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.