-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Description
Right now this library can detect if a given header is in violation of the rules specified in a pattern. If the pattern is partially matched, it would be nice to be able to reference capture groups in the pattern and apply those capture groups into the template (if matched), otherwise leave blank.
For example:
Say my header & configuration looked like the following:
Actual behavior
header:
// Copyright 2017-2020 Uber Technologies Inc.
rule:
const currentYear = (new Date()).getFullYear(); // = '2020'
...
{
pattern: ` Copyright (20\\d{2}\\-)?${currentYear} Uber Technologies Inc\.`,
template: ` Copyright ${currentYear} Uber Technologies Inc.`,
}
and time ticked over to 2021
header (fixed):
// Copyright 2021 Uber Technologies Inc.
Desired behavior
header:
// Copyright 2017-2020 Uber Technologies Inc.
rule:
const currentYear = (new Date()).getFullYear(); // = '2020'
...
{
pattern: ` Copyright (?<firstYear>20\\d{2}\\-)?${currentYear} Uber Technologies Inc\.`,
template: ` Copyright (\\k<firstYear>)${currentYear} Uber Technologies Inc.`,
}
When the year ticks over to 2021, it would be nice if it updated current year only, and left first year as-is.
header (fixed):
// Copyright 2017-2021 Uber Technologies Inc.
Metadata
Metadata
Assignees
Labels
No labels