【问题标题】:pre-commit --comment-style regex预提交 --comment-style 正则表达式
【发布时间】:2021-10-15 00:04:03
【问题描述】:

我有一个预提交文件,用于检查 .cfg 文件中的注释行格式。当前的注释样式是分号,因此如果对文件 cmets 使用井号,这将失败。 RegEx 可以以某种方式用于匹配多个评论模式吗?例如:

      - --comment-style
      - ';'|'#'|'some other comment'
    files: |
      (?x)(
        \.cfg
      )$

这是预提交测试的来源:

https://github.com/Lucas-C/pre-commit-hooks/blob/master/tests/insert_license_test.py

谢谢。

【问题讨论】:

  • 这不是 pre-commit 的问题——它是使用 --comment-style 的任何工具(您尚未显示,因此无法回答)
  • 好的,谢谢,我会更新的

标签: pre-commit-hook pre-commit


【解决方案1】:

不能

https://github.com/Lucas-C/pre-commit-hooks/blob/556aa509296132b8e2477f0a3e33c9916232e748/pre_commit_hooks/insert_license.py#L32-L35

    parser.add_argument('--comment-style', default='#',
                        help='Can be a single prefix or a triplet: '
                             '<comment-start>|<comment-prefix>|<comment-end>'
                             'E.g.: /*| *| */')

该钩子只允许一种注释类型

【讨论】:

    猜你喜欢
    • 2015-06-30
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多