我正在使用nuxt.js创建一个应用程序,但每次启动应用程序时,都会出现eslint错误,并提示“可能可以使用--fix
选项进行修复。”
我执行了命令npm run lint -- --fix
,它可以解决问题,但如果我在任何vue文件中做另一个更改,那么同样的错误会再次出现,我必须再次执行该命令。
有任何修复方法的想法吗?
将以下配置添加到nuxt配置文件中:
build: {
extend(config, ctx) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/,
options: {
fix: true
}
})
}
}
重要部分是:
options: {
fix: true
}
在nuxt.config.js
文件中扩展内置构建
build: {
extend(config, ctx) {
config.module.rules.push({
enforce: "pre",
test: /\.(js|vue)$/,
loader: "eslint-loader",
exclude: /(node_modules)/,
options: {
fix: true
}
})
}
}
functions
文件夹内的package.json
文件,替换其中的内容。"lint": "eslint --ext .js,.ts .",
随着
"lint": "eslint --ext .js,.ts . --fix",
然后再次运行该命令:
firebase deploy --only functions
它应该修复所有可以修复的问题。 如果还有任何错误留下(有时仍然会有1或2个),找到并手动编辑即可,即可解决问题。
settings.json
中拥有此ESlint扩展程序(可通过命令面板访问){
"editor.codeActionsOnSave": {
"source.fixAll": true, // this one will fix it on save for you
},
"eslint.options": {
"extensions": [
".html",
".js",
".vue",
".jsx",
]
},
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"html",
"vue",
],
}
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
parserOptions: {
parser: '@babel/eslint-parser',
requireConfigFile: false,
},
extends: ['@nuxtjs']
}
我也遇到了同样的问题。
后来我找到了一个解决方案
使用这个命令:-> npm run lint:js -- --fix
希望你的问题能够得到解决。
npm run lint -- --fix
没有起作用。运行 npm run format
可以修复错误。
lint
用于标记错误format
用于修复错误"scripts": {
"lint": "eslint \"**/*.{js,mjs}\" && prettier --check --loglevel warn \"**/*.{js,mjs,json}\" && stylelint \"**/*.scss\"",
"format": "eslint \"**/*.{js,mjs}\" --fix && prettier --write --loglevel warn \"**/*.{js,mjs,json}\" && stylelint \"**/*.scss\" --fix",
}
npm ERR! Missing script: "format"
错误。
你的 format
脚本是什么? - Jake_3H
npm run lint -- --fix
- 谢谢! - Liran H