eslint 和 vue 的预提交挂钩

Pre commit hook for eslint and vue

我正在使用 pre-commit 用于多语言项目中的多个挂钩。我所有现有的挂钩都在工作。我现在正在尝试获得一个 eslint 挂钩设置,其中将包含 Vue 2 个文件。

这是我在 eslint 部分的 .pre-commit-config.yaml

-   repo: https://github.com/pre-commit/mirrors-eslint
    rev: 'v7.18.0'
    hooks:
    -   id: eslint
        types_or: [javascript, jsx, ts, tsx, vue]
        additional_dependencies:
        -   eslint-plugin-vue@v7.5.0

这适用于 javascript 文件,但完全忽略 Vue 2 文件。我已经基于此设置了上述配置: Eslint for vue and pre-commit eslint.

我尝试在项目的根目录中添加以下 .eslintrc 文件,但没有帮助:

module.exports = {
  extends: [
    'plugin:vue/recommended'
  ]
}

Vue 文件被完全忽略。

base configuration at that version指定types: [javascript]

当与您的配置一起折叠时,这会设置:

types: [javascript]
types_or: [javascript, jsx, ts, tsx, vue]

来自 the documentation:

types, types_or, and files are evaluated together with AND when filtering. Tags within types are also evaluated using AND.

new in 2.9.0: Tags within types_or are evaluated using OR.

将它们放在一起(使用一些集合符号),您正在请求 {javascript} & {javascript, jsx, ts, tsx, vue} -- 简化:{javascript}

README of mirrors-eslint 告诉你在这里做什么,你需要覆盖 types 回到默认值 [file] 在应用额外的过滤之前:

    -   id: eslint
        types: [file]
        types_or: [javascript, jsx, ts, tsx, vue]

免责声明:我是 pre-commit 的创建者,以后请不要 post 你的问题 both issue tracker 和 Whosebug,谢谢!