@tony.ganchev/eslint-plugin-header 3.2.0 → 3.2.1

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 CHANGED
@@ -45,6 +45,10 @@ It addresses the following issus:
45
45
  The plugin supports ESLint 7 / 8 / 9 / 10rc0 (check package.json for details).
46
46
  Both flat config and legacy, hierarchical config can be used.
47
47
 
48
+ The NPM package provides TypeScript type definitions and can be used with
49
+ TypeScript-based ESLint flat configuration without the need for `@ts-ignore`
50
+ statements.
51
+
48
52
  ## Usage
49
53
 
50
54
  The plugin and its _header_ rule goes through evolution of its configuration in
@@ -63,14 +67,27 @@ This _header_ rule takes a single object as configuration, after the severity
63
67
  level. At the very least, the object should contain a `header` field describing
64
68
  the expected header to match in the source files.
65
69
 
70
+ For TypesScript-based flat ESLint configuration, two types are provided:
71
+
72
+ - `HeaderRuleConfig` defines the overall rule configuration for the `header`
73
+ rule and includes severity level and supports both the modern object-based
74
+ configuration and the legacy array-based configuration.
75
+ - `HeaderOptions` helper type that defines the structure of the configuration
76
+ object used in the modern configuration style that is used in this document.
77
+ It can be used to either simplify auto-completion since this type is not mixed
78
+ with a large number of named tuple types, or it can be used when the config
79
+ object is defined outside of the definition of a specific rule.
80
+
66
81
  ### File-based Configuration
67
82
 
68
83
  In this configuration mode, the header template is read from a file.
69
84
 
70
- _eslint.config.mjs_:
85
+ _eslint.config.ts_:
71
86
 
72
- ```js
73
- import header from "@tony.ganchev/eslint-plugin-header";
87
+ ```ts
88
+ import header, {
89
+ HeaderOptions, HeaderRuleConfig
90
+ } from "@tony.ganchev/eslint-plugin-header";
74
91
  import { defineConfig } from "eslint/config";
75
92
 
76
93
  export default defineConfig([
@@ -86,8 +103,8 @@ export default defineConfig([
86
103
  header: {
87
104
  file: "config/header.js"
88
105
  }
89
- }
90
- ]
106
+ } as HeaderOptions
107
+ ] as HeaderRuleConfig
91
108
  }
92
109
  }
93
110
  ]);
@@ -132,8 +149,8 @@ All of the following configurations will match the header:
132
149
 
133
150
  - **Single string**:
134
151
 
135
- ```js
136
- import header from "@tony.ganchev/eslint-plugin-header";
152
+ ```ts
153
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
137
154
  import { defineConfig } from "eslint/config";
138
155
 
139
156
  export default defineConfig([
@@ -150,7 +167,7 @@ All of the following configurations will match the header:
150
167
  commentType: "block",
151
168
  lines: ["\n * Copyright (c) 2015\n * My Company\n "]
152
169
  }
153
- },
170
+ } as HeaderOptions
154
171
  ]
155
172
  }
156
173
  }
@@ -173,8 +190,8 @@ All of the following configurations will match the header:
173
190
  You can match the whole header with a regular expression. To do it, simply
174
191
  pass a `RegExp` object in place of a string.
175
192
 
176
- ```js
177
- import header from "@tony.ganchev/eslint-plugin-header";
193
+ ```ts
194
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
178
195
  import { defineConfig } from "eslint/config";
179
196
 
180
197
  export default defineConfig([
@@ -193,7 +210,7 @@ All of the following configurations will match the header:
193
210
  /\n \* Copyright \(c\) 2015\n \* Company\n /
194
211
  ]
195
212
  }
196
- }
213
+ } as HeaderOptions
197
214
  ]
198
215
  }
199
216
  }
@@ -203,8 +220,8 @@ All of the following configurations will match the header:
203
220
  If you still use hierarchical configuration, you can define the regular
204
221
  expression as a string.
205
222
 
206
- ```js
207
- import header from "@tony.ganchev/eslint-plugin-header";
223
+ ```ts
224
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
208
225
  import { defineConfig } from "eslint/config";
209
226
 
210
227
  export default defineConfig([
@@ -224,7 +241,7 @@ All of the following configurations will match the header:
224
241
  + "\\n \\* My Company\\n "}
225
242
  ]
226
243
  }
227
- }
244
+ } as HeaderOptions
228
245
  ]
229
246
  }
230
247
  }
@@ -239,8 +256,8 @@ All of the following configurations will match the header:
239
256
  you want to add an aut-fix for the line as we will explain further in this
240
257
  document.
241
258
 
242
- ```js
243
- import header from "@tony.ganchev/eslint-plugin-header";
259
+ ```ts
260
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
244
261
  import { defineConfig } from "eslint/config";
245
262
 
246
263
  export default defineConfig([
@@ -259,7 +276,7 @@ All of the following configurations will match the header:
259
276
  { pattern: /Copyright \(c\) 20\d{2}/ }
260
277
  ]
261
278
  }
262
- }
279
+ } as HeaderOptions
263
280
  ]
264
281
  }
265
282
  }
@@ -268,8 +285,8 @@ All of the following configurations will match the header:
268
285
 
269
286
  - **Array of strings**:
270
287
 
271
- ```js
272
- import header from "@tony.ganchev/eslint-plugin-header";
288
+ ```ts
289
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
273
290
  import { defineConfig } from "eslint/config";
274
291
 
275
292
  export default defineConfig([
@@ -291,7 +308,7 @@ All of the following configurations will match the header:
291
308
  " "
292
309
  ]
293
310
  }
294
- }
311
+ } as HeaderOptions
295
312
  ]
296
313
  }
297
314
  }
@@ -300,8 +317,8 @@ All of the following configurations will match the header:
300
317
 
301
318
  - **Array of strings and/or patterns**:
302
319
 
303
- ```js
304
- import header from "@tony.ganchev/eslint-plugin-header";
320
+ ```ts
321
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
305
322
  import { defineConfig } from "eslint/config";
306
323
 
307
324
  export default defineConfig([
@@ -323,7 +340,7 @@ All of the following configurations will match the header:
323
340
  " "
324
341
  ]
325
342
  }
326
- }
343
+ } as HeaderOptions
327
344
  ]
328
345
  }
329
346
  }
@@ -355,8 +372,8 @@ support:
355
372
 
356
373
  We can use a regular expression to support all of these cases for your header:
357
374
 
358
- ```js
359
- import header from "@tony.ganchev/eslint-plugin-header";
375
+ ```ts
376
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
360
377
  import { defineConfig } from "eslint/config";
361
378
 
362
379
  export default defineConfig([
@@ -378,7 +395,7 @@ export default defineConfig([
378
395
  " "
379
396
  ]
380
397
  }
381
- }
398
+ } as HeaderOptions
382
399
  ]
383
400
  }
384
401
  }
@@ -391,8 +408,8 @@ to replace a header comment that did not pass validation. This is not possible
391
408
  with regular expressions. For regular expression pattern-objects, a second
392
409
  property `template` adds a replacement string.
393
410
 
394
- ```js
395
- import header from "@tony.ganchev/eslint-plugin-header";
411
+ ```ts
412
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
396
413
  import { defineConfig } from "eslint/config";
397
414
 
398
415
  export default defineConfig([
@@ -415,7 +432,7 @@ export default defineConfig([
415
432
  " My Company"
416
433
  ]
417
434
  }
418
- }
435
+ } as HeaderOptions
419
436
  ]
420
437
  }
421
438
  }
@@ -437,8 +454,8 @@ number of newlines that are enforced after the header.
437
454
 
438
455
  Zero newlines:
439
456
 
440
- ```js
441
- import header from "@tony.ganchev/eslint-plugin-header";
457
+ ```ts
458
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
442
459
  import { defineConfig } from "eslint/config";
443
460
 
444
461
  export default defineConfig([
@@ -461,7 +478,7 @@ export default defineConfig([
461
478
  trailingEmptyLines: {
462
479
  minimum: 0
463
480
  }
464
- }
481
+ } as HeaderOptions
465
482
  ]
466
483
  }
467
484
  }
@@ -475,8 +492,8 @@ My Company */ console.log(1)
475
492
 
476
493
  One newline (default):
477
494
 
478
- ```js
479
- import header from "@tony.ganchev/eslint-plugin-header";
495
+ ```ts
496
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
480
497
  import { defineConfig } from "eslint/config";
481
498
 
482
499
  export default defineConfig([
@@ -499,7 +516,7 @@ export default defineConfig([
499
516
  trailingEmptyLines: {
500
517
  minimum: 1
501
518
  }
502
- }
519
+ } as HeaderOptions
503
520
  ]
504
521
  }
505
522
  }
@@ -514,8 +531,8 @@ console.log(1)
514
531
 
515
532
  Two newlines:
516
533
 
517
- ```js
518
- import header from "@tony.ganchev/eslint-plugin-header";
534
+ ```ts
535
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
519
536
  import { defineConfig } from "eslint/config";
520
537
 
521
538
  export default defineConfig([
@@ -538,7 +555,7 @@ export default defineConfig([
538
555
  trailingEmptyLines: {
539
556
  minimum: 2
540
557
  }
541
- }
558
+ } as HeaderOptions
542
559
  ]
543
560
  }
544
561
  }
@@ -558,8 +575,8 @@ The rule works with both Unix/POSIX and Windows line endings. For ESLint
558
575
  `--fix`, the rule will use the line ending format of the current operating
559
576
  system (via Node's `os` package). This setting can be overwritten as follows:
560
577
 
561
- ```js
562
- import header from "@tony.ganchev/eslint-plugin-header";
578
+ ```ts
579
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
563
580
  import { defineConfig } from "eslint/config";
564
581
 
565
582
  export default defineConfig([
@@ -580,7 +597,7 @@ export default defineConfig([
580
597
  ]
581
598
  },
582
599
  lineEndings: "windows"
583
- }
600
+ } as HeaderOptions
584
601
  ]
585
602
  }
586
603
  }
@@ -594,8 +611,8 @@ The default value is `"os"` which means assume the system-specific line endings.
594
611
 
595
612
  The following examples are all valid.
596
613
 
597
- ```js
598
- import header from "@tony.ganchev/eslint-plugin-header";
614
+ ```ts
615
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
599
616
  import { defineConfig } from "eslint/config";
600
617
 
601
618
  export default defineConfig([
@@ -612,7 +629,7 @@ export default defineConfig([
612
629
  commentType: "block",
613
630
  lines: ["Copyright 2015, My Company"]
614
631
  }
615
- }
632
+ } as HeaderOptions
616
633
  ]
617
634
  }
618
635
  }
@@ -624,8 +641,8 @@ export default defineConfig([
624
641
  console.log(1);
625
642
  ```
626
643
 
627
- ```js
628
- import header from "@tony.ganchev/eslint-plugin-header";
644
+ ```ts
645
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
629
646
  import { defineConfig } from "eslint/config";
630
647
 
631
648
  export default defineConfig([
@@ -645,7 +662,7 @@ export default defineConfig([
645
662
  "My Company"
646
663
  ]
647
664
  }
648
- }
665
+ } as HeaderOptions
649
666
  ]
650
667
  }
651
668
  }
@@ -658,8 +675,8 @@ export default defineConfig([
658
675
  console.log(1)
659
676
  ```
660
677
 
661
- ```js
662
- import header from "@tony.ganchev/eslint-plugin-header";
678
+ ```ts
679
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
663
680
  import { defineConfig } from "eslint/config";
664
681
 
665
682
  export default defineConfig([
@@ -679,7 +696,7 @@ export default defineConfig([
679
696
  /^My Company$/
680
697
  ]
681
698
  }
682
- }
699
+ } as HeaderOptions
683
700
  ]
684
701
  }
685
702
  }
@@ -694,8 +711,8 @@ console.log(1)
694
711
 
695
712
  With more decoration:
696
713
 
697
- ```js
698
- import header from "@tony.ganchev/eslint-plugin-header";
714
+ ```ts
715
+ import header, { HeaderOptions } from "@tony.ganchev/eslint-plugin-header";
699
716
  import { defineConfig } from "eslint/config";
700
717
 
701
718
  export default defineConfig([
@@ -717,7 +734,7 @@ export default defineConfig([
717
734
  " ************************"
718
735
  ]
719
736
  }
720
- }
737
+ } as HeaderOptions
721
738
  ]
722
739
  }
723
740
  }
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
- module.exports = {
27
+ const { header } = require("./lib/rules/header");
28
+
29
+ /** @type {import('eslint').ESLint.Plugin} */
30
+ const pluginDefinition = {
28
31
  rules: {
29
- "header": require("./lib/rules/header")
30
- },
31
- rulesConfig: {
32
- "header": 0
32
+ header
33
33
  }
34
34
  };
35
+
36
+ module.exports = pluginDefinition;
@@ -24,7 +24,7 @@
24
24
 
25
25
  "use strict";
26
26
 
27
- const assert = require("assert");
27
+ const assert = require("node:assert");
28
28
 
29
29
  /**
30
30
  * Parses a line or block comment and returns the type of comment and an array
@@ -29,11 +29,11 @@ const assert = require("node:assert");
29
29
  const fs = require("node:fs");
30
30
  const path = require("node:path");
31
31
 
32
- const packageJsonContent = fs.readFileSync(path.resolve(__dirname, "../../package.json"));
32
+ const packageJsonContent = fs.readFileSync(path.resolve(__dirname, "../../package.json"), "utf8");
33
33
  const packageJson = JSON.parse(packageJsonContent);
34
34
  assert.equal(Object.prototype.hasOwnProperty.call(packageJson, "version"), true,
35
35
  "The plugin's package.json should be available two directories above the rule.");
36
- const pluginVersion = packageJsonContent.version;
36
+ const pluginVersion = packageJson.version;
37
37
 
38
38
  exports.description = "";
39
39
  exports.recommended = true;