eslint 和 vue 的预提交钩子

dar*_*ool 3 git pre-commit-hook eslint vue.js pre-commit.com

我正在多语言项目中对多个挂钩使用预提交。我现有的所有钩子都可以工作。我现在正在尝试获取eslint包含Vue 2文件的挂钩设置。

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

-   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
Run Code Online (Sandbox Code Playgroud)

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

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

module.exports = {
  extends: [
    'plugin:vue/recommended'
  ]
}
Run Code Online (Sandbox Code Playgroud)

Vue 文件被完全忽略。

Ant*_*ile 7

该版本的基本配置指定types: [javascript]

当与您的配置折叠在一起时,此设置:

types: [javascript]
types_or: [javascript, jsx, ts, tsx, vue]
Run Code Online (Sandbox Code Playgroud)

文档中:

过滤时,types、types_or 和 files 与 AND 一起评估。类型中的标签也使用 AND 进行评估。

2.9.0 中的新增功能: types_or 中的标签使用 OR 进行评估。

将它们放在一起(带有一些设置符号),您所要求的{javascript} & {javascript, jsx, ts, tsx, vue}就是简化的:{javascript}

mirrors-eslint 的自述文件告诉您在这里要做什么,您需要在应用附加过滤之前覆盖types回默认值:[file]

    -   id: eslint
        types: [file]
        types_or: [javascript, jsx, ts, tsx, vue]
Run Code Online (Sandbox Code Playgroud)

免责声明:我是预提交的创建者,以后请不要将您的问题同时发布到问题跟踪器和 stackoverflow,谢谢!