Search code examples
pre-commit-hookpre-commit

pre-commit --comment-style regex


I have a precommit file which checks for commented line format in .cfg files. The current comment style is a semicolon, so this will fail if a pound sign is used for file comments. Can RegEx somehow be used to match multiple comment patterns? For example:

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

This is the source of the precommit test:

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

Thanks.


Solution

  • it cannot

    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.: /*| *| */')
    

    there is only one comment type that is allowed by that hook