Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 views
in Technique[技术] by (71.8m points)

git - Pre commit hook for eslint and vue

I am using pre-commit for several hooks within a multi language project. All my existing hooks are working. I am now trying to get a eslint hook setup that will include Vue 2 files.

Here's my .pre-commit-config.yaml for the eslint section:

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

This works for javascript files but completely ignores the Vue 2 files. I have setup the above config based on this: Eslint for vue and pre-commit eslint.

I have tried adding the following .eslintrc file in the root of the project which hasn't helped:

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

The Vue files are completely ignored.

question from:https://stackoverflow.com/questions/65839519/pre-commit-hook-for-eslint-and-vue

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The base configuration at that version specifies types: [javascript]

when folded together with your configuration this sets:

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

from 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.

Putting that together (with a bit of set notation), you're requesting {javascript} & {javascript, jsx, ts, tsx, vue} -- simplified: {javascript}

the README of mirrors-eslint tells you what to do here, you need to override types back to the default [file] before applying additional filtering:

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

disclaimer: I'm the creator of pre-commit, in the future please don't post your question to both the issue tracker and stackoverflow, thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...