#header #source #license #add #automatic #config-file #language

app licensesnip

A tool to add license headers to your source code

8 releases (stable)

1.6.0 Mar 6, 2024
1.5.0 Jun 23, 2023
1.3.1 May 27, 2022
1.1.2 Mar 31, 2022
0.1.0 Mar 30, 2022

#686 in Development tools

Download history 35/week @ 2024-06-19 4/week @ 2024-06-26 3/week @ 2024-07-03 28/week @ 2024-07-10 85/week @ 2024-07-17 111/week @ 2024-07-24 67/week @ 2024-07-31 58/week @ 2024-08-07 63/week @ 2024-08-14 97/week @ 2024-08-21 75/week @ 2024-08-28 47/week @ 2024-09-04 80/week @ 2024-09-11 117/week @ 2024-09-18 137/week @ 2024-09-25 170/week @ 2024-10-02

515 downloads per month
Used in kicad-api-rs

MIT license

50KB
853 lines

🔑 licensesnip

Tool to automatically add license headers to your source code. Customizable for any language.

Licensesnip is written is Rust and is fast and reliable ⚡.

📦 Install

With Cargo

cargo install licensesnip

📜 Usage

In your project's root directory, add a file named .licensesnip and write your license header there. Licensesnip will automatically replace %FILENAME% with the file name and %YEAR% with the year.

To add license headers to all your source code:

licensesnip

Licensesnip ignores files in your .gitignore file by default. You can also add a file named .licensesnipignore and specify patterns the same way as in a .gitignore file.

To remove license headers from all source code:

licensesnip remove

To check if license headers are present in all of your source files:

licensesnip check

You can also specify a specific path or file to modify:

# Add licenses to src/main.rs
licensesnip src/main.rs
# Remove licenses from src folder
licensesnip remove src/

Pre-commit hook

You can use licensesnip with pre-commit. Add it to your local .pre-commit-config.yaml as follows:

- repo: https://github.com/notken12/licensesnip
  rev: 19b1186 # choose your preferred tag or commit hash
  hooks:
    - id: licensesnip
      args: ["check"] # optionally modify the arguments for licensesnip (default arguments shown here)

⚙️ Configuration

Find your global Licensesnip config file:

licensesnip config

Create/find the local config file for the current directory:

licensesnip config -d

Example configuration:

{
  "use_gitignore": true,
  "file_types": {
    "js,mjs,ts,cjs,jsx,tsx": {
      "before_line": "// "
    },
    "vue,html": {
      "before_block": "<!--",
      "before_line": "  ",
      "after_block": "-->"
    },
    "rs": {
      "before_line": "// "
    },
    "c": {
      "enable": false
    }
  }
}

To configure a language just specify how the comments for that language work. Supported properties are before_line, after_line, before_block, and after_block. To disable adding licenses to a filetype, set enable to false.

❤️ Contribution

I haven't added builtin support for many languages yet. Please help out and add your favorite languages to src/base-config.jsonc and submit a pull request. Thank you!

Dependencies

~7–17MB
~208K SLoC