Giter Site home page Giter Site logo

copyright_notice_precommit's Introduction

copyright-notice-precommit

GitHub PyPI - Python Version Build Status codecov pre-commit.ci status Code quality: Inspector Code style: black

This is a pre-commit hook to make sure you don't forget adding the copyright notice when committing a (new) file.

Usage

If you haven't installed pre-commit yet, please follow the instructions in the official website.

To install this hook, add the following to your .pre-commit-config.yaml:

-   repo: https://github.com/leoll2/copyright_notice_precommit
    rev: latest
    hooks:
    -   id: copyright-notice
        args: [--notice=copyright.txt]

with --notice pointing to a template file containing the copyright to match.

Note: the template file must contain exclusively the copyright notice as text. It's recommended not to insert extra spaces or linebreaks at the beginning and end of the file.

Example

Let's assume this is your copyright notice template file:

# Copyright (C) ACME Inc - All Rights Reserved

Then, this file will pass the pre-commit check:

#!/usr/bin/env python

# Copyright (C) ACME Inc - All Rights Reserved

print("hello world")

Conversely, this one shall NOT pass (due to missing notice):

#!/usr/bin/env python

print("hello world")

License

This hook is released under the MIT License.

Contributing

Do you want to report a bug? Would you like to see new features? Feel free to open an issue or a pull request. All contributions are welcome!

copyright_notice_precommit's People

Contributors

leoll2 avatar pierre-sassoulas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

copyright_notice_precommit's Issues

New Option: --ignore-files

Context:

Some files committed to a repo do not need or do not allow for comments.

Proposed Solution:
--ignore-files=[]

examples:
public_text.txt
small.pkl
*.csp

How/Purpose: ignore files that match the pattern, or if a wildcard is used, ignore files that match the regex pattern created from replacing asterisks with .*

Sync notice and year

Copyright notices which include a year, e.g. Copyright 2021 Acme Co., should be updated when the year changes.1

This pre-commit could support it in various ways:

  1. Check if the template contains a year which is not the current one
  2. Test the source files against a variable-year notice template and flag those files whose year doesn't match the actual one.

1 Actually, depending on the laws, this is not strictly required after the software has been released. It's still useful while the software is being developed, though.

Scan only the first N bytes of the files

The copyright notice is almost always at the beginning of the file, if present. So, if it's found in the first few lines, it's very unlikely that it will be positioned later. This suggests a performance optimization: scan only the first N bytes of each file (how many by default?).

New option: ignore-empty-files

As the name suggests, if --ignore-empty-files is specified, then the hook won't complain about missing notice for files that are empty.

New option: autofix

Add a new optional --autofix flag, which enables inserting a copyright notice automatically at the beginning of those files which don't already have it.

Things to consider

  • if the file contains a shebang and/or a BOM, then the copyright should be inserted immediately after them
  • if the file contains words like "copyright" or "license", chances are that a notice is present but actually invalid. In that case, do not attempt to fix the file, and let the user do it manually.

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.