Giter VIP home page Giter VIP logo

pre-commit-hooks's Introduction

pre_commit_hooks


Table of Contents

Usage

check-header-footer

Some example usages of this are to check for the License or Copyright header. For the footer the use case presented in the example is for a specific doxygen tag,

Arguments:

  • --lines: How many lines to search from the top of the file.
  • --footer-lines: How many lines to search from the bottom of the file.
  • --header-config: <config_filename>:comma,separated,rules to apply to the header check.
  • --footer-config: <config_filename>:comma,separated,rules to apply to the footer check.

The config file is a json of {rule: expected lines}. The lines are separated using an array. Internally we use a regex comparison to find the exact strings.

// config.json Example
{
    "license": [
        "# SPDX-FileCopyrightText: 2022-present adehad <[email protected]>",
        "#",
        "# SPDX-License-Identifier: GPL-3.0-or-later"
    ],
    "c_license": [
        "/*",
        " * Copyright (c) 2023 COMPANY_NAME",
        " * All rights reserved",
        " */"
    ],
    "doxygen": [
        "/// @}"
    ]
}

With pre-commit we can specify the types_or for specific file types, and restrict to a subset of files. Running header and footer checks at the same time.

repos:
  - repo: https://github.com/adehad/pre-commit-hooks
    rev: main
    hooks:
      - id: check-header-footer
        files: ^Source/(?!Generated).*
        types_or: [c, c++]
        args:
          - --header-config=config.json:c_license
          - --footer-config=config.json:doxygen

or for verbosity the header and footer stages can be isolated, this can be used for checking the header and footer separated (see below) or can be used to select different rules for different languages.

repos:
  - repo: https://github.com/adehad/pre-commit-hooks
    rev: main
    hooks:
      - id: check-header-footer
        name: Checking for License
        files: ^Source/(?!Generated).*
        types_or: [c, c++]
        args:
          - --header-config=config.json:c_license
  - repo: https://github.com/adehad/pre-commit-hooks
    rev: main
    hooks:
      - id: check-header-footer
        name: Checking for Doxygen file group
        files: ^Source/(?!Generated).*
        types_or: [c, c++]
        args:
          - --footer-config=config.json:doxygen

Future work:

  1. Support a year parameter that can be used to apply fixes.

Local Installation

pipx install git+https://github.com/adehad/pre-commit-hooks.git@main

Development

hatch shell
hatch run lint
hatch run docs
hatch run cov

License

pre_commit_hooks is distributed under the terms of the GPL-3.0-or-later license.

pre-commit-hooks's People

Contributors

adehad avatar pre-commit-ci[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.