Ensures all source files have a license header
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-licenses
:
npm install eslint-plugin-licenses --save-dev
Add licenses
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": [
"licenses"
]
}
Then configure the header you want to use
{
"rules": {
"licenses/header": [
2,
{
"comment": "line",
"header": [
"Copyright (c) {YEAR} fallaciousreasoning. All rights reserved."
]
}
]
}
}
The {YEAR} placeholder will be generated as the current year when running eslint --fix
and will match any year (including ones in the future).
If you have existing headers with different formats, you can add them as altHeaders
{
"rules": {
"licenses/header": [
2,
{
"comment": "line",
"header": [
"Copyright (c) {YEAR} fallaciousreasoning. All rights reserved."
],
"altHeaders": [
{
"comment": "block",
"header": [
"",
"Copyright (c) Me, always & forever",
""
]
}
]
}
]
}
}
This will match the headers
// Copyright (c) 2022 fallaciousreasoning. All rights reserved
and
/*
* Copyright (c) Me, always & forever
*/
but when generating fixes will use the first format.