/
home
/
techb158
/
balavpn.abdallabala.com
/
node_modules
/
eslint
/
lib
/
rules
/
/home/techb158/balavpn.abdallabala.com/node_modules/eslint/lib/rules
mkdir
upload
Name
Size
Mode
Actions
utils/
-
0777
rm
accessor-pairs.js
11210
0666
edit
dl
rm
array-bracket-newline.js
8123
0666
edit
dl
rm
array-bracket-spacing.js
8071
0666
edit
dl
rm
array-callback-return.js
12815
0666
edit
dl
rm
array-element-newline.js
9070
0666
edit
dl
rm
arrow-body-style.js
10365
0666
edit
dl
rm
arrow-parens.js
7119
0666
edit
dl
rm
arrow-spacing.js
4618
0666
edit
dl
rm
block-scoped-var.js
3501
0666
edit
dl
rm
block-spacing.js
5159
0666
edit
dl
rm
brace-style.js
7592
0666
edit
dl
rm
callback-return.js
5879
0666
edit
dl
rm
camelcase.js
10363
0666
edit
dl
rm
capitalized-comments.js
9285
0666
edit
dl
rm
class-methods-use-this.js
6393
0666
edit
dl
rm
comma-dangle.js
11652
0666
edit
dl
rm
comma-spacing.js
5892
0666
edit
dl
rm
comma-style.js
10241
0666
edit
dl
rm
complexity.js
5194
0666
edit
dl
rm
computed-property-spacing.js
6703
0666
edit
dl
rm
consistent-return.js
5739
0666
edit
dl
rm
consistent-this.js
4429
0666
edit
dl
rm
constructor-super.js
12051
0666
edit
dl
rm
curly.js
11758
0666
edit
dl
rm
default-case-last.js
1103
0666
edit
dl
rm
default-case.js
2311
0666
edit
dl
rm
default-param-last.js
1690
0666
edit
dl
rm
dot-location.js
3404
0666
edit
dl
rm
dot-notation.js
5192
0666
edit
dl
rm
eol-last.js
3566
0666
edit
dl
rm
eqeqeq.js
4874
0666
edit
dl
rm
for-direction.js
4305
0666
edit
dl
rm
func-call-spacing.js
8290
0666
edit
dl
rm
func-name-matching.js
8835
0666
edit
dl
rm
func-names.js
5135
0666
edit
dl
rm
func-style.js
5337
0666
edit
dl
rm
function-call-argument-newline.js
4222
0666
edit
dl
rm
function-paren-newline.js
10198
0666
edit
dl
rm
generator-star-spacing.js
6319
0666
edit
dl
rm
getter-return.js
5756
0666
edit
dl
rm
global-require.js
2853
0666
edit
dl
rm
grouped-accessor-pairs.js
7185
0666
edit
dl
rm
guard-for-in.js
1924
0666
edit
dl
rm
handle-callback-err.js
3247
0666
edit
dl
rm
id-blacklist.js
6700
0666
edit
dl
rm
id-denylist.js
6357
0666
edit
dl
rm
id-length.js
5613
0666
edit
dl
rm
id-match.js
9208
0666
edit
dl
rm
implicit-arrow-linebreak.js
3147
0666
edit
dl
rm
indent-legacy.js
35743
0666
edit
dl
rm
indent.js
66474
0666
edit
dl
rm
index.js
17913
0666
edit
dl
rm
init-declarations.js
3974
0666
edit
dl
rm
jsx-quotes.js
3147
0666
edit
dl
rm
key-spacing.js
21268
0666
edit
dl
rm
keyword-spacing.js
20417
0666
edit
dl
rm
line-comment-position.js
3736
0666
edit
dl
rm
linebreak-style.js
3569
0666
edit
dl
rm
lines-around-comment.js
15497
0666
edit
dl
rm
lines-around-directive.js
7023
0666
edit
dl
rm
lines-between-class-members.js
10129
0666
edit
dl
rm
logical-assignment-operators.js
19047
0666
edit
dl
rm
max-classes-per-file.js
1858
0666
edit
dl
rm
max-depth.js
3633
0666
edit
dl
rm
max-len.js
13652
0666
edit
dl
rm
max-lines-per-function.js
6050
0666
edit
dl
rm
max-lines.js
4403
0666
edit
dl
rm
max-nested-callbacks.js
2691
0666
edit
dl
rm
max-params.js
3075
0666
edit
dl
rm
max-statements-per-line.js
6738
0666
edit
dl
rm
max-statements.js
4575
0666
edit
dl
rm
multiline-comment-style.js
18395
0666
edit
dl
rm
multiline-ternary.js
6541
0666
edit
dl
rm
new-cap.js
7204
0666
edit
dl
rm
new-parens.js
3167
0666
edit
dl
rm
newline-after-var.js
8852
0666
edit
dl
rm
newline-before-return.js
7126
0666
edit
dl
rm
newline-per-chained-call.js
3883
0666
edit
dl
rm
no-alert.js
3843
0666
edit
dl
rm
no-array-constructor.js
4995
0666
edit
dl
rm
no-async-promise-executor.js
1007
0666
edit
dl
rm
no-await-in-loop.js
2494
0666
edit
dl
rm
no-bitwise.js
2948
0666
edit
dl
rm
no-buffer-constructor.js
1868
0666
edit
dl
rm
no-caller.js
1086
0666
edit
dl
rm
no-case-declarations.js
1867
0666
edit
dl
rm
no-catch-shadow.js
2515
0666
edit
dl
rm
no-class-assign.js
1566
0666
edit
dl
rm
no-compare-neg-zero.js
1662
0666
edit
dl
rm
no-cond-assign.js
4837
0666
edit
dl
rm
no-confusing-arrow.js
3232
0666
edit
dl
rm
no-console.js
6233
0666
edit
dl
rm
no-const-assign.js
1848
0666
edit
dl
rm
no-constant-binary-expression.js
18150
0666
edit
dl
rm
no-constant-condition.js
4469
0666
edit
dl
rm
no-constructor-return.js
1191
0666
edit
dl
rm
no-continue.js
784
0666
edit
dl
rm
no-control-regex.js
3830
0666
edit
dl
rm
no-debugger.js
793
0666
edit
dl
rm
no-delete-var.js
852
0666
edit
dl
rm
no-div-regex.js
1245
0666
edit
dl
rm
no-dupe-args.js
2387
0666
edit
dl
rm
no-dupe-class-members.js
2905
0666
edit
dl
rm
no-dupe-else-if.js
4197
0666
edit
dl
rm
no-dupe-keys.js
3963
0666
edit
dl
rm
no-duplicate-case.js
1765
0666
edit
dl
rm
no-duplicate-imports.js
10024
0666
edit
dl
rm
no-else-return.js
13405
0666
edit
dl
rm
no-empty-character-class.js
1938
0666
edit
dl
rm
no-empty-function.js
5754
0666
edit
dl
rm
no-empty-pattern.js
1841
0666
edit
dl
rm
no-empty-static-block.js
1589
0666
edit
dl
rm
no-empty.js
3202
0666
edit
dl
rm
no-eq-null.js
1117
0666
edit
dl
rm
no-eval.js
7542
0666
edit
dl
rm
no-ex-assign.js
1301
0666
edit
dl
rm
no-extend-native.js
5421
0666
edit
dl
rm
no-extra-bind.js
6007
0666
edit
dl
rm
no-extra-boolean-cast.js
10590
0666
edit
dl
rm
no-extra-label.js
4265
0666
edit
dl
rm
no-extra-parens.js
43596
0666
edit
dl
rm
no-extra-semi.js
4628
0666
edit
dl
rm
no-fallthrough.js
6966
0666
edit
dl
rm
no-floating-decimal.js
2568
0666
edit
dl
rm
no-func-assign.js
1861
0666
edit
dl
rm
no-global-assign.js
2426
0666
edit
dl
rm
no-implicit-coercion.js
12600
0666
edit
dl
rm
no-implicit-globals.js
4626
0666
edit
dl
rm
no-implied-eval.js
4339
0666
edit
dl
rm
no-import-assign.js
6179
0666
edit
dl
rm
no-inline-comments.js
2691
0666
edit
dl
rm
no-inner-declarations.js
3221
0666
edit
dl
rm
no-invalid-regexp.js
5962
0666
edit
dl
rm
no-invalid-this.js
4488
0666
edit
dl
rm
no-irregular-whitespace.js
7853
0666
edit
dl
rm
no-iterator.js
1110
0666
edit
dl
rm
no-label-var.js
2063
0666
edit
dl
rm
no-labels.js
3365
0666
edit
dl
rm
no-lone-blocks.js
3320
0666
edit
dl
rm
no-lonely-if.js
3303
0666
edit
dl
rm
no-loop-func.js
7035
0666
edit
dl
rm
no-loss-of-precision.js
7393
0666
edit
dl
rm
no-magic-numbers.js
10580
0666
edit
dl
rm
no-misleading-character-class.js
16369
0666
edit
dl
rm
no-mixed-operators.js
7147
0666
edit
dl
rm
no-mixed-requires.js
6383
0666
edit
dl
rm
no-mixed-spaces-and-tabs.js
3465
0666
edit
dl
rm
no-multi-assign.js
1327
0666
edit
dl
rm
no-multi-spaces.js
4588
0666
edit
dl
rm
no-multi-str.js
1610
0666
edit
dl
rm
no-multiple-empty-lines.js
5581
0666
edit
dl
rm
no-native-reassign.js
2765
0666
edit
dl
rm
no-negated-condition.js
2431
0666
edit
dl
rm
no-negated-in-lhs.js
1338
0666
edit
dl
rm
no-nested-ternary.js
960
0666
edit
dl
rm
no-new-func.js
2393
0666
edit
dl
rm
no-new-native-nonconstructor.js
1754
0666
edit
dl
rm
no-new-object.js
1866
0666
edit
dl
rm
no-new-require.js
1588
0666
edit
dl
rm
no-new-symbol.js
1739
0666
edit
dl
rm
no-new-wrappers.js
1460
0666
edit
dl
rm
no-new.js
905
0666
edit
dl
rm
no-nonoctal-decimal-escape.js
4566
0666
edit
dl
rm
no-obj-calls.js
2466
0666
edit
dl
rm
no-object-constructor.js
2923
0666
edit
dl
rm
no-octal-escape.js
1175
0666
edit
dl
rm
no-octal.js
832
0666
edit
dl
rm
no-param-reassign.js
6363
0666
edit
dl
rm
no-path-concat.js
2012
0666
edit
dl
rm
no-plusplus.js
2672
0666
edit
dl
rm
no-process-env.js
1646
0666
edit
dl
rm
no-process-exit.js
1735
0666
edit
dl
rm
no-promise-executor-return.js
6675
0666
edit
dl
rm
no-proto.js
1093
0666
edit
dl
rm
no-prototype-builtins.js
4721
0666
edit
dl
rm
no-redeclare.js
4425
0666
edit
dl
rm
no-regex-spaces.js
5276
0666
edit
dl
rm
no-restricted-exports.js
5636
0666
edit
dl
rm
no-restricted-globals.js
6229
0666
edit
dl
rm
no-restricted-imports.js
23880
0666
edit
dl
rm
no-restricted-modules.js
6128
0666
edit
dl
rm
no-restricted-properties.js
5948
0666
edit
dl
rm
no-restricted-syntax.js
1698
0666
edit
dl
rm
no-return-assign.js
2259
0666
edit
dl
rm
no-return-await.js
4457
0666
edit
dl
rm
no-script-url.js
1512
0666
edit
dl
rm
no-self-assign.js
4666
0666
edit
dl
rm
no-self-compare.js
1705
0666
edit
dl
rm
no-sequences.js
4011
0666
edit
dl
rm
no-setter-return.js
5725
0666
edit
dl
rm
no-shadow-restricted-names.js
2672
0666
edit
dl
rm
no-shadow.js
17353
0666
edit
dl
rm
no-spaced-func.js
2603
0666
edit
dl
rm
no-sparse-arrays.js
1483
0666
edit
dl
rm
no-sync.js
1887
0666
edit
dl
rm
no-tabs.js
2449
0666
edit
dl
rm
no-template-curly-in-string.js
989
0666
edit
dl
rm
no-ternary.js
785
0666
edit
dl
rm
no-this-before-super.js
9043
0666
edit
dl
rm
no-throw-literal.js
1088
0666
edit
dl
rm
no-trailing-spaces.js
6110
0666
edit
dl
rm
no-unassigned-vars.js
1964
0666
edit
dl
rm
no-undef-init.js
2409
0666
edit
dl
rm
no-undef.js
1899
0666
edit
dl
rm
no-undefined.js
1861
0666
edit
dl
rm
no-underscore-dangle.js
9535
0666
edit
dl
rm
no-unexpected-multiline.js
3477
0666
edit
dl
rm
no-unmodified-loop-condition.js
10035
0666
edit
dl
rm
no-unneeded-ternary.js
5935
0666
edit
dl
rm
no-unreachable-loop.js
5076
0666
edit
dl
rm
no-unreachable.js
7498
0666
edit
dl
rm
no-unsafe-finally.js
3339
0666
edit
dl
rm
no-unsafe-negation.js
3972
0666
edit
dl
rm
no-unsafe-optional-chaining.js
5389
0666
edit
dl
rm
no-unused-expressions.js
5520
0666
edit
dl
rm
no-unused-labels.js
3878
0666
edit
dl
rm
no-unused-private-class-members.js
6277
0666
edit
dl
rm
no-unused-vars.js
48552
0666
edit
dl
rm
no-use-before-define.js
11866
0666
edit
dl
rm
no-useless-assignment.js
19334
0666
edit
dl
rm
no-useless-backreference.js
7662
0666
edit
dl
rm
no-useless-call.js
2779
0666
edit
dl
rm
no-useless-catch.js
1310
0666
edit
dl
rm
no-useless-computed-key.js
5936
0666
edit
dl
rm
no-useless-concat.js
2966
0666
edit
dl
rm
no-useless-constructor.js
6986
0666
edit
dl
rm
no-useless-escape.js
11065
0666
edit
dl
rm
no-useless-rename.js
4929
0666
edit
dl
rm
no-useless-return.js
11954
0666
edit
dl
rm
no-var.js
11461
0666
edit
dl
rm
no-void.js
1366
0666
edit
dl
rm
no-warning-comments.js
5670
0666
edit
dl
rm
no-whitespace-before-property.js
3883
0666
edit
dl
rm
no-with.js
757
0666
edit
dl
rm
nonblock-statement-body-position.js
4418
0666
edit
dl
rm
object-curly-newline.js
10115
0666
edit
dl
rm
object-curly-spacing.js
10399
0666
edit
dl
rm
object-property-newline.js
3758
0666
edit
dl
rm
object-shorthand.js
18543
0666
edit
dl
rm
one-var-declaration-per-line.js
2995
0666
edit
dl
rm
one-var.js
19182
0666
edit
dl
rm
operator-assignment.js
7536
0666
edit
dl
rm
operator-linebreak.js
8901
0666
edit
dl
rm
padded-blocks.js
8910
0666
edit
dl
rm
padding-line-between-statements.js
16989
0666
edit
dl
rm
prefer-arrow-callback.js
11667
0666
edit
dl
rm
prefer-const.js
15780
0666
edit
dl
rm
prefer-destructuring.js
8931
0666
edit
dl
rm
prefer-exponentiation-operator.js
6727
0666
edit
dl
rm
prefer-named-capture-group.js
5048
0666
edit
dl
rm
prefer-numeric-literals.js
4504
0666
edit
dl
rm
prefer-object-has-own.js
3804
0666
edit
dl
rm
prefer-object-spread.js
9489
0666
edit
dl
rm
prefer-promise-reject-errors.js
4614
0666
edit
dl
rm
prefer-reflect.js
3828
0666
edit
dl
rm
prefer-regex-literals.js
14379
0666
edit
dl
rm
prefer-rest-params.js
3032
0666
edit
dl
rm
prefer-spread.js
2555
0666
edit
dl
rm
prefer-template.js
10537
0666
edit
dl
rm
preserve-caught-error.js
16269
0666
edit
dl
rm
quote-props.js
10129
0666
edit
dl
rm
quotes.js
10934
0666
edit
dl
rm
radix.js
5549
0666
edit
dl
rm
require-atomic-updates.js
9293
0666
edit
dl
rm
require-await.js
4564
0666
edit
dl
rm
require-unicode-regexp.js
7765
0666
edit
dl
rm
require-yield.js
1718
0666
edit
dl
rm
rest-spread-spacing.js
3739
0666
edit
dl
rm
semi-spacing.js
7384
0666
edit
dl
rm
semi-style.js
5246
0666
edit
dl
rm
semi.js
13324
0666
edit
dl
rm
sort-imports.js
8603
0666
edit
dl
rm
sort-keys.js
5880
0666
edit
dl
rm
sort-vars.js
3320
0666
edit
dl
rm
space-before-blocks.js
6328
0666
edit
dl
rm
space-before-function-paren.js
5253
0666
edit
dl
rm
space-in-parens.js
9314
0666
edit
dl
rm
space-infix-ops.js
5890
0666
edit
dl
rm
space-unary-ops.js
10644
0666
edit
dl
rm
spaced-comment.js
11246
0666
edit
dl
rm
strict.js
9141
0666
edit
dl
rm
switch-colon-spacing.js
4701
0666
edit
dl
rm
symbol-description.js
1701
0666
edit
dl
rm
template-curly-spacing.js
4337
0666
edit
dl
rm
template-tag-spacing.js
3059
0666
edit
dl
rm
unicode-bom.js
1716
0666
edit
dl
rm
use-isnan.js
7130
0666
edit
dl
rm
valid-typeof.js
4262
0666
edit
dl
rm
vars-on-top.js
4304
0666
edit
dl
rm
wrap-iife.js
6914
0666
edit
dl
rm
wrap-regex.js
2167
0666
edit
dl
rm
yield-star-spacing.js
3992
0666
edit
dl
rm
yoda.js
9713
0666
edit
dl
rm
Edit:
/home/techb158/balavpn.abdallabala.com/node_modules/eslint/lib/rules/multiline-comment-style.js
(18395B)
/** * @fileoverview enforce a particular style for multiline comments * @author Teddy Katz * @deprecated in ESLint v9.3.0 */ "use strict"; const astUtils = require("./utils/ast-utils"); //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ /** @type {import('../types').Rule.RuleModule} */ module.exports = { meta: { deprecated: { message: "Formatting rules are being moved out of ESLint core.", url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/", deprecatedSince: "9.3.0", availableUntil: "11.0.0", replacedBy: [ { message: "ESLint Stylistic now maintains deprecated stylistic core rules.", url: "https://eslint.style/guide/migration", plugin: { name: "@stylistic/eslint-plugin", url: "https://eslint.style", }, rule: { name: "multiline-comment-style", url: "https://eslint.style/rules/multiline-comment-style", }, }, ], }, type: "suggestion", docs: { description: "Enforce a particular style for multiline comments", recommended: false, url: "https://eslint.org/docs/latest/rules/multiline-comment-style", }, fixable: "whitespace", schema: { anyOf: [ { type: "array", items: [ { enum: ["starred-block", "bare-block"], }, ], additionalItems: false, }, { type: "array", items: [ { enum: ["separate-lines"], }, { type: "object", properties: { checkJSDoc: { type: "boolean", }, }, additionalProperties: false, }, ], additionalItems: false, }, ], }, messages: { expectedBlock: "Expected a block comment instead of consecutive line comments.", expectedBareBlock: "Expected a block comment without padding stars.", startNewline: "Expected a linebreak after '/*'.", endNewline: "Expected a linebreak before '*/'.", missingStar: "Expected a '*' at the start of this line.", alignment: "Expected this line to be aligned with the start of the comment.", expectedLines: "Expected multiple line comments instead of a block comment.", }, }, create(context) { const sourceCode = context.sourceCode; const option = context.options[0] || "starred-block"; const params = context.options[1] || {}; const checkJSDoc = !!params.checkJSDoc; //---------------------------------------------------------------------- // Helpers //---------------------------------------------------------------------- /** * Checks if a comment line is starred. * @param {string} line A string representing a comment line. * @returns {boolean} Whether or not the comment line is starred. */ function isStarredCommentLine(line) { return /^\s*\*/u.test(line); } /** * Checks if a comment group is in starred-block form. * @param {Token[]} commentGroup A group of comments, containing either multiple line comments or a single block comment. * @returns {boolean} Whether or not the comment group is in starred block form. */ function isStarredBlockComment([firstComment]) { if (firstComment.type !== "Block") { return false; } const lines = firstComment.value.split(astUtils.LINEBREAK_MATCHER); // The first and last lines can only contain whitespace. return ( lines.length > 0 && lines.every((line, i) => (i === 0 || i === lines.length - 1 ? /^\s*$/u : /^\s*\*/u ).test(line), ) ); } /** * Checks if a comment group is in JSDoc form. * @param {Token[]} commentGroup A group of comments, containing either multiple line comments or a single block comment. * @returns {boolean} Whether or not the comment group is in JSDoc form. */ function isJSDocComment([firstComment]) { if (firstComment.type !== "Block") { return false; } const lines = firstComment.value.split(astUtils.LINEBREAK_MATCHER); return ( /^\*\s*$/u.test(lines[0]) && lines.slice(1, -1).every(line => /^\s* /u.test(line)) && /^\s*$/u.test(lines.at(-1)) ); } /** * Processes a comment group that is currently in separate-line form, calculating the offset for each line. * @param {Token[]} commentGroup A group of comments containing multiple line comments. * @returns {string[]} An array of the processed lines. */ function processSeparateLineComments(commentGroup) { const allLinesHaveLeadingSpace = commentGroup .map(({ value }) => value) .filter(line => line.trim().length) .every(line => line.startsWith(" ")); return commentGroup.map(({ value }) => allLinesHaveLeadingSpace ? value.replace(/^ /u, "") : value, ); } /** * Processes a comment group that is currently in starred-block form, calculating the offset for each line. * @param {Token} comment A single block comment token in starred-block form. * @returns {string[]} An array of the processed lines. */ function processStarredBlockComment(comment) { const lines = comment.value .split(astUtils.LINEBREAK_MATCHER) .filter( (line, i, linesArr) => !(i === 0 || i === linesArr.length - 1), ) .map(line => line.replace(/^\s*$/u, "")); const allLinesHaveLeadingSpace = lines .map(line => line.replace(/\s*\*/u, "")) .filter(line => line.trim().length) .every(line => line.startsWith(" ")); return lines.map(line => line.replace( allLinesHaveLeadingSpace ? /\s*\* ?/u : /\s*\*/u, "", ), ); } /** * Processes a comment group that is currently in bare-block form, calculating the offset for each line. * @param {Token} comment A single block comment token in bare-block form. * @returns {string[]} An array of the processed lines. */ function processBareBlockComment(comment) { const lines = comment.value .split(astUtils.LINEBREAK_MATCHER) .map(line => line.replace(/^\s*$/u, "")); const leadingWhitespace = `${sourceCode.text.slice(comment.range[0] - comment.loc.start.column, comment.range[0])} `; let offset = ""; /* * Calculate the offset of the least indented line and use that as the basis for offsetting all the lines. * The first line should not be checked because it is inline with the opening block comment delimiter. */ for (const [i, line] of lines.entries()) { if (!line.trim().length || i === 0) { continue; } const [, lineOffset] = line.match(/^(\s*\*?\s*)/u); if (lineOffset.length < leadingWhitespace.length) { const newOffset = leadingWhitespace.slice( lineOffset.length - leadingWhitespace.length, ); if (newOffset.length > offset.length) { offset = newOffset; } } } return lines.map(line => { const match = line.match(/^(\s*\*?\s*)(.*)/u); const [, lineOffset, lineContents] = match; if (lineOffset.length > leadingWhitespace.length) { return `${lineOffset.slice(leadingWhitespace.length - (offset.length + lineOffset.length))}${lineContents}`; } if (lineOffset.length < leadingWhitespace.length) { return `${lineOffset.slice(leadingWhitespace.length)}${lineContents}`; } return lineContents; }); } /** * Gets a list of comment lines in a group, formatting leading whitespace as necessary. * @param {Token[]} commentGroup A group of comments containing either multiple line comments or a single block comment. * @returns {string[]} A list of comment lines. */ function getCommentLines(commentGroup) { const [firstComment] = commentGroup; if (firstComment.type === "Line") { return processSeparateLineComments(commentGroup); } if (isStarredBlockComment(commentGroup)) { return processStarredBlockComment(firstComment); } return processBareBlockComment(firstComment); } /** * Gets the initial offset (whitespace) from the beginning of a line to a given comment token. * @param {Token} comment The token to check. * @returns {string} The offset from the beginning of a line to the token. */ function getInitialOffset(comment) { return sourceCode.text.slice( comment.range[0] - comment.loc.start.column, comment.range[0], ); } /** * Converts a comment into starred-block form * @param {Token} firstComment The first comment of the group being converted * @param {string[]} commentLinesList A list of lines to appear in the new starred-block comment * @returns {string} A representation of the comment value in starred-block form, excluding start and end markers */ function convertToStarredBlock(firstComment, commentLinesList) { const initialOffset = getInitialOffset(firstComment); return `/*\n${commentLinesList.map(line => `${initialOffset} * ${line}`).join("\n")}\n${initialOffset} */`; } /** * Converts a comment into separate-line form * @param {Token} firstComment The first comment of the group being converted * @param {string[]} commentLinesList A list of lines to appear in the new starred-block comment * @returns {string} A representation of the comment value in separate-line form */ function convertToSeparateLines(firstComment, commentLinesList) { return commentLinesList .map(line => `// ${line}`) .join(`\n${getInitialOffset(firstComment)}`); } /** * Converts a comment into bare-block form * @param {Token} firstComment The first comment of the group being converted * @param {string[]} commentLinesList A list of lines to appear in the new starred-block comment * @returns {string} A representation of the comment value in bare-block form */ function convertToBlock(firstComment, commentLinesList) { return `/* ${commentLinesList.join(`\n${getInitialOffset(firstComment)} `)} */`; } /** * Each method checks a group of comments to see if it's valid according to the given option. * @param {Token[]} commentGroup A list of comments that appear together. This will either contain a single * block comment or multiple line comments. * @returns {void} */ const commentGroupCheckers = { "starred-block"(commentGroup) { const [firstComment] = commentGroup; const commentLines = getCommentLines(commentGroup); if (commentLines.some(value => value.includes("*/"))) { return; } if (commentGroup.length > 1) { context.report({ loc: { start: firstComment.loc.start, end: commentGroup.at(-1).loc.end, }, messageId: "expectedBlock", fix(fixer) { const range = [ firstComment.range[0], commentGroup.at(-1).range[1], ]; return commentLines.some(value => value.startsWith("/"), ) ? null : fixer.replaceTextRange( range, convertToStarredBlock( firstComment, commentLines, ), ); }, }); } else { const lines = firstComment.value.split( astUtils.LINEBREAK_MATCHER, ); const expectedLeadingWhitespace = getInitialOffset(firstComment); const expectedLinePrefix = `${expectedLeadingWhitespace} *`; if (!/^\*?\s*$/u.test(lines[0])) { const start = firstComment.value.startsWith("*") ? firstComment.range[0] + 1 : firstComment.range[0]; context.report({ loc: { start: firstComment.loc.start, end: { line: firstComment.loc.start.line, column: firstComment.loc.start.column + 2, }, }, messageId: "startNewline", fix: fixer => fixer.insertTextAfterRange( [start, start + 2], `\n${expectedLinePrefix}`, ), }); } if (!/^\s*$/u.test(lines.at(-1))) { context.report({ loc: { start: { line: firstComment.loc.end.line, column: firstComment.loc.end.column - 2, }, end: firstComment.loc.end, }, messageId: "endNewline", fix: fixer => fixer.replaceTextRange( [ firstComment.range[1] - 2, firstComment.range[1], ], `\n${expectedLinePrefix}/`, ), }); } for ( let lineNumber = firstComment.loc.start.line + 1; lineNumber <= firstComment.loc.end.line; lineNumber++ ) { const lineText = sourceCode.lines[lineNumber - 1]; const errorType = isStarredCommentLine(lineText) ? "alignment" : "missingStar"; if (!lineText.startsWith(expectedLinePrefix)) { context.report({ loc: { start: { line: lineNumber, column: 0 }, end: { line: lineNumber, column: lineText.length, }, }, messageId: errorType, fix(fixer) { const lineStartIndex = sourceCode.getIndexFromLoc({ line: lineNumber, column: 0, }); if (errorType === "alignment") { const [, commentTextPrefix = ""] = lineText.match(/^(\s*\*)/u) || []; const commentTextStartIndex = lineStartIndex + commentTextPrefix.length; return fixer.replaceTextRange( [ lineStartIndex, commentTextStartIndex, ], expectedLinePrefix, ); } const [, commentTextPrefix = ""] = lineText.match(/^(\s*)/u) || []; const commentTextStartIndex = lineStartIndex + commentTextPrefix.length; let offset; for (const [idx, line] of lines.entries()) { if (!/\S+/u.test(line)) { continue; } const lineTextToAlignWith = sourceCode.lines[ firstComment.loc.start.line - 1 + idx ]; const [ , prefix = "", initialOffset = "", ] = lineTextToAlignWith.match( /^(\s*(?:\/?\*)?(\s*))/u, ) || []; offset = `${commentTextPrefix.slice(prefix.length)}${initialOffset}`; if ( /^\s*\//u.test(lineText) && offset.length === 0 ) { offset += " "; } break; } return fixer.replaceTextRange( [lineStartIndex, commentTextStartIndex], `${expectedLinePrefix}${offset}`, ); }, }); } } } }, "separate-lines"(commentGroup) { const [firstComment] = commentGroup; const isJSDoc = isJSDocComment(commentGroup); if (firstComment.type !== "Block" || (!checkJSDoc && isJSDoc)) { return; } let commentLines = getCommentLines(commentGroup); if (isJSDoc) { commentLines = commentLines.slice( 1, commentLines.length - 1, ); } const tokenAfter = sourceCode.getTokenAfter(firstComment, { includeComments: true, }); if ( tokenAfter && firstComment.loc.end.line === tokenAfter.loc.start.line ) { return; } context.report({ loc: { start: firstComment.loc.start, end: { line: firstComment.loc.start.line, column: firstComment.loc.start.column + 2, }, }, messageId: "expectedLines", fix(fixer) { return fixer.replaceText( firstComment, convertToSeparateLines(firstComment, commentLines), ); }, }); }, "bare-block"(commentGroup) { if (isJSDocComment(commentGroup)) { return; } const [firstComment] = commentGroup; const commentLines = getCommentLines(commentGroup); // Disallows consecutive line comments in favor of using a block comment. if ( firstComment.type === "Line" && commentLines.length > 1 && !commentLines.some(value => value.includes("*/")) ) { context.report({ loc: { start: firstComment.loc.start, end: commentGroup.at(-1).loc.end, }, messageId: "expectedBlock", fix(fixer) { return fixer.replaceTextRange( [ firstComment.range[0], commentGroup.at(-1).range[1], ], convertToBlock(firstComment, commentLines), ); }, }); } // Prohibits block comments from having a * at the beginning of each line. if (isStarredBlockComment(commentGroup)) { context.report({ loc: { start: firstComment.loc.start, end: { line: firstComment.loc.start.line, column: firstComment.loc.start.column + 2, }, }, messageId: "expectedBareBlock", fix(fixer) { return fixer.replaceText( firstComment, convertToBlock(firstComment, commentLines), ); }, }); } }, }; //---------------------------------------------------------------------- // Public //---------------------------------------------------------------------- return { Program() { return sourceCode .getAllComments() .filter(comment => comment.type !== "Shebang") .filter( comment => !astUtils.COMMENTS_IGNORE_PATTERN.test( comment.value, ), ) .filter(comment => { const tokenBefore = sourceCode.getTokenBefore(comment, { includeComments: true, }); return ( !tokenBefore || tokenBefore.loc.end.line < comment.loc.start.line ); }) .reduce((commentGroups, comment, index, commentList) => { const tokenBefore = sourceCode.getTokenBefore(comment, { includeComments: true, }); if ( comment.type === "Line" && index && commentList[index - 1].type === "Line" && tokenBefore && tokenBefore.loc.end.line === comment.loc.start.line - 1 && tokenBefore === commentList[index - 1] ) { commentGroups.at(-1).push(comment); } else { commentGroups.push([comment]); } return commentGroups; }, []) .filter( commentGroup => !( commentGroup.length === 1 && commentGroup[0].loc.start.line === commentGroup[0].loc.end.line ), ) .forEach(commentGroupCheckers[option]); }, }; }, };
Save
cmd:
run