标签: pre-commit-hook

eslint 和 vue 的预提交钩子

我正在多语言项目中对多个挂钩使用预提交。我现有的所有钩子都可以工作。我现在正在尝试获取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 文件被完全忽略。

git pre-commit-hook eslint vue.js pre-commit.com

3
推荐指数
1
解决办法
3518
查看次数

预提交 isort 没有名为“setuptools”的模块

我正在尝试运行预提交挂钩,但是当它们遇到 isort 挂钩时会失败,该挂钩会引发以下错误:

  File "/home/el/.cache/pre-commit/repoffrjhcx0/py_env-python3/lib/python3.10/site-packages/_distutils_hack/__init__.py", line 92, in create_module
    return importlib.import_module('setuptools._distutils')
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'setuptools'
Run Code Online (Sandbox Code Playgroud)

我正在使用 docker,并且我已经检查了 setuptools 是否已安装在我的全局计算机和 docker 上。我不明白为什么会出现这个错误。我认为 isort 设置了它自己的环境,但是为什么它不会被安装,因为它是在配置文件pyproject.toml中定义的。

以下是我的预提交和 isort 配置:

.pre-commit-config.yaml

repos:
- repo: https://github.com/pycqa/isort
  rev: 5.8.0
  hooks:
    - id: isort
      args: ["--multi-line=5", "--line-length=120", "--use-parentheses", "--filter-files"]
      exclude: "migrations"
      stages: [commit]
Run Code Online (Sandbox Code Playgroud)

毒物文件

[isort]
line_length=120
skip_glob=*migrations*
multi_line_output=5
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
use_parentheses=true
include_trailing_comma=true
lines_between_types=1
lines_after_imports=2
[testenv:isort]
deps =
    isort
commands =
    isort . --check-only --diff
Run Code Online (Sandbox Code Playgroud)

系统上的Python版本:3.10.1 …

python pre-commit pre-commit-hook isort pre-commit.com

3
推荐指数
1
解决办法
1508
查看次数

Bitbucket 管道 - 安装预提交 ts-lint 时出错

我的管道中有一个步骤在 Bitbucket 上运行我们配置的预提交:

...
- step:
    name: Passing linters
    image: python:3.7-slim-stretch
    script:
      - pip3 install "pre-commit==2.17.0"
      - apt-get update && apt-get --assume-yes install git
      - pre-commit run --all-files

Run Code Online (Sandbox Code Playgroud)

没有进行任何更改,但它突然停止工作。

管道结果:

+ pre-commit run --all-files
[INFO] Initializing environment for https://github.com/psf/black.
[INFO] Initializing environment for https://github.com/psf/black:click==8.0.4.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/maximevast/pre-commit-tslint/.
[INFO] Initializing environment for https://github.com/maximevast/pre-commit-tslint/:tslint-react@4.1.0,tslint@5.20.1,typescript@4.0.2.
[INFO] Installing environment for https://github.com/psf/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] …
Run Code Online (Sandbox Code Playgroud)

bitbucket pre-commit pre-commit-hook bitbucket-pipelines pre-commit.com

3
推荐指数
1
解决办法
1826
查看次数

我可以通过传递 git commit 标志来忽略 flake8 错误吗?

我有一个flake8:check todo预提交挂钩,我现在想忽略它。

git commit --no-verify如果我确实希望所有其他挂钩运行,我可以忽略一切

我也可以编辑我的.pre-commit-hooks.yaml以删除相关的挂钩,但我确实想要它。只是现在不...

是否可以仅针对此提交/推送跳过挂钩检查?


我的配置.pre-commit-config.yaml:

default_language_version:
    python: python3.6
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.1.0 # 4.2.0 drops python<3.7
  hooks:
  - id: check-added-large-files
  - id: check-case-conflict
  - id: check-docstring-first
  - id: check-executables-have-shebangs
  - id: check-toml
  - id: check-merge-conflict
  - id: check-yaml
  - id: debug-statements
  - id: end-of-file-fixer
  - id: mixed-line-ending
  - id: sort-simple-yaml
  - id: trailing-whitespace
- repo: local
  hooks:
  - id: todo
    name: Check TODO
    language: pygrep
    args: [-i] …
Run Code Online (Sandbox Code Playgroud)

git pre-commit-hook pre-commit.com

3
推荐指数
1
解决办法
9489
查看次数

使用自定义 Pypi 索引中的 extra_dependencies 预提交 mypy

在我的中.pre-commit-config.yaml,我有以下配置mypy

  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v0.971
    hooks:
      - id: mypy
        args: [--strict]
        additional_dependencies:
          [
            apache-airflow==2.3.3,
            apache-airflow-providers-apache-hive==4.0.0,
            apache-airflow-providers-apache-livy==3.1.0,
            types-protobuf==3.20.4,
          ]
Run Code Online (Sandbox Code Playgroud)

如果所有这些依赖项都来自公共 pypi 索引,则此方法可以正常工作。如果我有一个包来自自定义 pypi 索引,我该怎么办?在这种情况下我该如何更新我的配置?谢谢。

pre-commit pre-commit-hook python-3.x mypy pre-commit.com

3
推荐指数
1
解决办法
2624
查看次数

git precommit hook以确保HEAD是来自master repo的最新版本

我正在将我的团队从旧的CVS存储库转移到使用git.我希望添加一个precommit钩子,以确保在本地完成提交(并推送)之前,每个人都有一个最新的回购.

例如,在CVS中,每个人都会在进行更改之前进行'cvs up',然后进行提交.我想强制它,所以人们不能提交更改,除非他们已经做了git pull origin master第一次(我们不会使用额外的分支)

是否有捷径可寻?欢呼任何帮助:)

git hook pre-commit-hook

2
推荐指数
1
解决办法
1404
查看次数

预提交钩子验证c ++代码

今天我更新了我们的存储库并尝试重新编译它(它是一个c ++应用程序).它不编译.我的第一反应是杀死我的同事,但因为我不能这样做,我需要找到另一个解决方案.

是否可以阻止提交不编译的代码?我们有一个Makefile以及预提交钩子需要做什么,以便检查命令make的输出状态.这样对吗?

如何在实践中实现它(我从未使用过svn hook)?

c++ svn pre-commit-hook

2
推荐指数
1
解决办法
758
查看次数

SVN预提交问题

我在网上发现了这个脚本,很少有人说他们正在为他们的存储库工作.该脚本允许预先提交检查以在检查时强制检查注释.问题是我将它添加到SVN中的hooks目录,现在所有提交(甚至是带注释的提交)都失败并显示此错误消息 "提交被预提交阻止(退出代码255)没有输出"

现在,我无法更改脚本或删除它,因为我得到相同的错误.有关如何还原此预提交脚本的任何建议?

#!/bin/bash # [1] REPOS-PATH (the path to this repository) # [2] TXN-NAME (the name of the txn about to be committed) REPOS="$1" REV="$2" @echo off :: :: Stops commits that have empty log messages. :: @echo off setlocal # rem Subversion sends through the path to the repository and transaction id set REPOS=%1 set TXN=%2 # rem check for an empty log message svnlook log %REPOS% -t %TXN% | findstr . > nul if %errorlevel% gtr 0 …
Run Code Online (Sandbox Code Playgroud)

svn pre-commit-hook

2
推荐指数
1
解决办法
7764
查看次数

我可以像git一样跳过mercurial pre-commit hooks吗?

我想做一些像git commit --no-verifymercurial 这样的事情.有什么办法吗?

git mercurial hook pre-commit pre-commit-hook

2
推荐指数
1
解决办法
416
查看次数

Bash确认将不等待用户输入

我正在尝试使用bash脚本实现确认提示,但是由于某些原因,提示将不等待用户输入。我已经尝试了很多例子,但到目前为止还没有运气。如果有任何不同,我使用MacOS。

我尝试过的几个示例(SO中所有其他答案的所有副本+粘贴):

#!/bin/bash

read -p "Are you sure? " -n 1 -r
echo    # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
    # do dangerous stuff
fi
Run Code Online (Sandbox Code Playgroud)
#!/bin/bash

read -p "Continue (y/n)?" CONT
if [ "$CONT" = "y" ]; then
  echo "yaaa";
else
  echo "booo";
fi
Run Code Online (Sandbox Code Playgroud)
#!/bin/bash

while true; do
read -rsn1 input
if [ "$input" = "a" ]; then
    echo "hello world"
fi
done
Run Code Online (Sandbox Code Playgroud)
#!/bin/bash

read -p "Continue (y/n)?" choice
case "$choice" in
  y|Y …
Run Code Online (Sandbox Code Playgroud)

bash pre-commit-hook githooks

2
推荐指数
2
解决办法
1010
查看次数