From a531a9dc2e758c2d2ec073e2b4b83f22ed67e479 Mon Sep 17 00:00:00 2001 From: Ben Carey Date: Mon, 16 Nov 2026 22:43:21 -0500 Subject: [PATCH 01/12] chore: trim comments in policy scripts --- scripts/test-knip-policy.sh | 3 +-- scripts/test-shared-policy.sh | 3 +-- scripts/test-swift-policy.sh | 3 +-- scripts/test-terraform-policy.sh | 8 +++----- scripts/test-trivy-policy.sh | 8 +++----- scripts/test-zizmor-policy.sh | 3 +-- 6 files changed, 10 insertions(+), 18 deletions(-) diff --git a/scripts/test-knip-policy.sh b/scripts/test-knip-policy.sh index 2b4e517..34096d9 100755 --- a/scripts/test-knip-policy.sh +++ b/scripts/test-knip-policy.sh @@ -10,8 +10,7 @@ fi repository_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" fixtures="${repository_root}/tests/knip-consumer/Fixtures" -# TMPDIR is unset in many shells. Left bare, the template collapses to a path at -# the filesystem root and mktemp fails with an error that names neither cause. +# TMPDIR is often unset; without a fallback mktemp targets the filesystem root. knip_consumer_dir="$(mktemp -d "${TMPDIR:-/tmp}/coding-standards-knip.XXXXXX")" cleanup() { diff --git a/scripts/test-shared-policy.sh b/scripts/test-shared-policy.sh index 8da2db9..4b5f800 100755 --- a/scripts/test-shared-policy.sh +++ b/scripts/test-shared-policy.sh @@ -9,8 +9,7 @@ fi repository_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -# TMPDIR is unset in many shells. Left bare, the template collapses to a path at -# the filesystem root and mktemp fails with an error that names neither cause. +# TMPDIR is often unset; without a fallback mktemp targets the filesystem root. consumer_dir="$(mktemp -d "${TMPDIR:-/tmp}/coding-standards-shared.XXXXXX")" cleanup() { diff --git a/scripts/test-swift-policy.sh b/scripts/test-swift-policy.sh index 257d63e..4707b70 100755 --- a/scripts/test-swift-policy.sh +++ b/scripts/test-swift-policy.sh @@ -9,8 +9,7 @@ fi repository_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -# TMPDIR is unset in many shells. Left bare, the template collapses to a path at -# the filesystem root and mktemp fails with an error that names neither cause. +# TMPDIR is often unset; without a fallback mktemp targets the filesystem root. swift_consumer_dir="$(mktemp -d "${TMPDIR:-/tmp}/coding-standards-swift.XXXXXX")" cleanup() { diff --git a/scripts/test-terraform-policy.sh b/scripts/test-terraform-policy.sh index 5814fdc..204cea2 100755 --- a/scripts/test-terraform-policy.sh +++ b/scripts/test-terraform-policy.sh @@ -9,8 +9,7 @@ fi repository_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -# TMPDIR is unset in many shells. Left bare, the template collapses to a path at -# the filesystem root and mktemp fails with an error that names neither cause. +# TMPDIR is often unset; without a fallback mktemp targets the filesystem root. terraform_consumer_dir="$(mktemp -d "${TMPDIR:-/tmp}/coding-standards-terraform.XXXXXX")" cleanup() { @@ -42,9 +41,8 @@ diff -ru "${repository_root}/tests/terraform-consumer/modules" modules cmp "${repository_root}/tests/terraform-consumer/Fixtures/unaligned.tf.fixture" "${vendored_dir}/unaligned.tf" qlty check --all --no-cache --no-formatters -# Undocumented variables are reported only at the "all" preset, and TFLint runs -# from the module's own directory, away from where qlty stages the config. This -# finding therefore proves the exported policy reached a nested module. +# Only the "all" preset reports undocumented variables, and TFLint runs from the +# module directory, so this proves the exported policy reached a nested module. cp "${repository_root}/tests/terraform-consumer/Fixtures/undocumented.tf.fixture" \ modules/greeting/undocumented.tf diff --git a/scripts/test-trivy-policy.sh b/scripts/test-trivy-policy.sh index a13c4fd..c23776d 100755 --- a/scripts/test-trivy-policy.sh +++ b/scripts/test-trivy-policy.sh @@ -9,8 +9,7 @@ fi repository_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -# TMPDIR is unset in many shells. Left bare, the template collapses to a path at -# the filesystem root and mktemp fails with an error that names neither cause. +# TMPDIR is often unset; without a fallback mktemp targets the filesystem root. trivy_consumer_dir="$(mktemp -d "${TMPDIR:-/tmp}/coding-standards-trivy.XXXXXX")" cleanup() { @@ -55,9 +54,8 @@ for reported in Dockerfile deploy/pod.yaml; do fi done -# qlty drops vendor and node_modules paths from its own report whatever Trivy -# scanned, so what Trivy walked is read from its raw output in the invocation -# record instead. +# qlty drops vendor and node_modules paths from its report, so what Trivy walked +# is read from the raw invocation record. trivy_record="$(grep -l 'trivy config' .qlty/out/invoke-*.yaml)" if ! grep -qF 'Loaded\tfile_path=\"trivy.yaml\"' "${trivy_record}"; then diff --git a/scripts/test-zizmor-policy.sh b/scripts/test-zizmor-policy.sh index d72a311..b5fca64 100755 --- a/scripts/test-zizmor-policy.sh +++ b/scripts/test-zizmor-policy.sh @@ -9,8 +9,7 @@ fi repository_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -# TMPDIR is unset in many shells. Left bare, the template collapses to a path at -# the filesystem root and mktemp fails with an error that names neither cause. +# TMPDIR is often unset; without a fallback mktemp targets the filesystem root. zizmor_consumer_dir="$(mktemp -d "${TMPDIR:-/tmp}/coding-standards-zizmor.XXXXXX")" cleanup() { From 0e953ec09576fee47b51b7de6db81d40d2d813e6 Mon Sep 17 00:00:00 2001 From: Ben Carey Date: Mon, 16 Nov 2026 22:47:43 -0500 Subject: [PATCH 02/12] chore: trim comments in ESLint rule tests --- js/eslint/__tests__/config.test.js | 27 +-------- .../rules/__tests__/align-doc-tags.test.js | 15 ++--- .../__tests__/boolean-method-name.test.js | 56 +++++-------------- .../rules/__tests__/comment-line-wrap.test.js | 29 +++------- .../__tests__/max-methods-per-class.test.js | 24 +------- .../__tests__/multiline-function-doc.test.js | 20 +------ .../rules/__tests__/no-base-error.test.js | 34 +++-------- .../__tests__/no-interface-prefix.test.js | 18 +++--- .../rules/__tests__/no-mutable-static.test.js | 29 +++------- .../rules/__tests__/require-copyright.test.js | 18 +----- .../require-file-description.test.js | 24 ++------ .../require-readonly-public-property.test.js | 10 ++-- .../single-line-property-doc.test.js | 17 +----- js/eslint/rules/__tests__/tester.js | 15 +---- .../__tests__/valid-enum-member-name.test.js | 21 +------ 15 files changed, 78 insertions(+), 279 deletions(-) diff --git a/js/eslint/__tests__/config.test.js b/js/eslint/__tests__/config.test.js index d97ef81..50a0175 100644 --- a/js/eslint/__tests__/config.test.js +++ b/js/eslint/__tests__/config.test.js @@ -11,9 +11,7 @@ import config from '../index.js'; const linter = new Linter({ configType: 'flat' }); -// One documented function whose tags carry both a type and a description, so -// every jsdoc rule under test has something to say about it. The source is -// valid in either language, leaving the file extension as the only variable. +// Valid in either language, so the file extension is the only variable. const TYPED_TAGS = [ '/**', ' * Adds two numbers.', @@ -28,13 +26,8 @@ const TYPED_TAGS = [ '', ].join('\n'); -// The same function with the types stripped and the descriptions left, which is -// what no-types asks a TypeScript file to become. const UNTYPED_TAGS = TYPED_TAGS.replace(/ \{number\}/g, ''); -// A file header in the shape the convention describes: a summary, then the tags -// that annotate it. Stripping the summary leaves the tags-only header the -// description rule exists to catch. const DESCRIBED_HEADER = [ '/**', ' * Adds numbers, and says so.', @@ -47,17 +40,11 @@ const DESCRIBED_HEADER = [ const TAGS_ONLY_HEADER = DESCRIBED_HEADER.replace(' * Adds numbers, and says so.\n *\n', ''); -// The same tags with the descriptions stripped and the types left, which is -// what a plain-JavaScript codebase looks like where the tag is doing the typing -// rather than the describing. const DESCRIPTIONLESS_TAGS = TYPED_TAGS .replace(' augend The number added to.', ' augend') .replace(' addend The number added.', ' addend') .replace(' The sum of the two.', ''); -// A spec file's furniture: a helper declared beside the test case that uses it. -// The helper is what require-jsdoc reaches in a test file; the arrow passed to -// `it` is a call argument, which none of the rule's contexts match. const SPEC = [ "describe('build', () => {", ' function build(values) {', @@ -71,8 +58,6 @@ const SPEC = [ '', ].join('\n'); -// The same spec with its helper removed: nothing but the arrows the test -// framework takes as call arguments. const CASES_ONLY = [ "describe('build', () => {", " it('builds', () => {", @@ -82,8 +67,6 @@ const CASES_ONLY = [ '', ].join('\n'); -// A documented function whose body is both long enough and nested deeply enough -// to fault the metric rules, which a test body is still exempt from. const OVERSIZED = [ '/** Runs a scenario. */', 'function scenario(a, b, c, d, e) {', @@ -103,10 +86,7 @@ const OVERSIZED = [ '', ].join('\n'); -/** - * Lint a source under the base config as the given filename and return the - * rules that reported, deduplicated. - */ +/** The distinct rules that reported on a source linted as the given filename. */ function report(source, filename) { return [...new Set(linter.verify(source, config, filename).map(message => message.ruleId))]; } @@ -170,9 +150,6 @@ describe('jsdoc/require-jsdoc in test files', () => { }); it('asks nothing of a spec that declares no helper of its own', () => { - // Every function in it is an arrow passed as a call argument, which - // none of the rule's contexts match, so a spec of test cases alone - // carries no documentation burden at all. expect(linesReported(CASES_ONLY, 'build.spec.ts', 'jsdoc/require-jsdoc')).toEqual([]); }); }); diff --git a/js/eslint/rules/__tests__/align-doc-tags.test.js b/js/eslint/rules/__tests__/align-doc-tags.test.js index a61b369..2ad317d 100644 --- a/js/eslint/rules/__tests__/align-doc-tags.test.js +++ b/js/eslint/rules/__tests__/align-doc-tags.test.js @@ -12,7 +12,6 @@ ruleTester.run('align-doc-tags', rule, { valid: [ // Both tags aligned at the default column. '/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', - // A summary above the aligned tags. '/**\n * Summary.\n *\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', // Unlisted tags keep whatever spacing they carry. '/**\n * @param foo - a thing\n * @returns a value\n */\nexport const a = 1;', @@ -22,17 +21,16 @@ ruleTester.run('align-doc-tags', rule, { '// @author Y\nexport const a = 1;', // A plain block comment is not a documentation block. '/*\n * @author Y\n */\nexport const a = 1;', - // A custom column. { code: '/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', options: [{ column: 11 }], }, - // A custom tag set: @copyright is no longer listed, so it is untouched. + // @copyright is outside the custom tag set. { code: '/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', options: [{ tags: ['author'] }], }, - // A tag too long to reach the column is skipped, not reported. + // A tag too long to reach the column is skipped. { code: '/**\n * @averyverylongtagname Y\n */\nexport const a = 1;', options: [{ tags: ['averyverylongtagname'] }], @@ -42,7 +40,6 @@ ruleTester.run('align-doc-tags', rule, { ], invalid: [ { - // The single-spaced tags this rule exists to correct. code: '/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', output: '/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', errors: [ @@ -63,27 +60,25 @@ ruleTester.run('align-doc-tags', rule, { errors: [{ messageId: 'misaligned' }], }, { - // Only the misaligned tag is reported; the aligned one is left be. + // Only the misaligned tag is reported. code: '/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', output: '/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', errors: [{ messageId: 'misaligned', data: { tag: 'copyright', column: 14 } }], }, { - // Tag matching is case-insensitive, and the reported name is the - // one the source carries. + // Matching is case-insensitive; the source casing is reported. code: '/**\n * @Author Y\n */\nexport const a = 1;', output: '/**\n * @Author Y\n */\nexport const a = 1;', errors: [{ messageId: 'misaligned', data: { tag: 'Author', column: 14 } }], }, { - // A custom column. code: '/**\n * @author Y\n */\nexport const a = 1;', options: [{ column: 11 }], output: '/**\n * @author Y\n */\nexport const a = 1;', errors: [{ messageId: 'misaligned', data: { tag: 'author', column: 11 } }], }, { - // A block below the header is aligned on the same terms. + // A block after the imports is aligned too. code: "import { z } from 'z';\n/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = z;", output: "import { z } from 'z';\n/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = z;", errors: [{ messageId: 'misaligned', data: { tag: 'author', column: 14 } }], diff --git a/js/eslint/rules/__tests__/boolean-method-name.test.js b/js/eslint/rules/__tests__/boolean-method-name.test.js index 357da2b..2375bd6 100644 --- a/js/eslint/rules/__tests__/boolean-method-name.test.js +++ b/js/eslint/rules/__tests__/boolean-method-name.test.js @@ -18,7 +18,7 @@ typedRuleTester.run('boolean-method-name', rule, { 'function willExpire(): boolean { return true; }', 'function wasSaved(): boolean { return true; }', - // Third-person / past-tense verbs and idiomatic predicates. + // Third-person and past-tense verbs, and idiomatic predicates. 'function permits(): boolean { return true; }', 'function succeeded(): boolean { return true; }', 'function successful(): boolean { return true; }', @@ -32,13 +32,13 @@ typedRuleTester.run('boolean-method-name', rule, { 'function attemptLogin(): boolean { return true; }', 'function rotateKeys(): boolean { return true; }', - // An overriding member's name is set by the parent it overrides. + // An override's name is set by its parent. 'class Base { /** @imperative */ valid(): boolean { return true; } } class C extends Base { override valid(): boolean { return false; } }', 'abstract class Base { /** @imperative */ abstract valid(): boolean; } class C extends Base { override valid(): boolean { return true; } }', 'abstract class Base { /** @imperative */ abstract valid(): boolean; } abstract class C extends Base { abstract override valid(): boolean; }', 'class Base { /** @imperative */ valid = (): boolean => true; } class C extends Base { override valid = (): boolean => false; }', - // on* event-handler callbacks read as handlers, not predicates. + // on* event handlers are not predicates. 'const o = { onUnauthorized(): boolean { return true; } };', 'class C { onError(): boolean { return true; } }', @@ -46,22 +46,18 @@ typedRuleTester.run('boolean-method-name', rule, { 'class C { boolean(): boolean { return true; } }', 'interface Env { boolean(key: string): boolean; }', - // Inferred boolean return with a predicate name. 'function isReady() { return 1 > 0; }', - // Non-boolean returns are out of scope regardless of the name. + // Non-boolean returns are out of scope. 'function widget(): string { return ""; }', 'function build(): number { return 1; }', - // Generics resolve to a concrete boolean return. 'function isThing(x: T): boolean { return true; }', - // Awaited booleans read as predicates when named as one. 'async function isReady(): Promise { return true; }', 'async function validate(): Promise { return true; }', - // Type-predicate guards are predicates by structure; the descriptive - // name need not start with is/has. + // Type-predicate guards are predicates by structure. 'function nonNullable(x: T): x is NonNullable { return x != null; }', 'function present(x: T | null): x is T { return x !== null; }', @@ -72,13 +68,11 @@ typedRuleTester.run('boolean-method-name', rule, { 'class C { ["ready"](): boolean { return true; } }', 'function __internal(): boolean { return true; }', - // Well-named methods, overloads and abstract members. 'class C { isValid(): boolean { return true; } }', 'class C { hasItems(x: string): boolean; hasItems(x: number): boolean; ' + 'hasItems(x: any): boolean { return true; } }', 'abstract class A { abstract isValid(): boolean; }', - // Arrow-bound class fields, object methods and const-bound functions. 'class C { isValid = (): boolean => true; }', 'const o = { isReady(): boolean { return true; } };', 'const o = { isReady: (): boolean => true };', @@ -86,18 +80,14 @@ typedRuleTester.run('boolean-method-name', rule, { 'const isReady = (): boolean => true;', 'const isReady = function (): boolean { return true; };', - // Interface and type-literal signatures. 'interface Foo { isValid(): boolean; }', 'type Foo = { isValid(): boolean };', - // Ambient declarations, including nested and class members, with - // predicate names. 'declare function isReady(): boolean;', 'declare namespace N { function isReady(): boolean; }', 'declare class C { isValid(): boolean; }', - // Opt-out via an @imperative docblock, including through a decorator - // and on a const binding. + // The @imperative opt-out, including behind a decorator. '/** @imperative */\nfunction frobnicate(): boolean { return true; }', '/** @imperative */\nconst frobnicate = (): boolean => true;', 'const dec = (_v: any, _c: any) => {};\nclass C {\n /** @imperative */\n' @@ -105,7 +95,6 @@ typedRuleTester.run('boolean-method-name', rule, { 'const dec = (_v: any, _c: any) => {};\nclass C {\n @dec\n' + ' /** @imperative */\n frobnicate(): boolean { return true; }\n}', - // Consumer-supplied vocabulary widens the accepted names. { code: 'function frobnicate(): boolean { return true; }', options: [{ additionalCommandVerbs: ['frobnicate'] }], @@ -115,7 +104,6 @@ typedRuleTester.run('boolean-method-name', rule, { options: [{ additionalPrefixes: ['wibble'] }], }, - // A component in a TSX file returns markup, not boolean. { code: 'function panel() { return
; }', filename: 'react.tsx' }, ], invalid: [ @@ -124,22 +112,19 @@ typedRuleTester.run('boolean-method-name', rule, { errors: [{ messageId: 'notPredicate', data: { name: 'frobnicate' } }], }, { - // Inferred boolean return, proving the rule reads type information. + // An inferred boolean return. code: 'function frobnicate() { return 1 > 0; }', errors: [{ messageId: 'notPredicate', data: { name: 'frobnicate' } }], }, { - // An awaited boolean is still a predicate concern. code: 'async function frobnicate(): Promise { return true; }', errors: [{ messageId: 'notPredicate', data: { name: 'frobnicate' } }], }, { - // Inferred and awaited together resolve to boolean. code: 'async function frobnicate() { return true; }', errors: [{ messageId: 'notPredicate', data: { name: 'frobnicate' } }], }, { - // An awaited nullable boolean keeps its predicate tail. code: 'async function widget(): Promise { return true; }', errors: [{ messageId: 'notPredicate', data: { name: 'widget' } }], }, @@ -148,18 +133,15 @@ typedRuleTester.run('boolean-method-name', rule, { errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, { - // Only the overriding member is exempt; the parent's own name is - // still checked where it is declared. + // The parent's own declaration is still checked. code: 'class Base { valid(): boolean { return true; } } class C extends Base { override valid(): boolean { return false; } }', errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, { - // Arrow-bound class fields are methods too. code: 'class C { valid = (): boolean => true; }', errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, { - // Object shorthand methods and arrow properties are inspected. code: 'const o = { valid(): boolean { return true; } };', errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, @@ -168,7 +150,6 @@ typedRuleTester.run('boolean-method-name', rule, { errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, { - // Const-bound arrow and function expressions are inspected. code: 'const valid = (): boolean => true;', errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, @@ -177,7 +158,6 @@ typedRuleTester.run('boolean-method-name', rule, { errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, { - // Interface and type-literal method signatures are inspected. code: 'interface Foo { valid(): boolean; }', errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, @@ -186,7 +166,6 @@ typedRuleTester.run('boolean-method-name', rule, { errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, { - // String-literal method keys are inspected like identifier keys. code: 'class C { "valid"(): boolean { return true; } }', errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, @@ -199,8 +178,7 @@ typedRuleTester.run('boolean-method-name', rule, { errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, { - // as/satisfies-wrapped arrow values are unwrapped before - // inspection. + // as/satisfies wrappers are unwrapped. code: 'const valid = ((): boolean => true) satisfies () => boolean;', errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, @@ -231,54 +209,48 @@ typedRuleTester.run('boolean-method-name', rule, { errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, { - // A nullable boolean still reads as a predicate concern. code: 'function widget(): boolean | undefined { return true; }', errors: [{ messageId: 'notPredicate', data: { name: 'widget' } }], }, { - // Function overloads report once, on the implementation. + // Overloads report once, on the implementation. code: 'function widget(x: string): boolean;\n' + 'function widget(x: number): boolean;\n' + 'function widget(x: any): boolean { return true; }', errors: [{ messageId: 'notPredicate', data: { name: 'widget' } }], }, { - // Method overloads report once, on the implementation. code: 'class C { widget(x: string): boolean; widget(x: any): boolean { return true; } }', errors: [{ messageId: 'notPredicate', data: { name: 'widget' } }], }, { - // Decorators do not exempt a mis-named boolean method. code: 'const dec = (_v: any, _c: any) => {};\nclass C {\n @dec\n valid(): boolean { return true; }\n}', errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, { - // @imperative buried in prose is not a tag and does not exempt. + // @imperative in prose is not a tag. code: '/** handles @imperative flows */\nfunction valid(): boolean { return true; }', errors: [{ messageId: 'notPredicate', data: { name: 'valid' } }], }, { - // The rule still bites inside a TSX file. code: 'function widget(): boolean { return true; }', filename: 'react.tsx', errors: [{ messageId: 'notPredicate', data: { name: 'widget' } }], }, { - // `on` without a following capital is not an event handler (online -> isOnline). + // `on` without a following capital is not an event handler. code: 'function online(): boolean { return true; }', errors: [{ messageId: 'notPredicate', data: { name: 'online' } }], }, { - // Only the exact primitive-type name is a typed accessor; a longer - // name is not. + // Only the exact primitive-type name is a typed accessor. code: 'class C { booleanFlag(): boolean { return true; } }', errors: [{ messageId: 'notPredicate', data: { name: 'booleanFlag' } }], }, ], }); -// Without a tsconfig program the rule cannot resolve return types, so it must -// degrade to a no-op rather than throw on files outside the consumer's project. +// Without type information the rule is a no-op rather than a crash. ruleTester.run('boolean-method-name (no type information)', rule, { valid: [ 'function frobnicate(): boolean { return true; }', diff --git a/js/eslint/rules/__tests__/comment-line-wrap.test.js b/js/eslint/rules/__tests__/comment-line-wrap.test.js index 7eaf4f2..3a98f4b 100644 --- a/js/eslint/rules/__tests__/comment-line-wrap.test.js +++ b/js/eslint/rules/__tests__/comment-line-wrap.test.js @@ -10,7 +10,6 @@ import { ruleTester, yamlRuleTester } from './tester.js'; ruleTester.run('comment-line-wrap', rule, { valid: [ - // A short standalone comment well within the width. '// A short standalone comment well within the width.\nconst x = 1;', // A `//` run already wrapped as tightly as the width allows. '// A longer standalone comment that has already been wrapped greedily so that\n// every one of its lines is filled as far as the width will allow it to be.\nconst x = 1;', @@ -20,8 +19,7 @@ ruleTester.run('comment-line-wrap', rule, { '//ThisIsASingleVeryLongCommentTokenWithoutAnySpacesThatExceedsTheEightyCharacterLimitForSureXX\nconst x = 1;', // A directive line is never reflowed, whatever its length. '// prettier-ignore because the construct below is intentionally formatted by hand and must be left exactly so\nconst x = 1;', - // A hashbang is not a line comment, so its leading `#` never reads as - // prose; reflowing one would break the interpreter line outright. + // A hashbang is not a line comment. '#!/usr/bin/env -S node --experimental-vm-modules --no-warnings --enable-source-maps\nconst x = 1;', // A tool-directive comment is exempt from the length and wrap checks. '// biome-ignore lint/suspicious/noExplicitAny: the upstream type is genuinely any so we accept it here now\nconst x = 1;', @@ -66,8 +64,7 @@ ruleTester.run('comment-line-wrap', rule, { // A capitalised line after a finished one opens a paragraph of its own. '// Section title\n// A sentence that follows the title as a separate note.\nconst x = 1;', '// A finished sentence.\n// Another sentence on its own line.\nconst x = 1;', - // A word that merely ends in a joining word does not hold the sentence - // open. + // A word merely ending in a joining word does not join. '// Wraps after Santa\n// Claus arrives.\nconst x = 1;', ], invalid: [ @@ -109,8 +106,7 @@ ruleTester.run('comment-line-wrap', rule, { errors: [{ messageId: 'tooLong' }], }, { - // Adjacent `//` comments at different indents are separate runs; the - // deeper one reflows within its own indent and the other is left be. + // Comments at different indents are separate runs. code: '// Short comment at column one that fits within the width comfortably here now.\n // A deeper indented standalone comment that runs on well beyond the eighty character limit for sure.\nconst value = 1;', output: '// Short comment at column one that fits within the width comfortably here now.\n // A deeper indented standalone comment that runs on well beyond the eighty\n // character limit for sure.\nconst value = 1;', errors: [{ messageId: 'tooLong' }], @@ -156,23 +152,18 @@ ruleTester.run('comment-line-wrap', rule, { yamlRuleTester.run('comment-line-wrap (yaml)', rule, { valid: [ - // A short standalone `#` comment well within the width. '# A short standalone comment.\nname: CI\n', - // A `#` comment filling the line to its final column exactly. The `#` - // token reclaims one column less than `//`, so eighty holds a content - // line of seventy-eight; a margin measured as `//` would fault this. + // `#` is one column narrower than `//`, so this line fits exactly. '# A standalone YAML comment whose prose is filled right up to the last column ok\nname: CI\n', // A `#` run already wrapped as tightly as the width allows. '# A standalone YAML comment run whose prose fills each line as far as the width\n# will allow before the next word is carried onto the line beneath it.\nname: CI\n', - // A long `run:` command is a value, not a comment, and is never - // touched. + // A long `run:` command is a value, not a comment. 'jobs:\n build:\n steps:\n - run: npx some-tool --with-a-very-long-flag=value --and-another-flag=value --more\n', // A long `uses:` action reference is a value and is left alone. 'jobs:\n build:\n steps:\n - uses: sinemacula/some-really-long-reusable-workflow-name/.github/actions/build@v5\n', - // A comment trailing a value is not standalone, so it is not governed. + // A comment trailing a value is not standalone. 'jobs:\n build:\n steps:\n - uses: actions/checkout@v5 # pinned deliberately to the major tag for now ok yes\n', - // A `#` inside a plain scalar parses as a trailing comment, not a - // standalone one, so a `run:` line carrying one is still left alone. + // A `#` inside a plain scalar parses as a trailing comment. 'jobs:\n build:\n steps:\n - run: echo "a # b" and then some more text to carry this line past eighty chars\n', // A shell comment inside a block scalar is content, not a comment. 'jobs:\n build:\n steps:\n - run: |\n # A shell comment inside a block scalar that runs far past the eighty character limit.\n npm ci\n', @@ -191,8 +182,7 @@ yamlRuleTester.run('comment-line-wrap (yaml)', rule, { ], invalid: [ { - // An overflowing `#` line wraps, filling the first line to the last - // column available to a `#` comment. + // An overflowing `#` line wraps to the last available column. code: '# A standalone YAML comment whose prose is filled right up to the last column ok and then some more.\nname: CI\n', output: '# A standalone YAML comment whose prose is filled right up to the last column ok\n# and then some more.\nname: CI\n', errors: [{ messageId: 'tooLong' }], @@ -204,8 +194,7 @@ yamlRuleTester.run('comment-line-wrap (yaml)', rule, { errors: [{ messageId: 'prematureWrap' }, { messageId: 'prematureWrap' }], }, { - // An indented comment inside a `steps:` block wraps within its own - // indent, which the margin reclaims from the width. + // An indented comment wraps within its own indent. code: 'jobs:\n build:\n steps:\n # An indented comment inside the steps block that runs past the width allowed here.\n - run: echo hello\n', output: 'jobs:\n build:\n steps:\n # An indented comment inside the steps block that runs past the width\n # allowed here.\n - run: echo hello\n', errors: [{ messageId: 'tooLong' }], diff --git a/js/eslint/rules/__tests__/max-methods-per-class.test.js b/js/eslint/rules/__tests__/max-methods-per-class.test.js index ffb2ac6..a6d0d33 100644 --- a/js/eslint/rules/__tests__/max-methods-per-class.test.js +++ b/js/eslint/rules/__tests__/max-methods-per-class.test.js @@ -13,19 +13,14 @@ const methods = n => Array.from({ length: n }, (_, i) => `m${i}() {}`).join(' ') ruleTester.run('max-methods-per-class', rule, { valid: [ - // A count equal to the maximum is allowed; only exceeding it is - // flagged. { code: 'class C { a() {} b() {} }', options: [{ max: 2 }] }, { code: 'class C { a() {} }', options: [{ max: 2 }] }, 'class C {}', - // The default maximum is twenty. `class C { ${methods(20)} }`, - // The constructor counts, but a class within the limit still passes. { code: 'class C { constructor() {} a() {} }', options: [{ max: 2 }] }, - // Accessors and static methods count towards the same total. { code: 'class C { get x() { return 1; } set x(v: number) {} }', options: [{ max: 2 }] }, { code: 'class C { static a() {} static b() {} }', options: [{ max: 2 }] }, - // A method spread across overload signatures counts once, via its body. + // Overloads count once, via the implementation. { code: `class C { foo(a: number): number; @@ -35,15 +30,11 @@ ruleTester.run('max-methods-per-class', rule, { }`, options: [{ max: 2 }], }, - // Abstract signatures declare a contract, not a method body, so are not - // counted. + // Abstract signatures are not counted. { code: 'abstract class C { abstract foo(): void; abstract bar(): void; run() {} }', options: [{ max: 1 }] }, - // Methods on a nested class belong to it, not the class enclosing it. { code: 'class Outer { a() {} run() { class Inner { x() {} } } }', options: [{ max: 2 }] }, - // An anonymous class expression within the limit passes. { code: 'const C = class { a() {} }; C;', options: [{ max: 1 }] }, - // Test classes gather many methods legitimately: by name, by parent, or - // by path. + // Test classes are exempt by name, parent or path. { code: `class WidgetTest { ${methods(5)} }`, options: [{ max: 1 }] }, { code: `class C extends TestCase { ${methods(5)} }`, options: [{ max: 1 }] }, { code: `class C { ${methods(5)} }`, filename: 'widget.test.ts', options: [{ max: 1 }] }, @@ -55,26 +46,21 @@ ruleTester.run('max-methods-per-class', rule, { options: [{ max: 2 }], errors: [{ messageId: 'tooMany', data: { count: 3, max: 2 } }], }, - // The constructor is one of the counted methods. { code: 'class C { constructor() {} a() {} b() {} }', options: [{ max: 2 }], errors: [{ messageId: 'tooMany', data: { count: 3, max: 2 } }], }, - // Get and set accessors each add to the total. { code: 'class C { get x() { return 1; } set x(v: number) {} }', options: [{ max: 1 }], errors: [{ messageId: 'tooMany', data: { count: 2, max: 1 } }], }, - // Static methods count alongside instance methods. { code: 'class C { static a() {} static b() {} }', options: [{ max: 1 }], errors: [{ messageId: 'tooMany', data: { count: 2, max: 1 } }], }, - // Overload signatures do not inflate the count, but the implementation - // does. { code: `class C { foo(a: number): number; @@ -86,19 +72,15 @@ ruleTester.run('max-methods-per-class', rule, { options: [{ max: 2 }], errors: [{ messageId: 'tooMany', data: { count: 3, max: 2 } }], }, - // A nested class is measured on its own, independently of its - // enclosure. { code: 'class Outer { run() { class Inner { a() {} b() {} } } }', options: [{ max: 1 }], errors: [{ messageId: 'tooMany', data: { count: 2, max: 1 } }], }, - // The default limit of twenty is exceeded at twenty-one methods. { code: `class C { ${methods(21)} }`, errors: [{ messageId: 'tooMany', data: { count: 21, max: 20 } }], }, - // An anonymous class expression is reported on its class keyword. { code: 'const C = class { a() {} b() {} }; C;', options: [{ max: 1 }], diff --git a/js/eslint/rules/__tests__/multiline-function-doc.test.js b/js/eslint/rules/__tests__/multiline-function-doc.test.js index f716bef..fa7c395 100644 --- a/js/eslint/rules/__tests__/multiline-function-doc.test.js +++ b/js/eslint/rules/__tests__/multiline-function-doc.test.js @@ -10,56 +10,42 @@ import { ruleTester } from './tester.js'; ruleTester.run('multiline-function-doc', rule, { valid: [ - // A class method already spanning lines. 'class C {\n /**\n * Tick.\n */\n tick(): void {}\n}', - // An interface method signature already spanning lines. 'interface I {\n /**\n * Run.\n */\n run(): void;\n}', - // A class field holding a function, already spanning lines. 'class C {\n /**\n * Handle.\n */\n onTick = (): void => {};\n}', - // A free function keeps the freedom of a single line. + // Free functions and module arrows may stay on one line. '/** Do it. */\nfunction go(): void {}', - // A module arrow constant is likewise left to the author. '/** Do it. */\nconst go = (): void => {};', - // A data property is not a method; its one-line comment is left be. + // Data properties are out of scope. 'class C {\n /** A count. */\n count = 0;\n}', - // A data property with a multi-line comment is still not this rule's - // concern. 'interface I {\n /**\n * A value.\n */\n a: number;\n}', - // A method with no documentation comment is not governed here. 'class C {\n tick(): void {}\n}', - // A leading line comment is not a documentation block. 'class C {\n // tick\n tick(): void {}\n}', - // An empty block carries no prose to unfold and is left to the - // description rule. + // An empty block is left to the description rule. 'class C {\n /** */\n tick(): void {}\n}', ], invalid: [ { - // A one-line class-method comment unfolds onto three lines. code: 'class C {\n /** Tick. */\n tick(): void {}\n}', output: 'class C {\n /**\n * Tick.\n */\n tick(): void {}\n}', errors: [{ messageId: 'singleLine' }], }, { - // A one-line interface method signature unfolds. code: 'interface I {\n /** Run. */\n run(): void;\n}', output: 'interface I {\n /**\n * Run.\n */\n run(): void;\n}', errors: [{ messageId: 'singleLine' }], }, { - // A one-line function field unfolds. code: 'class C {\n /** Handle. */\n onTick = (): void => {};\n}', output: 'class C {\n /**\n * Handle.\n */\n onTick = (): void => {};\n}', errors: [{ messageId: 'singleLine' }], }, { - // A one-line abstract method signature unfolds. code: 'abstract class C {\n /** Tick. */\n abstract tick(): void;\n}', output: 'abstract class C {\n /**\n * Tick.\n */\n abstract tick(): void;\n}', errors: [{ messageId: 'singleLine' }], }, { - // A tag-only one-line comment unfolds, the tag moving to its line. code: 'class C {\n /** @override */\n tick(): void {}\n}', output: 'class C {\n /**\n * @override\n */\n tick(): void {}\n}', errors: [{ messageId: 'singleLine' }], diff --git a/js/eslint/rules/__tests__/no-base-error.test.js b/js/eslint/rules/__tests__/no-base-error.test.js index 9f8e468..2362100 100644 --- a/js/eslint/rules/__tests__/no-base-error.test.js +++ b/js/eslint/rules/__tests__/no-base-error.test.js @@ -8,44 +8,32 @@ import rule from '../no-base-error.js'; import { ruleTester } from './tester.js'; -// The rule is syntactic and needs no parser services, so the type-free tester -// stands in for the "no type information available" case. ruleTester.run('no-base-error', rule, { valid: [ - // A domain-specific subclass is exactly what the rule asks for. 'throw new NotFoundError();', 'throw new ValidationError("bad input");', - // The specific built-ins are domain enough and are left alone. + // Specific built-ins are domain enough. 'throw new TypeError("not a number");', 'throw new RangeError();', - // Re-throwing a caught value is covered by the only-throw-error - // concern. + // Re-throws are only-throw-error's concern. 'function f(err: unknown) { throw err; }', 'try { work(); } catch (err) { throw err; }', - // Constructing the base Error for a non-throw use is fine. 'const e = new Error("boom");', 'function make() { return new Error("x"); }', 'const errors = [new Error("a"), new Error("b")];', - // Value throws are outside this rule's pattern. 'throw "boom";', 'throw { message: "x" };', - // Only a direct construction is inspected, not a conditional or a - // qualified name. + // Only a direct construction is inspected. 'throw cond ? new Error() : new NotFoundError();', 'throw new foo.Error("x");', - // A namespaced Error under a non-global object is a domain class, not - // the base. + // An Error under a non-global object is a domain class. 'throw new errors.Error("x");', 'throw new lib.window.Error("x");', - // A near-miss name is not the base Error. 'throw new ErrorReport();', - // The allow option permits the base construction in every form it can - // take. { code: 'throw new Error("x");', options: [{ allow: ['Error'] }] }, { code: 'throw new globalThis.Error("x");', options: [{ allow: ['Error'] }] }, { code: 'throw new Error("x") as CustomError;', options: [{ allow: ['Error'] }] }, - // Test files are exempt: stubs and fakes legitimately throw the base - // Error. + // Test stubs legitimately throw the base Error. { code: 'throw new Error("not implemented");', filename: 'client.test.ts' }, { code: 'throw new Error("boom");', filename: '/repo/__tests__/client.ts' }, ], @@ -58,8 +46,6 @@ ruleTester.run('no-base-error', rule, { code: 'throw new Error();', errors: [{ messageId: 'baseError' }], }, - // The argument-free construction with no parentheses is still a throw - // of Error. { code: 'throw new Error;', errors: [{ messageId: 'baseError' }], @@ -68,7 +54,6 @@ ruleTester.run('no-base-error', rule, { code: 'throw new Error(`interpolated ${value}`);', errors: [{ messageId: 'baseError' }], }, - // Wrapping a caught error in a base Error is still throwing the base. { code: 'try { work(); } catch { throw new Error("wrapped"); }', errors: [{ messageId: 'baseError' }], @@ -77,7 +62,6 @@ ruleTester.run('no-base-error', rule, { code: 'function f() { throw new Error("x"); }', errors: [{ messageId: 'baseError' }], }, - // A global object's Error member resolves to the base Error. { code: 'throw new globalThis.Error("x");', errors: [{ messageId: 'baseError' }], @@ -94,8 +78,7 @@ ruleTester.run('no-base-error', rule, { code: 'throw new self.Error();', errors: [{ messageId: 'baseError' }], }, - // A type annotation on the throw does not change the base construction - // underneath. + // Type annotations are unwrapped. { code: 'throw new Error("x") as CustomError;', errors: [{ messageId: 'baseError' }], @@ -108,14 +91,11 @@ ruleTester.run('no-base-error', rule, { code: 'throw new Error("x") satisfies Error;', errors: [{ messageId: 'baseError' }], }, - // Stacked annotations and a global callee still resolve to the base - // Error. { code: 'throw new globalThis.Error("x") as CustomError as unknown;', errors: [{ messageId: 'baseError' }], }, - // Only the base Error is ever a candidate, so a non-Error allow entry - // cannot permit it. + // Only `Error` in allow can permit the base Error. { code: 'throw new Error("x");', options: [{ allow: ['LegacyError'] }], diff --git a/js/eslint/rules/__tests__/no-interface-prefix.test.js b/js/eslint/rules/__tests__/no-interface-prefix.test.js index e256a77..b487e73 100644 --- a/js/eslint/rules/__tests__/no-interface-prefix.test.js +++ b/js/eslint/rules/__tests__/no-interface-prefix.test.js @@ -10,7 +10,6 @@ import { ruleTester } from './tester.js'; ruleTester.run('no-interface-prefix', rule, { valid: [ - // Plain, correctly named declarations. 'interface UserRepository {}', 'interface Item {}', 'type UserId = string;', @@ -21,16 +20,15 @@ ruleTester.run('no-interface-prefix', rule, { 'interface Interface {}', 'interface Iterable {}', - // Generic parameters are not the declaration name, so they are ignored. + // Generic parameters are not the declaration name. 'interface Box {}', 'type Container = TValue[];', 'interface Registry { value: IItem; }', - // Overload signatures and "I"-prefixed members are not declaration - // names. + // Members are not declaration names. 'interface Repository { find(id: number): void; find(id: string): void; ILoad(): void; ICount: number; }', - // The rule targets interfaces and type aliases only, never other kinds. + // Only interfaces and type aliases are checked. '@sealed class IController {}', 'abstract class Base { abstract IRun(): void; get IValue(): number { return 1; } ["IKey"](): void {} }', 'enum IStatus { Active }', @@ -38,8 +36,7 @@ ruleTester.run('no-interface-prefix', rule, { 'const IThing = 1;', 'namespace IUtils {}', - // References to an externally-owned "I"-prefixed type are never the - // declaration name, so nothing that merely mentions one is flagged. + // References to an external "I"-prefixed type are not declarations. 'import { IFoo } from "./types";', 'import type { IFoo } from "./types";', 'export { IFoo } from "./types";', @@ -48,13 +45,12 @@ ruleTester.run('no-interface-prefix', rule, { 'type Wrapped = IFoo;', 'interface Repository extends IFoo {}', - // Augmenting a string-named external module patches a type we cannot - // rename. + // Augmenting an external module patches a type we cannot rename. 'declare module "pkg" { interface INested {} }', 'declare module "some-lib" { interface IConfig { extra: string; } }', 'declare module "m" { type IBaz = number; }', - // Global augmentation patches ambient types we do not own. + // So does global augmentation. 'declare global { interface IWindow {} }', 'declare global { interface IToastOptions {} }', ], @@ -102,7 +98,7 @@ ruleTester.run('no-interface-prefix', rule, { errors: [{ messageId: 'prefixed', data: { kind: 'Interface', name: 'IThing' } }], }, - // A namespace or internal module you own does not exempt its members. + // An owned namespace does not exempt its members. { code: 'namespace Owned { interface INested {} }', errors: [{ messageId: 'prefixed', data: { kind: 'Interface', name: 'INested' } }], diff --git a/js/eslint/rules/__tests__/no-mutable-static.test.js b/js/eslint/rules/__tests__/no-mutable-static.test.js index d12c09d..0ebbd2d 100644 --- a/js/eslint/rules/__tests__/no-mutable-static.test.js +++ b/js/eslint/rules/__tests__/no-mutable-static.test.js @@ -8,8 +8,6 @@ import rule from '../no-mutable-static.js'; import { ruleTester } from './tester.js'; -// The rule is syntactic and needs no parser services, so the type-free tester -// also stands in for the "no type information available" case. ruleTester.run('no-mutable-static', rule, { valid: [ 'export const MAX = 10;', @@ -18,8 +16,7 @@ ruleTester.run('no-mutable-static', rule, { 'class Widget {} export { Widget };', "export { anything } from './other';", 'type T = number; export type { T };', - // Only exported bindings are in scope; an unexported module let/var - // stays local. + // Unexported module bindings stay local. 'let counter = 0;', 'var scratch = 0;', 'namespace N { export const x = 0; }', @@ -38,24 +35,21 @@ ruleTester.run('no-mutable-static', rule, { 'class Box { static readonly EMPTY = 0; }', 'class C { static of(value: T): T { return value; } }', 'abstract class C { abstract run(): void; abstract value: number; }', - // Deliberately mutated statics opt out with a doc tag on the field or - // class. + // The @managed-static opt-out, on the field or the class. 'class C { /** @managed-static */ static cache: Record = {}; }', '/** @managed-static */ class C { static cache = {}; static hits = 0; }', - // The opt-out tag is honoured even when tucked behind a decorator. + // The opt-out still applies behind a decorator. 'declare const track: any; class C { @track /** @managed-static */ static cache = {}; }', - // Test classes are exempt, by their own name, their parent's, or the - // file path. + // Test classes are exempt by name, parent or path. 'class WidgetTest { static shared = 0; }', 'class TestCase {} class C extends TestCase { static shared = 0; }', { code: 'class C { static shared = 0; }', filename: 'widget.test.ts' }, { code: 'class C { static shared = 0; }', filename: '/repo/__tests__/widget.ts' }, - // Ambient declarations describe existing shape, not runtime state. + // Ambient declarations hold no runtime state. 'export declare let external: number;', 'declare class C { static count: number; }', 'declare namespace N { export let x: number; }', 'class C { declare static count: number; }', - // Declaration files are ambient across all module extensions. { code: 'export let external: number;', filename: 'shape.d.ts' }, { code: 'export let external: number;', filename: 'shape.d.mts' }, { code: 'export let external: number;', filename: 'shape.d.cts' }, @@ -85,8 +79,7 @@ ruleTester.run('no-mutable-static', rule, { { messageId: 'mutableExport', data: { name: 'second' } }, ], }, - // Indirect specifier exports of a mutable local publish live module - // state. + // Specifier exports of a mutable local. { code: 'let counter = 0; export { counter };', errors: [{ messageId: 'mutableExport', data: { name: 'counter' } }], @@ -115,10 +108,7 @@ ruleTester.run('no-mutable-static', rule, { code: 'class C { static config: Record = {}; }', errors: [{ messageId: 'mutableStatic', data: { name: 'config' } }], }, - // A static callable slot is still reassignable state, so it is flagged - // like any other mutable static rather than exempted as behaviour. - // Function-typed, union-callable and any-typed slots are all treated - // the same way. + // A static callable slot is still reassignable state. { code: 'class C { static make = () => 1; }', errors: [{ messageId: 'mutableStatic', data: { name: 'make' } }], @@ -139,8 +129,7 @@ ruleTester.run('no-mutable-static', rule, { code: 'class C { static data: any = 1; }', errors: [{ messageId: 'mutableStatic', data: { name: 'data' } }], }, - // A static that is only read is still flagged; the check is - // write-insensitive. + // The check ignores whether the static is ever written. { code: 'const defaults = { a: 1 }; class C { static settings = defaults; ' + 'static read() { return C.settings; } }', @@ -166,7 +155,7 @@ ruleTester.run('no-mutable-static', rule, { code: 'abstract class C { static count = 0; }', errors: [{ messageId: 'mutableStatic', data: { name: 'count' } }], }, - // A near-miss tag does not opt out; the boundary is exact. + // A near-miss tag does not opt out. { code: 'class C { /** @managed-statics */ static count = 0; }', errors: [{ messageId: 'mutableStatic', data: { name: 'count' } }], diff --git a/js/eslint/rules/__tests__/require-copyright.test.js b/js/eslint/rules/__tests__/require-copyright.test.js index ae83f0b..3e81439 100644 --- a/js/eslint/rules/__tests__/require-copyright.test.js +++ b/js/eslint/rules/__tests__/require-copyright.test.js @@ -10,19 +10,13 @@ import { ruleTester } from './tester.js'; ruleTester.run('require-copyright', rule, { valid: [ - // Tags in a top-of-file docblock. '/**\n * @copyright 2026 X\n * @author Y\n */\nexport const a = 1;', - // Tags in the docblock that documents the export, after the imports. + // The docblock may follow the imports. "import { z } from 'z';\n/**\n * A module.\n *\n * @copyright 2026 X\n * @author Y\n */\nexport const a = z;", - // Description and tags together in one block. '/**\n * Summary line.\n *\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', - // Extra tags alongside the required ones, in any order. '/**\n * @author Y\n * @license MIT\n * @copyright 2026 X\n */\nexport const a = 1;', - // A shebang ahead of the documented block. '#!/usr/bin/env node\n/**\n * @copyright 2026 X\n * @author Y\n */\nconst a = 1;', - // Tag matching is case-insensitive. '/**\n * @Copyright 2026 X\n * @AUTHOR Y\n */\nexport const a = 1;', - // Custom required set: only @copyright. { code: '/**\n * @copyright 2026 X\n */\nexport const a = 1;', options: [{ tags: ['copyright'] }] }, ], invalid: [ @@ -31,34 +25,28 @@ ruleTester.run('require-copyright', rule, { errors: [{ messageId: 'missing' }], }, { - // Line comments carrying the tags do not count; a block comment is - // required. + // Line comments do not count. code: '// @copyright 2026 X\n// @author Y\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // The block is missing @author. code: '/**\n * @copyright 2026 X\n */\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // The block is missing @copyright. code: '/**\n * @author Y\n */\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // The tags are split across two blocks; a single block must carry - // both. + // One block must carry both tags. code: '/**\n * @copyright 2026 X\n */\n/**\n * @author Y\n */\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // A near-miss tag name does not satisfy the requirement. code: '/**\n * @copyrighted 2026 X\n * @author Y\n */\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // A custom required set naming a tag that is absent. code: '/**\n * @copyright 2026 X\n * @author Y\n */\nexport const a = 1;', options: [{ tags: ['copyright', 'author', 'license'] }], errors: [{ messageId: 'missing' }], diff --git a/js/eslint/rules/__tests__/require-file-description.test.js b/js/eslint/rules/__tests__/require-file-description.test.js index 83ce6d6..4b5de36 100644 --- a/js/eslint/rules/__tests__/require-file-description.test.js +++ b/js/eslint/rules/__tests__/require-file-description.test.js @@ -10,27 +10,18 @@ import { ruleTester } from './tester.js'; ruleTester.run('require-file-description', rule, { valid: [ - // A summary above the tags: the shape the convention describes. '/**\n * Summary line.\n *\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', - // The summary opening on the same line as the block. '/** Summary line.\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', - // A summary running to several paragraphs before the tags. '/**\n * Summary line.\n *\n * A second paragraph.\n *\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', - // The header documenting the export, below the imports. "import { z } from 'z';\n/**\n * A module.\n *\n * @author Y\n * @copyright 2026 X\n */\nexport const a = z;", - // A shebang ahead of the described header. '#!/usr/bin/env node\n/**\n * Summary line.\n *\n * @author Y\n * @copyright 2026 X\n */\nconst a = 1;', - // A plain block comment carrying the tags is read the same way. '/*\n * Summary line.\n *\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', - // No block carries the tags, so there is no header to describe; the - // absence is require-copyright's to report. + // No header at all is require-copyright's to report. 'export const a = 1;', '/**\n * @author Y\n */\nexport const a = 1;', - // An undescribed block that is not the header, alongside one that is. + // Only the block carrying every tag is the header. '/**\n * @author Y\n */\n/**\n * Summary line.\n *\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', - // A summary whose opening line is prose ending in an email address. '/**\n * Wraps mail sent to foo@example.com.\n *\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', - // A custom required set, describing the block it locates. { code: '/**\n * Summary line.\n *\n * @copyright 2026 X\n */\nexport const a = 1;', options: [{ tags: ['copyright'] }], @@ -38,43 +29,36 @@ ruleTester.run('require-file-description', rule, { ], invalid: [ { - // Tags alone: the shape the rule exists to catch. code: '/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // Blank lines ahead of the tags are not a description. code: '/**\n *\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // An empty block carrying the tags on its opening line. code: '/** @author Y @copyright 2026 X */\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // Prose below the tags is a trailing note, not the summary the - // convention puts above them. + // Prose below the tags is not a summary. code: '/**\n * @author Y\n * @copyright 2026 X\n *\n * A trailing note.\n */\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // A wrapped tag value's continuation line does not pass as prose. + // A wrapped tag value is not prose. code: '/**\n * @author Y\n * @copyright 2026 A Very Long Holder Name That\n * wraps onto a second line\n */\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // A described block elsewhere does not describe the header. code: '/**\n * A note about the line below.\n */\n/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = 1;', errors: [{ messageId: 'missing' }], }, { - // The header sitting below the imports, undescribed. code: "import { z } from 'z';\n/**\n * @author Y\n * @copyright 2026 X\n */\nexport const a = z;", errors: [{ messageId: 'missing' }], }, { - // A custom required set locating an undescribed block. code: '/**\n * @copyright 2026 X\n */\nexport const a = 1;', options: [{ tags: ['copyright'] }], errors: [{ messageId: 'missing' }], diff --git a/js/eslint/rules/__tests__/require-readonly-public-property.test.js b/js/eslint/rules/__tests__/require-readonly-public-property.test.js index a6bd24c..12c0680 100644 --- a/js/eslint/rules/__tests__/require-readonly-public-property.test.js +++ b/js/eslint/rules/__tests__/require-readonly-public-property.test.js @@ -10,14 +10,13 @@ import { ruleTester } from './tester.js'; ruleTester.run('require-readonly-public-property', rule, { valid: [ - // A public property is fine once it is readonly. 'class C { public readonly x = 1; }', 'class C { readonly x = 1; }', // Non-public properties are outside the mandate. 'class C { private x = 1; }', 'class C { protected x = 1; }', 'class C { #x = 1; }', - // Static state is left to a separate concern. + // Static state is no-mutable-static's concern. 'class C { static x = 1; }', 'class C { public static x = 1; }', // Constructor-promoted properties, readonly forms. @@ -49,7 +48,7 @@ ruleTester.run('require-readonly-public-property', rule, { 'class C { [k: string]: number; }', // Abstract public members may declare a readonly contract. 'abstract class C { public abstract readonly x: number; }', - // Ambient declarations describe external shapes; not enforced. + // Ambient declarations are not enforced. 'declare class C { public x: number; }', 'declare namespace N { class C { public x: number; } }', 'declare global { class C { public x: number; } }', @@ -68,7 +67,7 @@ ruleTester.run('require-readonly-public-property', rule, { code: 'class Product extends ns.Model { public name = ""; }', options: [{ ignoredParentClasses: ['Model'] }], }, - // Test fixtures are exempt: by class name, parent, or file location. + // Test classes are exempt by name, parent or path. 'class UserTest { public spy = 1; }', 'class Fake extends TestCase { public calls = 0; }', { code: 'class Fake { public calls = 0; }', filename: 'src/tests/Fake.ts' }, @@ -170,8 +169,7 @@ ruleTester.run('require-readonly-public-property', rule, { errors: [{ messageId: 'mutable', data: { name: 'Symbol.iterator' } }], }, { - // A mixin-produced base cannot be name-matched, so it stays - // enforced. + // A mixin-produced base cannot be name-matched. code: 'class C extends mixin(Base) { public x = 1; }', options: [{ ignoredParentClasses: ['Base'] }], errors: [{ messageId: 'mutable', data: { name: 'x' } }], diff --git a/js/eslint/rules/__tests__/single-line-property-doc.test.js b/js/eslint/rules/__tests__/single-line-property-doc.test.js index 2f07dff..b1341a8 100644 --- a/js/eslint/rules/__tests__/single-line-property-doc.test.js +++ b/js/eslint/rules/__tests__/single-line-property-doc.test.js @@ -10,43 +10,32 @@ import { ruleTester } from './tester.js'; ruleTester.run('single-line-property-doc', rule, { valid: [ - // An interface member already on one line. 'interface I {\n /** A value. */\n a: number;\n}', - // A class field already on one line. 'class C {\n /** A value. */\n a = 1;\n}', - // A property with no documentation comment is not this rule's concern. 'interface I {\n a: number;\n}', - // A long description stays on one line, however far it runs. 'interface I {\n /** A description kept deliberately long to run well past any reasonable wrap column ' + 'without being broken. */\n a: number;\n}', - // A class field holding a function may document across lines. + // Function fields and method signatures are not data properties. 'class C {\n /**\n * Handle activity.\n *\n * @param e - the event\n */\n' + ' onActivity = (e: Event): void => {};\n}', - // A method signature is not a data property. 'interface I {\n /**\n * Search.\n *\n * @param term - the term\n */\n' + ' search(term: string): void;\n}', - // A leading line comment is not a documentation block. 'interface I {\n // a value\n a: number;\n}', - // An enum member documented on one line passes. 'enum E {\n /** The active state. */\n ACTIVE,\n}', - // An enum member is never required to carry a comment. 'enum E {\n ACTIVE,\n}', ], invalid: [ { - // A multi-line interface-member block folds to one line. code: 'interface I {\n /**\n * A value.\n */\n a: number;\n}', output: 'interface I {\n /** A value. */\n a: number;\n}', errors: [{ messageId: 'multiline' }], }, { - // A multi-line class-field block folds to one line. code: 'class C {\n /**\n * A value.\n */\n a = 1;\n}', output: 'class C {\n /** A value. */\n a = 1;\n}', errors: [{ messageId: 'multiline' }], }, { - // A wrapped description joins with single spaces. code: 'interface I {\n /**\n * A description that the author\n' + ' * split across two lines.\n */\n a: number;\n}', output: 'interface I {\n /** A description that the author split across two lines. */\n' @@ -54,20 +43,18 @@ ruleTester.run('single-line-property-doc', rule, { errors: [{ messageId: 'multiline' }], }, { - // A function-typed data property is still data, so it folds. + // A function-typed property is still data. code: 'interface I {\n /**\n * A callback.\n */\n onDone: () => void;\n}', output: 'interface I {\n /** A callback. */\n onDone: () => void;\n}', errors: [{ messageId: 'multiline' }], }, { - // A block bearing a tag is reported but not folded. code: 'interface I {\n /**\n * A value.\n *\n * @deprecated use b\n */\n' + ' a: number;\n}', output: null, errors: [{ messageId: 'multiline' }], }, { - // A multi-line enum-member block folds to one line. code: 'enum E {\n /**\n * The active state.\n */\n ACTIVE,\n}', output: 'enum E {\n /** The active state. */\n ACTIVE,\n}', errors: [{ messageId: 'multiline' }], diff --git a/js/eslint/rules/__tests__/tester.js b/js/eslint/rules/__tests__/tester.js index 71cd38b..b78033d 100644 --- a/js/eslint/rules/__tests__/tester.js +++ b/js/eslint/rules/__tests__/tester.js @@ -10,7 +10,6 @@ import { RuleTester } from '@typescript-eslint/rule-tester'; import { afterAll, describe, it } from 'vitest'; import * as yamlParser from 'yaml-eslint-parser'; -// Bridge @typescript-eslint/rule-tester onto vitest's lifecycle globals. RuleTester.afterAll = afterAll; RuleTester.describe = describe; RuleTester.it = it; @@ -18,15 +17,11 @@ RuleTester.itOnly = it.only; const fixtures = path.join(import.meta.dirname, 'fixtures'); -/** - * Syntax-only tester. Use for rules that inspect the AST but never read types. - */ +/** Syntax-only tester for rules that never read types. */ export const ruleTester = new RuleTester(); /** - * Type-aware tester. Use for rules that call getTypeAtLocation and friends; - * types resolve against fixtures/tsconfig.json. RuleTester writes each test - * case into file.ts (or react.tsx for JSX), which the tsconfig includes. + * Type-aware tester; each case is written to fixtures/file.ts (or react.tsx). */ export const typedRuleTester = new RuleTester({ languageOptions: { @@ -37,11 +32,7 @@ export const typedRuleTester = new RuleTester({ }, }); -/** - * YAML tester. Use for the rules the base config carries over `.yml`; each case - * is parsed by yaml-eslint-parser, which surfaces a `#` comment as a `Block` - * comment rather than the `Line` a `//` comment arrives as. - */ +/** YAML tester; the parser surfaces a `#` comment as a `Block` comment. */ export const yamlRuleTester = new RuleTester({ languageOptions: { parser: yamlParser, diff --git a/js/eslint/rules/__tests__/valid-enum-member-name.test.js b/js/eslint/rules/__tests__/valid-enum-member-name.test.js index fbc14f0..5b343dc 100644 --- a/js/eslint/rules/__tests__/valid-enum-member-name.test.js +++ b/js/eslint/rules/__tests__/valid-enum-member-name.test.js @@ -10,32 +10,22 @@ import { ruleTester } from './tester.js'; ruleTester.run('valid-enum-member-name', rule, { valid: [ - // Plain SCREAMING_SNAKE_CASE members. 'enum Color { RED, GREEN, BLUE }', // Single letter, digits and underscores are permitted. 'enum Grade { A, B, C }', 'enum HttpStatus { OK_200, NOT_FOUND_404 }', 'enum Flag { RED_ }', - // Explicit initialisers do not change the member name. 'enum Level { LOW = 1, HIGH = 2 }', 'enum Suit { CLUB = "club", HEART = "heart" }', - // String-literal member names that resolve to SCREAMING_SNAKE_CASE. 'enum Weird { "RED" = 1, "GREEN_LIGHT" = 2 }', - // A string literal is checked by its resolved value, so an escaped name - // that decodes to SCREAMING_SNAKE_CASE passes even though the raw - // source text does not match the pattern. + // A string literal is checked by its decoded value, not its raw text. 'enum Escaped { "R\\u0045D" = 1 }', - // const enums and ambient declarations are still checked. 'const enum Mode { ON, OFF }', 'declare enum Ambient { YES, NO }', - // Ambient members in a declaration file. { code: 'enum Ambient { YES, NO }', filename: 'types.d.ts' }, - // Enum inside a TSX file. { code: 'enum Theme { LIGHT, DARK }', filename: 'react.tsx' }, - // The selector must not fire on non-enum constructs. Object-literal "as - // const" pseudo-enum members are a documented gap. + // Non-enum constructs; `as const` pseudo-enums are a known gap. 'const config = { red: 1, greenLight: 2 };', - // A switch `case` is a SwitchCase node, never an enum member. 'function grade(n: number) { switch (n) { case 1: return "a"; default: return "b"; } }', 'interface Options { red: number; greenLight: string; }', 'class Box { private width = 0; get size() { return this.width; } set size(v: number) { this.width = v; } }', @@ -81,24 +71,19 @@ ruleTester.run('valid-enum-member-name', rule, { errors: [{ messageId: 'notUpperSnakeCase', data: { name: '1RED' } }], }, { - // An empty string-literal name never matches the pattern. code: 'enum Weird { "" = 1 }', errors: [{ messageId: 'notUpperSnakeCase', data: { name: '' } }], }, { - // A string-literal name that is a valid identifier in the wrong - // case. code: 'enum Weird { "redValue" = 1 }', errors: [{ messageId: 'notUpperSnakeCase', data: { name: 'redValue' } }], }, { - // The pattern is ASCII-only, so a unicode uppercase letter is - // flagged. + // The pattern is ASCII-only. code: 'enum Accent { Ä }', errors: [{ messageId: 'notUpperSnakeCase', data: { name: 'Ä' } }], }, { - // A dollar-prefixed identifier does not start with an ASCII A-Z. code: 'enum Dollar { $VALUE }', errors: [{ messageId: 'notUpperSnakeCase', data: { name: '$VALUE' } }], }, From 38425b3876ec2ca83ea1179560bada739ce83ccd Mon Sep 17 00:00:00 2001 From: Ben Carey Date: Mon, 16 Nov 2026 22:48:03 -0500 Subject: [PATCH 03/12] chore: trim comments in ESLint rules and configs --- eslint.config.js | 6 +- js/eslint/index.js | 52 +++----------- js/eslint/plugin.js | 6 +- js/eslint/rules/align-doc-tags.js | 18 ++--- js/eslint/rules/boolean-method-name.js | 70 +++++-------------- js/eslint/rules/comment-classifier.js | 13 +--- js/eslint/rules/comment-line-wrap.js | 36 +++------- js/eslint/rules/comment-paragraph.js | 10 +-- js/eslint/rules/comment-reflow.js | 19 +---- js/eslint/rules/comment-tokenizer.js | 8 +-- js/eslint/rules/lib.js | 9 +-- js/eslint/rules/max-methods-per-class.js | 13 +--- js/eslint/rules/multiline-function-doc.js | 19 ++--- js/eslint/rules/no-base-error.js | 33 ++------- js/eslint/rules/no-interface-prefix.js | 13 ++-- js/eslint/rules/no-mutable-static.js | 41 +++-------- js/eslint/rules/require-copyright.js | 12 +--- js/eslint/rules/require-file-description.js | 22 +----- .../rules/require-readonly-public-property.js | 21 ++---- js/eslint/rules/single-line-property-doc.js | 21 ++---- js/eslint/rules/valid-enum-member-name.js | 13 +--- js/eslint/type-checked.js | 10 +-- js/eslint/vue.js | 15 +--- 23 files changed, 106 insertions(+), 374 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 01aec22..755298a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,11 +1,7 @@ import base from './js/eslint/index.js'; /** - * Dogfood config: lint this package's own source with its own rules. The base - * config's file scoping already covers the JavaScript implementations under - * js/eslint and exempts the test specs from the metric rules; the ignores below - * bound the rest, so `eslint .` reaches the rule source and this repository's - * own workflow YAML, whose comment width the base config now governs too. + * Lints this package's own rule source and workflow YAML with its own config. */ export default [ { diff --git a/js/eslint/index.js b/js/eslint/index.js index c178f5b..041596f 100644 --- a/js/eslint/index.js +++ b/js/eslint/index.js @@ -8,16 +8,8 @@ const TS_AND_JS_FILES = [...TS_FILES, '**/*.js', '**/*.jsx', '**/*.mjs', '**/*.c const YAML_FILES = ['**/*.yml', '**/*.yaml']; /** - * Base flat config: the AST-only custom rules that need no type information. - * - * Requires no tsconfig, so it stays cheap. The typescript-eslint parser - * resolves TypeScript syntax. The interface, readonly-property and enum rules - * target TypeScript-only constructs, as does jsdoc/no-types, which presumes a - * signature to hold the type it strips from the tag; no-mutable-static also - * applies to plain JavaScript (exported let/var, mutable static fields), so it - * runs across both. A final block carries the comment-wrap rule alone over - * YAML, which otherwise bounds nothing about a comment's width. The opt-in - * type-aware layer lives in ./type-checked.js. + * Base flat config: the custom rules that need no type information, so no + * tsconfig. The type-aware layer is in ./type-checked.js. * * @author Ben Carey * @copyright 2026 Sine Macula Limited @@ -40,12 +32,8 @@ export default [ '@typescript-eslint/no-explicit-any': 'error', - // A TypeScript signature already records the type, so a tag that - // repeats it is a second copy free to drift from the first. Plain - // JavaScript has no signature to hold one, which is why this rule - // stops at TypeScript: there the tag is the only place a type is - // written down, and clearing it would delete the type rather than - // move it to where the reader already looks. + // TypeScript only: in plain JavaScript the tag is the only place + // the type is recorded. 'jsdoc/no-types': 'error', }, }, @@ -73,15 +61,6 @@ export default [ 'max-lines-per-function': ['error', { max: 50, skipComments: true, skipBlankLines: true, IIFEs: true }], 'max-depth': ['error', 4], - // Every declared function, method, class, assigned arrow and - // property carries a documentation comment describing intent, so a - // reader meets each member's purpose before its type. Interface - // members and class fields are held to the same bar as methods. - // Every @param and @returns says what the value means, whether or - // not the tag also carries a type; the type itself is governed by - // no-types in the TypeScript block above, which is the only place a - // signature holds one. Each block stands off from the code above - // it, single-line blocks included. 'jsdoc/require-jsdoc': ['error', { require: { ClassDeclaration: true, @@ -97,9 +76,8 @@ export default [ 'PropertyDefinition', ], checkConstructors: false, - // Report only; the autofix inserts an empty stub that then - // fails require-description, so a blind fix would scatter - // hollow comments rather than resolve the finding. + // The autofix inserts an empty stub that fails + // require-description. enableFixer: false, }], 'jsdoc/require-description': 'error', @@ -109,11 +87,7 @@ export default [ }, }, { - // YAML carries the comment-wrap rule and nothing else. The parser is - // registered for its `#` comments alone, so no eslint-plugin-yml rule - // is enabled: pulling that plugin's own set in would fault every - // consumer's YAML on quoting, key order and indentation at once, none - // of which this package governs. yamllint keeps the rest of YAML. + // Only comment width; yamllint governs the rest of YAML. files: YAML_FILES, plugins: { '@sinemacula': plugin, @@ -126,15 +100,9 @@ export default [ }, }, { - // Test code keeps the length and depth exemptions and nothing else. A - // spec body is a long, deeply nested account of one scenario, and - // splitting it to satisfy a metric hides the scenario rather than - // simplifying it. Documentation is a different matter: require-jsdoc's - // contexts reach declared functions, assigned arrows and classes, which - // in a spec file are its helpers, factories and builders - the code a - // reader has to understand before the assertions mean anything. A test - // case itself is an arrow passed as a call argument, which no context - // reaches, so `it('...', () => {})` is never asked to carry a block. + // Specs are exempt from the size metrics but not from documentation; + // an `it()` callback is a call argument, which require-jsdoc never + // reaches. files: ['**/*.{test,spec}.{ts,tsx,mts,cts,js,jsx,mjs,cjs}', '**/__tests__/**', '**/tests/**', '**/test-support/**'], rules: { 'max-lines-per-function': 'off', diff --git a/js/eslint/plugin.js b/js/eslint/plugin.js index 77db7a2..0db6f7a 100644 --- a/js/eslint/plugin.js +++ b/js/eslint/plugin.js @@ -13,11 +13,7 @@ import singleLinePropertyDoc from './rules/single-line-property-doc.js'; import validEnumMemberName from './rules/valid-enum-member-name.js'; /** - * The @sinemacula ESLint plugin. - * - * Bundles this package's custom structural rules. Each rule is registered in - * the map below; the flat configs in index.js and type-checked.js are what - * switch them on. + * The @sinemacula ESLint plugin; index.js and type-checked.js enable its rules. * * @author Ben Carey * @copyright 2026 Sine Macula Limited diff --git a/js/eslint/rules/align-doc-tags.js b/js/eslint/rules/align-doc-tags.js index 777227f..b654162 100644 --- a/js/eslint/rules/align-doc-tags.js +++ b/js/eslint/rules/align-doc-tags.js @@ -17,19 +17,10 @@ function padding(tag, column) { } /** - * Align the values of the documentation tags a file's header declares, - * `@author` and `@copyright` by default. + * Align the values of the listed documentation tags (`@author` and `@copyright` + * by default) at one column, counted from the `@`. * - * The tags a file must carry read as a block, so their values line up at a - * single column rather than sitting at whatever offset each tag's own length - * happens to produce. The column counts from the `@`, which at the default of - * 14 gives `@author` six spaces and `@copyright` three. - * - * Only the run of whitespace between a listed tag and its value is considered, - * and only on the line the tag opens; a wrapped value's continuation lines, a - * tag with no value and every unlisted tag are left alone. A tag longer than - * the column can accommodate is skipped rather than reported, as no spacing - * would satisfy the requirement. Presence of the tags is a separate concern, + * A tag too long to reach the column is skipped. Presence of the tags is * enforced by `require-copyright`. * * @author Ben Carey @@ -110,8 +101,7 @@ export default createRule({ continue; } - // The comment's value begins after the opening `/*`, so an - // offset within it maps onto the source two characters in. + // Skip the opening `/*`. let offset = comment.range[0] + 2; for (const line of comment.value.split('\n')) { diff --git a/js/eslint/rules/boolean-method-name.js b/js/eslint/rules/boolean-method-name.js index a3dc11e..668d960 100644 --- a/js/eslint/rules/boolean-method-name.js +++ b/js/eslint/rules/boolean-method-name.js @@ -60,10 +60,8 @@ function isEventHandler(name) { } /** - * Whether a return type resolves to boolean, ignoring a nullable `?bool`-style - * null/undefined/void tail so an optional boolean still counts. Promise - * wrappers are unwrapped before this is called, so an awaited boolean counts - * too. + * Whether a return type resolves to boolean, ignoring a null, undefined or void + * union member. */ function returnsBoolean(type) { if (type.flags & (ts.TypeFlags.Boolean | ts.TypeFlags.BooleanLiteral)) { @@ -81,9 +79,7 @@ function returnsBoolean(type) { return false; } -/** - * Whether the node is a function expression carrying an inspectable signature. - */ +/** Whether the node is an arrow or function expression. */ function isFunctionExpression(node) { return node != null && (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression'); @@ -102,9 +98,7 @@ function keyName(keyNode) { return null; } -/** - * Peel `as`/`satisfies`/non-null wrappers off an expression to reach the value. - */ +/** Peel `as`, `satisfies` and non-null wrappers off an expression. */ function unwrapExpression(node) { let current = node; @@ -141,10 +135,8 @@ function hasImperativeTag(sourceCode, docHost, nameNode) { } /** - * Whether the name is outside the rule's reach: a magic member, a name that - * already reads as a predicate, a command or event handler, a well-known type - * accessor, a member whose name is set by the parent it overrides, or a member - * carrying the @imperative opt-out tag. + * Whether the member is exempt: magic, an override, a type accessor, already a + * predicate, a command or event handler, or tagged @imperative. */ function isExempt(state, nameNode, name, docHost) { if (name.startsWith('__') || TYPE_ACCESSOR_NAMES.has(name) || docHost.override === true) { @@ -163,9 +155,8 @@ function isExempt(state, nameNode, name, docHost) { } /** - * Report the name when it neither reads as a predicate nor is exempt and the - * resolved (awaited) return type is boolean. Type-predicate guards are - * predicates by structure and left alone. + * Report a non-exempt name whose awaited return type is boolean, skipping + * type-predicate guards. */ function inspect(state, nameNode, name, fnNode, docHost) { const { checker, services, context } = state; @@ -189,10 +180,7 @@ function inspect(state, nameNode, name, fnNode, docHost) { context.report({ node: nameNode, messageId: 'notPredicate', data: { name } }); } -/** - * Guard a statically named function value (arrow field, object method or const - * binding) down to a named key, then inspect it. - */ +/** Inspect a function value bound to a statically named key. */ function inspectFunctionValue(state, keyNode, valueNode, docHost) { const name = keyName(keyNode); @@ -202,10 +190,8 @@ function inspectFunctionValue(state, keyNode, valueNode, docHost) { } /** - * Guard a class member down to a statically named, non-accessor method, then - * inspect it. A bodiless member is dropped as an overload signature so the - * implementation reports once, unless it is abstract or ambient, where the - * bodiless declaration is the real thing to check. + * Inspect a statically named method. A bodiless overload signature is skipped + * unless abstract or ambient, so the implementation reports once. */ function inspectMember(state, node, allowEmptyBody) { if (node.computed || node.kind !== 'method') { @@ -225,11 +211,7 @@ function inspectMember(state, node, allowEmptyBody) { inspect(state, node.key, name, node, node); } -/** - * The visitor: inspect each named function, method, signature and - * function-valued member for a boolean return that does not read as a - * predicate. - */ +/** The listeners for every named function, method and signature form. */ function buildListeners(state) { return { FunctionDeclaration(node) { @@ -282,25 +264,12 @@ function buildListeners(state) { } /** - * Boolean method name rule. + * Require a function or method returning boolean (awaited included) to read as + * a predicate. * - * A function, method, arrow-bound class field, object method or interface/type - * signature returning boolean should read as a predicate. A name is accepted - * when its first camelCase word is a copular or modal prefix (is, has, can, - * ...), an idiomatic predicate from ALLOWED_PREDICATES (e.g. successful), or a - * verb ending in `s` (third-person: permits, passes) or `ed` (past tense: - * succeeded, failed, expired). An imperative command verb (execute, persist, - * guard, ...) that returns a result bool is exempt via COMMAND_VERBS. A member - * may also opt out with an - * @imperative docblock tag. An on* event-handler callback (onError) and a - * method named after a primitive type (a typed accessor such as boolean()) are - * exempt, as is a member carrying the override modifier, whose name is set by - * the parent it overrides and is checked where that declares it, and so are - * accessors, the constructor, computed names, magic names and type-predicate - * guards (x is T). The return type is resolved from type information - inferred - * booleans and awaited Promise included - so the rule degrades to a - * no-op when no type information is available. The accepted vocabulary can be - * widened per consumer through the rule options. + * Its first camelCase word must be an allowed prefix or predicate, or a verb + * ending in `s` or `ed`. Command verbs, `on*` handlers, overrides and members + * tagged `@imperative` are exempt. Needs type information; a no-op without it. * * @author Ben Carey * @copyright 2026 Sine Macula Limited @@ -329,15 +298,10 @@ export default createRule({ create(context, [options]) { const services = ESLintUtils.getParserServices(context, true); - // Without a type-checker program the return type can't be resolved, so - // the rule cannot decide anything; degrade to a no-op rather than - // throw. if (!services.program) { return {}; } - // Merge consumer additions onto the defaults so a downstream ruleset - // can widen the accepted vocabulary without losing the built-in words. const state = { context, services, diff --git a/js/eslint/rules/comment-classifier.js b/js/eslint/rules/comment-classifier.js index 0b4f139..f9c2025 100644 --- a/js/eslint/rules/comment-classifier.js +++ b/js/eslint/rules/comment-classifier.js @@ -1,14 +1,7 @@ /** - * Classifies a single content line of a comment. - * - * Only prose and list items are reflowed; every other kind is preserved - * verbatim and acts as a paragraph boundary. Directives, docblock tags, fenced - * or indented code, tables and rule separators are left exactly as written, so - * a reflow never disturbs a construct whose position or spacing carries - * meaning. The directive set spans the tools that read instructions out of a - * comment in any of the governed languages, YAML's included: a schema - * association or a Renovate manager hint is machine-read, so wrapping it would - * silently sever it from the key it annotates. + * Classifies a single content line of a comment. Only prose and list items + * reflow; every other kind is kept verbatim as a paragraph boundary, so a + * machine-read directive is never wrapped away from what it annotates. * * @author Ben Carey * @copyright 2026 Sine Macula Limited diff --git a/js/eslint/rules/comment-line-wrap.js b/js/eslint/rules/comment-line-wrap.js index c89d63e..622bbd8 100644 --- a/js/eslint/rules/comment-line-wrap.js +++ b/js/eslint/rules/comment-line-wrap.js @@ -20,13 +20,9 @@ function isStandalone(comment, sourceCode) { } /** - * The line-comment token a comment opens with, or null when it opens none. - * - * Read from the source text rather than inferred from the comment's type, - * because parsers label the same shape differently: a `//` comment arrives as - * `Line`, while yaml-eslint-parser tags a `#` comment `Block`. Requiring one of - * the two recognised types first leaves out a hashbang, which is neither and - * whose leading `#` must never be read as prose. + * The line-comment token a comment opens with, or null. Read from the source + * because yaml-eslint-parser types a `#` comment as `Block`; the type check + * still excludes a hashbang. */ function lineToken(comment, sourceCode) { if (!COMMENT_TYPES.includes(comment.type)) { @@ -166,27 +162,13 @@ function enforce(context, descriptor, maxLength) { } /** - * Keep standalone comment prose wrapped to a readable width. - * - * The syntax-only counterpart of the PHP comment line length sniff. It fills - * each line greedily with as many whole words as fit and reports two faults on - * their own footings: a line that overflows the width, and a line that wraps - * earlier than it needs to. Standalone runs of the line-comment tokens `//` and - * `#` and multi-line docblocks are governed; tag lines, suppression directives, - * fenced or indented code, tables, separators and trailing comments after code - * are left untouched, as is a line whose overflow is a single unbreakable token - * such as a long name or URL, and a compact single-line docblock, which the - * single-line property rule governs. In a line-comment run, a line opening with - * a capital letter starts a paragraph of its own unless the line above ends - * mid-sentence, so a title or a one-line note is not merged into the sentence - * below it. The fix reflows each faulted paragraph to its greedy canonical form - * and is idempotent. + * Keep standalone comment prose wrapped greedily to a readable width. * - * The `#` token carries the rule into YAML through yaml-eslint-parser, where it - * reaches only standalone comments: block-scalar bodies are content rather than - * comments, so a shell comment inside a `run:` step is never seen, and a - * comment trailing a value is not standalone. Each token reclaims its own - * width, so a `#` comment fills one column further than a `//` one. + * Reports a line that overflows and a line that wraps before it needs to, over + * standalone `//` and `#` runs and multi-line docblocks. Trailing comments, + * single-line docblocks and an overflow caused by one unbreakable token are + * left alone. In YAML, block-scalar bodies are content, so a shell comment in a + * `run:` step is never seen. * * @author Ben Carey * @copyright 2026 Sine Macula Limited diff --git a/js/eslint/rules/comment-paragraph.js b/js/eslint/rules/comment-paragraph.js index 897bf3d..0e0be7b 100644 --- a/js/eslint/rules/comment-paragraph.js +++ b/js/eslint/rules/comment-paragraph.js @@ -1,12 +1,6 @@ /** - * Reflows a single paragraph of comment prose to its greedy canonical form. - * - * A paragraph is a run of prose lines, or one list item with its continuation - * lines. It is filled line by line with as many whole words as the width - * allows, never splitting a word and keeping any list marker's hanging indent. - * A paragraph is reflowed only when it is safe to: it holds no token wider than - * the line, is not too narrow, and would still read as prose once wrapped. - * Otherwise it is returned untouched. + * Reflows one paragraph (a prose run, or a list item with its continuation) to + * its greedy canonical form, leaving it untouched when wrapping is unsafe. * * @author Ben Carey * @copyright 2026 Sine Macula Limited diff --git a/js/eslint/rules/comment-reflow.js b/js/eslint/rules/comment-reflow.js index 5cffbe2..096f97f 100644 --- a/js/eslint/rules/comment-reflow.js +++ b/js/eslint/rules/comment-reflow.js @@ -1,21 +1,6 @@ /** - * Deterministic greedy re-wrapper for comment prose. - * - * The syntax-only counterpart of the PHP comment line length sniff: given the - * content lines of one comment block (their margin already stripped) and the - * width that margin will reclaim, it walks the block and hands each run of - * prose and each list item to a paragraph reflow, gathering the canonical lines - * and the indices of the input lines that overflow or wrap prematurely. A - * fenced block, a type-annotation tag whose value opens a bracketed type across - * lines, headings, indented code, tags, directives, tables and separators are - * left verbatim and bound the paragraph around them. When asked to, a line - * opening with a capital letter begins a paragraph of its own unless the line - * above ends mid-sentence, so a short standalone note such as a title is not - * merged into the sentence below. - * - * Widths count Unicode code points and whitespace is matched as ASCII only, so - * the output is byte-for-byte identical to the PHP engine (mb_strlen and the - * non-unicode PCRE `\s`). + * Greedy re-wrapper for comment prose, the counterpart of the PHP comment line + * length sniff. Its output must stay byte-identical to the PHP engine. * * @author Ben Carey * @copyright 2026 Sine Macula Limited diff --git a/js/eslint/rules/comment-tokenizer.js b/js/eslint/rules/comment-tokenizer.js index 7fe68e1..04e0434 100644 --- a/js/eslint/rules/comment-tokenizer.js +++ b/js/eslint/rules/comment-tokenizer.js @@ -1,10 +1,6 @@ /** - * Text primitives for the comment reflow engine. - * - * Splits prose into wrapping tokens, keeping inline code, an inline `{@link}` - * tag and a Markdown link whole even when they hold spaces, and measures widths - * in Unicode code points. Widths and whitespace match the PHP engine exactly: - * code points as mb_strlen counts them, and ASCII-only trimming as trim does. + * Text primitives for the comment reflow engine. Widths and trimming match the + * PHP engine (mb_strlen code points, ASCII-only trim). * * @author Ben Carey * @copyright 2026 Sine Macula Limited diff --git a/js/eslint/rules/lib.js b/js/eslint/rules/lib.js index 1c4027e..9d0cba4 100644 --- a/js/eslint/rules/lib.js +++ b/js/eslint/rules/lib.js @@ -101,13 +101,8 @@ export function tagMatcher(tag) { } /** - * The file's descriptive docblock: the block comment carrying all of the given - * tags together, or null when no comment carries them. - * - * The block is found by its tags rather than its position, since the header - * need not open the file: a module documented at its export sits below the - * imports. Requiring one comment to carry every tag is what makes the match a - * single block rather than a header split across several. + * The first block comment carrying all of the given tags, or null. Matched by + * tags, not position, since a module may be documented at its export. */ export function fileDocBlock(sourceCode, tags) { const matchers = tags.map(tagMatcher); diff --git a/js/eslint/rules/max-methods-per-class.js b/js/eslint/rules/max-methods-per-class.js index ff63ce8..eb5196b 100644 --- a/js/eslint/rules/max-methods-per-class.js +++ b/js/eslint/rules/max-methods-per-class.js @@ -2,8 +2,7 @@ import { createRule, isTestClass, isTestPath } from './lib.js'; /** Whether a class member counts towards the method total. */ function isCountedMethod(member) { - // An overload signature shares its name with the implementation below it, - // so it carries no body and is not counted a second time. + // Overload signatures have no body and count once, via the implementation. return member.type === 'MethodDefinition' && member.value.type !== 'TSEmptyBodyFunctionExpression'; } @@ -22,14 +21,8 @@ function countMethods(node) { } /** - * Cap the number of methods declared directly on a single class. - * - * A class that grows past the limit is doing too many jobs and should be split. - * Every method declared on the class body counts, including the constructor, - * static methods and get/set accessors; a method spread across overload - * signatures counts once, through its implementation. Methods on a nested class - * belong to that class, not the one enclosing it. Test code legitimately - * gathers many methods on one fixture, so a test file or test class is exempt. + * Cap the number of methods declared directly on a single class, constructor + * and accessors included. Test files and test classes are exempt. * * @author Ben Carey * @copyright 2026 Sine Macula Limited diff --git a/js/eslint/rules/multiline-function-doc.js b/js/eslint/rules/multiline-function-doc.js index 8c0924e..fc3a2d3 100644 --- a/js/eslint/rules/multiline-function-doc.js +++ b/js/eslint/rules/multiline-function-doc.js @@ -26,19 +26,11 @@ function singleLineContent(value) { } /** - * Require a method's documentation comment to span multiple lines. + * Require a method's documentation comment to span multiple lines, the mirror + * of the single-line form data properties take. * - * A method earns a fuller account than a data field: what it does, and in time - * its parameters and what it returns. Holding its comment open across lines - * keeps that room ready and sets behaviour apart from data at a glance, the - * mirror of the single-line form data properties take. Class methods, interface - * method signatures and class fields that hold a function are governed; a data - * property keeps its one line, and a free function is left to the author, since - * a short helper reads well on a single line. - * - * A block already spanning lines passes. A one-line block is unfolded onto - * three, its prose moved to the middle line; an empty one is left for the - * description rule to report, since there is nothing to unfold. + * Governs class methods, interface method signatures and function-valued class + * fields; free functions are left to the author. * * @author Ben Carey * @copyright 2026 Sine Macula Limited @@ -78,8 +70,7 @@ export default createRule({ const content = singleLineContent(doc.value); - // An empty block is the description rule's to report; there is no - // prose to move onto the middle line. + // An empty block is the description rule's to report. if (content.length === 0) { return; } diff --git a/js/eslint/rules/no-base-error.js b/js/eslint/rules/no-base-error.js index 9e70a38..3e8532a 100644 --- a/js/eslint/rules/no-base-error.js +++ b/js/eslint/rules/no-base-error.js @@ -3,10 +3,7 @@ import { createRule, isTestPath } from './lib.js'; /** Global objects whose `Error` member resolves to the base `Error`. */ const GLOBAL_OBJECTS = new Set(['globalThis', 'window', 'global', 'self']); -/** - * Strips the `as`, `satisfies` and non-null wrappers a throw argument may - * carry. - */ +/** Strips `as`, `satisfies` and non-null wrappers from a throw argument. */ function unwrapType(node) { let current = node; @@ -39,10 +36,7 @@ function isGlobalError(callee) { && isErrorProperty(callee.property); } -/** - * Whether a construction callee denotes the base `Error`, directly or through a - * global object. - */ +/** Whether a callee is the base `Error`, directly or via a global object. */ function isBaseError(callee) { if (callee.type === 'Identifier') { return callee.name === 'Error'; @@ -52,26 +46,11 @@ function isBaseError(callee) { } /** - * Disallow throwing the base `Error`. - * - * A bare `throw new Error(...)`, including the argument-free `throw new Error`, - * gives a caller no type to catch on, so a domain-specific subclass such as - * `ValidationError` must be thrown instead. - * - * The check is syntactic. It flags a throw whose argument constructs the base - * `Error`, whether named directly (`new Error()`) or reached through a global - * object (`new globalThis.Error()`, `new window.Error()`). A `throw ... as X`, - * `throw ...!` or `satisfies` annotation is unwrapped before the construction - * is inspected, so the annotation cannot hide the throw. Subclasses - * (`new NotFoundError()`) and the specific built-ins (`new TypeError()`) read - * as domain-specific and pass; a re-thrown variable (`throw err`), a qualified - * name (`new foo.Error()`) and a base `Error` built for a non-throw use - * (`const e = new Error()`) fall outside the pattern. Only the base `Error` is - * ever a candidate, so listing `Error` in the `allow` option is the one way to - * permit it; any other name has nothing to match and stays inert. + * Disallow throwing the base `Error`, directly or via a global object such as + * `globalThis`, since it gives a caller no type to catch on. * - * Test files are exempt: stubs and fakes legitimately throw the base `Error` - * (`throw new Error('not implemented')`), where a domain subclass adds nothing. + * The check is syntactic; a type assertion around the throw is unwrapped first. + * Only `Error` in the `allow` option has any effect. Test files are exempt. * * @author Ben Carey * @copyright 2026 Sine Macula Limited diff --git a/js/eslint/rules/no-interface-prefix.js b/js/eslint/rules/no-interface-prefix.js index fef8948..20cd075 100644 --- a/js/eslint/rules/no-interface-prefix.js +++ b/js/eslint/rules/no-interface-prefix.js @@ -1,9 +1,6 @@ import { createRule } from './lib.js'; -/** - * Disallowed "I" prefix: a capital I directly followed by another uppercase - * letter. - */ +/** A capital I directly followed by another uppercase letter. */ const PREFIX_PATTERN = /^I[A-Z]/; /** A global or string-named module block augments types we do not own. */ @@ -12,8 +9,8 @@ const isExternalAugmentation = node => && (node.kind === 'global' || node.id.type === 'Literal'); /** - * Forbids the Hungarian "I" prefix on interface and type-alias names - * (IUserRepository), which adds nothing over the language's own type system. + * Forbids the Hungarian "I" prefix on interface and type-alias names, such as + * `IUserRepository`. * * @author Ben Carey * @copyright 2026 Sine Macula Limited @@ -44,8 +41,8 @@ export default createRule({ return; } - // Augmenting an external module or the global scope cannot rename - // it. + // An augmentation of an external module or the global scope cannot + // rename the type. if (sourceCode.getAncestors(node).some(isExternalAugmentation)) { return; } diff --git a/js/eslint/rules/no-mutable-static.js b/js/eslint/rules/no-mutable-static.js index 331ff67..b0e2e41 100644 --- a/js/eslint/rules/no-mutable-static.js +++ b/js/eslint/rules/no-mutable-static.js @@ -1,9 +1,7 @@ import { ASTUtils } from '@typescript-eslint/utils'; import { createRule, isAmbient, isDeclarationFile, isTestClass, isTestPath, nearestClass } from './lib.js'; -/** - * Unwrap a rest element to its bound target, else return the node unchanged. - */ +/** Unwrap a rest element to its bound target. */ function restTarget(node) { return node.type === 'RestElement' ? node.argument : node; } @@ -41,11 +39,7 @@ function boundIdentifiers(pattern, out) { } } -/** - * Whether a resolved binding is a mutable local `let`/`var` (not const, class, - * function, import or an ambient declaration), and so publishes live module - * state. - */ +/** Whether a resolved binding is a non-ambient local `let` or `var`. */ function bindsMutableVariable(variable, filename) { if (isDeclarationFile(filename)) { return false; @@ -72,8 +66,6 @@ function hasManagedTag(node, sourceCode) { return true; } - // A docblock tucked between the decorators and the declaration sits before - // the first token after the last decorator, not before the whole member. if (node.decorators?.length) { const afterDecorators = sourceCode.getTokenAfter(node.decorators.at(-1)); const inner = afterDecorators && sourceCode.getCommentsBefore(afterDecorators).at(-1); @@ -84,9 +76,7 @@ function hasManagedTag(node, sourceCode) { return false; } -/** - * A readable name for a class member key, including private and computed forms. - */ +/** A readable name for a class member key, private and computed included. */ function describeKey(node, sourceCode) { if (node.computed) { return `[${sourceCode.getText(node.key)}]`; @@ -131,8 +121,7 @@ function reportInlineExports(node, context) { /** Report `export { x }` specifiers that publish a mutable local binding. */ function reportSpecifierExports(node, context) { - // A re-export carries no local binding; a type-only export carries no - // runtime one. + // Re-exports and type-only exports bind no local runtime value. if (node.source || node.exportKind === 'type') { return; } @@ -153,18 +142,12 @@ function reportSpecifierExports(node, context) { } /** - * Forbids mutable module-level and class-level static state: exported - * `let`/`var` bindings (declared inline or published through an - * `export { ... }` specifier) and non-readonly `static` class fields, including - * `static accessor` auto-accessors. All are global mutable state; `const` and - * `readonly` express the read-only configuration this allows. + * Forbids exported `let`/`var` bindings and non-readonly `static` class fields + * (auto-accessors included). * - * The check is syntactic, not write-sensitive: a static is flagged whether or - * not a reassignment is visible, since cross-file writes are out of a per-file - * rule's reach. Deliberately mutated statics opt out with a `@managed-static` - * doc tag on the field or its declaring class, and test classes are exempt. - * Module scope is limited to exported bindings; an unexported module `let` - * stays local and is left alone. + * The check is syntactic, since a per-file rule cannot see cross-file writes. A + * `@managed-static` tag on the field or its class opts out, and test classes + * are exempt. * * @author Ben Carey * @copyright 2026 Sine Macula Limited @@ -187,8 +170,7 @@ export default createRule({ const { sourceCode } = context; /** - * Whether a static member is exempt: test code or an opted-out - * declaration. + * Whether a static member is exempt as test code or by opt-out tag. */ const isStaticExempt = node => { if (isTestPath(context.filename)) { @@ -205,8 +187,7 @@ export default createRule({ }; /** - * Flag a non-readonly static field or auto-accessor as mutable static - * state. + * Flag a non-readonly static field or auto-accessor. */ const inspectStatic = node => { if (!node.static || node.readonly || isAmbient(node, context.filename) || isStaticExempt(node)) { diff --git a/js/eslint/rules/require-copyright.js b/js/eslint/rules/require-copyright.js index 0b7d9c5..a82bc85 100644 --- a/js/eslint/rules/require-copyright.js +++ b/js/eslint/rules/require-copyright.js @@ -3,16 +3,8 @@ import { createRule, fileDocBlock } from './lib.js'; const DEFAULT_TAGS = ['copyright', 'author']; /** - * Require a documentation comment carrying the tags every source file must - * declare, `@copyright` and `@author` by default. - * - * A single block comment must carry all of the required tags together, so they - * sit inside the file's descriptive docblock alongside its summary rather than - * in a separate header. Only the presence of each tag is checked, never its - * value or alignment, which are matters of formatting. The required set is - * configurable, so a project may drop `@author` or add tags of its own. The - * summary those tags sit beside is the separate concern of - * `require-file-description`, which locates the same block by the same tags. + * Require one documentation comment carrying every listed tag (`@copyright` and + * `@author` by default). Only presence is checked, not value or alignment. * * @author Ben Carey * @copyright 2026 Sine Macula Limited diff --git a/js/eslint/rules/require-file-description.js b/js/eslint/rules/require-file-description.js index 5d200bb..83bcd50 100644 --- a/js/eslint/rules/require-file-description.js +++ b/js/eslint/rules/require-file-description.js @@ -26,26 +26,10 @@ function described(comment) { } /** - * Require the file's descriptive docblock to carry a summary, not tags alone. + * Require the file's docblock to open with a prose summary above its tags. * - * The house convention is a prose summary followed by the tags every file - * declares, so `@author` and `@copyright` annotate a description rather than - * standing as a header of their own. `require-copyright` has always asked for - * the tags; this asks for the sentence they were meant to sit beneath, which - * was the intent all along and the half nothing enforced. A file whose entire - * header is two tags says who owns it and nothing about what it is. - * - * The block is located exactly as `require-copyright` locates it, by the tags - * it carries, so the two rules always speak about the same comment; a project - * changing one rule's `tags` should change the other's to match. A file with no - * such block is left alone, since `require-copyright` already owns the block's - * existence and faulting one omission twice would only double the report. - * - * Only the block's first non-blank line is read, and only whether it is prose. - * That places the summary above the tags, as the convention writes it, and - * keeps a wrapped tag value's continuation line from passing as a description. - * What the sentence says is the author's business: the rule asserts that prose - * is there, never that it is good. + * The block is found by its tags, as `require-copyright` finds it, so the two + * rules' `tags` options should match. A missing block is left to that rule. * * @author Ben Carey * @copyright 2026 Sine Macula Limited diff --git a/js/eslint/rules/require-readonly-public-property.js b/js/eslint/rules/require-readonly-public-property.js index 377406d..4777104 100644 --- a/js/eslint/rules/require-readonly-public-property.js +++ b/js/eslint/rules/require-readonly-public-property.js @@ -9,16 +9,11 @@ import { } from './lib.js'; /** - * Require the `readonly` modifier on public class properties. + * Require the `readonly` modifier on public class properties, declared or + * constructor-promoted. * - * Public properties, whether declared or constructor-promoted, must be - * `readonly`. Mutable public state breaks encapsulation; the legitimate - * data-holder case is expressed with `public readonly`. Public auto-accessors - * have no `readonly` form and always expose a setter, so they are disallowed - * outright. Static properties are left to the mutable static state concern, - * non-public properties are unaffected, and ambient declarations plus test - * fixtures are exempt. TypeScript has no whole-class readonly modifier, so - * there is no class-level exemption. + * A public auto-accessor has no readonly form, so it is disallowed outright. + * Statics are left to `no-mutable-static`. * * @author Ben Carey * @copyright 2026 Sine Macula Limited @@ -52,7 +47,6 @@ export default createRule({ const ignoredParents = options.ignoredParentClasses ?? []; const { sourceCode } = context; - // Declaration files and test directories are exempt wholesale. if (isDeclarationFile(context.filename) || isTestPath(context.filename)) { return {}; } @@ -82,8 +76,6 @@ export default createRule({ }); }, 'AccessorProperty, TSAbstractAccessorProperty'(node) { - // An auto-accessor cannot be readonly, so a public one is - // always mutable. if (isOutOfScope(node) || isExempt(node)) { return; } @@ -116,10 +108,7 @@ function isNonPublic(node) { || node.accessibility === 'protected'; } -/** - * Whether a class property is outside the public-mutable scope: static, - * ambient, or non-public. - */ +/** Whether a class property is static, ambient or non-public. */ function isOutOfScope(node) { return node.static || node.declare || isNonPublic(node); } diff --git a/js/eslint/rules/single-line-property-doc.js b/js/eslint/rules/single-line-property-doc.js index 6723a6e..80a560b 100644 --- a/js/eslint/rules/single-line-property-doc.js +++ b/js/eslint/rules/single-line-property-doc.js @@ -28,21 +28,11 @@ function contentLines(value) { } /** - * Require a data member's documentation comment to sit on a single line. + * Require a data member's documentation comment (interface property, enum + * member, non-function class field) to sit on a single line. * - * A field's description is a single phrase, so it belongs on one line however - * long it runs; nothing wraps a comment to a width, and breaking it by hand - * only scatters the phrase down the file. Interface property signatures, enum - * members and class fields that hold data are governed; a class field holding a - * function reads as behaviour, may document parameters and is left to span as - * many lines as it needs, as are methods and every free function. A comment is - * never required here, only held to one line where it is present, so enum - * members stay documented at the author's discretion. - * - * A block already on one line passes. A multi-line block collapses to one, its - * lines joined by single spaces, provided it carries prose alone: a block - * bearing a tag such as `@deprecated` keeps its shape and is reported without a - * fix, since folding a tag into a running line would change its meaning. + * A block carrying a tag such as `@deprecated` is reported without a fix, since + * folding the tag into running prose would change its meaning. * * @author Ben Carey * @copyright 2026 Sine Macula Limited @@ -83,8 +73,7 @@ export default createRule({ const lines = contentLines(doc.value); - // An empty block is the description rule's to report; there is no - // prose to fold onto one line. + // An empty block is the description rule's to report. if (lines.length === 0) { return; } diff --git a/js/eslint/rules/valid-enum-member-name.js b/js/eslint/rules/valid-enum-member-name.js index 36e3202..0342728 100644 --- a/js/eslint/rules/valid-enum-member-name.js +++ b/js/eslint/rules/valid-enum-member-name.js @@ -4,11 +4,8 @@ import { createRule } from './lib.js'; const NAME_PATTERN = /^[A-Z][A-Z0-9_]*$/; /** - * Enum member naming rule. - * - * Ensures every enum member is declared in SCREAMING_SNAKE_CASE, matching the - * Sine Macula house convention for enum members. Only real `enum` declarations - * are checked; object-literal "as const" pseudo-enums are out of scope. + * Require enum members in SCREAMING_SNAKE_CASE. Object-literal `as const` + * pseudo-enums are not checked. * * @author Ben Carey * @copyright 2026 Sine Macula Limited @@ -27,14 +24,10 @@ export default createRule({ }, defaultOptions: [], create(context) { - // Only enum members are visited; a switch `case` is a SwitchCase node - // and never reaches this visitor. return { TSEnumMember(node) { const id = node.id; - // A member name is either a bare identifier or a string - // literal; a string literal is checked by its resolved value, - // not the raw source text. + // A string-literal name is checked by its value. const name = id.type === 'Identifier' ? id.name : String(id.value); if (!NAME_PATTERN.test(name)) { diff --git a/js/eslint/type-checked.js b/js/eslint/type-checked.js index 934facf..c1f20de 100644 --- a/js/eslint/type-checked.js +++ b/js/eslint/type-checked.js @@ -3,11 +3,7 @@ import base from './index.js'; import plugin from './plugin.js'; /** - * Opt-in type-aware layer: the cross-file and type-driven rules. Spreads the - * base config, then turns on type information via the project service so the - * type-aware custom rules and the curated typescript-eslint rules can resolve. - * Layered on only where a consumer tsconfig exists, keeping the base config the - * cheap fast path. + * Opt-in type-aware layer over the base config, for repos with a tsconfig. * * @author Ben Carey * @copyright 2026 Sine Macula Limited @@ -31,14 +27,12 @@ export default [ '@typescript-eslint/await-thenable': 'error', '@typescript-eslint/consistent-type-imports': 'error', - // Type-aware replacement for Biome's useLiteralKeys: dot access for - // real properties, bracket access allowed on index signatures. + // Type-aware replacement for Biome's useLiteralKeys. '@typescript-eslint/dot-notation': ['error', { allowIndexSignaturePropertyAccess: true }], '@typescript-eslint/explicit-module-boundary-types': 'error', '@typescript-eslint/no-floating-promises': 'error', '@typescript-eslint/no-misused-promises': 'error', '@typescript-eslint/only-throw-error': 'error', - // '@typescript-eslint/strict-boolean-expressions': 'error', }, }, ]; diff --git a/js/eslint/vue.js b/js/eslint/vue.js index db9722f..1d59103 100644 --- a/js/eslint/vue.js +++ b/js/eslint/vue.js @@ -3,19 +3,10 @@ import pluginVue from 'eslint-plugin-vue'; import tseslint from 'typescript-eslint'; /** - * Opt-in Vue layer: the single-file-component rules. Registers the SFC parser - * so `.vue` files are linted at all, resolves `