【问题标题】:potentially fixable with the `--fix` option可能使用 `--fix` 选项修复
【发布时间】:2019-06-07 23:03:40
【问题描述】:

我正在使用 nuxt.js 创建一个应用程序,但每次启动该应用程序时,都会给我 eslint 的错误并说“可以使用 --fix 选项修复。”

我执行了命令 npm run lint -- --fix 并且它可以工作,但是如果我对任何 vue 文件进行另一次更改,它会再次出现相同的错误,我必须再次执行此操作

知道如何解决这个问题吗?

【问题讨论】:

  • 您的编辑器是否在保存时格式化?它的执行方式与 ESLint 执行的方式相同吗?
  • 不,不是。应该是@jonrsharpe 吗?
  • 我问了两个问题,你回答的是哪一个?如果你问你的编辑器是否应该应用你的 linter 期望的相同格式:是的,否则你必须重新格式化它
  • 是的,你说得对。我的回答适合你的两个问题。是的,这是第一个。谢谢解释
  • 正在寻找这个:npm run lint -- --fix - 谢谢!

标签: vue.js eslint nuxt.js


【解决方案1】:

在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
}

【讨论】:

  • 你能逐行解释第 2 到 5 行吗?可能对后代有价值
  • @ledawg 现在不再需要这个解决方案了。
  • 有趣的是,我在 2021 年不断遇到这些问题......
【解决方案2】:

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
      }
    })
  }
}

【讨论】:

    猜你喜欢
    • 2019-12-24
    • 2019-07-26
    • 2018-12-18
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 2021-09-09
    相关资源
    最近更新 更多