@tony.ganchev/eslint-plugin-header 3.2.0 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +210 -77
- package/index.d.ts +29 -0
- package/index.js +7 -5
- package/lib/comment-parser.js +1 -1
- package/lib/rules/eslint-utils.js +2 -1
- package/lib/rules/header.docs.js +1 -12
- package/lib/rules/header.js +256 -145
- package/lib/rules/header.schema.js +1 -0
- package/package.json +55 -14
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +1 -0
- package/types/lib/comment-parser.d.ts +3 -0
- package/types/lib/comment-parser.d.ts.map +1 -0
- package/types/lib/rules/eslint-utils.d.ts +10 -0
- package/types/lib/rules/eslint-utils.d.ts.map +1 -0
- package/types/lib/rules/header.d.ts +100 -0
- package/types/lib/rules/header.d.ts.map +1 -0
- package/types/lib/rules/header.docs.d.ts +3 -0
- package/types/lib/rules/header.docs.d.ts.map +1 -0
- package/types/lib/rules/header.schema.d.ts +20 -0
- package/types/lib/rules/header.schema.d.ts.map +1 -0
package/README.md
CHANGED
|
@@ -1,49 +1,67 @@
|
|
|
1
|
-
# eslint-plugin-header
|
|
1
|
+
# @tony.ganchev/eslint-plugin-header
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@tony.ganchev/eslint-plugin-header)
|
|
4
|
+
[](http://www.npmtrends.com/@tony.ganchev/eslint-plugin-header)
|
|
5
|
+
[](https://github.com/tonyganchev/eslint-plugin-header)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
The native ESLint 9/10 standard header-validating plugin. A zero-bloat, drop-in
|
|
8
|
+
replacement for [eslint-plugin-header](https://github.com/Stuk/eslint-plugin-header)
|
|
9
|
+
with first-class Flat Config & TypeScript support. Auto-fix copyright, license,
|
|
10
|
+
and banner comments in JavaScript and TypeScript files.
|
|
9
11
|
|
|
10
12
|
## Table of Contents
|
|
11
13
|
|
|
12
|
-
1. [
|
|
14
|
+
1. [Motivation and Acknowledgements](#motivation-and-acknowledgements)
|
|
13
15
|
2. [Compatibility](#compatibility)
|
|
14
16
|
3. [Usage](#usage)
|
|
15
17
|
1. [File-based Configuration](#file-based-configuration)
|
|
16
18
|
2. [Inline Configuration](#inline-configuration)
|
|
17
19
|
1. [Header Contents Configuration](#header-contents-configuration)
|
|
18
|
-
2. [
|
|
19
|
-
3. [
|
|
20
|
-
4. [
|
|
20
|
+
2. [Providing To-year in Auto-fix](#providing-to-year-in-auto-fix)
|
|
21
|
+
3. [Trailing Empty Lines Configuration](#trailing-empty-lines-configuration)
|
|
22
|
+
4. [Line Endings](#line-endings)
|
|
23
|
+
3. [Examples](#examples)
|
|
24
|
+
4. [Comparison to Alternatives](#comparison-to-alternatives)
|
|
25
|
+
1. [Compared to eslint-plugin-headers](#compared-to-eslint-plugin-headers)
|
|
26
|
+
1. [Health Scans](#health-scans)
|
|
27
|
+
2. [Compared to eslint-plugin-license-header](#compared-to-eslint-plugin-license-header)
|
|
21
28
|
5. [Versioning](#versioning)
|
|
22
29
|
1. [What is a Feature?](#what-is-a-feature)
|
|
23
30
|
2. [What is Backward-compatibility?](#what-is-backward-compatibility)
|
|
24
31
|
6. [License](#license)
|
|
25
32
|
|
|
26
|
-
##
|
|
33
|
+
## Motivation and Acknowledgements
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
The plugin started as a fork of [eslint-plugin-header](https://github.com/Stuk/eslint-plugin-header)
|
|
36
|
+
to address missing ESLint 9 compatibility.
|
|
29
37
|
|
|
30
|
-
|
|
38
|
+
Today it addresses the following issues:
|
|
31
39
|
|
|
32
|
-
-
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
|
|
40
|
+
- Support for ESLint 9/10 with a fully-validated configuration schema.
|
|
41
|
+
- Continued support for ESLint 7/8.
|
|
42
|
+
- Complete Windows support.
|
|
43
|
+
- New object-based configuration providing the bases for future enhancements.
|
|
44
|
+
- Continued support for _eslint-plugin-header_ array configuration.
|
|
45
|
+
- Bugfixes where the original project has not been updated for the three
|
|
46
|
+
years before the fork.
|
|
37
47
|
- Fixes issues with she-bangs and empty lines before the header. See PR history
|
|
38
48
|
for more details.
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
- Good error reporting and improved auto-fixes.
|
|
50
|
+
- Complete drop-in-replacement compatibility with existing projects using
|
|
51
|
+
_eslint-plugin-header_.
|
|
52
|
+
|
|
53
|
+
Multiple other projects took from where _eslint-plugin-header_ left off. A
|
|
54
|
+
comparison of the current project to these alternatives is available in a
|
|
55
|
+
dedicated section.
|
|
42
56
|
|
|
43
57
|
## Compatibility
|
|
44
58
|
|
|
45
|
-
The plugin supports ESLint 7 / 8 / 9 /
|
|
46
|
-
|
|
59
|
+
The plugin supports ESLint 7 / 8 / 9 / 10. Both flat config and legacy,
|
|
60
|
+
hierarchical config can be used.
|
|
61
|
+
|
|
62
|
+
The NPM package provides TypeScript type definitions and can be used with
|
|
63
|
+
TypeScript-based ESLint flat configuration without the need for `@ts-ignore`
|
|
64
|
+
statements.
|
|
47
65
|
|
|
48
66
|
## Usage
|
|
49
67
|
|
|
@@ -63,14 +81,27 @@ This _header_ rule takes a single object as configuration, after the severity
|
|
|
63
81
|
level. At the very least, the object should contain a `header` field describing
|
|
64
82
|
the expected header to match in the source files.
|
|
65
83
|
|
|
84
|
+
For TypesScript-based flat ESLint configuration, two types are provided:
|
|
85
|
+
|
|
86
|
+
- `HeaderRuleConfig` defines the overall rule configuration for the `header`
|
|
87
|
+
rule and includes severity level and supports both the modern object-based
|
|
88
|
+
configuration and the legacy array-based configuration.
|
|
89
|
+
- `HeaderOptions` helper type that defines the structure of the configuration
|
|
90
|
+
object used in the modern configuration style that is used in this document.
|
|
91
|
+
It can be used to either simplify auto-completion since this type is not mixed
|
|
92
|
+
with a large number of named tuple types, or it can be used when the config
|
|
93
|
+
object is defined outside of the definition of a specific rule.
|
|
94
|
+
|
|
66
95
|
### File-based Configuration
|
|
67
96
|
|
|
68
97
|
In this configuration mode, the header template is read from a file.
|
|
69
98
|
|
|
70
|
-
_eslint.config.
|
|
99
|
+
_eslint.config.ts_:
|
|
71
100
|
|
|
72
|
-
```
|
|
73
|
-
import header
|
|
101
|
+
```ts
|
|
102
|
+
import header, {
|
|
103
|
+
HeaderOptions, HeaderRuleConfig
|
|
104
|
+
} from "@tony.ganchev/eslint-plugin-header";
|
|
74
105
|
import { defineConfig } from "eslint/config";
|
|
75
106
|
|
|
76
107
|
export default defineConfig([
|
|
@@ -86,8 +117,8 @@ export default defineConfig([
|
|
|
86
117
|
header: {
|
|
87
118
|
file: "config/header.js"
|
|
88
119
|
}
|
|
89
|
-
}
|
|
90
|
-
]
|
|
120
|
+
} as HeaderOptions
|
|
121
|
+
] as HeaderRuleConfig
|
|
91
122
|
}
|
|
92
123
|
}
|
|
93
124
|
]);
|
|
@@ -132,8 +163,8 @@ All of the following configurations will match the header:
|
|
|
132
163
|
|
|
133
164
|
- **Single string**:
|
|
134
165
|
|
|
135
|
-
```
|
|
136
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
166
|
+
```ts
|
|
167
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
137
168
|
import { defineConfig } from "eslint/config";
|
|
138
169
|
|
|
139
170
|
export default defineConfig([
|
|
@@ -150,7 +181,7 @@ All of the following configurations will match the header:
|
|
|
150
181
|
commentType: "block",
|
|
151
182
|
lines: ["\n * Copyright (c) 2015\n * My Company\n "]
|
|
152
183
|
}
|
|
153
|
-
}
|
|
184
|
+
} as HeaderOptions
|
|
154
185
|
]
|
|
155
186
|
}
|
|
156
187
|
}
|
|
@@ -173,8 +204,8 @@ All of the following configurations will match the header:
|
|
|
173
204
|
You can match the whole header with a regular expression. To do it, simply
|
|
174
205
|
pass a `RegExp` object in place of a string.
|
|
175
206
|
|
|
176
|
-
```
|
|
177
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
207
|
+
```ts
|
|
208
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
178
209
|
import { defineConfig } from "eslint/config";
|
|
179
210
|
|
|
180
211
|
export default defineConfig([
|
|
@@ -193,7 +224,7 @@ All of the following configurations will match the header:
|
|
|
193
224
|
/\n \* Copyright \(c\) 2015\n \* Company\n /
|
|
194
225
|
]
|
|
195
226
|
}
|
|
196
|
-
}
|
|
227
|
+
} as HeaderOptions
|
|
197
228
|
]
|
|
198
229
|
}
|
|
199
230
|
}
|
|
@@ -203,8 +234,8 @@ All of the following configurations will match the header:
|
|
|
203
234
|
If you still use hierarchical configuration, you can define the regular
|
|
204
235
|
expression as a string.
|
|
205
236
|
|
|
206
|
-
```
|
|
207
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
237
|
+
```ts
|
|
238
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
208
239
|
import { defineConfig } from "eslint/config";
|
|
209
240
|
|
|
210
241
|
export default defineConfig([
|
|
@@ -224,7 +255,7 @@ All of the following configurations will match the header:
|
|
|
224
255
|
+ "\\n \\* My Company\\n "}
|
|
225
256
|
]
|
|
226
257
|
}
|
|
227
|
-
}
|
|
258
|
+
} as HeaderOptions
|
|
228
259
|
]
|
|
229
260
|
}
|
|
230
261
|
}
|
|
@@ -239,8 +270,8 @@ All of the following configurations will match the header:
|
|
|
239
270
|
you want to add an aut-fix for the line as we will explain further in this
|
|
240
271
|
document.
|
|
241
272
|
|
|
242
|
-
```
|
|
243
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
273
|
+
```ts
|
|
274
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
244
275
|
import { defineConfig } from "eslint/config";
|
|
245
276
|
|
|
246
277
|
export default defineConfig([
|
|
@@ -259,7 +290,7 @@ All of the following configurations will match the header:
|
|
|
259
290
|
{ pattern: /Copyright \(c\) 20\d{2}/ }
|
|
260
291
|
]
|
|
261
292
|
}
|
|
262
|
-
}
|
|
293
|
+
} as HeaderOptions
|
|
263
294
|
]
|
|
264
295
|
}
|
|
265
296
|
}
|
|
@@ -268,8 +299,8 @@ All of the following configurations will match the header:
|
|
|
268
299
|
|
|
269
300
|
- **Array of strings**:
|
|
270
301
|
|
|
271
|
-
```
|
|
272
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
302
|
+
```ts
|
|
303
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
273
304
|
import { defineConfig } from "eslint/config";
|
|
274
305
|
|
|
275
306
|
export default defineConfig([
|
|
@@ -291,7 +322,7 @@ All of the following configurations will match the header:
|
|
|
291
322
|
" "
|
|
292
323
|
]
|
|
293
324
|
}
|
|
294
|
-
}
|
|
325
|
+
} as HeaderOptions
|
|
295
326
|
]
|
|
296
327
|
}
|
|
297
328
|
}
|
|
@@ -300,8 +331,8 @@ All of the following configurations will match the header:
|
|
|
300
331
|
|
|
301
332
|
- **Array of strings and/or patterns**:
|
|
302
333
|
|
|
303
|
-
```
|
|
304
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
334
|
+
```ts
|
|
335
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
305
336
|
import { defineConfig } from "eslint/config";
|
|
306
337
|
|
|
307
338
|
export default defineConfig([
|
|
@@ -323,7 +354,7 @@ All of the following configurations will match the header:
|
|
|
323
354
|
" "
|
|
324
355
|
]
|
|
325
356
|
}
|
|
326
|
-
}
|
|
357
|
+
} as HeaderOptions
|
|
327
358
|
]
|
|
328
359
|
}
|
|
329
360
|
}
|
|
@@ -355,8 +386,8 @@ support:
|
|
|
355
386
|
|
|
356
387
|
We can use a regular expression to support all of these cases for your header:
|
|
357
388
|
|
|
358
|
-
```
|
|
359
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
389
|
+
```ts
|
|
390
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
360
391
|
import { defineConfig } from "eslint/config";
|
|
361
392
|
|
|
362
393
|
export default defineConfig([
|
|
@@ -378,7 +409,7 @@ export default defineConfig([
|
|
|
378
409
|
" "
|
|
379
410
|
]
|
|
380
411
|
}
|
|
381
|
-
}
|
|
412
|
+
} as HeaderOptions
|
|
382
413
|
]
|
|
383
414
|
}
|
|
384
415
|
}
|
|
@@ -391,8 +422,8 @@ to replace a header comment that did not pass validation. This is not possible
|
|
|
391
422
|
with regular expressions. For regular expression pattern-objects, a second
|
|
392
423
|
property `template` adds a replacement string.
|
|
393
424
|
|
|
394
|
-
```
|
|
395
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
425
|
+
```ts
|
|
426
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
396
427
|
import { defineConfig } from "eslint/config";
|
|
397
428
|
|
|
398
429
|
export default defineConfig([
|
|
@@ -415,7 +446,7 @@ export default defineConfig([
|
|
|
415
446
|
" My Company"
|
|
416
447
|
]
|
|
417
448
|
}
|
|
418
|
-
}
|
|
449
|
+
} as HeaderOptions
|
|
419
450
|
]
|
|
420
451
|
}
|
|
421
452
|
}
|
|
@@ -430,6 +461,44 @@ There are a number of things to consider:
|
|
|
430
461
|
- Templates are hardcoded strings therefore it may be better to hand-fix a bad
|
|
431
462
|
header in order not to lose the from- and to-years in the copyright notice.
|
|
432
463
|
|
|
464
|
+
#### Providing To-year in Auto-fix
|
|
465
|
+
|
|
466
|
+
A common request across similar plugins is to provide for `{year}` variable to
|
|
467
|
+
not change the ESLint configuration every year. While such special requests were
|
|
468
|
+
relevant to old JSON-based configuration, this can be handled with JavaScript in
|
|
469
|
+
the flat configuration format:
|
|
470
|
+
|
|
471
|
+
```ts
|
|
472
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
473
|
+
import { defineConfig } from "eslint/config";
|
|
474
|
+
|
|
475
|
+
export default defineConfig([
|
|
476
|
+
{
|
|
477
|
+
files: ["**/*.js"],
|
|
478
|
+
plugins: {
|
|
479
|
+
"@tony.ganchev": header
|
|
480
|
+
},
|
|
481
|
+
rules: {
|
|
482
|
+
"@tony.ganchev/header": [
|
|
483
|
+
"error",
|
|
484
|
+
{
|
|
485
|
+
header: {
|
|
486
|
+
commentType: "line",
|
|
487
|
+
lines: [
|
|
488
|
+
{
|
|
489
|
+
pattern: / Copyright \(c\) (\d{4}-)?\d{4}/,
|
|
490
|
+
template: ` Copyright ${new Date().getFullYear()}`,
|
|
491
|
+
},
|
|
492
|
+
" My Company"
|
|
493
|
+
]
|
|
494
|
+
}
|
|
495
|
+
} as HeaderOptions
|
|
496
|
+
]
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
]);
|
|
500
|
+
```
|
|
501
|
+
|
|
433
502
|
#### Trailing Empty Lines Configuration
|
|
434
503
|
|
|
435
504
|
The third argument of the rule configuration which defaults to 1 specifies the
|
|
@@ -437,8 +506,8 @@ number of newlines that are enforced after the header.
|
|
|
437
506
|
|
|
438
507
|
Zero newlines:
|
|
439
508
|
|
|
440
|
-
```
|
|
441
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
509
|
+
```ts
|
|
510
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
442
511
|
import { defineConfig } from "eslint/config";
|
|
443
512
|
|
|
444
513
|
export default defineConfig([
|
|
@@ -461,7 +530,7 @@ export default defineConfig([
|
|
|
461
530
|
trailingEmptyLines: {
|
|
462
531
|
minimum: 0
|
|
463
532
|
}
|
|
464
|
-
}
|
|
533
|
+
} as HeaderOptions
|
|
465
534
|
]
|
|
466
535
|
}
|
|
467
536
|
}
|
|
@@ -475,8 +544,8 @@ My Company */ console.log(1)
|
|
|
475
544
|
|
|
476
545
|
One newline (default):
|
|
477
546
|
|
|
478
|
-
```
|
|
479
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
547
|
+
```ts
|
|
548
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
480
549
|
import { defineConfig } from "eslint/config";
|
|
481
550
|
|
|
482
551
|
export default defineConfig([
|
|
@@ -499,7 +568,7 @@ export default defineConfig([
|
|
|
499
568
|
trailingEmptyLines: {
|
|
500
569
|
minimum: 1
|
|
501
570
|
}
|
|
502
|
-
}
|
|
571
|
+
} as HeaderOptions
|
|
503
572
|
]
|
|
504
573
|
}
|
|
505
574
|
}
|
|
@@ -514,8 +583,8 @@ console.log(1)
|
|
|
514
583
|
|
|
515
584
|
Two newlines:
|
|
516
585
|
|
|
517
|
-
```
|
|
518
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
586
|
+
```ts
|
|
587
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
519
588
|
import { defineConfig } from "eslint/config";
|
|
520
589
|
|
|
521
590
|
export default defineConfig([
|
|
@@ -538,7 +607,7 @@ export default defineConfig([
|
|
|
538
607
|
trailingEmptyLines: {
|
|
539
608
|
minimum: 2
|
|
540
609
|
}
|
|
541
|
-
}
|
|
610
|
+
} as HeaderOptions
|
|
542
611
|
]
|
|
543
612
|
}
|
|
544
613
|
}
|
|
@@ -558,8 +627,8 @@ The rule works with both Unix/POSIX and Windows line endings. For ESLint
|
|
|
558
627
|
`--fix`, the rule will use the line ending format of the current operating
|
|
559
628
|
system (via Node's `os` package). This setting can be overwritten as follows:
|
|
560
629
|
|
|
561
|
-
```
|
|
562
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
630
|
+
```ts
|
|
631
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
563
632
|
import { defineConfig } from "eslint/config";
|
|
564
633
|
|
|
565
634
|
export default defineConfig([
|
|
@@ -580,7 +649,7 @@ export default defineConfig([
|
|
|
580
649
|
]
|
|
581
650
|
},
|
|
582
651
|
lineEndings: "windows"
|
|
583
|
-
}
|
|
652
|
+
} as HeaderOptions
|
|
584
653
|
]
|
|
585
654
|
}
|
|
586
655
|
}
|
|
@@ -590,12 +659,12 @@ export default defineConfig([
|
|
|
590
659
|
Possible values are `"unix"` for `\n` and `"windows"` for `\r\n` line endings.
|
|
591
660
|
The default value is `"os"` which means assume the system-specific line endings.
|
|
592
661
|
|
|
593
|
-
|
|
662
|
+
### Examples
|
|
594
663
|
|
|
595
664
|
The following examples are all valid.
|
|
596
665
|
|
|
597
|
-
```
|
|
598
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
666
|
+
```ts
|
|
667
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
599
668
|
import { defineConfig } from "eslint/config";
|
|
600
669
|
|
|
601
670
|
export default defineConfig([
|
|
@@ -612,7 +681,7 @@ export default defineConfig([
|
|
|
612
681
|
commentType: "block",
|
|
613
682
|
lines: ["Copyright 2015, My Company"]
|
|
614
683
|
}
|
|
615
|
-
}
|
|
684
|
+
} as HeaderOptions
|
|
616
685
|
]
|
|
617
686
|
}
|
|
618
687
|
}
|
|
@@ -624,8 +693,8 @@ export default defineConfig([
|
|
|
624
693
|
console.log(1);
|
|
625
694
|
```
|
|
626
695
|
|
|
627
|
-
```
|
|
628
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
696
|
+
```ts
|
|
697
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
629
698
|
import { defineConfig } from "eslint/config";
|
|
630
699
|
|
|
631
700
|
export default defineConfig([
|
|
@@ -645,7 +714,7 @@ export default defineConfig([
|
|
|
645
714
|
"My Company"
|
|
646
715
|
]
|
|
647
716
|
}
|
|
648
|
-
}
|
|
717
|
+
} as HeaderOptions
|
|
649
718
|
]
|
|
650
719
|
}
|
|
651
720
|
}
|
|
@@ -658,8 +727,8 @@ export default defineConfig([
|
|
|
658
727
|
console.log(1)
|
|
659
728
|
```
|
|
660
729
|
|
|
661
|
-
```
|
|
662
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
730
|
+
```ts
|
|
731
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
663
732
|
import { defineConfig } from "eslint/config";
|
|
664
733
|
|
|
665
734
|
export default defineConfig([
|
|
@@ -679,7 +748,7 @@ export default defineConfig([
|
|
|
679
748
|
/^My Company$/
|
|
680
749
|
]
|
|
681
750
|
}
|
|
682
|
-
}
|
|
751
|
+
} as HeaderOptions
|
|
683
752
|
]
|
|
684
753
|
}
|
|
685
754
|
}
|
|
@@ -694,8 +763,8 @@ console.log(1)
|
|
|
694
763
|
|
|
695
764
|
With more decoration:
|
|
696
765
|
|
|
697
|
-
```
|
|
698
|
-
import header from "@tony.ganchev/eslint-plugin-header";
|
|
766
|
+
```ts
|
|
767
|
+
import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
|
|
699
768
|
import { defineConfig } from "eslint/config";
|
|
700
769
|
|
|
701
770
|
export default defineConfig([
|
|
@@ -717,7 +786,7 @@ export default defineConfig([
|
|
|
717
786
|
" ************************"
|
|
718
787
|
]
|
|
719
788
|
}
|
|
720
|
-
}
|
|
789
|
+
} as HeaderOptions
|
|
721
790
|
]
|
|
722
791
|
}
|
|
723
792
|
}
|
|
@@ -732,6 +801,70 @@ export default defineConfig([
|
|
|
732
801
|
console.log(1);
|
|
733
802
|
```
|
|
734
803
|
|
|
804
|
+
## Comparison to Alternatives
|
|
805
|
+
|
|
806
|
+
A number of projects have been aiming to solve problems similar to
|
|
807
|
+
_\@tony.ganchev/eslint-plugin-header_ - mainly with respect to providing ESLint
|
|
808
|
+
9 support. The section below tries to outline why developers may choose either.
|
|
809
|
+
The evaluation is based on the versions of each project as of the time of
|
|
810
|
+
publishing the current version of _\@tony.ganchev/eslint-plugin-header_.
|
|
811
|
+
|
|
812
|
+
Further iterations of this document would add migration information.
|
|
813
|
+
|
|
814
|
+
### Compared to [eslint-plugin-headers](https://github.com/robmisasi/eslint-plugin-headers)
|
|
815
|
+
|
|
816
|
+
_\@tony.ganchev/eslint-plugin-header_ is a drop-in replacement for
|
|
817
|
+
_eslint-plugin-header_ and all plugins that already use the latter can migrate
|
|
818
|
+
to the fork right away. At the same time, it provides improved user experience
|
|
819
|
+
and windows support.
|
|
820
|
+
|
|
821
|
+
eslint-plugin-headers is not a drop-in replacement. It offers additional
|
|
822
|
+
features. Some of them, such as support for Vue templates do not have an
|
|
823
|
+
analogue in the current version of _\@tony.ganchev/eslint-plugin-header_ while
|
|
824
|
+
others such as `{year}` variable placeholders are redundant in the world of
|
|
825
|
+
ESLint 9's flat, JavaScript-based configuration as [already pointed out in this
|
|
826
|
+
document](#providing-to-year-in-auto-fix).
|
|
827
|
+
|
|
828
|
+
The configuration format philosophy of the two plugin differs.
|
|
829
|
+
_\@tony.ganchev/eslint-plugin-header_ supports both the legacy model inherited
|
|
830
|
+
from _eslint-plugin-header_ and a new object-based configuration that is easy to
|
|
831
|
+
adopt and offers both a lot of power to the user as to what the headers should
|
|
832
|
+
look like, and keeps the configuration compact - just a few lines defining the
|
|
833
|
+
content inside the comment. At the same time, the configuration is structured in
|
|
834
|
+
a way that can evolve without breaking compatibility, which is critical for a
|
|
835
|
+
tool that is not differentiating for the critical delivery of teams.
|
|
836
|
+
|
|
837
|
+
_eslint-plugin-headers_ also offers an object-based format, but the content is
|
|
838
|
+
flat and may need breaking changes to be kept concise as new features come
|
|
839
|
+
about. Further, it makes assumption that then need to be corrected such as a
|
|
840
|
+
block comment starting with `/**` instead of `/*` by default. The correction
|
|
841
|
+
needs to happen not by adjusting the header template but through a separate
|
|
842
|
+
confusing configuration properties.
|
|
843
|
+
Overall, the configuration tends to be noisier nad harder to read than that of
|
|
844
|
+
_\@tony.ganchev/eslint-plugin-header_.
|
|
845
|
+
|
|
846
|
+
#### Health Scans
|
|
847
|
+
|
|
848
|
+
- _\@tony.ganchev/eslint-plugin-header_</th> -
|
|
849
|
+
[snyk.io](https://security.snyk.io/package/npm/%40tony.ganchev%2Feslint-plugin-header),
|
|
850
|
+
[socket.dev](https://socket.dev/npm/package/@tony.ganchev/eslint-plugin-header/overview/3.2.2)
|
|
851
|
+
|
|
852
|
+
- _eslint-plugin-headers_ -
|
|
853
|
+
[snyk.io](https://security.snyk.io/package/npm/eslint-plugin-headers),
|
|
854
|
+
[socket.dev](https://socket.dev/npm/package/eslint-plugin-headers/overview/1.3.4)
|
|
855
|
+
|
|
856
|
+
At the time of the publishing of the current version of
|
|
857
|
+
_\@tony.ganchev/eslint-plugin-header_, the latter has a slight edge in both
|
|
858
|
+
scans against _eslint-plugin-headers_.
|
|
859
|
+
|
|
860
|
+
### Compared to [eslint-plugin-license-header](https://github.com/nikku/eslint-plugin-license-header)
|
|
861
|
+
|
|
862
|
+
_eslint-plugin-license-header_ per its limited documentation does not have a lot
|
|
863
|
+
of features including not matching arbitrary from-years in the copyright notice.
|
|
864
|
+
This on one hand leads to it having a nice, dead-simple configuration, but means
|
|
865
|
+
no complex multi-year project would be happy with it. Surprisingly, given the
|
|
866
|
+
limited feature set, the plugin has more peer dependencies than the competition.
|
|
867
|
+
|
|
735
868
|
## Versioning
|
|
736
869
|
|
|
737
870
|
The project follows standard [NPM semantic versioning policy](
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2026-present Tony Ganchev and contributors
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the “Software”), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export { HeaderOptions, HeaderRuleConfig } from "./types/lib/rules/header";
|
|
26
|
+
|
|
27
|
+
import plugin = require("./types");
|
|
28
|
+
|
|
29
|
+
export default plugin;
|
package/index.js
CHANGED
|
@@ -24,11 +24,13 @@
|
|
|
24
24
|
|
|
25
25
|
"use strict";
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const { header } = require("./lib/rules/header");
|
|
28
|
+
|
|
29
|
+
/** @type {import('eslint').ESLint.Plugin} */
|
|
30
|
+
const pluginDefinition = {
|
|
28
31
|
rules: {
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
rulesConfig: {
|
|
32
|
-
"header": 0
|
|
32
|
+
header
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
+
|
|
36
|
+
module.exports = pluginDefinition;
|
package/lib/comment-parser.js
CHANGED
|
@@ -37,6 +37,7 @@ module.exports = {
|
|
|
37
37
|
* @returns {SourceCode} the source-code object.
|
|
38
38
|
*/
|
|
39
39
|
contextSourceCode: function(context) {
|
|
40
|
-
return context.sourceCode
|
|
40
|
+
return context.sourceCode
|
|
41
|
+
|| /** @type {RuleContext & { getSourceCode: () => SourceCode }} */(context).getSourceCode();
|
|
41
42
|
}
|
|
42
43
|
};
|
package/lib/rules/header.docs.js
CHANGED
|
@@ -25,16 +25,5 @@
|
|
|
25
25
|
|
|
26
26
|
"use strict";
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
const fs = require("node:fs");
|
|
30
|
-
const path = require("node:path");
|
|
31
|
-
|
|
32
|
-
const packageJsonContent = fs.readFileSync(path.resolve(__dirname, "../../package.json"));
|
|
33
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
34
|
-
assert.equal(Object.prototype.hasOwnProperty.call(packageJson, "version"), true,
|
|
35
|
-
"The plugin's package.json should be available two directories above the rule.");
|
|
36
|
-
const pluginVersion = packageJsonContent.version;
|
|
37
|
-
|
|
38
|
-
exports.description = "";
|
|
28
|
+
exports.description = "The rule validates that the source file starts with a specific header comment pattern.";
|
|
39
29
|
exports.recommended = true;
|
|
40
|
-
exports.url = "https://www.npmjs.com/package/@tony.ganchev/eslint-plugin-header/v/" + pluginVersion;
|