Skip to content

Commit 7a1f7a0

Browse files
committed
Tweak AST traversal to support ESLint 10. Update dev dependencies.
1 parent d31dee9 commit 7a1f7a0

File tree

5 files changed

+946
-925
lines changed

5 files changed

+946
-925
lines changed

docs/rules/header-format.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Verifies the content and format of a file's leading comment block (`headers/header-format`)
1+
# headers/header-format
2+
3+
📝 Verifies the content and format of a file's leading comment block.
24

35
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
46

eslint.config.js renamed to eslint.config.mjs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
const js = require("@eslint/js");
2-
const eslintPlugin = require("eslint-plugin-eslint-plugin");
3-
const nodePlugin = require("eslint-plugin-n");
4-
const globals = require("globals");
1+
import js from "@eslint/js";
2+
import eslintPlugin from "eslint-plugin-eslint-plugin";
3+
import nodePlugin from "eslint-plugin-n";
4+
import globals from "globals";
5+
6+
const configConfig = {
7+
name: "eslint-config",
8+
files: ["eslint.config.mjs"],
9+
languageOptions: {
10+
globals: {
11+
...globals.node,
12+
},
13+
sourceType: "module",
14+
},
15+
};
516

617
const srcConfig = {
718
name: "lib",
@@ -25,10 +36,11 @@ const testConfig = {
2536
},
2637
};
2738

28-
module.exports = [
39+
export default [
2940
js.configs.recommended,
30-
eslintPlugin.configs["flat/recommended"],
41+
eslintPlugin.configs.recommended,
3142
nodePlugin.configs["flat/recommended"],
43+
configConfig,
3244
srcConfig,
3345
testConfig,
3446
];

lib/rules/header-format.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ function hasHeaderComment(program, context) {
5454
return vueHasHeaderComment(program);
5555
}
5656

57-
const firstComments = context.sourceCode.getCommentsBefore(program);
57+
const firstProgramToken = context.sourceCode.getFirstToken(program);
58+
if (!firstProgramToken) {
59+
return false;
60+
}
61+
62+
const firstComments = context.sourceCode.getCommentsBefore(firstProgramToken);
5863
if (firstComments.length === 0) {
5964
return false;
6065
} else if (
@@ -241,40 +246,56 @@ module.exports = {
241246
trailingNewlinesMismatch: "Mismatched trailing newlines",
242247
},
243248
fixable: "code",
249+
defaultOptions: [
250+
{ style: "jsdoc", preservePragmas: true, enableVueSupport: false },
251+
],
244252
schema: [
245253
{
246254
type: "object",
247255
properties: {
248256
source: {
257+
description: "The source of the header content.",
249258
enum: ["file", "string"],
250259
},
251260
style: {
261+
description:
262+
"The style to apply when formatting the header content.",
252263
enum: ["line", "jsdoc"],
253-
default: "jsdoc",
254264
},
255265
content: {
266+
description: "The header content.",
256267
type: "string",
257268
},
258269
path: {
270+
description: "The path to a file containing the header content.",
259271
type: "string",
260272
},
261273
preservePragmas: {
274+
description:
275+
"The value indicating whether to preserve pragmas/directives in the leading comment.",
262276
type: "boolean",
263-
default: true,
264277
},
265278
blockPrefix: {
279+
description: "The string prefixed to the header comment block.",
266280
type: "string",
267281
},
268282
blockSuffix: {
283+
description: "The string suffixed to the header comment block.",
269284
type: "string",
270285
},
271286
linePrefix: {
287+
description:
288+
"The string prefixed to each line of the header comment block.",
272289
type: "string",
273290
},
274291
trailingNewlines: {
292+
description:
293+
"The number of validated newline characters which follow the header comment block.",
275294
type: "number",
276295
},
277296
variables: {
297+
description:
298+
"A mapping of keys and values interpolated into the header comment block.",
278299
type: "object",
279300
patternProperties: {
280301
"^.+$": {
@@ -284,6 +305,8 @@ module.exports = {
284305
additionalProperties: false,
285306
},
286307
patterns: {
308+
description:
309+
"A mapping of keys to regular expressions and default values to validate in the header comment block.",
287310
type: "object",
288311
patternProperties: {
289312
"^\\w+$": {
@@ -302,8 +325,9 @@ module.exports = {
302325
additionalProperties: false,
303326
},
304327
enableVueSupport: {
328+
description:
329+
"A value indicating whether to enable support for linting .vue files.",
305330
type: "boolean",
306-
default: false,
307331
},
308332
},
309333
required: ["source"],
@@ -419,16 +443,16 @@ module.exports = {
419443
return {
420444
Program: function (node) {
421445
if (!hasHeaderComment(node, context)) {
422-
const missingHeaderinsertionPoint = getMissingHeaderInsertionNode(
446+
const missingHeaderInsertionPoint = getMissingHeaderInsertionNode(
423447
context,
424448
node,
425449
);
426450
context.report({
427-
node: missingHeaderinsertionPoint,
451+
node: missingHeaderInsertionPoint,
428452
messageId: "missingHeader",
429453
fix: getFixerFn(function (fixer) {
430454
return fixer.insertTextBefore(
431-
missingHeaderinsertionPoint,
455+
missingHeaderInsertionPoint,
432456
appendNewlines(
433457
headerFormatter.format(style),
434458
sourceEol,

0 commit comments

Comments
 (0)