eslint-plugin-header
eslint-plugin-header copied to clipboard
Use placeholder in "template" to set current year
First of all: I love your plugin! It saved me from the cumbersome task of adding a license header to all code that I write during business hours. 🙇
In my config I am using the "template" functionality and I was wondering if it is possible to add placeholders to it so that the current year can be used?
Example:
"header/header": [
"error",
"block",
[
{
"pattern": "Copyright",
"template": "\r\n * Title\r\n * Copyright ({{ currentYear }}) 2021 Company\r\n"
}
],
2
]
To build this feature a templating engine like "Nunjucks" could be used: https://mozilla.github.io/nunjucks/
I did this by converting to .eslintrc.js:
{
rules: [
'header/header': [
'error',
'line',
[
{
pattern: ' Copyright © \\d{4}',
template: ` Copyright © ${new Date().getFullYear()}`,
},
],
2
]
]
}
It would be nice to be able to pass a function that gets the file path so that the years can be based on commit years for the file but, that template gets pretty close and at least works for new files.