@tony.ganchev/eslint-plugin-header 3.1.4 → 3.1.6

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/index.js CHANGED
@@ -1,3 +1,27 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2015-present Stuart Knightley 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 all
14
+ * 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
+
1
25
  "use strict";
2
26
 
3
27
  module.exports = {
@@ -1,10 +1,39 @@
1
- "use strict";
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2015-present Stuart Knightley 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 all
14
+ * 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
+ */
2
24
 
3
- // This is a really simple and dumb parser, that looks just for a
4
- // single kind of comment. It won't detect multiple block comments.
25
+ "use strict";
5
26
 
6
- module.exports = function commentParser(text) {
7
- text = text.trim();
27
+ /**
28
+ * Parses a line or block comment and returns the type of comment and an array of content lines.
29
+ *
30
+ * This is a really simple and dumb parser, that looks just for a
31
+ * single kind of comment. It won't detect multiple block comments.
32
+ * @param {string} commentText comment text.
33
+ * @returns {['block' | 'line', string[]]} comment type and comment content broken into lines.
34
+ */
35
+ module.exports = function commentParser(commentText) {
36
+ const text = commentText.trim();
8
37
 
9
38
  if (text.substr(0, 2) === "//") {
10
39
  return [
@@ -1,13 +1,85 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2015-present Stuart Knightley 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 all
14
+ * 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
+
1
25
  "use strict";
2
26
 
27
+ /**
28
+ * Import type definitions.
29
+ * @typedef {import('estree').Comment} Comment
30
+ * @typedef {import('estree').Program} Program
31
+ * @typedef {import('eslint').Rule.Fix} Fix
32
+ * @typedef {import('eslint').Rule.NodeListener} NodeListener
33
+ * @typedef {import('eslint').Rule.ReportFixer} ReportFixer
34
+ * @typedef {import('eslint').Rule.RuleFixer} RuleFixer
35
+ * @typedef {import('eslint').Rule.RuleTextEdit} RuleTextEdit
36
+ * @typedef {import('eslint').Rule.RuleTextEditor} RuleTextEditor
37
+ * @typedef {import('eslint').Rule.RuleContext} RuleContext
38
+ */
39
+
40
+ /**
41
+ * @enum {string}
42
+ */
43
+ const lineEndingOptions = Object.freeze({
44
+ unix: "unix", // \n
45
+ windows: "windows", // \n
46
+ });
47
+
48
+ /**
49
+ * @enum {string}
50
+ */
51
+ const commentTypeOptions = Object.freeze({
52
+ block: "block",
53
+ line: "line"
54
+ });
55
+
56
+ /**
57
+ * Local type defintions.
58
+ * @typedef {string | { pattern: string, template?: string }} HeaderLine
59
+ * @typedef {(HeaderLine | HeaderLine[])} HeaderLines
60
+ * @typedef {{ lineEndings: ('unix' | 'windows') }} HeaderSettings
61
+ * @typedef {([string] | [string, HeaderSettings] | [('block' | 'line') | HeaderLines ] | [('block' | 'line') | HeaderLines | HeaderSettings] | [('block' | 'line') | HeaderLines | number ] | [('block' | 'line') | HeaderLines | number | HeaderSettings])} HeaderOptions
62
+ */
63
+
3
64
  var fs = require("fs");
4
65
  var commentParser = require("../comment-parser");
5
66
  var os = require("os");
6
67
 
68
+ /**
69
+ * Tests if the passed line configuration string or object is a pattern definition.
70
+ * @param {HeaderLine} object line configuration object or string
71
+ * @returns {boolean} `true` if the line configuration is a pattern-dfining object or `false` otherwise.
72
+ */
7
73
  function isPattern(object) {
8
74
  return typeof object === "object" && Object.prototype.hasOwnProperty.call(object, "pattern");
9
75
  }
10
76
 
77
+ /**
78
+ * Utility over a line config argument to match an expected string either against a regex or for full match against a string.
79
+ * @param {HeaderLine} actual the string to test.
80
+ * @param {string} expected The string or regex to test again.
81
+ * @returns {boolean} `true` if the passed string matches the expected line config or `false` otherwise.
82
+ */
11
83
  function match(actual, expected) {
12
84
  if (expected.test) {
13
85
  return expected.test(actual);
@@ -16,19 +88,29 @@ function match(actual, expected) {
16
88
  }
17
89
  }
18
90
 
91
+ /**
92
+ * Remove Unix she-bangs from the list of comments.
93
+ * @param {Comment[]} comments the list of comment lines.
94
+ * @returns {Comment[]} the list of comments with containing all incomming comments from `comments` with the shebang comments omitted.
95
+ */
19
96
  function excludeShebangs(comments) {
20
97
  return comments.filter(function(comment) {
21
98
  return comment.type !== "Shebang";
22
99
  });
23
100
  }
24
101
 
25
- // Returns either the first block comment or the first set of line comments that
26
- // are ONLY separated by a single newline. Note that this does not actually
27
- // check if they are at the start of the file since that is already checked by
28
- // hasHeader().
102
+ /**
103
+ * Returns either the first block comment or the first set of line comments that
104
+ * are ONLY separated by a single newline. Note that this does not actually
105
+ * check if they are at the start of the file since that is already checked by
106
+ * `hasHeader()`.
107
+ * @param {RuleContext} context ESLint execution environment.
108
+ * @param {Program} node ESLint AST treee node being processed.
109
+ * @returns {Comment[]} lines that constitute the leading comment.
110
+ */
29
111
  function getLeadingComments(context, node) {
30
112
  var all = excludeShebangs(context.getSourceCode().getAllComments(node.body.length ? node.body[0] : node));
31
- if (all[0].type.toLowerCase() === "block") {
113
+ if (all[0].type.toLowerCase() === commentTypeOptions.block) {
32
114
  return [all[0]];
33
115
  }
34
116
  for (var i = 1; i < all.length; ++i) {
@@ -40,33 +122,70 @@ function getLeadingComments(context, node) {
40
122
  return all.slice(0, i);
41
123
  }
42
124
 
125
+ /**
126
+ * Generate a comment including trailing spaces out of a number of comment body lines.
127
+ * @param {'block' | 'line'} commentType the type of comment to generate.
128
+ * @param {string[]} textArray list of lines of the comment content.
129
+ * @param {'\n' | '\r\n'} eol end-of-line characters.
130
+ * @param {number} numNewlines number of trailing lines after the comment.
131
+ * @returns {string} resulting comment.
132
+ */
43
133
  function genCommentBody(commentType, textArray, eol, numNewlines) {
44
134
  var eols = eol.repeat(numNewlines);
45
- if (commentType === "block") {
135
+ if (commentType === commentTypeOptions.block) {
46
136
  return "/*" + textArray.join(eol) + "*/" + eols;
47
137
  } else {
48
138
  return "//" + textArray.join(eol + "//") + eols;
49
139
  }
50
140
  }
51
141
 
142
+ /**
143
+ * ...
144
+ * @param {RuleContext} context ESLint rule execution context.
145
+ * @param {string[]} comments list of comments.
146
+ * @param {'\n' | '\r\n'} eol end-of-line characters
147
+ * @returns {[number, number]} resulting range.
148
+ */
52
149
  function genCommentsRange(context, comments, eol) {
53
150
  var start = comments[0].range[0];
54
151
  var end = comments.slice(-1)[0].range[1];
55
- if (context.getSourceCode().text[end] === eol) {
152
+ const sourceCode = context.getSourceCode().text;
153
+ const headerTrailingChars = sourceCode.substring(end, end + eol.length);
154
+ if (headerTrailingChars === eol) {
56
155
  end += eol.length;
57
156
  }
58
157
  return [start, end];
59
158
  }
60
159
 
160
+ /**
161
+ * Factory for fixer that adds a missing header.
162
+ * @param {'block' | 'line'} commentType type of comment to use.
163
+ * @param {Program} node ESLint AST program node.
164
+ * @param {string[]} headerLines lines of the header comment.
165
+ * @param {'\n' | '\r\n'} eol end-of-line characters
166
+ * @param {number} numNewlines number of trailing lines after the comment.
167
+ * @returns {ReportFixer} the fixer.
168
+ */
61
169
  function genPrependFixer(commentType, node, headerLines, eol, numNewlines) {
62
170
  return function(fixer) {
63
- return fixer.insertTextBefore(
64
- node,
171
+ const insertPos = (node.comments.length && node.comments[0].type === "Shebang") ? node.comments[0].range[1] + eol.length : 0;
172
+ return fixer.insertTextBeforeRange(
173
+ [insertPos, 0 /* don't care */],
65
174
  genCommentBody(commentType, headerLines, eol, numNewlines)
66
175
  );
67
176
  };
68
177
  }
69
178
 
179
+ /**
180
+ * Factory for fixer that replaces an incorrect header.
181
+ * @param {'block' | 'line'} commentType type of comment to use.
182
+ * @param {RuleContext} context ESLint rule execution context.
183
+ * @param {Comment[]} leadingComments comment elements to replace.
184
+ * @param {string[]} headerLines lines of the header comment.
185
+ * @param {'\n' | '\r\n'} eol end-of-line characters
186
+ * @param {number} numNewlines number of trailing lines after the comment.
187
+ * @returns {(fixer: RuleTextEditor) => RuleTextEdit | RuleTextEdit[] | null} the fixer.
188
+ */
70
189
  function genReplaceFixer(commentType, context, leadingComments, headerLines, eol, numNewlines) {
71
190
  return function(fixer) {
72
191
  return fixer.replaceTextRange(
@@ -76,6 +195,11 @@ function genReplaceFixer(commentType, context, leadingComments, headerLines, eol
76
195
  };
77
196
  }
78
197
 
198
+ /**
199
+ * Finds the option parameter within the list of rule config options.
200
+ * @param {HeaderOptions} options the config options passed to the rule.
201
+ * @returns {HeaderSettings | null} the settings parameter or `null` if no such is defined.
202
+ */
79
203
  function findSettings(options) {
80
204
  var lastOption = options.length > 0 ? options[options.length - 1] : null;
81
205
  if (typeof lastOption === "object" && !Array.isArray(lastOption) && lastOption !== null
@@ -85,17 +209,30 @@ function findSettings(options) {
85
209
  return null;
86
210
  }
87
211
 
212
+ /**
213
+ * Returns the used line-termination characters per the rule's config if any or else based on the runtime environments.
214
+ * @param {HeaderOptions} options rule configuration.
215
+ * @returns {'\n' | '\r\n'} the correct line ending characters for the environment.
216
+ */
88
217
  function getEOL(options) {
89
218
  var settings = findSettings(options);
90
- if (settings && settings.lineEndings === "unix") {
91
- return "\n";
92
- }
93
- if (settings && settings.lineEndings === "windows") {
94
- return "\r\n";
219
+ if (settings) {
220
+ if (settings.lineEndings === lineEndingOptions.unix) {
221
+ return "\n";
222
+ }
223
+ if (settings.lineEndings === lineEndingOptions.windows) {
224
+ return "\r\n";
225
+ }
95
226
  }
96
227
  return os.EOL;
97
228
  }
98
229
 
230
+ /**
231
+ * Tests if the first line in the source code (after a Unix she-bang) is a comment. Does not tolerate empty lines before the first match.
232
+ * @param {string} src source code to test.
233
+ * @returns {boolean} `true` if there is a comment or `false` otherwise.
234
+ */
235
+ // TODO: check if it is valid to have the copyright notice separated by an empty line from the shebang.
99
236
  function hasHeader(src) {
100
237
  if (src.substr(0, 2) === "#!") {
101
238
  var m = src.match(/(\r\n|\r|\n)/);
@@ -106,6 +243,12 @@ function hasHeader(src) {
106
243
  return src.substr(0, 2) === "/*" || src.substr(0, 2) === "//";
107
244
  }
108
245
 
246
+ /**
247
+ * Ensures that the right amount of empty lines trail the header.
248
+ * @param {string} src source to validate.
249
+ * @param {number} num expected number of trailing empty lines.
250
+ * @returns {boolean} `true` if the `num` number of empty lines are appended at the end or `false` otherwise.
251
+ */
109
252
  function matchesLineEndings(src, num) {
110
253
  for (var j = 0; j < num; ++j) {
111
254
  var m = src.match(/^(\r\n|\r|\n)/);
@@ -127,7 +270,7 @@ module.exports = {
127
270
  definitions: {
128
271
  commentType: {
129
272
  type: "string",
130
- enum: ["block", "line"]
273
+ enum: [commentTypeOptions.block, commentTypeOptions.line]
131
274
  },
132
275
  line: {
133
276
  anyOf: [
@@ -171,7 +314,7 @@ module.exports = {
171
314
  properties: {
172
315
  lineEndings: {
173
316
  type: "string",
174
- enum: ["unix", "windows"]
317
+ enum: [lineEndingOptions.unix, lineEndingOptions.windows]
175
318
  }
176
319
  },
177
320
  additionalProperties: false
@@ -213,6 +356,11 @@ module.exports = {
213
356
  }
214
357
  }
215
358
  },
359
+ /**
360
+ * Rule creation function.
361
+ * @param {RuleContext} context ESLint rule execution context.
362
+ * @returns {NodeListener} the rule definition.
363
+ */
216
364
  create: function(context) {
217
365
  var options = context.options;
218
366
  var numNewlines = options.length > 2 && typeof options[2] === "number" ? options[2] : 1;
@@ -280,7 +428,7 @@ module.exports = {
280
428
  fix: canFix ? genReplaceFixer(commentType, context, leadingComments, fixLines, eol, numNewlines) : null
281
429
  });
282
430
  } else {
283
- if (commentType === "line") {
431
+ if (commentType === commentTypeOptions.line) {
284
432
  if (leadingComments.length < headerLines.length) {
285
433
  context.report({
286
434
  loc: node.loc,
@@ -321,8 +469,11 @@ module.exports = {
321
469
  hasError = true;
322
470
  }
323
471
  for (i = 0; !hasError && i < headerLines.length; i++) {
324
- if (!match(leadingLines[i], headerLines[i])) {
472
+ const leadingLine = leadingLines[i];
473
+ const headerLine = headerLines[i];
474
+ if (!match(leadingLine, headerLine)) {
325
475
  hasError = true;
476
+ break;
326
477
  }
327
478
  }
328
479
 
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@tony.ganchev/eslint-plugin-header",
3
- "version": "3.1.4",
3
+ "version": "3.1.6",
4
4
  "description": "ESLint plugin to ensure files begin with a given comment, usually a copyright or license notice.",
5
5
  "main": "index.js",
6
+ "files": [
7
+ "/lib/**/*.js",
8
+ "!/lib/rules/test-utils.js"
9
+ ],
6
10
  "scripts": {
7
11
  "test": "npm run lint && npm run unit",
8
- "unit": "mocha tests/lib/*.js tests/lib/**/*.js",
12
+ "unit": "nyc --reporter=html --reporter=text --reporter=text-summary --check-coverage=true --statements=98 --branches=90 --lines=98 --functions=100 mocha tests/lib/**/*.js",
9
13
  "lint": "eslint ."
10
14
  },
11
15
  "devDependencies": {
@@ -13,7 +17,9 @@
13
17
  "@eslint/js": "^9.32.0",
14
18
  "eslint": "^9.32.0",
15
19
  "eslint-plugin-jsdoc": "^52.0.4",
16
- "mocha": "^11.7.1"
20
+ "mocha": "^11.7.1",
21
+ "nyc": "^17.1.0",
22
+ "testdouble": "^3.20.2"
17
23
  },
18
24
  "peerDependencies": {
19
25
  "eslint": ">=7.7.0"
@@ -1,33 +0,0 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
6
- on:
7
- release:
8
- types: [created]
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v4
15
- - uses: actions/setup-node@v4
16
- with:
17
- node-version: 24
18
- - run: npm ci
19
- - run: npm test
20
-
21
- publish-npm:
22
- needs: build
23
- runs-on: ubuntu-latest
24
- steps:
25
- - uses: actions/checkout@v4
26
- - uses: actions/setup-node@v4
27
- with:
28
- node-version: 24
29
- registry-url: https://registry.npmjs.org/
30
- - run: npm ci
31
- - run: npm publish
32
- env:
33
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
@@ -1,22 +0,0 @@
1
- name: Test
2
-
3
- on:
4
- push:
5
- branches: [ main ]
6
- pull_request:
7
- branches: [ main ]
8
-
9
- jobs:
10
- build:
11
-
12
- runs-on: ubuntu-latest
13
-
14
- steps:
15
- - uses: actions/checkout@v2
16
- - name: Use Node.js
17
- uses: actions/setup-node@v1
18
- with:
19
- node-version: '24.x'
20
- - name: Install dependencies
21
- run: npm ci
22
- - run: npm test
package/CHANGELOG.md DELETED
@@ -1,47 +0,0 @@
1
- # 3.1.3
2
-
3
- * Detailed ESLint 9 validation schema.
4
-
5
- # 3.1.2
6
-
7
- * Support ESLint 9.
8
-
9
- # 3.1.1
10
-
11
- * Fix detecting header below shebang comment with Windows EOL (#30)
12
-
13
- # 3.1.0
14
-
15
- * Update to eslint 7.7.0
16
- * Add a third option to specify number of linebreaks after the header. (#29)
17
-
18
- # 3.0.0
19
-
20
- * Allow regexp in multiline arrays (#23)
21
- * Add `template` option for regexps, for `eslint --fix` (#23)
22
- * Update eslint to v5.12.0 (#19)
23
-
24
- # 2.0.0
25
-
26
- * Use the OS's line endings (`\n` on *nix, `\r\n` on Windows) when parsing and fixing comments. This can be configured with the `lineEndings` option. Major version bump as this could be a breaking change for projects.
27
-
28
- # 1.2.0
29
-
30
- * Add auto fix functionality (eslint `--fix` option) (#12)
31
-
32
- # 1.1.0
33
-
34
- * Ignore shebangs above header comments to support ESLint 4+ (#11)
35
-
36
- # 1.0.0
37
-
38
- * Allow RegExp patterns in addition to strings (#2, #4)
39
- * Fix line comment length mismatch issue (#3)
40
-
41
- # 0.1.0
42
-
43
- * Add config option to read header from file
44
-
45
- # 0.0.2
46
-
47
- * Initial release
package/eslint.config.mjs DELETED
@@ -1,168 +0,0 @@
1
- import { defineConfig } from "eslint/config";
2
- import globals from "globals";
3
- import path from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- import js from "@eslint/js";
6
- import { FlatCompat } from "@eslint/eslintrc";
7
- import jsdoc from "eslint-plugin-jsdoc";
8
-
9
- const filename = fileURLToPath(import.meta.url);
10
- const dirname = path.dirname(filename);
11
- const compat = new FlatCompat({
12
- baseDirectory: dirname,
13
- recommendedConfig: js.configs.recommended,
14
- allConfig: js.configs.all
15
- });
16
-
17
- const jsRules = {
18
- extends: [
19
- ...compat.extends("eslint:recommended"),
20
- ],
21
- rules: {
22
- indent: [2, 4, {
23
- SwitchCase: 1,
24
- }],
25
-
26
- "brace-style": [2, "1tbs"],
27
-
28
- camelcase: [2, {
29
- properties: "never",
30
- }],
31
-
32
- "callback-return": [2, ["cb", "callback", "next"]],
33
- "comma-spacing": 2,
34
- "comma-style": [2, "last"],
35
- "consistent-return": 2,
36
- curly: [2, "all"],
37
- "default-case": 2,
38
-
39
- "dot-notation": [2, {
40
- allowKeywords: true,
41
- }],
42
-
43
- "eol-last": 2,
44
- eqeqeq: 2,
45
- "func-style": [2, "declaration"],
46
- "guard-for-in": 2,
47
-
48
- "key-spacing": [2, {
49
- beforeColon: false,
50
- afterColon: true,
51
- }],
52
-
53
- "new-cap": 2,
54
- "new-parens": 2,
55
- "no-alert": 2,
56
- "no-array-constructor": 2,
57
- "no-caller": 2,
58
- "no-console": 0,
59
- "no-delete-var": 2,
60
- "no-eval": 2,
61
- "no-extend-native": 2,
62
- "no-extra-bind": 2,
63
- "no-fallthrough": 2,
64
- "no-floating-decimal": 2,
65
- "no-implied-eval": 2,
66
- "no-invalid-this": 2,
67
- "no-iterator": 2,
68
- "no-label-var": 2,
69
- "no-labels": 2,
70
- "no-lone-blocks": 2,
71
- "no-loop-func": 2,
72
- "no-mixed-spaces-and-tabs": [2, false],
73
- "no-multi-spaces": 2,
74
- "no-multi-str": 2,
75
- "no-native-reassign": 2,
76
- "no-nested-ternary": 2,
77
- "no-new": 2,
78
- "no-new-func": 2,
79
- "no-new-object": 2,
80
- "no-new-wrappers": 2,
81
- "no-octal": 2,
82
- "no-octal-escape": 2,
83
- "no-process-exit": 2,
84
- "no-proto": 2,
85
- "no-redeclare": 2,
86
- "no-return-assign": 2,
87
- "no-script-url": 2,
88
- "no-sequences": 2,
89
- "no-shadow": 2,
90
- "no-shadow-restricted-names": 2,
91
- "no-spaced-func": 2,
92
- "no-trailing-spaces": 2,
93
- "no-undef": 2,
94
- "no-undef-init": 2,
95
- "no-undefined": 2,
96
- "no-underscore-dangle": 2,
97
- "no-unused-expressions": 2,
98
-
99
- "no-unused-vars": [2, {
100
- vars: "all",
101
- args: "after-used",
102
- }],
103
-
104
- "no-use-before-define": 2,
105
- "no-with": 2,
106
- quotes: [2, "double"],
107
- radix: 2,
108
- semi: 2,
109
-
110
- "semi-spacing": [2, {
111
- before: false,
112
- after: true,
113
- }],
114
-
115
- "keyword-spacing": [2, {
116
- after: true,
117
- }],
118
-
119
- "space-before-blocks": 2,
120
- "space-before-function-paren": [2, "never"],
121
- "space-infix-ops": 2,
122
-
123
- "space-unary-ops": [2, {
124
- words: true,
125
- nonwords: false,
126
- }],
127
-
128
- "spaced-comment": [2, "always", {
129
- exceptions: ["-"],
130
- }],
131
-
132
- strict: [2, "global"],
133
-
134
- "wrap-iife": 2,
135
- yoda: [2, "never"],
136
- "no-catch-shadow": 0,
137
- "no-mixed-requires": 2,
138
- "no-new-require": 2,
139
- "no-path-concat": 2,
140
- "global-strict": [0, "always"],
141
- "handle-callback-err": [2, "err"],
142
- }
143
- };
144
-
145
- export default defineConfig([
146
- jsdoc.configs["flat/recommended"],
147
- {
148
- files: ["lib/**/*.js"],
149
- languageOptions: {
150
- sourceType: "commonjs",
151
- globals: {
152
- ...globals.node,
153
- },
154
- },
155
- ...jsRules,
156
- },
157
- {
158
- files: ["tests/**/*.js"],
159
- languageOptions: {
160
- sourceType: "script",
161
- globals: {
162
- ...globals.node,
163
- ...globals.mocha,
164
- },
165
- },
166
- ...jsRules,
167
- },
168
- ]);
@@ -1,23 +0,0 @@
1
- /* eslint-env mocha */
2
- "use strict";
3
-
4
- var assert = require("assert");
5
- var commentParser = require("../../lib/comment-parser");
6
-
7
- describe("comment parser", function() {
8
- it("parses block comments", function() {
9
- var result = commentParser("/* pass1\n pass2 */ ");
10
- assert.deepEqual(result, ["block", " pass1\n pass2 "]);
11
- });
12
-
13
- it("throws an error when a block comment isn't ended", function() {
14
- assert.throws(function() {
15
- commentParser("/* fail");
16
- });
17
- });
18
-
19
- it("parses line comments", function() {
20
- var result = commentParser("// pass1\n// pass2\n ");
21
- assert.deepEqual(result, ["line", [" pass1", " pass2"]]);
22
- });
23
- });
@@ -1,285 +0,0 @@
1
- "use strict";
2
-
3
- var rule = require("../../../lib/rules/header");
4
- var RuleTester = require("eslint").RuleTester;
5
-
6
- var ruleTester = new RuleTester();
7
- ruleTester.run("header", rule, {
8
- valid: [
9
- {
10
- code: "/*Copyright 2015, My Company*/\nconsole.log(1);",
11
- options: ["block", "Copyright 2015, My Company"]
12
- },
13
- {
14
- code: "//Copyright 2015, My Company\nconsole.log(1);",
15
- options: ["line", "Copyright 2015, My Company"]
16
- },
17
- {
18
- code: "/*Copyright 2015, My Company*/",
19
- options: ["block", "Copyright 2015, My Company", 0]
20
- },
21
- {
22
- code: "//Copyright 2015\n//My Company\nconsole.log(1)",
23
- options: ["line", "Copyright 2015\nMy Company"]
24
- },
25
- {
26
- code: "//Copyright 2015\n//My Company\nconsole.log(1)",
27
- options: ["line", ["Copyright 2015", "My Company"]]
28
- },
29
- {
30
- code: "/*Copyright 2015\nMy Company*/\nconsole.log(1)",
31
- options: ["block", ["Copyright 2015", "My Company"]]
32
- },
33
- {
34
- code: "/*************************\n * Copyright 2015\n * My Company\n *************************/\nconsole.log(1)",
35
- options: ["block", [
36
- "************************",
37
- " * Copyright 2015",
38
- " * My Company",
39
- " ************************"
40
- ]]
41
- },
42
- {
43
- code: "/*\nCopyright 2015\nMy Company\n*/\nconsole.log(1)",
44
- options: ["tests/support/block.js"]
45
- },
46
- {
47
- code: "// Copyright 2015\n// My Company\nconsole.log(1)",
48
- options: ["tests/support/line.js"]
49
- },
50
- {
51
- code: "//Copyright 2015\n//My Company\n/* DOCS */",
52
- options: ["line", "Copyright 2015\nMy Company"]
53
- },
54
- {
55
- code: "// Copyright 2017",
56
- options: ["line", {pattern: "^ Copyright \\d+$"}, 0]
57
- },
58
- {
59
- code: "// Copyright 2017\n// Author: abc@example.com",
60
- options: ["line", [{pattern: "^ Copyright \\d+$"}, {pattern: "^ Author: \\w+@\\w+\\.\\w+$"}], 0]
61
- },
62
- {
63
- code: "/* Copyright 2017\n Author: abc@example.com */",
64
- options: ["block", {pattern: "^ Copyright \\d{4}\\n Author: \\w+@\\w+\\.\\w+ $"}, 0]
65
- },
66
- {
67
- code: "#!/usr/bin/env node\n/**\n * Copyright\n */",
68
- options: ["block", [
69
- "*",
70
- " * Copyright",
71
- " "
72
- ], 0]
73
- },
74
- {
75
- code: "// Copyright 2015\r\n// My Company\r\nconsole.log(1)",
76
- options: ["tests/support/line.js"]
77
- },
78
- {
79
- code: "//Copyright 2018\r\n//My Company\r\n/* DOCS */",
80
- options: ["line", ["Copyright 2018", "My Company"]]
81
- },
82
- {
83
- code: "/*Copyright 2018\r\nMy Company*/\r\nconsole.log(1)",
84
- options: ["block", ["Copyright 2018", "My Company"], {"lineEndings": "windows"}]
85
- },
86
- {
87
- code: "/*Copyright 2018\nMy Company*/\nconsole.log(1)",
88
- options: ["block", ["Copyright 2018", "My Company"], {"lineEndings": "unix"}]
89
- },
90
- {
91
- code: "/*************************\n * Copyright 2015\n * My Company\n *************************/\nconsole.log(1)",
92
- options: ["block", [
93
- "************************",
94
- { pattern: " \\* Copyright \\d{4}" },
95
- " * My Company",
96
- " ************************"
97
- ]]
98
- },
99
- {
100
- code: "/*Copyright 2020, My Company*/\nconsole.log(1);",
101
- options: ["block", "Copyright 2020, My Company", 1],
102
- },
103
- {
104
- code: "/*Copyright 2020, My Company*/\n\nconsole.log(1);",
105
- options: ["block", "Copyright 2020, My Company", 2],
106
- },
107
- {
108
- code: "/*Copyright 2020, My Company*/\n\n// Log number one\nconsole.log(1);",
109
- options: ["block", "Copyright 2020, My Company", 2],
110
- },
111
- {
112
- code: "/*Copyright 2020, My Company*/\n\n/*Log number one*/\nconsole.log(1);",
113
- options: ["block", "Copyright 2020, My Company", 2],
114
- },
115
- {
116
- code: "/**\n * Copyright 2020\n * My Company\n **/\n\n/*Log number one*/\nconsole.log(1);",
117
- options: ["block", "*\n * Copyright 2020\n * My Company\n *", 2],
118
- },
119
- {
120
- code: "#!/usr/bin/env node\r\n/**\r\n * Copyright\r\n */",
121
- options: ["block", [
122
- "*",
123
- " * Copyright",
124
- " "
125
- ], 0]
126
- }
127
- ],
128
- invalid: [
129
- {
130
- code: "console.log(1);",
131
- options: ["block", "Copyright 2015, My Company"],
132
- errors: [
133
- {message: "missing header"}
134
- ],
135
- output: "/*Copyright 2015, My Company*/\nconsole.log(1);"
136
- },
137
- {
138
- code: "//Copyright 2014, My Company\nconsole.log(1);",
139
- options: ["block", "Copyright 2015, My Company"],
140
- errors: [
141
- {message: "header should be a block comment"}
142
- ],
143
- output: "/*Copyright 2015, My Company*/\nconsole.log(1);"
144
- },
145
- {
146
- code: "/*Copyright 2014, My Company*/\nconsole.log(1);",
147
- options: ["line", "Copyright 2015, My Company"],
148
- errors: [
149
- {message: "header should be a line comment"}
150
- ],
151
- output: "//Copyright 2015, My Company\nconsole.log(1);"
152
- },
153
- {
154
- code: "/*Copyright 2014, My Company*/\nconsole.log(1);",
155
- options: ["block", "Copyright 2015, My Company"],
156
- errors: [
157
- {message: "incorrect header"}
158
- ],
159
- output: "/*Copyright 2015, My Company*/\nconsole.log(1);"
160
- },
161
- {
162
- // Test extra line in comment
163
- code: "/*Copyright 2015\nMy Company\nExtra*/\nconsole.log(1);",
164
- options: ["block", ["Copyright 2015", "My Company"]],
165
- errors: [
166
- {message: "incorrect header"}
167
- ],
168
- output: "/*Copyright 2015\nMy Company*/\nconsole.log(1);"
169
- },
170
- {
171
- code: "/*Copyright 2015\n*/\nconsole.log(1);",
172
- options: ["block", ["Copyright 2015", "My Company"]],
173
- errors: [
174
- {message: "incorrect header"}
175
- ],
176
- output: "/*Copyright 2015\nMy Company*/\nconsole.log(1);"
177
- },
178
- {
179
- code: "//Copyright 2014\n//My Company\nconsole.log(1)",
180
- options: ["line", "Copyright 2015\nMy Company"],
181
- errors: [
182
- {message: "incorrect header"}
183
- ],
184
- output: "//Copyright 2015\n//My Company\nconsole.log(1)"
185
- },
186
- {
187
- code: "//Copyright 2015",
188
- options: ["line", "Copyright 2015\nMy Company"],
189
- errors: [
190
- {message: "incorrect header"}
191
- ],
192
- output: "//Copyright 2015\n//My Company\n"
193
- },
194
- {
195
- code: "// Copyright 2017 trailing",
196
- options: ["line", {pattern: "^ Copyright \\d+$"}],
197
- errors: [
198
- {message: "incorrect header"}
199
- ]
200
- },
201
- {
202
- code: "// Copyright 2017 trailing",
203
- options: ["line", {pattern: "^ Copyright \\d+$", template: " Copyright 2018"}],
204
- errors: [
205
- {message: "incorrect header"}
206
- ],
207
- output: "// Copyright 2018\n"
208
- },
209
- {
210
- code: "// Copyright 2017 trailing\n// Someone",
211
- options: ["line", [{pattern: "^ Copyright \\d+$", template: " Copyright 2018"}, " My Company"]],
212
- errors: [
213
- {message: "incorrect header"}
214
- ],
215
- output: "// Copyright 2018\n// My Company\n"
216
- },
217
- {
218
- code: "// Copyright 2017\n// Author: ab-c@example.com",
219
- options: ["line", [{pattern: "Copyright \\d+"}, {pattern: "^ Author: \\w+@\\w+\\.\\w+$"}]],
220
- errors: [
221
- {message: "incorrect header"}
222
- ]
223
- },
224
- {
225
- code: "/* Copyright 2017-01-02\n Author: abc@example.com */",
226
- options: ["block", {pattern: "^ Copyright \\d+\\n Author: \\w+@\\w+\\.\\w+ $"}],
227
- errors: [
228
- {message: "incorrect header"}
229
- ]
230
- },
231
- {
232
- code: "/*************************\n * Copyright 2015\n * All your base are belong to us!\n *************************/\nconsole.log(1)",
233
- options: ["block", [
234
- "************************",
235
- { pattern: " \\* Copyright \\d{4}", template: " * Copyright 2019" },
236
- " * My Company",
237
- " ************************"
238
- ]],
239
- errors: [
240
- {message: "incorrect header"}
241
- ],
242
- output: "/*************************\n * Copyright 2019\n * My Company\n *************************/\nconsole.log(1)"
243
- },
244
- {
245
- code: "/*Copyright 2020, My Company*/console.log(1);",
246
- options: ["block", "Copyright 2020, My Company", 2],
247
- errors: [
248
- {message: "no newline after header"}
249
- ],
250
- output: "/*Copyright 2020, My Company*/\n\nconsole.log(1);"
251
- },
252
- {
253
- code: "/*Copyright 2020, My Company*/console.log(1);",
254
- options: ["block", "Copyright 2020, My Company", 1],
255
- errors: [
256
- {message: "no newline after header"}
257
- ],
258
- output: "/*Copyright 2020, My Company*/\nconsole.log(1);"
259
- },
260
- {
261
- code: "//Copyright 2020\n//My Company\nconsole.log(1);",
262
- options: ["line", ["Copyright 2020", "My Company"], 2],
263
- errors: [
264
- {message: "no newline after header"}
265
- ],
266
- output: "//Copyright 2020\n//My Company\n\nconsole.log(1);"
267
- },
268
- {
269
- code: "/*Copyright 2020, My Company*/\nconsole.log(1);\n//Comment\nconsole.log(2);\n//Comment",
270
- options: ["block", "Copyright 2020, My Company", 2],
271
- errors: [
272
- {message: "no newline after header"}
273
- ],
274
- output: "/*Copyright 2020, My Company*/\n\nconsole.log(1);\n//Comment\nconsole.log(2);\n//Comment"
275
- },
276
- {
277
- code: "//Copyright 2020\n//My Company\nconsole.log(1);\n//Comment\nconsole.log(2);\n//Comment",
278
- options: ["line", ["Copyright 2020", "My Company"], 2],
279
- errors: [
280
- {message: "no newline after header"}
281
- ],
282
- output: "//Copyright 2020\n//My Company\n\nconsole.log(1);\n//Comment\nconsole.log(2);\n//Comment"
283
- }
284
- ]
285
- });
@@ -1,4 +0,0 @@
1
- /*
2
- Copyright 2015
3
- My Company
4
- */
@@ -1,2 +0,0 @@
1
- // Copyright 2015
2
- // My Company