Giter VIP home page Giter VIP logo

buildingcodes's Introduction

building-codes is a hook for the pre-commit framework.

The problem that this hook intends to solve is to help with maintaining large-codebases that need to keep up with changes in libraries and languages. The solution offered is to borrow from the concept of building codes from conventional home/building construction. As long as a file is unchanged, it is allowed to use the "old" technology/interface/library. However, when a file is edited it must be brought up to date with current standards. Using this principle, a pre-commit hook is the ideal way to enforce the new standards because it is only run against files that are being committed.

Configuration

building-codes expects a configuration file, .buildingcodes.yaml in the root of the code repository. The purpose of the flie is to specify what to look for and suggest what to replace it with. Not configuring correctly building-codes will produce errors when using the hook. An example is

- pattern: Poco::Path
  message: use something else than Poco::Path
  ignore:
    - file: Framework/Kernel/src/Glob.cpp
    - file: Framework/Kernel/src/ConfigService.cpp
      lines: 189,246
- pattern: Poco::File
  message: use something other than Poco::File
  ignore:
    - file: Framework/Kernel/src/ConfigService.cpp
      lines: 160
- pattern: os.path
  message: use Pathlib instead

Each rule requires a pattern to find on a single line of source code (currently simple string comparison) and a message which will instruct the developer how the code needs to be modernized. While this will not find every occurance that needs to be modernized, it does allow for a large variety to look for. Suppressing a rule in a file can be used with the ignore parameter which has a file parameter and an optional lines parameter. If the lines is not supplied, it is assumed that the entire file should be ignored.

Limitations

This pre-commit hook is registered to work with all languages and does not tokenize the files as more advanced tools (e.g. clang-modernize). As a result, the pattern matching can be fooled by the clever developer.

Use in Continuous Integration

pre-commit points out that it is possible to run pre-commit in CI. If this hoook is only run on files that are changed, then the appropriate behavior will be observed. Otherwise, one should disable this hook in CI or files that do not currently need to be modernized will fail the build.

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.