@tony.ganchev/eslint-plugin-header 3.4.1 → 3.4.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 CHANGED
@@ -7,8 +7,8 @@
7
7
  The native ESLint 9/10 standard header-validating plugin. A zero-bloat, drop-in
8
8
  replacement for [eslint-plugin-header](https://github.com/Stuk/eslint-plugin-header)
9
9
  with first-class Flat Config & TypeScript support. Auto-fix copyright, license,
10
- and banner comments in JavaScript, TypeScript, Vue, CSS, HTML, and Markdown files.
11
- Supports _oxlint_.
10
+ and banner comments in JavaScript, TypeScript, Vue, Svelte, CSS, HTML, and
11
+ Markdown files. Supports _oxlint_.
12
12
 
13
13
  ## Table of Contents
14
14
 
@@ -31,7 +31,8 @@ Supports _oxlint_.
31
31
  5. [Linting CSS](#linting-css)
32
32
  6. [Linting HTML](#linting-html)
33
33
  7. [Linting Vue](#linting-vue)
34
- 8. [Linting Markdown](#linting-markdown)
34
+ 8. [Linting Svelte](#linting-svelte)
35
+ 9. [Linting Markdown](#linting-markdown)
35
36
  5. [Comparison to Alternatives](#comparison-to-alternatives)
36
37
  1. [Compared to eslint-plugin-headers](#compared-to-eslint-plugin-headers)
37
38
  1. [Health Scans](#health-scans)
@@ -133,9 +134,9 @@ statements. Smoke tests cover this support as well.
133
134
  ### Languages
134
135
 
135
136
  Currently the plugin supports linting copyright headers in JavaScript,
136
- TypeScript and their JSX / TSX flavors; Vue, CSS, HTML, and Markdown files. As
137
- mentioned in the previous sections, not all languages are supported for oxlint
138
- or ESLint older than 9. Refer to the table below for more details.
137
+ TypeScript and their JSX / TSX flavors; Vue, Svelte, CSS, HTML, and Markdown
138
+ files. As mentioned in the previous sections, not all languages are supported
139
+ for oxlint or ESLint older than 9. Refer to the table below for more details.
139
140
 
140
141
  | Language | ESLint 7 / 8 | ESLint 9 / 10 | oxlint |
141
142
  |------------|---------------|---------------|--------|
@@ -144,6 +145,7 @@ or ESLint older than 9. Refer to the table below for more details.
144
145
  | JSX | ✅ Yes | ✅ Yes | ✅ Yes |
145
146
  | TSX | ✅ Yes | ✅ Yes | ✅ Yes |
146
147
  | Vue | ✅ Yes | ✅ Yes | ❌ No |
148
+ | Svelte | ✅ Yes | ✅ Yes | ❌ No |
147
149
  | CSS | ❌ No | ✅ Yes | ❌ No |
148
150
  | HTML | ❌ No | ✅ Yes | ❌ No |
149
151
  | Markdown | ❌ No | ✅ Yes | ❌ No |
@@ -1379,6 +1381,55 @@ export default [
1379
1381
  As with HTML and CSS, only block comments are supported at the top of the file -
1380
1382
  no line- or shebang comments.
1381
1383
 
1384
+ ### Linting Svelte
1385
+
1386
+ The rule supports linting copyright notices in Svelte files. The rule works with
1387
+ the _eslint-plugin-svelte_ plugin and its parser.
1388
+
1389
+ To turn on header validation for Svelte files, configure the parser and the rule:
1390
+
1391
+ ```ts
1392
+ import header from "@tony.ganchev/eslint-plugin-header";
1393
+ import svelteParser from "svelte-eslint-parser";
1394
+ import sveltePlugin from "eslint-plugin-svelte";
1395
+
1396
+ export default [
1397
+ {
1398
+ files: ["**/*.svelte"],
1399
+ plugins: {
1400
+ "@tony.ganchev": header,
1401
+ svelte: sveltePlugin
1402
+ },
1403
+ languageOptions: {
1404
+ parser: svelteParser
1405
+ },
1406
+ rules: {
1407
+ "@tony.ganchev/header": [
1408
+ "error",
1409
+ {
1410
+ header: {
1411
+ commentType: "block",
1412
+ lines: [" Copyright 2025 "]
1413
+ }
1414
+ }
1415
+ ]
1416
+ }
1417
+ }
1418
+ ];
1419
+ ```
1420
+
1421
+ ```svelte
1422
+ <!-- Copyright 2025 -->
1423
+ <script>
1424
+ let name = 'world';
1425
+ </script>
1426
+
1427
+ <h1>Hello {name}!</h1>
1428
+ ```
1429
+
1430
+ As with Vue, HTML and CSS, only block comments are supported at the top of the
1431
+ file - no line- or shebang comments.
1432
+
1382
1433
  ### Linting Markdown
1383
1434
 
1384
1435
  The rule supports copyright comments in Markdown syntax in both _commonmark_ and
@@ -37,10 +37,8 @@ const assert = require("node:assert");
37
37
  * This is a really simple and dumb parser, that looks just for a
38
38
  * single kind of comment. It won't detect multiple block comments.
39
39
  * @param {string} commentText Content to parse.
40
- * @param {Language} language The language
41
- * configuration.
42
- * @returns {[CommentType, string[]]} Comment type and
43
- * content.
40
+ * @param {Language} language The language configuration.
41
+ * @returns {[CommentType, string[]]} Comment type and content.
44
42
  * @throws {Error} If `commentText` starts with an unrecognized comment token.
45
43
  */
46
44
  module.exports = function commentParser(commentText, language) {
@@ -1205,16 +1205,46 @@ const headerRule = {
1205
1205
  }
1206
1206
  };
1207
1207
 
1208
+ /**
1209
+ * Tests if the source code was parsed by _@html-eslint/eslint-plugin_'s
1210
+ * parser.
1211
+ * @returns {boolean} `true` if the source code is parsed by the parser.
1212
+ */
1213
+ function isHtmlParser() {
1214
+ return sourceCode.constructor.name === "HTMLSourceCode";
1215
+ }
1216
+
1217
+ /**
1218
+ * Tests if the source code was parsed by _vue-eslint-parser_.
1219
+ * @returns {boolean} `true` if the source code is parsed by the parser.
1220
+ */
1221
+ function isVueParser() {
1222
+ // Vue parser mimic JS parser identity but has a
1223
+ // template section under its AST.
1224
+ return "templateBody" in sourceCode.ast;
1225
+ }
1226
+
1227
+ /**
1228
+ * Tests if the source code was parsed by _svelte-eslint-parser_.
1229
+ * @returns {boolean} `true` if the source code is parsed by the parser.
1230
+ */
1231
+ function isSvelteParser() {
1232
+ // Svelte parser mimic JS parser identity but has an
1233
+ // identifier in its `parserServices` section.
1234
+ return sourceCode.parserServices.isSvelte;
1235
+ }
1236
+
1237
+ /**
1238
+ * Tests if the source code is parsed by a HTML-style language parser.
1239
+ * @returns {boolean} `true` if the source code is parsed by a
1240
+ * HTML-style language parser.
1241
+ */
1242
+ function isHtmlStyleLanguage() {
1243
+ return isHtmlParser() || isVueParser() || isSvelteParser();
1244
+ };
1245
+
1208
1246
  const hooks = {
1209
- Program: () =>
1210
- onRootNode(
1211
- (sourceCode.constructor.name === "HTMLSourceCode"
1212
- // Vue parser mimics JS parser identity but has a
1213
- // template section.
1214
- || "templateBody" in sourceCode.ast)
1215
- ? htmlStyleLanguage
1216
- : jsStyleLanguage
1217
- ),
1247
+ Program: () => onRootNode(isHtmlStyleLanguage() ? htmlStyleLanguage : jsStyleLanguage),
1218
1248
  StyleSheet: () => onRootNode(cssStyleLanguage),
1219
1249
  // eslint/markdown
1220
1250
  root: () => onRootNode(htmlStyleLanguage),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tony.ganchev/eslint-plugin-header",
3
- "version": "3.4.1",
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 JavaScript, TypeScript, Vue, CSS, HTML, and Markdown files. Supports oxlint.",
3
+ "version": "3.4.2",
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 JavaScript, TypeScript, Vue, Svelte, CSS, HTML, and Markdown files. Supports oxlint.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "exports": {
@@ -32,10 +32,12 @@
32
32
  "eslint-plugin-eslint-plugin": "^7.3.2",
33
33
  "eslint-plugin-jsdoc": "^62.9.0",
34
34
  "eslint-plugin-n": "^17.24.0",
35
+ "eslint-plugin-svelte": "^3.17.0",
35
36
  "eslint-plugin-vue": "^10.8.0",
36
37
  "globals": "^17.4.0",
37
38
  "markdownlint-cli": "^0.48.0",
38
39
  "mocha": "12.0.0-beta-10",
40
+ "svelte-eslint-parser": "^1.6.0",
39
41
  "testdouble": "^3.20.2",
40
42
  "typescript": "^5.9.3",
41
43
  "typescript-eslint": "^8.58.0",
@@ -76,6 +78,9 @@
76
78
  "oxc",
77
79
  "react",
78
80
  "source-header",
81
+ "svelte",
82
+ "sveltejs",
83
+ "svelte-js",
79
84
  "typescript",
80
85
  "vue",
81
86
  "vuejs",
@@ -1 +1 @@
1
- {"version":3,"file":"comment-parser.d.ts","sourceRoot":"","sources":["../../lib/comment-parser.js"],"names":[],"mappings":"AA6CiB,uCAPN,MAAM,YACN,QAAQ,GAEN,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC,CA4BnC;;8BAxCyC,gBAAgB;iCAAhB,gBAAgB"}
1
+ {"version":3,"file":"comment-parser.d.ts","sourceRoot":"","sources":["../../lib/comment-parser.js"],"names":[],"mappings":"AA2CiB,uCALN,MAAM,YACN,QAAQ,GACN,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC,CA2BnC;;8BAtCyC,gBAAgB;iCAAhB,gBAAgB"}
@@ -1 +1 @@
1
- {"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../../lib/rules/header.js"],"names":[],"mappings":"2BAsCa,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;;;;;;;;;;;;cAQZ,CAAC,eAAe,GAAG,YAAY,CAAC,EAAE;;;;;;;;;;;;;;;;;;YAclC,eAAe,GAAG,YAAY;;;;;;;;;;;;;;;;;4BAU/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,W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