@tony.ganchev/eslint-plugin-header 3.2.4 → 3.2.5
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/CONTRIBUTING.md +8 -8
- package/LICENSE.md +2 -1
- package/index.d.ts +5 -5
- package/index.js +6 -6
- package/lib/comment-parser.js +9 -8
- package/lib/rules/eslint-utils.js +8 -8
- package/lib/rules/header.docs.js +5 -6
- package/lib/rules/header.js +200 -123
- package/lib/rules/header.schema.js +7 -6
- package/package.json +24 -25
- package/types/index.d.ts +1 -1
- package/types/lib/comment-parser.d.ts +1 -1
- package/types/lib/comment-parser.d.ts.map +1 -1
- package/types/lib/rules/header.d.ts +88 -53
- package/types/lib/rules/header.d.ts.map +1 -1
- package/types/lib/rules/header.schema.d.ts +1 -1
- package/types/lib/rules/header.schema.d.ts.map +1 -1
package/CONTRIBUTING.md
CHANGED
|
@@ -45,20 +45,20 @@ There are two product lines as of today:
|
|
|
45
45
|
After cloning the repository you can try to do a full CI/CD run:
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
|
-
$
|
|
48
|
+
$ pnpm install
|
|
49
49
|
...
|
|
50
|
-
$
|
|
50
|
+
$ pnpm run test
|
|
51
51
|
...
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
It will run a number of other npm scripts that together verify the code:
|
|
55
55
|
|
|
56
|
-
| script
|
|
57
|
-
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
56
|
+
| script | Description |
|
|
57
|
+
|--------------|---------------------------------------------------------------|
|
|
58
|
+
| `pnpm lint` | Lints the source and docs. |
|
|
59
|
+
| `pnpm unit` | Runs all mocha unit tests. |
|
|
60
|
+
| `pnpm build` | Generates TypeScript bindings. Prerequisite for E2E tests. |
|
|
61
|
+
| `pnpm e2e` | Runs E2E smoke tests for all supported versions of ESLint. |
|
|
62
62
|
|
|
63
63
|
## Development
|
|
64
64
|
|
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2015-present Stuart Knightley
|
|
3
|
+
Copyright (c) 2015-present Stuart Knightley and contributors
|
|
4
|
+
Copyright (c) 2024-present Tony Ganchev
|
|
4
5
|
|
|
5
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
7
|
this software and associated documentation files (the “Software”), to deal in
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2026
|
|
5
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @file Entry point `index.js` type definitions to support TypeScript-based
|
|
3
|
+
* ESLint configuration. Ensures only the public interfaces are exposed.
|
|
4
|
+
* @copyright Copyright (c) 2026 Tony Ganchev
|
|
5
|
+
* @license MIT
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the “Software”), to deal
|
|
8
8
|
* in the Software without restriction, including without limitation the rights
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c)
|
|
5
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @file Entry point for the plugin.
|
|
3
|
+
* @copyright Copyright (c) 2015-present Stuart Knightley and contributors
|
|
4
|
+
* @copyright Copyright (c) 2025-2026 Tony Ganchev
|
|
5
|
+
* @license MIT
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the “Software”), to deal
|
|
8
8
|
* in the Software without restriction, including without limitation the rights
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
const { header } = require("./lib/rules/header");
|
|
28
28
|
|
|
29
|
-
/** @type {import(
|
|
29
|
+
/** @type {import("eslint").ESLint.Plugin} */
|
|
30
30
|
const pluginDefinition = {
|
|
31
31
|
rules: {
|
|
32
32
|
header
|
package/lib/comment-parser.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c)
|
|
5
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @file Parsing utility for JavaScript comments to get text content and type.
|
|
3
|
+
* @copyright Copyright (c) 2015-present Stuart Knightley and contributors
|
|
4
|
+
* @copyright Copyright (c) 2025-2026 Tony Ganchev
|
|
5
|
+
* @license MIT
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the “Software”), to deal
|
|
8
8
|
* in the Software without restriction, including without limitation the rights
|
|
@@ -32,9 +32,10 @@ const assert = require("node:assert");
|
|
|
32
32
|
*
|
|
33
33
|
* This is a really simple and dumb parser, that looks just for a
|
|
34
34
|
* single kind of comment. It won't detect multiple block comments.
|
|
35
|
-
* @param {string} commentText
|
|
36
|
-
* @returns {[
|
|
37
|
-
*
|
|
35
|
+
* @param {string} commentText Content to parse.
|
|
36
|
+
* @returns {[import("./rules/header").CommentType, string[]]} Comment type and
|
|
37
|
+
* comment content broken into lines.
|
|
38
|
+
* @throws {Error} If `commentText` starts with an unrecognized comment token.
|
|
38
39
|
*/
|
|
39
40
|
module.exports = function commentParser(commentText) {
|
|
40
41
|
assert.strictEqual(typeof commentText, "string");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025-
|
|
5
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @file Utilities to bridge incompatible versions of ESLint APIs. Currently it
|
|
3
|
+
* wraps methods removed in ESLint 10 but required for ESLint 7.
|
|
4
|
+
* @copyright Copyright (c) 2025-2026 Tony Ganchev
|
|
5
|
+
* @license MIT
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the “Software”), to deal
|
|
8
8
|
* in the Software without restriction, including without limitation the rights
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"use strict";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* @typedef {import(
|
|
29
|
-
* @typedef {import(
|
|
28
|
+
* @typedef {import("eslint").Rule.RuleContext} RuleContext
|
|
29
|
+
* @typedef {import("eslint").SourceCode} SourceCode
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
module.exports = {
|
|
@@ -34,7 +34,7 @@ module.exports = {
|
|
|
34
34
|
* Provides compatibility wrapper for ESLint 7 through 10 for getting the
|
|
35
35
|
* full source code object from the execution context.
|
|
36
36
|
* @param {RuleContext} context ESLint execution context.
|
|
37
|
-
* @returns {SourceCode}
|
|
37
|
+
* @returns {SourceCode} The source-code object.
|
|
38
38
|
*/
|
|
39
39
|
contextSourceCode: function(context) {
|
|
40
40
|
return context.sourceCode
|
package/lib/rules/header.docs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025-
|
|
5
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @file Constants to use when constructing the metadata of the `header` rule.
|
|
3
|
+
* It aims to reduce the size of the already large main header.js.
|
|
4
|
+
* @copyright Copyright (c) 2025-2026 Tony Ganchev
|
|
5
|
+
* @license MIT
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the “Software”), to deal
|
|
8
8
|
* in the Software without restriction, including without limitation the rights
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
26
25
|
"use strict";
|
|
27
26
|
|
|
28
27
|
exports.description = "The rule validates that the source file starts with a specific header comment pattern.";
|
package/lib/rules/header.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c)
|
|
5
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @file Header validation rule implementation.
|
|
3
|
+
* @copyright Copyright (c) 2015-present Stuart Knightley and contributors
|
|
4
|
+
* @copyright Copyright (c) 2024-2026 Tony Ganchev
|
|
5
|
+
* @license MIT
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the “Software”), to deal
|
|
8
8
|
* in the Software without restriction, including without limitation the rights
|
|
@@ -33,66 +33,117 @@ const { description, recommended } = require("./header.docs");
|
|
|
33
33
|
const { lineEndingOptions, commentTypeOptions, schema } = require("./header.schema");
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
* @typedef {
|
|
39
|
-
* @typedef {
|
|
40
|
-
* @typedef {
|
|
41
|
-
* @typedef {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* @typedef {
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
55
|
-
*
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* }
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* }
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* @
|
|
86
|
-
* }
|
|
36
|
+
* @import { Linter, Rule } from "eslint"
|
|
37
|
+
* @import { Comment, SourceLocation, Program } from "estree"
|
|
38
|
+
* @typedef {Rule.NodeListener} NodeListener
|
|
39
|
+
* @typedef {Rule.ReportFixer} ReportFixer
|
|
40
|
+
* @typedef {Rule.RuleFixer} RuleFixer
|
|
41
|
+
* @typedef {Rule.RuleContext} RuleContext
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {"\n" | "\r\n"} LineEnding The sequence of characters that define
|
|
46
|
+
* the end of a line.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {object} HeaderLinePattern Matching rule for a line from the header
|
|
51
|
+
* using regular expression and optionally providing an auto-fix replacement.
|
|
52
|
+
* @property {string | RegExp} pattern A regular expression that should match
|
|
53
|
+
* the header line.
|
|
54
|
+
* @property {string} [template] When set, if the actual header line does not
|
|
55
|
+
* match `pattern`, this value is to be used when running auto-fix.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {string | RegExp | HeaderLinePattern} HeaderLine Matching rule for
|
|
60
|
+
* a single line of the header comment or the header comment as a whole if only
|
|
61
|
+
* one used.
|
|
62
|
+
* @typedef {HeaderLine | HeaderLine[]} HeaderLines The set of header comment-
|
|
63
|
+
* matching rules.
|
|
64
|
+
* @typedef {"os" | "unix" | "windows"} LineEndingOption Defines what EOL
|
|
65
|
+
* characters to expect - either forced to be Windows / POSIX-compatible, or
|
|
66
|
+
* defaulting to whatever the OS expects.
|
|
67
|
+
* @typedef {{ lineEndings?: LineEndingOption }} HeaderSettings How to treat
|
|
68
|
+
* line endings.
|
|
69
|
+
* @typedef {"block" | "line"} CommentType The expected type of comment to use
|
|
70
|
+
* for the header.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @typedef {object} FileBasedConfig Header content configuration defined in a
|
|
75
|
+
* separate JavaScript template file.
|
|
76
|
+
* @property {string} file Template file path relative to the directory
|
|
77
|
+
* from which ESLint runs.
|
|
78
|
+
* @property {BufferEncoding} [encoding] Encoding to use when reading the
|
|
79
|
+
* file. If omitted, `"utf8"` will be assumed.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @typedef {object} InlineConfig Header content configuration defined inline
|
|
84
|
+
* within the ESLint configuration.
|
|
85
|
+
* @property {CommentType} commentType The type of comment to expect.
|
|
86
|
+
* @property {HeaderLine[]} lines Matching rules for lines. If only one rule
|
|
87
|
+
* is provided, the rule would attempt to match either the first line ar all
|
|
88
|
+
* lines together.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @typedef {object} TrailingEmptyLines Rule configuration on the handling of
|
|
93
|
+
* empty lines after the header comment.
|
|
94
|
+
* @property {number} [minimum] If set, the rule would check that at least
|
|
95
|
+
* a `minimum` number of EOL characters trail the header.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @typedef {object} HeaderOptionsWithoutSettings
|
|
100
|
+
* @property {FileBasedConfig | InlineConfig} header The text matching rules
|
|
101
|
+
* for the header.
|
|
102
|
+
* @property {TrailingEmptyLines} [trailingEmptyLines] Rules about empty lines
|
|
103
|
+
* after the header comment.
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @typedef {HeaderOptionsWithoutSettings & HeaderSettings} HeaderOptions Modern
|
|
108
|
+
* object-based rule configuration.
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @typedef {[template: string]} LegacyFileBasedConfig
|
|
113
|
+
* @typedef {[template: string, settings: HeaderSettings]
|
|
114
|
+
* } LegacyFileBasedSettingsConfig
|
|
115
|
+
* @typedef {[type: CommentType, lines: HeaderLines]} LegacyInlineConfig
|
|
116
|
+
* @typedef {[type: CommentType, lines: HeaderLines, settings: HeaderSettings]
|
|
117
|
+
* } LegacyInlineSettingsConfig
|
|
118
|
+
* @typedef {[type: CommentType, lines: HeaderLines, minLines: number]
|
|
119
|
+
* } LegacyInlineMinLinesConfig
|
|
120
|
+
* @typedef {[
|
|
121
|
+
* type: CommentType,
|
|
122
|
+
* lines: HeaderLines,
|
|
123
|
+
* minLines: number,
|
|
124
|
+
* settings: HeaderSettings
|
|
125
|
+
* ]} LegacyInlineMinLinesSettingsConfig
|
|
126
|
+
* @typedef {[HeaderOptions]
|
|
127
|
+
* | LegacyFileBasedConfig
|
|
128
|
+
* | LegacyFileBasedSettingsConfig
|
|
129
|
+
* | LegacyInlineConfig
|
|
130
|
+
* | LegacyInlineSettingsConfig
|
|
131
|
+
* | LegacyInlineMinLinesConfig
|
|
132
|
+
* | LegacyInlineMinLinesSettingsConfig
|
|
133
|
+
* } AllHeaderOptions Full possible rule configuration options.
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @typedef {Linter.RuleEntry<AllHeaderOptions>} HeaderRuleConfig Rule
|
|
138
|
+
* configuration array including severity.
|
|
87
139
|
*/
|
|
88
140
|
|
|
89
141
|
/**
|
|
90
142
|
* Tests if the passed line configuration string or object is a pattern
|
|
91
143
|
* definition.
|
|
92
|
-
* @param {HeaderLine} object
|
|
144
|
+
* @param {HeaderLine} object Line configuration object or string.
|
|
93
145
|
* @returns {object is HeaderLinePattern} `true` if the line configuration is a
|
|
94
|
-
*
|
|
95
|
-
* otherwise.
|
|
146
|
+
* pattern-defining object or `false` otherwise.
|
|
96
147
|
*/
|
|
97
148
|
function isPattern(object) {
|
|
98
149
|
return typeof object === "object"
|
|
@@ -102,10 +153,10 @@ function isPattern(object) {
|
|
|
102
153
|
/**
|
|
103
154
|
* Utility over a line config argument to match an expected string either
|
|
104
155
|
* against a regex or for full match against a string.
|
|
105
|
-
* @param {string} actual
|
|
156
|
+
* @param {string} actual The string to test.
|
|
106
157
|
* @param {string | RegExp} expected The string or regex to test again.
|
|
107
158
|
* @returns {boolean} `true` if the passed string matches the expected line
|
|
108
|
-
*
|
|
159
|
+
* config or `false` otherwise.
|
|
109
160
|
*/
|
|
110
161
|
function match(actual, expected) {
|
|
111
162
|
if (expected instanceof RegExp) {
|
|
@@ -117,11 +168,10 @@ function match(actual, expected) {
|
|
|
117
168
|
|
|
118
169
|
/**
|
|
119
170
|
* Remove Unix she-bangs from the list of comments.
|
|
120
|
-
* @param {(Comment | { type: "Shebang" })[]} comments
|
|
121
|
-
*
|
|
122
|
-
* @returns {Comment[]}
|
|
123
|
-
*
|
|
124
|
-
* omitted.
|
|
171
|
+
* @param {(Comment | { type: "Shebang" })[]} comments The list of comment
|
|
172
|
+
* lines.
|
|
173
|
+
* @returns {Comment[]} The list of comments with containing all incoming
|
|
174
|
+
* comments from `comments` with the shebang comments omitted.
|
|
125
175
|
*/
|
|
126
176
|
function excludeShebangs(comments) {
|
|
127
177
|
/** @type {Comment[]} */
|
|
@@ -132,9 +182,9 @@ function excludeShebangs(comments) {
|
|
|
132
182
|
|
|
133
183
|
/**
|
|
134
184
|
* TypeScript helper to confirm defined type.
|
|
135
|
-
* @template T
|
|
136
|
-
* @param {T | undefined} val
|
|
137
|
-
* @returns {asserts val is T}
|
|
185
|
+
* @template T Target type to validate for definiteness.
|
|
186
|
+
* @param {T | undefined} val The value to validate.
|
|
187
|
+
* @returns {asserts val is T} Validates defined type.
|
|
138
188
|
*/
|
|
139
189
|
function assertDefined(val) {
|
|
140
190
|
assert.strict.notEqual(typeof val, "undefined");
|
|
@@ -142,9 +192,9 @@ function assertDefined(val) {
|
|
|
142
192
|
|
|
143
193
|
/**
|
|
144
194
|
* TypeScript helper to confirm non-null type.
|
|
145
|
-
* @template T
|
|
146
|
-
* @param {T | null} val
|
|
147
|
-
* @returns {asserts val is T}
|
|
195
|
+
* @template T Target type to validate is non-null.
|
|
196
|
+
* @param {T | null} val The value to validate.
|
|
197
|
+
* @returns {asserts val is T} Validates non-null type.
|
|
148
198
|
*/
|
|
149
199
|
function assertNotNull(val) {
|
|
150
200
|
assert.strict.notEqual(val, null);
|
|
@@ -156,7 +206,7 @@ function assertNotNull(val) {
|
|
|
156
206
|
* check if they are at the start of the file since that is already checked by
|
|
157
207
|
* `hasHeader()`.
|
|
158
208
|
* @param {RuleContext} context ESLint execution environment.
|
|
159
|
-
* @returns {Comment[]}
|
|
209
|
+
* @returns {Comment[]} Lines That constitute the leading comment.
|
|
160
210
|
*/
|
|
161
211
|
function getLeadingComments(context) {
|
|
162
212
|
const sourceCode = contextSourceCode(context);
|
|
@@ -183,10 +233,10 @@ function getLeadingComments(context) {
|
|
|
183
233
|
/**
|
|
184
234
|
* Generate a comment including trailing spaces out of a number of comment body
|
|
185
235
|
* lines.
|
|
186
|
-
* @param {CommentType} commentType
|
|
187
|
-
* @param {string[]} textArray
|
|
188
|
-
* @param {
|
|
189
|
-
* @returns {string}
|
|
236
|
+
* @param {CommentType} commentType The type of comment to generate.
|
|
237
|
+
* @param {string[]} textArray List of lines of the comment content.
|
|
238
|
+
* @param {LineEnding} eol End-of-line characters.
|
|
239
|
+
* @returns {string} Resulting comment.
|
|
190
240
|
*/
|
|
191
241
|
function genCommentBody(commentType, textArray, eol) {
|
|
192
242
|
if (commentType === commentTypeOptions.block) {
|
|
@@ -201,8 +251,8 @@ function genCommentBody(commentType, textArray, eol) {
|
|
|
201
251
|
/**
|
|
202
252
|
* Determines the start and end position in the source code of the leading
|
|
203
253
|
* comment.
|
|
204
|
-
* @param {Comment[]} comments
|
|
205
|
-
* @returns {[number, number]}
|
|
254
|
+
* @param {Comment[]} comments List of comments.
|
|
255
|
+
* @returns {[number, number]} Resulting range.
|
|
206
256
|
*/
|
|
207
257
|
function genCommentsRange(comments) {
|
|
208
258
|
assert.ok(comments.length);
|
|
@@ -222,8 +272,8 @@ function genCommentsRange(comments) {
|
|
|
222
272
|
/**
|
|
223
273
|
* Calculates the number of leading empty lines in the source code. The function
|
|
224
274
|
* counts both Windows and POSIX line endings.
|
|
225
|
-
* @param {string} src
|
|
226
|
-
* @returns {number}
|
|
275
|
+
* @param {string} src The source code to traverse.
|
|
276
|
+
* @returns {number} The number of leading empty lines.
|
|
227
277
|
*/
|
|
228
278
|
function leadingEmptyLines(src) {
|
|
229
279
|
let numLines = 0;
|
|
@@ -241,12 +291,12 @@ function leadingEmptyLines(src) {
|
|
|
241
291
|
|
|
242
292
|
/**
|
|
243
293
|
* Factory for fixer that adds a missing header.
|
|
244
|
-
* @param {CommentType} commentType
|
|
294
|
+
* @param {CommentType} commentType Type of comment to use.
|
|
245
295
|
* @param {RuleContext} context ESLint execution runtime.
|
|
246
|
-
* @param {string[]} headerLines
|
|
247
|
-
* @param {
|
|
248
|
-
* @param {number} numNewlines
|
|
249
|
-
* @returns {ReportFixer}
|
|
296
|
+
* @param {string[]} headerLines Lines of the header comment.
|
|
297
|
+
* @param {LineEnding} eol End-of-line characters.
|
|
298
|
+
* @param {number} numNewlines Number of trailing lines after the comment.
|
|
299
|
+
* @returns {ReportFixer} The fix to apply.
|
|
250
300
|
*/
|
|
251
301
|
function genPrependFixer(commentType, context, headerLines, eol, numNewlines) {
|
|
252
302
|
return function(fixer) {
|
|
@@ -272,13 +322,13 @@ function genPrependFixer(commentType, context, headerLines, eol, numNewlines) {
|
|
|
272
322
|
|
|
273
323
|
/**
|
|
274
324
|
* Factory for fixer that replaces an incorrect header.
|
|
275
|
-
* @param {CommentType} commentType
|
|
325
|
+
* @param {CommentType} commentType Type of comment to use.
|
|
276
326
|
* @param {RuleContext} context ESLint execution context.
|
|
277
|
-
* @param {Comment[]} leadingComments
|
|
278
|
-
* @param {string[]} headerLines
|
|
279
|
-
* @param {
|
|
280
|
-
* @param {number} numNewlines
|
|
281
|
-
* @returns {
|
|
327
|
+
* @param {Comment[]} leadingComments Comment elements to replace.
|
|
328
|
+
* @param {string[]} headerLines Lines of the header comment.
|
|
329
|
+
* @param {LineEnding} eol End-of-line characters.
|
|
330
|
+
* @param {number} numNewlines Number of trailing lines after the comment.
|
|
331
|
+
* @returns {ReportFixer} The fix to apply.
|
|
282
332
|
*/
|
|
283
333
|
function genReplaceFixer(commentType, context, leadingComments, headerLines, eol, numNewlines) {
|
|
284
334
|
return function(fixer) {
|
|
@@ -295,11 +345,11 @@ function genReplaceFixer(commentType, context, leadingComments, headerLines, eol
|
|
|
295
345
|
|
|
296
346
|
/**
|
|
297
347
|
* Factory for fixer that replaces an incorrect header.
|
|
298
|
-
* @param {Comment[]} leadingComments
|
|
299
|
-
* @param {
|
|
300
|
-
* @param {number} missingEmptyLinesCount
|
|
301
|
-
*
|
|
302
|
-
* @returns {
|
|
348
|
+
* @param {Comment[]} leadingComments Comment elements to replace.
|
|
349
|
+
* @param {LineEnding} eol End-of-line characters.
|
|
350
|
+
* @param {number} missingEmptyLinesCount Number of trailing lines after the
|
|
351
|
+
* comment.
|
|
352
|
+
* @returns {ReportFixer} The fix to apply.
|
|
303
353
|
*/
|
|
304
354
|
function genEmptyLinesFixer(leadingComments, eol, missingEmptyLinesCount) {
|
|
305
355
|
return function(fixer) {
|
|
@@ -313,9 +363,8 @@ function genEmptyLinesFixer(leadingComments, eol, missingEmptyLinesCount) {
|
|
|
313
363
|
/**
|
|
314
364
|
* Returns the used line-termination characters per the rule's config if any or
|
|
315
365
|
* else based on the runtime environments.
|
|
316
|
-
* @param {LineEndingOption} style
|
|
317
|
-
* @returns {
|
|
318
|
-
* environment.
|
|
366
|
+
* @param {LineEndingOption} style Line-ending styles.
|
|
367
|
+
* @returns {LineEnding} The correct line ending characters for the environment.
|
|
319
368
|
*/
|
|
320
369
|
function getEol(style) {
|
|
321
370
|
assert.strictEqual(Object.prototype.hasOwnProperty.call(lineEndingOptions, style), true,
|
|
@@ -327,14 +376,14 @@ function getEol(style) {
|
|
|
327
376
|
return "\r\n";
|
|
328
377
|
case lineEndingOptions.os:
|
|
329
378
|
default:
|
|
330
|
-
return /** @type {
|
|
379
|
+
return /** @type {LineEnding} */ (os.EOL);
|
|
331
380
|
}
|
|
332
381
|
}
|
|
333
382
|
|
|
334
383
|
/**
|
|
335
384
|
* Tests if the first line in the source code (after a Unix she-bang) is a
|
|
336
385
|
* comment. Does not tolerate empty lines before the first match.
|
|
337
|
-
* @param {string} src
|
|
386
|
+
* @param {string} src Source code to test.
|
|
338
387
|
* @returns {boolean} `true` if there is a comment or `false` otherwise.
|
|
339
388
|
*/
|
|
340
389
|
function hasHeader(src) {
|
|
@@ -343,10 +392,10 @@ function hasHeader(src) {
|
|
|
343
392
|
}
|
|
344
393
|
|
|
345
394
|
/**
|
|
346
|
-
*
|
|
395
|
+
* Asserts on an expression and adds template texts to the failure message.
|
|
347
396
|
* Helper to write cleaner code.
|
|
348
|
-
* @param {boolean} condition
|
|
349
|
-
* @param {string} message
|
|
397
|
+
* @param {boolean} condition Condition to verify.
|
|
398
|
+
* @param {string} message Assert message on violation.
|
|
350
399
|
*/
|
|
351
400
|
function schemaAssert(condition, message) {
|
|
352
401
|
assert.strictEqual(condition, true, message + " - should have been handled by eslint schema validation.");
|
|
@@ -359,10 +408,10 @@ function schemaAssert(condition, message) {
|
|
|
359
408
|
* options in that some settings are still union types and unspecified
|
|
360
409
|
* properties are not replaced by defaults. If the options follow the new
|
|
361
410
|
* format, a simple seep copy would be returned.
|
|
362
|
-
* @param {AllHeaderOptions} originalOptions
|
|
363
|
-
*
|
|
364
|
-
* @returns {HeaderOptions}
|
|
365
|
-
*
|
|
411
|
+
* @param {AllHeaderOptions} originalOptions The options as configured by the
|
|
412
|
+
* user.
|
|
413
|
+
* @returns {HeaderOptions} The transformed new-style options with no
|
|
414
|
+
* normalization.
|
|
366
415
|
*/
|
|
367
416
|
function transformLegacyOptions(originalOptions) {
|
|
368
417
|
schemaAssert(originalOptions?.length > 0,
|
|
@@ -428,17 +477,20 @@ function transformLegacyOptions(originalOptions) {
|
|
|
428
477
|
}
|
|
429
478
|
|
|
430
479
|
/**
|
|
431
|
-
*
|
|
432
|
-
* @
|
|
480
|
+
* Type guard for `FileBasedConfig`.
|
|
481
|
+
* @param {FileBasedConfig | InlineConfig} config The header configuration.
|
|
482
|
+
* @returns {config is FileBasedConfig} `true` if `config` is `FileBasedConfig`,
|
|
483
|
+
* else `false`.
|
|
433
484
|
*/
|
|
434
485
|
function isFileBasedHeaderConfig(config) {
|
|
435
486
|
return Object.prototype.hasOwnProperty.call(config, "file");
|
|
436
487
|
}
|
|
437
488
|
|
|
438
489
|
/**
|
|
439
|
-
*
|
|
440
|
-
* @
|
|
441
|
-
*
|
|
490
|
+
* Type guard for `InlineConfig`.
|
|
491
|
+
* @param {FileBasedConfig | InlineConfig} config The header configuration.
|
|
492
|
+
* @returns {asserts config is InlineConfig} Asserts `config` is
|
|
493
|
+
* `LineBasedConfig`.
|
|
442
494
|
*/
|
|
443
495
|
function assertLineBasedHeaderConfig(config) {
|
|
444
496
|
assert.ok(Object.prototype.hasOwnProperty.call(config, "lines"));
|
|
@@ -447,8 +499,8 @@ function assertLineBasedHeaderConfig(config) {
|
|
|
447
499
|
/**
|
|
448
500
|
* Transforms a set of new-style options adding defaults and standardizing on
|
|
449
501
|
* one of multiple config styles.
|
|
450
|
-
* @param {HeaderOptions} originalOptions
|
|
451
|
-
* @returns {HeaderOptions}
|
|
502
|
+
* @param {HeaderOptions} originalOptions New-style options to normalize.
|
|
503
|
+
* @returns {HeaderOptions} Normalized options.
|
|
452
504
|
*/
|
|
453
505
|
function normalizeOptions(originalOptions) {
|
|
454
506
|
const options = structuredClone(originalOptions);
|
|
@@ -498,11 +550,11 @@ function normalizeOptions(originalOptions) {
|
|
|
498
550
|
* insufficient) lines that trail the comment. A special case is when there are
|
|
499
551
|
* no empty lines after the header in which case we highlight the next character
|
|
500
552
|
* in the source regardless of which one it is).
|
|
501
|
-
* @param {Comment[]} leadingComments
|
|
502
|
-
*
|
|
503
|
-
* @param {number} actualEmptyLines
|
|
504
|
-
*
|
|
505
|
-
* @returns {SourceLocation}
|
|
553
|
+
* @param {Comment[]} leadingComments The comment lines that constitute the
|
|
554
|
+
* header.
|
|
555
|
+
* @param {number} actualEmptyLines The number of empty lines that follow the
|
|
556
|
+
* header.
|
|
557
|
+
* @returns {SourceLocation} The location (line and column) of the violation.
|
|
506
558
|
*/
|
|
507
559
|
function missingEmptyLinesViolationLoc(leadingComments, actualEmptyLines) {
|
|
508
560
|
assert.ok(leadingComments);
|
|
@@ -519,7 +571,7 @@ function missingEmptyLinesViolationLoc(leadingComments, actualEmptyLines) {
|
|
|
519
571
|
};
|
|
520
572
|
}
|
|
521
573
|
|
|
522
|
-
/** @type {
|
|
574
|
+
/** @type {Rule.RuleModule} */
|
|
523
575
|
const headerRule = {
|
|
524
576
|
meta: {
|
|
525
577
|
type: "layout",
|
|
@@ -551,10 +603,11 @@ const headerRule = {
|
|
|
551
603
|
noNewlineAfterHeader: "not enough newlines after header: expected: {{expected}}, actual: {{actual}}"
|
|
552
604
|
}
|
|
553
605
|
},
|
|
606
|
+
|
|
554
607
|
/**
|
|
555
608
|
* Rule creation function.
|
|
556
609
|
* @param {RuleContext} context ESLint rule execution context.
|
|
557
|
-
* @returns {NodeListener}
|
|
610
|
+
* @returns {NodeListener} The rule definition.
|
|
558
611
|
*/
|
|
559
612
|
create: function(context) {
|
|
560
613
|
|
|
@@ -851,6 +904,30 @@ const headerRule = {
|
|
|
851
904
|
/** @type {null | SourceLocation} */
|
|
852
905
|
let errorMessageLoc = null;
|
|
853
906
|
for (let i = 0; i < headerLines.length; i++) {
|
|
907
|
+
if (leadingLines.length - 1 < i) {
|
|
908
|
+
assertDefined(lastLeadingCommentLoc);
|
|
909
|
+
assertNotNull(lastLeadingCommentLoc);
|
|
910
|
+
context.report({
|
|
911
|
+
loc: {
|
|
912
|
+
start: lastLeadingCommentLoc.end,
|
|
913
|
+
end: lastLeadingCommentLoc.end
|
|
914
|
+
},
|
|
915
|
+
messageId: "headerTooShort",
|
|
916
|
+
data: {
|
|
917
|
+
remainder: headerLines.slice(i).join(eol)
|
|
918
|
+
},
|
|
919
|
+
fix: canFix
|
|
920
|
+
? genReplaceFixer(
|
|
921
|
+
commentType,
|
|
922
|
+
context,
|
|
923
|
+
leadingComments,
|
|
924
|
+
fixLines,
|
|
925
|
+
eol,
|
|
926
|
+
numLines)
|
|
927
|
+
: null
|
|
928
|
+
});
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
854
931
|
const leadingLine = leadingLines[i];
|
|
855
932
|
const headerLine = headerLines[i];
|
|
856
933
|
if (typeof headerLine === "string") {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025-
|
|
5
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* @file Schema definition for `header` rule.
|
|
3
|
+
* @copyright Copyright (c) 2015-present Stuart Knightley and contributors
|
|
4
|
+
* @copyright Copyright (c) 2025-2026 Tony Ganchev
|
|
5
|
+
* @license MIT
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the “Software”), to deal
|
|
8
8
|
* in the Software without restriction, including without limitation the rights
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
|
|
25
26
|
"use strict";
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -41,7 +42,7 @@ const commentTypeOptions = Object.freeze({
|
|
|
41
42
|
line: "line"
|
|
42
43
|
});
|
|
43
44
|
|
|
44
|
-
/** @type {import(
|
|
45
|
+
/** @type {import("json-schema").JSONSchema4} */
|
|
45
46
|
const schema = Object.freeze({
|
|
46
47
|
$ref: "#/definitions/options",
|
|
47
48
|
definitions: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tony.ganchev/eslint-plugin-header",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.5",
|
|
4
4
|
"description": "The native ESLint 9/10 header plugin. A zero-bloat, drop-in replacement for 'eslint-plugin-header' with first-class Flat Config & TypeScript support. Auto-fix Copyright, License, and banner comments in JavaScrip and TypeScript files.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,38 +17,28 @@
|
|
|
17
17
|
"types",
|
|
18
18
|
"CONTRIBUTING.md"
|
|
19
19
|
],
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "npx tsc",
|
|
22
|
-
"e2e": "npm run build && npx mocha --timeout 60000 tests/e2e/*.js",
|
|
23
|
-
"eslint": "npx eslint .",
|
|
24
|
-
"lint": "npm run eslint && npm run markdownlint",
|
|
25
|
-
"markdownlint": "npx markdownlint-cli *.md",
|
|
26
|
-
"test": "npm run lint && npm run unit && npm run e2e",
|
|
27
|
-
"unit": "npx nyc --reporter=html --reporter=text --reporter=text-summary --reporter=lcov --check-coverage=true --statements=100 --branches=100 --lines=100 --functions=100 mocha tests/lib/*.js tests/lib/**/*.js"
|
|
28
|
-
},
|
|
29
20
|
"devDependencies": {
|
|
30
|
-
"@eslint/eslintrc": "^3.3.3",
|
|
31
21
|
"@eslint/js": "^10.0.1",
|
|
32
22
|
"@eslint/markdown": "^7.5.1",
|
|
33
|
-
"@stylistic/eslint-plugin": "^5.
|
|
34
|
-
"@types/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"eslint
|
|
23
|
+
"@stylistic/eslint-plugin": "^5.9.0",
|
|
24
|
+
"@types/estree": "^1.0.8",
|
|
25
|
+
"@types/json-schema": "^7.0.15",
|
|
26
|
+
"@types/node": "^25.3.0",
|
|
27
|
+
"c8": "^10.1.3",
|
|
28
|
+
"eslint": "^10.0.2",
|
|
29
|
+
"eslint-plugin-eslint-plugin": "^7.3.1",
|
|
30
|
+
"eslint-plugin-jsdoc": "^62.7.1",
|
|
31
|
+
"eslint-plugin-n": "^17.24.0",
|
|
32
|
+
"globals": "^17.3.0",
|
|
39
33
|
"markdownlint-cli": "^0.47.0",
|
|
40
|
-
"mocha": "
|
|
41
|
-
"nyc": "^17.1.0",
|
|
34
|
+
"mocha": "12.0.0-beta-9",
|
|
42
35
|
"testdouble": "^3.20.2",
|
|
43
36
|
"typescript": "^5.9.3",
|
|
44
|
-
"typescript-eslint": "^8.56.
|
|
37
|
+
"typescript-eslint": "^8.56.1"
|
|
45
38
|
},
|
|
46
39
|
"peerDependencies": {
|
|
47
40
|
"eslint": ">=7.7.0"
|
|
48
41
|
},
|
|
49
|
-
"overrides": {
|
|
50
|
-
"eslint": "^10.0.0"
|
|
51
|
-
},
|
|
52
42
|
"keywords": [
|
|
53
43
|
"eslint",
|
|
54
44
|
"eslint-plugin",
|
|
@@ -86,5 +76,14 @@
|
|
|
86
76
|
"contributors": [
|
|
87
77
|
"Josh Kelley",
|
|
88
78
|
"Stuart Knightley"
|
|
89
|
-
]
|
|
90
|
-
|
|
79
|
+
],
|
|
80
|
+
"scripts": {
|
|
81
|
+
"build": "tsc",
|
|
82
|
+
"e2e": "pnpm build && mocha --timeout 60000 tests/e2e/*.js",
|
|
83
|
+
"eslint": "eslint .",
|
|
84
|
+
"lint": "pnpm eslint && pnpm markdownlint",
|
|
85
|
+
"markdownlint": "markdownlint *.md",
|
|
86
|
+
"test": "pnpm lint && pnpm unit && pnpm e2e",
|
|
87
|
+
"unit": "c8 --reporter=html --reporter=text --reporter=text-summary --reporter=lcov --check-coverage --100 mocha tests/lib/*.js tests/lib/**/*.js"
|
|
88
|
+
}
|
|
89
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment-parser.d.ts","sourceRoot":"","sources":["../../lib/comment-parser.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"comment-parser.d.ts","sourceRoot":"","sources":["../../lib/comment-parser.js"],"names":[],"mappings":"AAuCiB,uCALN,MAAM,GACJ,CAAC,OAAO,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAoB5D"}
|
|
@@ -1,100 +1,135 @@
|
|
|
1
1
|
export { headerRule as header };
|
|
2
|
+
export type NodeListener = Rule.NodeListener;
|
|
3
|
+
export type ReportFixer = Rule.ReportFixer;
|
|
4
|
+
export type RuleFixer = Rule.RuleFixer;
|
|
5
|
+
export type RuleContext = Rule.RuleContext;
|
|
2
6
|
/**
|
|
3
|
-
*
|
|
7
|
+
* The sequence of characters that define
|
|
8
|
+
* the end of a line.
|
|
4
9
|
*/
|
|
5
|
-
export type
|
|
10
|
+
export type LineEnding = "\n" | "\r\n";
|
|
6
11
|
/**
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
export type NodeListener = import("eslint").Rule.NodeListener;
|
|
10
|
-
/**
|
|
11
|
-
* Import type definitions.
|
|
12
|
-
*/
|
|
13
|
-
export type ReportFixer = import("eslint").Rule.ReportFixer;
|
|
14
|
-
/**
|
|
15
|
-
* Import type definitions.
|
|
16
|
-
*/
|
|
17
|
-
export type RuleFixer = import("eslint").Rule.RuleFixer;
|
|
18
|
-
/**
|
|
19
|
-
* Import type definitions.
|
|
20
|
-
*/
|
|
21
|
-
export type RuleContext = import("eslint").Rule.RuleContext;
|
|
22
|
-
/**
|
|
23
|
-
* Import type definitions.
|
|
24
|
-
*/
|
|
25
|
-
export type Comment = import("estree").Comment;
|
|
26
|
-
/**
|
|
27
|
-
* Import type definitions.
|
|
28
|
-
*/
|
|
29
|
-
export type Program = import("estree").Program;
|
|
30
|
-
/**
|
|
31
|
-
* Import type definitions.
|
|
32
|
-
*/
|
|
33
|
-
export type SourceLocation = import("estree").SourceLocation;
|
|
34
|
-
/**
|
|
35
|
-
* Local type definitions.
|
|
12
|
+
* Matching rule for a line from the header
|
|
13
|
+
* using regular expression and optionally providing an auto-fix replacement.
|
|
36
14
|
*/
|
|
37
15
|
export type HeaderLinePattern = {
|
|
16
|
+
/**
|
|
17
|
+
* A regular expression that should match
|
|
18
|
+
* the header line.
|
|
19
|
+
*/
|
|
38
20
|
pattern: string | RegExp;
|
|
39
|
-
|
|
21
|
+
/**
|
|
22
|
+
* When set, if the actual header line does not
|
|
23
|
+
* match `pattern`, this value is to be used when running auto-fix.
|
|
24
|
+
*/
|
|
25
|
+
template?: string | undefined;
|
|
40
26
|
};
|
|
41
27
|
/**
|
|
42
|
-
*
|
|
28
|
+
* Matching rule for
|
|
29
|
+
* a single line of the header comment or the header comment as a whole if only
|
|
30
|
+
* one used.
|
|
43
31
|
*/
|
|
44
32
|
export type HeaderLine = string | RegExp | HeaderLinePattern;
|
|
45
33
|
/**
|
|
46
|
-
*
|
|
34
|
+
* The set of header comment-
|
|
35
|
+
* matching rules.
|
|
47
36
|
*/
|
|
48
37
|
export type HeaderLines = HeaderLine | HeaderLine[];
|
|
49
38
|
/**
|
|
50
|
-
*
|
|
39
|
+
* Defines what EOL
|
|
40
|
+
* characters to expect - either forced to be Windows / POSIX-compatible, or
|
|
41
|
+
* defaulting to whatever the OS expects.
|
|
51
42
|
*/
|
|
52
43
|
export type LineEndingOption = "os" | "unix" | "windows";
|
|
53
44
|
/**
|
|
54
|
-
*
|
|
45
|
+
* How to treat
|
|
46
|
+
* line endings.
|
|
55
47
|
*/
|
|
56
48
|
export type HeaderSettings = {
|
|
57
49
|
lineEndings?: LineEndingOption;
|
|
58
50
|
};
|
|
59
51
|
/**
|
|
60
|
-
*
|
|
52
|
+
* The expected type of comment to use
|
|
53
|
+
* for the header.
|
|
61
54
|
*/
|
|
62
55
|
export type CommentType = "block" | "line";
|
|
63
56
|
/**
|
|
64
|
-
*
|
|
57
|
+
* Header content configuration defined in a
|
|
58
|
+
* separate JavaScript template file.
|
|
65
59
|
*/
|
|
66
60
|
export type FileBasedConfig = {
|
|
61
|
+
/**
|
|
62
|
+
* Template file path relative to the directory
|
|
63
|
+
* from which ESLint runs.
|
|
64
|
+
*/
|
|
67
65
|
file: string;
|
|
68
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Encoding to use when reading the
|
|
68
|
+
* file. If omitted, `"utf8"` will be assumed.
|
|
69
|
+
*/
|
|
70
|
+
encoding?: BufferEncoding | undefined;
|
|
69
71
|
};
|
|
70
72
|
/**
|
|
71
|
-
*
|
|
73
|
+
* Header content configuration defined inline
|
|
74
|
+
* within the ESLint configuration.
|
|
72
75
|
*/
|
|
73
76
|
export type InlineConfig = {
|
|
77
|
+
/**
|
|
78
|
+
* The type of comment to expect.
|
|
79
|
+
*/
|
|
74
80
|
commentType: CommentType;
|
|
81
|
+
/**
|
|
82
|
+
* Matching rules for lines. If only one rule
|
|
83
|
+
* is provided, the rule would attempt to match either the first line ar all
|
|
84
|
+
* lines together.
|
|
85
|
+
*/
|
|
75
86
|
lines: HeaderLine[];
|
|
76
87
|
};
|
|
77
88
|
/**
|
|
78
|
-
*
|
|
89
|
+
* Rule configuration on the handling of
|
|
90
|
+
* empty lines after the header comment.
|
|
79
91
|
*/
|
|
80
92
|
export type TrailingEmptyLines = {
|
|
81
|
-
|
|
93
|
+
/**
|
|
94
|
+
* If set, the rule would check that at least
|
|
95
|
+
* a `minimum` number of EOL characters trail the header.
|
|
96
|
+
*/
|
|
97
|
+
minimum?: number | undefined;
|
|
98
|
+
};
|
|
99
|
+
export type HeaderOptionsWithoutSettings = {
|
|
100
|
+
/**
|
|
101
|
+
* The text matching rules
|
|
102
|
+
* for the header.
|
|
103
|
+
*/
|
|
104
|
+
header: FileBasedConfig | InlineConfig;
|
|
105
|
+
/**
|
|
106
|
+
* Rules about empty lines
|
|
107
|
+
* after the header comment.
|
|
108
|
+
*/
|
|
109
|
+
trailingEmptyLines?: TrailingEmptyLines | undefined;
|
|
82
110
|
};
|
|
83
111
|
/**
|
|
84
|
-
*
|
|
112
|
+
* Modern
|
|
113
|
+
* object-based rule configuration.
|
|
85
114
|
*/
|
|
86
|
-
export type HeaderOptions =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
115
|
+
export type HeaderOptions = HeaderOptionsWithoutSettings & HeaderSettings;
|
|
116
|
+
export type LegacyFileBasedConfig = [template: string];
|
|
117
|
+
export type LegacyFileBasedSettingsConfig = [template: string, settings: HeaderSettings];
|
|
118
|
+
export type LegacyInlineConfig = [type: CommentType, lines: HeaderLines];
|
|
119
|
+
export type LegacyInlineSettingsConfig = [type: CommentType, lines: HeaderLines, settings: HeaderSettings];
|
|
120
|
+
export type LegacyInlineMinLinesConfig = [type: CommentType, lines: HeaderLines, minLines: number];
|
|
121
|
+
export type LegacyInlineMinLinesSettingsConfig = [type: CommentType, lines: HeaderLines, minLines: number, settings: HeaderSettings];
|
|
90
122
|
/**
|
|
91
|
-
*
|
|
123
|
+
* Full possible rule configuration options.
|
|
92
124
|
*/
|
|
93
|
-
export type AllHeaderOptions = [HeaderOptions] |
|
|
125
|
+
export type AllHeaderOptions = [HeaderOptions] | LegacyFileBasedConfig | LegacyFileBasedSettingsConfig | LegacyInlineConfig | LegacyInlineSettingsConfig | LegacyInlineMinLinesConfig | LegacyInlineMinLinesSettingsConfig;
|
|
94
126
|
/**
|
|
95
|
-
*
|
|
127
|
+
* Rule
|
|
128
|
+
* configuration array including severity.
|
|
96
129
|
*/
|
|
97
|
-
export type HeaderRuleConfig =
|
|
98
|
-
/** @type {
|
|
99
|
-
declare const headerRule:
|
|
130
|
+
export type HeaderRuleConfig = Linter.RuleEntry<AllHeaderOptions>;
|
|
131
|
+
/** @type {Rule.RuleModule} */
|
|
132
|
+
declare const headerRule: Rule.RuleModule;
|
|
133
|
+
import type { Rule } from "eslint";
|
|
134
|
+
import type { Linter } from "eslint";
|
|
100
135
|
//# sourceMappingURL=header.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../../lib/rules/header.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../../lib/rules/header.js"],"names":[],"mappings":";2BAqCa,iBAAiB;0BACjB,gBAAgB;wBAChB,cAAc;0BACd,gBAAgB;;;;;yBAIhB,IAAI,GAAG,MAAM;;;;;;;;;;aAOZ,MAAM,GAAG,MAAM;;;;;;;;;;;;yBAOhB,MAAM,GAAG,MAAM,GAAG,iBAAiB;;;;;0BAGnC,UAAU,GAAG,UAAU,EAAE;;;;;;+BAEzB,IAAI,GAAG,MAAM,GAAG,SAAS;;;;;6BAGzB;IAAE,WAAW,CAAC,EAAE,gBAAgB,CAAA;CAAE;;;;;0BAElC,OAAO,GAAG,MAAM;;;;;;;;;;UAOf,MAAM;;;;;;;;;;;;;;;iBASN,WAAW;;;;;;WACX,UAAU,EAAE;;;;;;;;;;;;;;;;;;YAcZ,eAAe,GAAG,YAAY;;;;;;;;;;;4BAO/B,4BAA4B,GAAG,cAAc;oCAK7C,CAAC,QAAQ,EAAE,MAAM,CAAC;4CAClB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,CAAC;iCAE5C,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,CAAC;yCACvC,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,CAAC;yCAEjE,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC;iDAEzD,CACV,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,cAAc,CACvB;;;;+BACS,CAAC,aAAa,CAAC,GACvB,qBAAqB,GACrB,6BAA6B,GAC7B,kBAAkB,GAClB,0BAA0B,GAC1B,0BAA0B,GAC1B,kCAAkC;;;;;+BAK1B,iBAAiB,gBAAgB,CAAC;AAqb/C,8BAA8B;AAC9B,0BADW,eAAe,CAufxB;0BAjhC+B,QAAQ;4BAAR,QAAQ"}
|
|
@@ -15,6 +15,6 @@ export const commentTypeOptions: Readonly<{
|
|
|
15
15
|
block: "block";
|
|
16
16
|
line: "line";
|
|
17
17
|
}>;
|
|
18
|
-
/** @type {import(
|
|
18
|
+
/** @type {import("json-schema").JSONSchema4} */
|
|
19
19
|
export const schema: import("json-schema").JSONSchema4;
|
|
20
20
|
//# sourceMappingURL=header.schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header.schema.d.ts","sourceRoot":"","sources":["../../../lib/rules/header.schema.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"header.schema.d.ts","sourceRoot":"","sources":["../../../lib/rules/header.schema.js"],"names":[],"mappings":"gCA4BU,MAAM;AADhB;;GAEG;AACH;;;;GAIG;iCAGO,MAAM;AADhB;;GAEG;AACH;;;GAGG;AAEH,gDAAgD;AAChD,qBADW,OAAO,aAAa,EAAE,WAAW,CAwKzC"}
|