@hailstails/hone 1.5.0 → 2.0.0-pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADOPTING.md +104 -199
- package/CHANGELOG.md +138 -0
- package/MIGRATING.md +92 -47
- package/README.md +95 -244
- package/chunks/chunk-5HRMJ4O2.js +608 -0
- package/chunks/chunk-5U4JMWNV.js +9 -0
- package/chunks/{chunk-2O46EB4E.js → chunk-ASUN4AVC.js} +25 -12
- package/chunks/chunk-DGOLOS5A.js +9 -0
- package/chunks/{chunk-HJA4CX7C.js → chunk-FBZBSDED.js} +1 -1
- package/chunks/{chunk-Y2KPZDDV.js → chunk-GNOMK7CR.js} +201 -98
- package/chunks/chunk-IX2VZTBO.js +887 -0
- package/chunks/{chunk-QWA6OVLC.js → chunk-K2W3D3NB.js} +8 -2
- package/chunks/chunk-L7BGRC6D.js +22 -0
- package/chunks/chunk-M6SOGWT7.js +82 -0
- package/chunks/chunk-MWLBA4B3.js +849 -0
- package/chunks/chunk-NRIQD3PI.js +38 -0
- package/chunks/chunk-OKLYWD2Z.js +823 -0
- package/chunks/{chunk-3HFJHJDO.js → chunk-QP5TLOBY.js} +17 -8
- package/chunks/chunk-R75QELTA.js +481 -0
- package/chunks/chunk-RANAKCTW.js +31 -0
- package/chunks/{chunk-NA5L6PUE.js → chunk-RANIXNWY.js} +1 -2
- package/chunks/chunk-RFR3ITBS.js +9 -0
- package/chunks/{chunk-Z4UBS7WI.js → chunk-RGSHTPLA.js} +26 -7
- package/chunks/{chunk-T32FOWZA.js → chunk-TNY2PASL.js} +14 -18
- package/chunks/{chunk-Y4SMWOD2.js → chunk-UJONWHA4.js} +2 -2
- package/chunks/{chunk-WF3PPYRR.js → chunk-VYBO2Q65.js} +4 -2
- package/chunks/chunk-Z6JHBNDS.js +15 -0
- package/chunks/eslint-10-boundary-A4JIQ734.js +14 -0
- package/chunks/eslint-9-boundary-CL5DDBHX.js +34 -0
- package/docs/adding-a-discipline-or-mechanism.md +21 -19
- package/docs/extending.md +5 -5
- package/docs/output-contract.md +700 -14
- package/docs/why-chain-contract.md +6 -6
- package/methods/README.md +2 -2
- package/methods/assessment-template.md +1 -1
- package/methods/lenses/clean-architecture.md +19 -54
- package/methods/lenses/decomposition.md +7 -7
- package/methods/lenses/defended-on-intent.md +4 -4
- package/methods/lenses/di-discipline.md +8 -8
- package/methods/lenses/errors-as-data.md +6 -6
- package/methods/lenses/function-first.md +9 -9
- package/methods/lenses/naming.md +6 -6
- package/methods/lenses/test-discipline.md +8 -8
- package/methods/lenses/type-soundness.md +6 -6
- package/methods/lenses/zod-boundary.md +9 -9
- package/package.json +30 -28
- package/rules/README.md +268 -4
- package/rules/SPIRIT.md +1 -1
- package/rules/cases/a-value-is-one-of-several-kinds-or-states.md +20 -0
- package/rules/cases/an-adopter-is-not-handed-our-risk.md +17 -0
- package/rules/cases/an-operation-can-fail.md +20 -0
- package/rules/cases/builds-the-real-implementations.md +25 -0
- package/rules/cases/causes-an-effect.md +26 -0
- package/rules/cases/checks-a-value-that-may-be-one-of-several-outcomes.md +20 -0
- package/rules/cases/checks-conditions-before-its-work.md +20 -0
- package/rules/cases/coordinates-other-units.md +20 -0
- package/rules/cases/does-one-job.md +23 -0
- package/rules/cases/explains-something-in-prose.md +20 -0
- package/rules/cases/gives-a-value-its-type.md +26 -0
- package/rules/cases/gives-each-unit-its-test.md +20 -0
- package/rules/cases/keeps-state-or-settings-across-calls.md +20 -0
- package/rules/cases/makes-a-new-value-from-what-it-has.md +17 -0
- package/rules/cases/names-something.md +20 -0
- package/rules/cases/needs-the-current-time-a-random-value-a-new-id-or-an-outside-ordering.md +26 -0
- package/rules/cases/puts-code-in-a-file-or-folder.md +20 -0
- package/rules/cases/reads-data-from-outside.md +23 -0
- package/rules/cases/reuses-behaviour-from-another-unit-or-type.md +20 -0
- package/rules/cases/sends-data-out-of-the-program.md +20 -0
- package/rules/cases/sets-how-strictly-the-checker-works.md +14 -0
- package/rules/cases/ships-code-for-others.md +17 -0
- package/rules/cases/states-what-the-unit-gives-back-for-one-case-or-several.md +20 -0
- package/rules/cases/takes-an-outside-dependency.md +38 -0
- package/rules/cases/tests-across-units-or-against-a-real-system.md +20 -0
- package/rules/cases/uses-a-system-or-service-outside-the-program.md +29 -0
- package/rules/cases/uses-what-a-collaborator-gives-back.md +20 -0
- package/rules/cases/writes-basic-logic.md +17 -0
- package/rules/cases.md +36 -59
- package/rules/numbers.md +121 -121
- package/rules/principles/external-behaviour-sits-at-a-boundary.md +12 -0
- package/rules/principles/no-hidden-effects.md +17 -0
- package/rules/principles/no-leak-across-a-boundary.md +19 -0
- package/rules/principles/one-place-decides.md +12 -0
- package/rules/principles/our-code-reads-in-the-common-language.md +12 -0
- package/rules/principles/outside-risk-is-carried-on-purpose.md +13 -0
- package/rules/principles/tests-are-ours.md +12 -0
- package/rules/principles/the-type-checker-proves-it.md +12 -0
- package/rules/principles.md +50 -46
- package/rules/record-kinds/authorised-location.md +26 -0
- package/rules/record-kinds/boundary-record.md +9 -0
- package/rules/record-kinds/debt.md +23 -0
- package/rules/record-kinds/dependency-record.md +9 -0
- package/rules/record-kinds/deviation.md +9 -0
- package/rules/records.md +17 -30
- package/rules/rules/declared-not-asserted.md +16 -0
- package/rules/rules/doer-or-orchestrator.md +16 -0
- package/rules/rules/failures-are-values.md +15 -0
- package/rules/rules/fixed-versions.md +11 -0
- package/rules/rules/guard-first.md +14 -0
- package/rules/rules/handed-what-it-uses.md +16 -0
- package/rules/rules/kinds-are-named.md +16 -0
- package/rules/rules/one-reason-per-module.md +18 -0
- package/rules/rules/one-word-everywhere.md +19 -0
- package/rules/rules/outside-dependencies-justified.md +14 -0
- package/rules/rules/outside-dependencies-stay-at-boundaries.md +18 -0
- package/rules/rules/ports-declared-inside.md +22 -0
- package/rules/rules/shipped-risk-declared.md +11 -0
- package/rules/rules/straight-through-tests.md +15 -0
- package/rules/rules/tested-where-its-owned.md +20 -0
- package/rules/rules/tools-live-in-the-repo.md +11 -0
- package/rules/rules/upstream-stays-untouched.md +11 -0
- package/rules/rules/written-out-answers.md +17 -0
- package/rules/rules.md +117 -81
- package/rules/typescript/checks.md +1668 -202
- package/rules/typescript/recipes/adapter-per-outside-party.md +18 -0
- package/rules/typescript/recipes/assert-to-narrow.md +18 -0
- package/rules/typescript/recipes/bounded-context-generic.md +19 -0
- package/rules/typescript/recipes/closure-factory.md +20 -0
- package/rules/typescript/recipes/companion-test-file.md +18 -0
- package/rules/typescript/recipes/composed-orchestrator.md +18 -0
- package/rules/typescript/recipes/composition-root.md +18 -0
- package/rules/typescript/recipes/copy-never-write-in.md +18 -0
- package/rules/typescript/recipes/declared-not-bundled.md +17 -0
- package/rules/typescript/recipes/dependency-record.md +20 -0
- package/rules/typescript/recipes/domain-vocabulary-list.md +18 -0
- package/rules/typescript/recipes/entity-module.md +20 -0
- package/rules/typescript/recipes/exact-pins-and-a-lock-file.md +18 -0
- package/rules/typescript/recipes/extension-outside-the-vendored-code.md +18 -0
- package/rules/typescript/recipes/failure-asserted-as-a-value.md +18 -0
- package/rules/typescript/recipes/failure-mapping-at-the-adapter.md +20 -0
- package/rules/typescript/recipes/fix-the-declaration-not-the-value.md +18 -0
- package/rules/typescript/recipes/functional-iteration.md +18 -0
- package/rules/typescript/recipes/guard-clauses.md +18 -0
- package/rules/typescript/recipes/integration-test-owns-its-scratch.md +18 -0
- package/rules/typescript/recipes/integration-test-suffix.md +18 -0
- package/rules/typescript/recipes/iteach-over-typed-rows.md +18 -0
- package/rules/typescript/recipes/map-out-at-the-adapter.md +18 -0
- package/rules/typescript/recipes/meaning-in-names-not-comments.md +22 -0
- package/rules/typescript/recipes/named-exported-type.md +18 -0
- package/rules/typescript/recipes/narrow-ports.md +18 -0
- package/rules/typescript/recipes/one-argument-object.md +19 -0
- package/rules/typescript/recipes/port-in-the-domain.md +19 -0
- package/rules/typescript/recipes/ports-in-the-argument.md +18 -0
- package/rules/typescript/recipes/repo-scripts-only.md +18 -0
- package/rules/typescript/recipes/result-union.md +22 -0
- package/rules/typescript/recipes/screaming-folders.md +20 -0
- package/rules/typescript/recipes/shared-strict-base-config.md +20 -0
- package/rules/typescript/recipes/stub-with-vifn.md +20 -0
- package/rules/typescript/recipes/tagged-union-and-exhaustive-switch.md +18 -0
- package/rules/typescript/recipes/whole-words.md +18 -0
- package/rules/typescript/recipes/whole-written-out-expectation.md +18 -0
- package/rules/typescript/recipes/world-values-through-a-port.md +18 -0
- package/rules/typescript/recipes/zod-at-the-producers-adapter.md +19 -0
- package/rules/typescript/recipes.md +247 -218
- package/rules/typescript/symptoms/absence-standing-for-a-state.md +36 -0
- package/rules/typescript/symptoms/adapter-built-outside-the-root.md +30 -0
- package/rules/typescript/symptoms/ambient-randomness.md +36 -0
- package/rules/typescript/symptoms/answer-set-in-a-hook.md +45 -0
- package/rules/typescript/symptoms/authored-class-or-this/class-keyword.md +30 -0
- package/rules/typescript/symptoms/authored-class-or-this/static-members-only.md +18 -0
- package/rules/typescript/symptoms/authored-class-or-this.md +49 -0
- package/rules/typescript/symptoms/behaviour-tested-away-from-its-owner.md +44 -0
- package/rules/typescript/symptoms/boolean-in-a-signature/boolean-annotation.md +30 -0
- package/rules/typescript/symptoms/boolean-in-a-signature.md +43 -0
- package/rules/typescript/symptoms/branch-in-a-test/test-body.md +213 -0
- package/rules/typescript/symptoms/branch-in-a-test.md +48 -0
- package/rules/typescript/symptoms/bundled-dependency.md +28 -0
- package/rules/typescript/symptoms/catch-all-failure-kind.md +37 -0
- package/rules/typescript/symptoms/change-spread-across-modules.md +27 -0
- package/rules/typescript/symptoms/claimed-type/cast-to-any.md +29 -0
- package/rules/typescript/symptoms/claimed-type/non-null-assertions.md +34 -0
- package/rules/typescript/symptoms/claimed-type/unlisted-cast-site.md +34 -0
- package/rules/typescript/symptoms/claimed-type.md +56 -0
- package/rules/typescript/symptoms/computed-value-in-a-test/test-body.md +144 -0
- package/rules/typescript/symptoms/computed-value-in-a-test.md +36 -0
- package/rules/typescript/symptoms/coverage-gate.md +27 -0
- package/rules/typescript/symptoms/date-used-directly/clock-sources.md +31 -0
- package/rules/typescript/symptoms/date-used-directly.md +46 -0
- package/rules/typescript/symptoms/default-for-a-required-value.md +45 -0
- package/rules/typescript/symptoms/default-on-a-closed-union/default-arm.md +32 -0
- package/rules/typescript/symptoms/default-on-a-closed-union.md +32 -0
- package/rules/typescript/symptoms/dependency-without-a-record.md +33 -0
- package/rules/typescript/symptoms/doer-calling-our-own-unit.md +36 -0
- package/rules/typescript/symptoms/double-with-a-body/logic-in-a-passed-function.md +32 -0
- package/rules/typescript/symptoms/double-with-a-body/stub-implementation.md +31 -0
- package/rules/typescript/symptoms/double-with-a-body.md +55 -0
- package/rules/typescript/symptoms/drawer-path/drawer-names.md +28 -0
- package/rules/typescript/symptoms/drawer-path.md +32 -0
- package/rules/typescript/symptoms/duplicate-decision.md +36 -0
- package/rules/typescript/symptoms/edit-inside-vendored-code.md +33 -0
- package/rules/typescript/symptoms/failure-shaped-as-success.md +28 -0
- package/rules/typescript/symptoms/floating-version.md +27 -0
- package/rules/typescript/symptoms/inherited-environment-in-a-subprocess/git-spawn-environment.md +30 -0
- package/rules/typescript/symptoms/inherited-environment-in-a-subprocess.md +33 -0
- package/rules/typescript/symptoms/inner-layer-imports-outer.md +33 -0
- package/rules/typescript/symptoms/integration-heavy-suite.md +29 -0
- package/rules/typescript/symptoms/large-input-for-a-few-fields.md +37 -0
- package/rules/typescript/symptoms/library-class-built-in-place.md +42 -0
- package/rules/typescript/symptoms/long-function/function-length.md +47 -0
- package/rules/typescript/symptoms/long-function.md +75 -0
- package/rules/typescript/symptoms/loop-keyword/loop-statement.md +34 -0
- package/rules/typescript/symptoms/loop-keyword.md +49 -0
- package/rules/typescript/symptoms/machine-touched-in-a-unit-test.md +40 -0
- package/rules/typescript/symptoms/many-spellings-of-one-concept.md +29 -0
- package/rules/typescript/symptoms/module-level-state.md +30 -0
- package/rules/typescript/symptoms/module-or-global-patched/module-mock-call.md +29 -0
- package/rules/typescript/symptoms/module-or-global-patched.md +38 -0
- package/rules/typescript/symptoms/name-off-its-casing/filename-case.md +16 -0
- package/rules/typescript/symptoms/name-off-its-casing/naming-convention.md +20 -0
- package/rules/typescript/symptoms/name-off-its-casing.md +31 -0
- package/rules/typescript/symptoms/no-lock-file.md +27 -0
- package/rules/typescript/symptoms/orchestrator-that-computes.md +27 -0
- package/rules/typescript/symptoms/outside-dependency-vocabulary-for-basic-logic.md +33 -0
- package/rules/typescript/symptoms/outside-import-past-a-boundary/import-or-require.md +44 -0
- package/rules/typescript/symptoms/outside-import-past-a-boundary.md +45 -0
- package/rules/typescript/symptoms/outside-type-in-a-signature.md +37 -0
- package/rules/typescript/symptoms/own-type-guard.md +36 -0
- package/rules/typescript/symptoms/port-named-for-a-mechanism.md +34 -0
- package/rules/typescript/symptoms/port-outside-the-domain.md +28 -0
- package/rules/typescript/symptoms/positional-parameters/parameter-count.md +30 -0
- package/rules/typescript/symptoms/positional-parameters.md +43 -0
- package/rules/typescript/symptoms/process-global-used-in-place.md +53 -0
- package/rules/typescript/symptoms/prose-in-code.md +27 -0
- package/rules/typescript/symptoms/rebinding/parameter-reassignment.md +18 -0
- package/rules/typescript/symptoms/rebinding/test-body.md +32 -0
- package/rules/typescript/symptoms/rebinding.md +36 -0
- package/rules/typescript/symptoms/schema-past-its-adapter.md +41 -0
- package/rules/typescript/symptoms/shorthand-name/identifier-names.md +29 -0
- package/rules/typescript/symptoms/shorthand-name.md +32 -0
- package/rules/typescript/symptoms/strictness-weakened/exact-optional-property-types.md +51 -0
- package/rules/typescript/symptoms/strictness-weakened/no-fallthrough-cases-in-switch.md +51 -0
- package/rules/typescript/symptoms/strictness-weakened/no-implicit-override.md +51 -0
- package/rules/typescript/symptoms/strictness-weakened/no-property-access-from-index-signature.md +51 -0
- package/rules/{CD-3/CHECKS.md → typescript/symptoms/strictness-weakened/no-unchecked-indexed-access.md} +23 -40
- package/rules/typescript/symptoms/strictness-weakened/strict.md +51 -0
- package/rules/typescript/symptoms/strictness-weakened/use-unknown-in-catch-variables.md +51 -0
- package/rules/typescript/symptoms/strictness-weakened.md +32 -0
- package/rules/typescript/symptoms/tangled-function/cognitive-complexity.md +42 -0
- package/rules/typescript/symptoms/tangled-function.md +75 -0
- package/rules/typescript/symptoms/test-of-the-type-checker.md +24 -0
- package/rules/typescript/symptoms/test-switched-off/focused-tests.md +15 -0
- package/rules/typescript/symptoms/test-switched-off/skipped-tests.md +15 -0
- package/rules/typescript/symptoms/test-switched-off.md +25 -0
- package/rules/typescript/symptoms/text-past-its-reader/test-body.md +30 -0
- package/rules/typescript/symptoms/text-past-its-reader.md +71 -0
- package/rules/typescript/symptoms/throw-between-our-units.md +46 -0
- package/rules/typescript/symptoms/throw-or-catch-in-a-test/throw-statement.md +32 -0
- package/rules/typescript/symptoms/throw-or-catch-in-a-test/try-block.md +39 -0
- package/rules/typescript/symptoms/throw-or-catch-in-a-test.md +35 -0
- package/rules/typescript/symptoms/thrown-non-error/throw-only-error.md +15 -0
- package/rules/typescript/symptoms/thrown-non-error.md +27 -0
- package/rules/typescript/symptoms/tool-fetched-at-run-time.md +27 -0
- package/rules/typescript/symptoms/tuple-as-data.md +29 -0
- package/rules/typescript/symptoms/type-derived-from-code/factory-return-types.md +29 -0
- package/rules/typescript/symptoms/type-derived-from-code.md +41 -0
- package/rules/typescript/symptoms/types-only-file.md +36 -0
- package/rules/typescript/symptoms/unasserted-call.md +29 -0
- package/rules/typescript/symptoms/unit-without-a-running-test/companion-test-file.md +28 -0
- package/rules/typescript/symptoms/unit-without-a-running-test.md +28 -0
- package/rules/{CD-5/CHECKS.md → typescript/symptoms/untracked-escape/directive-pointers.md} +12 -25
- package/rules/typescript/symptoms/untracked-escape.md +32 -0
- package/rules/typescript/symptoms/untyped-value/explicit-any.md +14 -0
- package/rules/typescript/symptoms/untyped-value/implicit-any-let.md +14 -0
- package/rules/typescript/symptoms/untyped-value.md +36 -0
- package/rules/typescript/symptoms/wide-input.md +37 -0
- package/rules/typescript/symptoms/wide-port.md +32 -0
- package/rules/typescript/symptoms/work-inside-a-condition/else-after-an-exit.md +40 -0
- package/rules/typescript/symptoms/work-inside-a-condition.md +41 -0
- package/rules/typescript/symptoms/write-into-a-parameter/parameter-mutation.md +33 -0
- package/rules/typescript/symptoms/write-into-a-parameter.md +34 -0
- package/rules/typescript/symptoms.md +623 -414
- package/{core → src/application}/conformance/conformance-testing-types.d.ts +16 -6
- package/src/audit.d.ts +20 -0
- package/{api → src}/audit.js +6 -5
- package/{core/rule-set-reader → src/domain/rule-set}/authored-rule-set-types.d.ts +2 -2
- package/{core/values → src/domain/rule-set}/edition-types.d.ts +3 -3
- package/{core/values → src/domain/rule-set}/identifier-types.d.ts +2 -2
- package/{core/conformance → src/domain/runner}/conformance-types.d.ts +1 -1
- package/{core/mechanism-port → src/domain/runner}/piece-failure-types.d.ts +1 -1
- package/{core/mechanism-port → src/domain/runner}/runner-module-types.d.ts +4 -4
- package/src/domain/runner/runner-result-types.d.ts +88 -0
- package/src/eslint-plugin.d.ts +16 -0
- package/src/eslint-plugin.js +72 -0
- package/src/hone.js +13563 -0
- package/src/infrastructure/disciplines-file/version-one-names.json +634 -0
- package/src/infrastructure/engines/eslint/authored-class-or-this/class-keyword/class-keyword.examples.json +84 -0
- package/{mechanisms/eslint/CD-14/cd14/cd14.eslint-plugin.js → src/infrastructure/engines/eslint/authored-class-or-this/class-keyword/eslint-plugin.js} +9 -10
- package/src/infrastructure/engines/eslint/authored-class-or-this/class-keyword/piece.json +12 -0
- package/src/infrastructure/engines/eslint/authored-class-or-this/static-members-only/piece.json +24 -0
- package/src/infrastructure/engines/eslint/authored-class-or-this/static-members-only/static-members-only.examples.json +36 -0
- package/src/infrastructure/engines/eslint/claimed-type/non-null-assertions/eslint-plugin.js +16 -0
- package/src/infrastructure/engines/eslint/claimed-type/non-null-assertions/non-null-assertions.examples.json +48 -0
- package/src/infrastructure/engines/eslint/claimed-type/non-null-assertions/piece.json +22 -0
- package/src/infrastructure/engines/eslint/long-function/function-length/function-length.examples.json +42 -0
- package/src/infrastructure/engines/eslint/long-function/function-length/piece.json +16 -0
- package/{mechanisms/eslint/CD-7/cd7/cd7.eslint-plugin.js → src/infrastructure/engines/eslint/name-off-its-casing/filename-case/eslint-plugin.js} +5 -4
- package/src/infrastructure/engines/eslint/name-off-its-casing/filename-case/filename-case.examples.json +60 -0
- package/src/infrastructure/engines/eslint/name-off-its-casing/filename-case/piece.json +11 -0
- package/src/infrastructure/engines/eslint/name-off-its-casing/naming-convention/eslint-plugin.js +16 -0
- package/src/infrastructure/engines/eslint/name-off-its-casing/naming-convention/naming-convention.examples.json +78 -0
- package/src/infrastructure/engines/eslint/name-off-its-casing/naming-convention/piece.json +214 -0
- package/src/infrastructure/engines/eslint/positional-parameters/parameter-count/eslint-plugin.js +16 -0
- package/src/infrastructure/engines/eslint/positional-parameters/parameter-count/parameter-count.examples.json +30 -0
- package/src/infrastructure/engines/eslint/positional-parameters/parameter-count/piece.json +18 -0
- package/src/infrastructure/engines/eslint/rebinding/parameter-reassignment/eslint-plugin.js +16 -0
- package/src/infrastructure/engines/eslint/rebinding/parameter-reassignment/parameter-reassignment.examples.json +30 -0
- package/src/infrastructure/engines/eslint/rebinding/parameter-reassignment/piece.json +17 -0
- package/{mechanisms → src/infrastructure/engines}/eslint/runner/README.md +5 -5
- package/{mechanisms/eslint/runner → src/infrastructure/engines/eslint/runner/pieces}/eslint-piece-settings-types.d.ts +1 -1
- package/{mechanisms → src/infrastructure/engines}/eslint/runner/runner.js +2186 -1372
- package/{mechanisms/eslint/CD-41 → src/infrastructure/engines/eslint/tangled-function/cognitive-complexity}/README.md +1 -1
- package/src/infrastructure/engines/eslint/tangled-function/cognitive-complexity/cognitive-complexity.examples.json +48 -0
- package/{mechanisms/eslint/CD-41/cd41/cd41.eslint-plugin.js → src/infrastructure/engines/eslint/tangled-function/cognitive-complexity/eslint-plugin.js} +58 -14
- package/src/infrastructure/engines/eslint/tangled-function/cognitive-complexity/piece.json +12 -0
- package/{mechanisms/eslint/CD-27/cd27/cd27.eslint-plugin.js → src/infrastructure/engines/eslint/test-switched-off/focused-tests/eslint-plugin.js} +5 -4
- package/src/infrastructure/engines/eslint/test-switched-off/focused-tests/focused-tests.examples.json +60 -0
- package/src/infrastructure/engines/eslint/test-switched-off/focused-tests/piece.json +12 -0
- package/src/infrastructure/engines/eslint/test-switched-off/skipped-tests/piece.json +16 -0
- package/src/infrastructure/engines/eslint/test-switched-off/skipped-tests/skipped-tests.examples.json +54 -0
- package/{mechanisms/eslint/CD-10/cd10/cd10.eslint-plugin.js → src/infrastructure/engines/eslint/thrown-non-error/throw-only-error/eslint-plugin.js} +5 -4
- package/src/infrastructure/engines/eslint/thrown-non-error/throw-only-error/piece.json +12 -0
- package/src/infrastructure/engines/eslint/thrown-non-error/throw-only-error/throw-only-error.examples.json +54 -0
- package/{mechanisms/eslint/CD-1/cd1/cd1.eslint-plugin.js → src/infrastructure/engines/eslint/untyped-value/explicit-any/eslint-plugin.js} +14 -9
- package/src/infrastructure/engines/eslint/untyped-value/explicit-any/explicit-any.examples.json +36 -0
- package/src/infrastructure/engines/eslint/untyped-value/explicit-any/piece.json +12 -0
- package/src/infrastructure/engines/eslint/untyped-value/implicit-any-let/implicit-any-let.examples.json +48 -0
- package/src/infrastructure/engines/eslint/untyped-value/implicit-any-let/piece.json +16 -0
- package/src/infrastructure/engines/eslint/work-inside-a-condition/else-after-an-exit/else-after-an-exit.examples.json +36 -0
- package/{mechanisms/eslint/CD-42/cd42/cd42.eslint-plugin.js → src/infrastructure/engines/eslint/work-inside-a-condition/else-after-an-exit/eslint-plugin.js} +29 -13
- package/src/infrastructure/engines/eslint/work-inside-a-condition/else-after-an-exit/piece.json +12 -0
- package/src/infrastructure/engines/walker/authored-class-or-this/class-keyword/class-keyword.examples.json +84 -0
- package/{mechanisms/audit/CD-14 → src/infrastructure/engines/walker/authored-class-or-this/class-keyword}/class-syntax.js +6 -3
- package/src/infrastructure/engines/walker/authored-class-or-this/class-keyword/piece.json +10 -0
- package/src/infrastructure/engines/walker/boolean-in-a-signature/boolean-annotation/boolean-annotation.examples.json +42 -0
- package/{mechanisms/audit/CD-43 → src/infrastructure/engines/walker/boolean-in-a-signature/boolean-annotation}/boolean-signatures.js +14 -6
- package/src/infrastructure/engines/walker/boolean-in-a-signature/boolean-annotation/piece.json +9 -0
- package/src/infrastructure/engines/walker/branch-in-a-test/test-body/piece.json +95 -0
- package/{mechanisms/audit/CD-27 → src/infrastructure/engines/walker/branch-in-a-test/test-body}/test-body-logic.js +183 -54
- package/src/infrastructure/engines/walker/branch-in-a-test/test-body/test-body.examples.json +280 -0
- package/{mechanisms/audit/CD-1 → src/infrastructure/engines/walker/claimed-type/cast-to-any}/any-cast.js +7 -4
- package/src/infrastructure/engines/walker/claimed-type/cast-to-any/cast-to-any.examples.json +48 -0
- package/src/infrastructure/engines/walker/claimed-type/cast-to-any/piece.json +9 -0
- package/{mechanisms/audit/CD-2 → src/infrastructure/engines/walker/claimed-type/unlisted-cast-site}/cast-expressions.js +13 -6
- package/src/infrastructure/engines/walker/claimed-type/unlisted-cast-site/piece.json +14 -0
- package/src/infrastructure/engines/walker/claimed-type/unlisted-cast-site/unlisted-cast-site.examples.json +54 -0
- package/src/infrastructure/engines/walker/computed-value-in-a-test/test-body/piece.json +18 -0
- package/src/infrastructure/engines/walker/date-used-directly/clock-sources/clock-sources.examples.json +30 -0
- package/src/infrastructure/engines/walker/date-used-directly/clock-sources/clock-sources.js +36 -0
- package/src/infrastructure/engines/walker/date-used-directly/clock-sources/piece.json +9 -0
- package/src/infrastructure/engines/walker/default-on-a-closed-union/default-arm/default-arm.examples.json +36 -0
- package/src/infrastructure/engines/walker/default-on-a-closed-union/default-arm/piece.json +9 -0
- package/src/infrastructure/engines/walker/default-on-a-closed-union/default-arm/switch-defaults.js +54 -0
- package/src/infrastructure/engines/walker/double-with-a-body/logic-in-a-passed-function/piece.json +18 -0
- package/{mechanisms/audit/CD-25 → src/infrastructure/engines/walker/double-with-a-body/stub-implementation}/dependency-isolation.js +8 -4
- package/src/infrastructure/engines/walker/double-with-a-body/stub-implementation/piece.json +9 -0
- package/src/infrastructure/engines/walker/double-with-a-body/stub-implementation/stub-implementation.examples.json +36 -0
- package/{mechanisms/audit/CD-7 → src/infrastructure/engines/walker/drawer-path/drawer-names}/categorical-paths.js +23 -8
- package/src/infrastructure/engines/walker/drawer-path/drawer-names/drawer-names.examples.json +42 -0
- package/src/infrastructure/engines/walker/drawer-path/drawer-names/piece.json +9 -0
- package/src/infrastructure/engines/walker/inherited-environment-in-a-subprocess/git-spawn-environment/git-spawn-environment.examples.json +36 -0
- package/{mechanisms/audit/CD-47 → src/infrastructure/engines/walker/inherited-environment-in-a-subprocess/git-spawn-environment}/hermetic-git-spawns.js +13 -4
- package/src/infrastructure/engines/walker/inherited-environment-in-a-subprocess/git-spawn-environment/piece.json +9 -0
- package/src/infrastructure/engines/walker/loop-keyword/loop-statement/loop-statement.examples.json +48 -0
- package/{mechanisms/audit/CD-15 → src/infrastructure/engines/walker/loop-keyword/loop-statement}/loops.js +12 -4
- package/src/infrastructure/engines/walker/loop-keyword/loop-statement/piece.json +9 -0
- package/src/infrastructure/engines/walker/module-or-global-patched/module-mock-call/module-mock-call.examples.json +36 -0
- package/{mechanisms/audit/CD-26 → src/infrastructure/engines/walker/module-or-global-patched/module-mock-call}/module-mocking.js +8 -4
- package/src/infrastructure/engines/walker/module-or-global-patched/module-mock-call/piece.json +9 -0
- package/src/infrastructure/engines/walker/outside-import-past-a-boundary/import-or-require/import-boundaries.js +133 -0
- package/src/infrastructure/engines/walker/outside-import-past-a-boundary/import-or-require/import-or-require.examples.json +42 -0
- package/src/infrastructure/engines/walker/outside-import-past-a-boundary/import-or-require/piece.json +14 -0
- package/src/infrastructure/engines/walker/rebinding/test-body/piece.json +18 -0
- package/{mechanisms/audit/runner → src/infrastructure/engines/walker/runner/pieces}/walker-piece.d.ts +8 -14
- package/{mechanisms/audit → src/infrastructure/engines/walker}/runner/runner.js +191 -120
- package/{mechanisms/audit/runner → src/infrastructure/engines/walker/runner/toolchain}/typescript-parse.d.ts +1 -0
- package/src/infrastructure/engines/walker/shorthand-name/identifier-names/identifier-names.examples.json +42 -0
- package/{mechanisms/audit/CD-6 → src/infrastructure/engines/walker/shorthand-name/identifier-names}/identifier-names.js +32 -15
- package/src/infrastructure/engines/walker/shorthand-name/identifier-names/piece.json +9 -0
- package/src/infrastructure/engines/walker/strictness-weakened/exact-optional-property-types/exact-optional-property-types.examples.json +71 -0
- package/src/infrastructure/engines/walker/strictness-weakened/exact-optional-property-types/piece.json +17 -0
- package/src/infrastructure/engines/walker/strictness-weakened/no-fallthrough-cases-in-switch/no-fallthrough-cases-in-switch.examples.json +71 -0
- package/src/infrastructure/engines/walker/strictness-weakened/no-fallthrough-cases-in-switch/piece.json +17 -0
- package/src/infrastructure/engines/walker/strictness-weakened/no-implicit-override/no-implicit-override.examples.json +71 -0
- package/src/infrastructure/engines/walker/strictness-weakened/no-implicit-override/piece.json +17 -0
- package/src/infrastructure/engines/walker/strictness-weakened/no-property-access-from-index-signature/no-property-access-from-index-signature.examples.json +71 -0
- package/src/infrastructure/engines/walker/strictness-weakened/no-property-access-from-index-signature/piece.json +17 -0
- package/src/infrastructure/engines/walker/strictness-weakened/no-unchecked-indexed-access/no-unchecked-indexed-access.examples.json +71 -0
- package/src/infrastructure/engines/walker/strictness-weakened/no-unchecked-indexed-access/piece.json +17 -0
- package/{mechanisms/audit/CD-3 → src/infrastructure/engines/walker/strictness-weakened/strict}/compiler-overrides.js +102 -38
- package/src/infrastructure/engines/walker/strictness-weakened/strict/piece.json +13 -0
- package/src/infrastructure/engines/walker/strictness-weakened/strict/strict.examples.json +64 -0
- package/src/infrastructure/engines/walker/strictness-weakened/use-unknown-in-catch-variables/piece.json +17 -0
- package/src/infrastructure/engines/walker/strictness-weakened/use-unknown-in-catch-variables/use-unknown-in-catch-variables.examples.json +71 -0
- package/src/infrastructure/engines/walker/text-past-its-reader/test-body/piece.json +18 -0
- package/src/infrastructure/engines/walker/throw-or-catch-in-a-test/throw-statement/piece.json +9 -0
- package/src/infrastructure/engines/walker/throw-or-catch-in-a-test/throw-statement/throw-statement.examples.json +36 -0
- package/{mechanisms/audit/CD-10 → src/infrastructure/engines/walker/throw-or-catch-in-a-test/throw-statement}/throws-in-tests.js +6 -3
- package/src/infrastructure/engines/walker/throw-or-catch-in-a-test/try-block/piece.json +18 -0
- package/src/infrastructure/engines/walker/type-derived-from-code/factory-return-types/factory-return-types.examples.json +36 -0
- package/{mechanisms/audit/CD-7a → src/infrastructure/engines/walker/type-derived-from-code/factory-return-types}/factory-return-types.js +5 -3
- package/src/infrastructure/engines/walker/type-derived-from-code/factory-return-types/piece.json +9 -0
- package/src/infrastructure/engines/walker/unit-without-a-running-test/companion-test-file/companion-test-file.examples.json +36 -0
- package/{mechanisms/audit/CD-23 → src/infrastructure/engines/walker/unit-without-a-running-test/companion-test-file}/export-test-sibling.js +7 -4
- package/src/infrastructure/engines/walker/unit-without-a-running-test/companion-test-file/piece.json +9 -0
- package/{mechanisms/audit/CD-5 → src/infrastructure/engines/walker/untracked-escape/directive-pointers}/comments-directives.js +40 -19
- package/src/infrastructure/engines/walker/untracked-escape/directive-pointers/directive-pointers.examples.json +96 -0
- package/src/infrastructure/engines/walker/untracked-escape/directive-pointers/piece.json +16 -0
- package/src/infrastructure/engines/walker/write-into-a-parameter/parameter-mutation/parameter-mutation.examples.json +42 -0
- package/{mechanisms/audit/CD-44 → src/infrastructure/engines/walker/write-into-a-parameter/parameter-mutation}/parameter-mutation.js +22 -7
- package/src/infrastructure/engines/walker/write-into-a-parameter/parameter-mutation/piece.json +9 -0
- package/src/rule-set.d.ts +4 -0
- package/src/testing.d.ts +7 -0
- package/src/testing.js +524 -0
- package/api/audit.d.ts +0 -20
- package/api/rule-set.d.ts +0 -4
- package/api/testing.d.ts +0 -5
- package/api/testing.js +0 -238
- package/chunks/chunk-335ITLPO.js +0 -7
- package/chunks/chunk-5U4VTFD5.js +0 -1949
- package/chunks/chunk-E6VR3VRV.js +0 -268
- package/chunks/chunk-FR4FASVM.js +0 -108
- package/chunks/chunk-LDQUT742.js +0 -15
- package/chunks/chunk-MXSIQPCV.js +0 -13
- package/chunks/chunk-RWQ4UNKY.js +0 -24
- package/core/check/tool-command.js +0 -2909
- package/core/mechanism-port/runner-result-types.d.ts +0 -19
- package/mechanisms/audit/CD-1/piece.json +0 -13
- package/mechanisms/audit/CD-10/piece.json +0 -13
- package/mechanisms/audit/CD-14/piece.json +0 -13
- package/mechanisms/audit/CD-15/piece.json +0 -13
- package/mechanisms/audit/CD-17/clock-sources.js +0 -28
- package/mechanisms/audit/CD-17/piece.json +0 -13
- package/mechanisms/audit/CD-19/import-boundaries.js +0 -99
- package/mechanisms/audit/CD-19/piece.json +0 -18
- package/mechanisms/audit/CD-2/piece.json +0 -18
- package/mechanisms/audit/CD-23/piece.json +0 -13
- package/mechanisms/audit/CD-25/piece.json +0 -13
- package/mechanisms/audit/CD-26/piece.json +0 -13
- package/mechanisms/audit/CD-27/piece.json +0 -17
- package/mechanisms/audit/CD-3/piece.json +0 -77
- package/mechanisms/audit/CD-43/piece.json +0 -13
- package/mechanisms/audit/CD-44/piece.json +0 -13
- package/mechanisms/audit/CD-47/piece.json +0 -13
- package/mechanisms/audit/CD-5/piece.json +0 -20
- package/mechanisms/audit/CD-6/piece.json +0 -13
- package/mechanisms/audit/CD-7/piece.json +0 -13
- package/mechanisms/audit/CD-7a/piece.json +0 -13
- package/mechanisms/audit/CD-8/piece.json +0 -13
- package/mechanisms/audit/CD-8/switch-defaults.js +0 -42
- package/mechanisms/eslint/CD-1/piece.json +0 -23
- package/mechanisms/eslint/CD-10/piece.json +0 -15
- package/mechanisms/eslint/CD-14/piece.json +0 -31
- package/mechanisms/eslint/CD-2/cd2/cd2.eslint-plugin.js +0 -15
- package/mechanisms/eslint/CD-2/piece.json +0 -25
- package/mechanisms/eslint/CD-27/piece.json +0 -23
- package/mechanisms/eslint/CD-40/cd40/cd40.eslint-plugin.js +0 -15
- package/mechanisms/eslint/CD-40/piece.json +0 -21
- package/mechanisms/eslint/CD-41/piece.json +0 -23
- package/mechanisms/eslint/CD-42/piece.json +0 -15
- package/mechanisms/eslint/CD-44/cd44/cd44.eslint-plugin.js +0 -15
- package/mechanisms/eslint/CD-44/piece.json +0 -20
- package/mechanisms/eslint/CD-6/cd6/cd6.eslint-plugin.js +0 -15
- package/mechanisms/eslint/CD-6/piece.json +0 -217
- package/mechanisms/eslint/CD-7/piece.json +0 -15
- package/rules/CD-1/CHECKS.md +0 -41
- package/rules/CD-1/README.md +0 -15
- package/rules/CD-1/discipline.json +0 -195
- package/rules/CD-10/CHECKS.md +0 -51
- package/rules/CD-10/README.md +0 -15
- package/rules/CD-10/discipline.json +0 -133
- package/rules/CD-11/CHECKS.md +0 -15
- package/rules/CD-11/README.md +0 -15
- package/rules/CD-11/discipline.json +0 -12
- package/rules/CD-12/CHECKS.md +0 -15
- package/rules/CD-12/README.md +0 -15
- package/rules/CD-12/discipline.json +0 -12
- package/rules/CD-13/CHECKS.md +0 -15
- package/rules/CD-13/README.md +0 -15
- package/rules/CD-13/discipline.json +0 -12
- package/rules/CD-14/CHECKS.md +0 -51
- package/rules/CD-14/README.md +0 -15
- package/rules/CD-14/discipline.json +0 -173
- package/rules/CD-15/CHECKS.md +0 -44
- package/rules/CD-15/README.md +0 -15
- package/rules/CD-15/discipline.json +0 -73
- package/rules/CD-16/CHECKS.md +0 -9
- package/rules/CD-16/README.md +0 -15
- package/rules/CD-17/CHECKS.md +0 -39
- package/rules/CD-17/README.md +0 -15
- package/rules/CD-17/discipline.json +0 -51
- package/rules/CD-18/CHECKS.md +0 -15
- package/rules/CD-18/README.md +0 -15
- package/rules/CD-18/discipline.json +0 -12
- package/rules/CD-19/CHECKS.md +0 -51
- package/rules/CD-19/README.md +0 -15
- package/rules/CD-19/discipline.json +0 -63
- package/rules/CD-2/CHECKS.md +0 -60
- package/rules/CD-2/README.md +0 -15
- package/rules/CD-2/discipline.json +0 -151
- package/rules/CD-20/CHECKS.md +0 -9
- package/rules/CD-20/README.md +0 -15
- package/rules/CD-21/CHECKS.md +0 -15
- package/rules/CD-21/README.md +0 -15
- package/rules/CD-21/discipline.json +0 -12
- package/rules/CD-22/CHECKS.md +0 -15
- package/rules/CD-22/README.md +0 -15
- package/rules/CD-22/discipline.json +0 -12
- package/rules/CD-23/CHECKS.md +0 -37
- package/rules/CD-23/README.md +0 -15
- package/rules/CD-23/discipline.json +0 -57
- package/rules/CD-24/CHECKS.md +0 -9
- package/rules/CD-24/README.md +0 -15
- package/rules/CD-25/CHECKS.md +0 -40
- package/rules/CD-25/README.md +0 -15
- package/rules/CD-25/discipline.json +0 -57
- package/rules/CD-26/CHECKS.md +0 -38
- package/rules/CD-26/README.md +0 -15
- package/rules/CD-26/discipline.json +0 -57
- package/rules/CD-27/CHECKS.md +0 -460
- package/rules/CD-27/README.md +0 -15
- package/rules/CD-27/discipline.json +0 -437
- package/rules/CD-28/CHECKS.md +0 -15
- package/rules/CD-28/README.md +0 -15
- package/rules/CD-28/discipline.json +0 -12
- package/rules/CD-29/CHECKS.md +0 -15
- package/rules/CD-29/README.md +0 -15
- package/rules/CD-29/discipline.json +0 -12
- package/rules/CD-3/README.md +0 -15
- package/rules/CD-3/discipline.json +0 -641
- package/rules/CD-30/CHECKS.md +0 -15
- package/rules/CD-30/README.md +0 -15
- package/rules/CD-30/discipline.json +0 -12
- package/rules/CD-31/CHECKS.md +0 -15
- package/rules/CD-31/README.md +0 -15
- package/rules/CD-31/discipline.json +0 -12
- package/rules/CD-32/CHECKS.md +0 -15
- package/rules/CD-32/README.md +0 -26
- package/rules/CD-32/discipline.json +0 -12
- package/rules/CD-33/CHECKS.md +0 -15
- package/rules/CD-33/README.md +0 -26
- package/rules/CD-33/discipline.json +0 -12
- package/rules/CD-34/CHECKS.md +0 -15
- package/rules/CD-34/README.md +0 -25
- package/rules/CD-34/discipline.json +0 -12
- package/rules/CD-39/CHECKS.md +0 -15
- package/rules/CD-39/README.md +0 -26
- package/rules/CD-39/discipline.json +0 -12
- package/rules/CD-4/CHECKS.md +0 -15
- package/rules/CD-4/README.md +0 -15
- package/rules/CD-4/discipline.json +0 -12
- package/rules/CD-40/CHECKS.md +0 -41
- package/rules/CD-40/README.md +0 -15
- package/rules/CD-40/discipline.json +0 -58
- package/rules/CD-41/CHECKS.md +0 -66
- package/rules/CD-41/README.md +0 -15
- package/rules/CD-41/discipline.json +0 -138
- package/rules/CD-42/CHECKS.md +0 -49
- package/rules/CD-42/README.md +0 -15
- package/rules/CD-42/discipline.json +0 -61
- package/rules/CD-43/CHECKS.md +0 -39
- package/rules/CD-43/README.md +0 -15
- package/rules/CD-43/discipline.json +0 -65
- package/rules/CD-44/CHECKS.md +0 -50
- package/rules/CD-44/README.md +0 -15
- package/rules/CD-44/discipline.json +0 -111
- package/rules/CD-45/CHECKS.md +0 -15
- package/rules/CD-45/README.md +0 -15
- package/rules/CD-45/discipline.json +0 -12
- package/rules/CD-46/CHECKS.md +0 -9
- package/rules/CD-46/README.md +0 -27
- package/rules/CD-47/CHECKS.md +0 -39
- package/rules/CD-47/README.md +0 -15
- package/rules/CD-47/discipline.json +0 -57
- package/rules/CD-5/README.md +0 -15
- package/rules/CD-5/discipline.json +0 -131
- package/rules/CD-6/CHECKS.md +0 -53
- package/rules/CD-6/README.md +0 -15
- package/rules/CD-6/discipline.json +0 -165
- package/rules/CD-7/CHECKS.md +0 -48
- package/rules/CD-7/README.md +0 -15
- package/rules/CD-7/discipline.json +0 -142
- package/rules/CD-7a/CHECKS.md +0 -40
- package/rules/CD-7a/README.md +0 -15
- package/rules/CD-7a/discipline.json +0 -57
- package/rules/CD-8/CHECKS.md +0 -44
- package/rules/CD-8/README.md +0 -15
- package/rules/CD-8/discipline.json +0 -57
- package/rules/CD-9/CHECKS.md +0 -15
- package/rules/CD-9/README.md +0 -15
- package/rules/CD-9/discipline.json +0 -12
- package/rules/typescript/symptoms.json +0 -1005
- /package/{core/values → src/domain/finding}/anchor.d.ts +0 -0
- /package/{core/values → src/domain/repository}/branded.d.ts +0 -0
- /package/{core/values → src/domain/repository}/repo-path-types.d.ts +0 -0
- /package/{core/values → src/domain}/result.d.ts +0 -0
- /package/{core/values → src/domain/rule-set}/clause-address-types.d.ts +0 -0
- /package/{core/values → src/domain/settings/json-values}/json-value.d.ts +0 -0
- /package/{mechanisms/eslint/CD-14 → src/infrastructure/engines/eslint/authored-class-or-this/class-keyword}/README.md +0 -0
- /package/{mechanisms/eslint/CD-2 → src/infrastructure/engines/eslint/claimed-type/non-null-assertions}/README.md +0 -0
- /package/{mechanisms/eslint/CD-7 → src/infrastructure/engines/eslint/name-off-its-casing/filename-case}/README.md +0 -0
- /package/{mechanisms/eslint/CD-6 → src/infrastructure/engines/eslint/name-off-its-casing/naming-convention}/README.md +0 -0
- /package/{mechanisms/eslint/CD-40 → src/infrastructure/engines/eslint/positional-parameters/parameter-count}/README.md +0 -0
- /package/{mechanisms/eslint/CD-44 → src/infrastructure/engines/eslint/rebinding/parameter-reassignment}/README.md +0 -0
- /package/{mechanisms/eslint/CD-27 → src/infrastructure/engines/eslint/test-switched-off/focused-tests}/README.md +0 -0
- /package/{mechanisms/eslint/CD-10 → src/infrastructure/engines/eslint/thrown-non-error/throw-only-error}/README.md +0 -0
- /package/{mechanisms/eslint/CD-1 → src/infrastructure/engines/eslint/untyped-value/explicit-any}/README.md +0 -0
- /package/{mechanisms/eslint/CD-42 → src/infrastructure/engines/eslint/work-inside-a-condition/else-after-an-exit}/README.md +0 -0
- /package/{mechanisms/audit → src/infrastructure/engines/walker}/runner/README.md +0 -0
- /package/{api → src}/rule-set.js +0 -0
|
@@ -1,219 +1,1685 @@
|
|
|
1
1
|
# Checks in TypeScript
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
##
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
3
|
+
## Authored class or this
|
|
4
|
+
|
|
5
|
+
### class-keyword
|
|
6
|
+
|
|
7
|
+
- **Misses:** `this` outside a class.
|
|
8
|
+
- **Settings traced to:** none.
|
|
9
|
+
|
|
10
|
+
A class declaration or expression outside ambient code.
|
|
11
|
+
|
|
12
|
+
## Flags
|
|
13
|
+
- TypeScript source files; declaration files (`.d.ts`) are skipped. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped by the audit mechanism. The ESLint piece lints whatever files the team's ESLint run includes.
|
|
14
|
+
- Any class declaration, class expression, `abstract class`, nested class, or class inside a runtime `namespace`, reported at the `class` keyword.
|
|
15
|
+
- Allowed: `declare class`, classes inside `declare module`, `declare global` or `declare namespace`, and `new Client()` on a class imported from a library.
|
|
16
|
+
- Other generated code can be left out of the audit mechanism's scope with `exclude` in disciplines.json. Hand-written classes are not out of scope.
|
|
17
|
+
|
|
18
|
+
## Example
|
|
19
|
+
```ts
|
|
20
|
+
export class Counter {}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Fix
|
|
24
|
+
```ts
|
|
25
|
+
export const createCounter = () => {
|
|
26
|
+
let count = 0;
|
|
27
|
+
return { increment: () => (count += 1) };
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
Return an object of functions from a factory that closes over its state.
|
|
31
|
+
|
|
32
|
+
### static-members-only
|
|
33
|
+
|
|
34
|
+
- **Misses:** `this` outside a class.
|
|
35
|
+
- **Settings traced to:** none.
|
|
36
|
+
|
|
37
|
+
A class whose members are all static.
|
|
38
|
+
|
|
39
|
+
## Flags
|
|
40
|
+
- TypeScript source files; declaration files (`.d.ts`) are skipped. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped by the audit mechanism. The ESLint piece lints whatever files the team's ESLint run includes.
|
|
41
|
+
|
|
42
|
+
Needs ESLint adopted through the projection.
|
|
43
|
+
- Under ESLint, this is typescript-eslint's `no-extraneous-class` with `allowConstructorOnly: true`, `allowEmpty: true`, `allowStaticOnly: false` and `allowWithDecorator: true`.
|
|
44
|
+
- It flags a class whose members are all static.
|
|
45
|
+
- Allowed: empty classes, decorated classes and classes that extend another class.
|
|
46
|
+
|
|
47
|
+
## Boolean in a signature
|
|
48
|
+
|
|
49
|
+
### boolean-annotation
|
|
50
|
+
|
|
51
|
+
- **Flags beyond the symptom:** a predicate's boolean return.
|
|
52
|
+
- **Settings traced to:** none.
|
|
53
|
+
|
|
54
|
+
A boolean type in a parameter, property signature or return.
|
|
55
|
+
|
|
56
|
+
## Flags
|
|
57
|
+
|
|
58
|
+
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
59
|
+
- A declared type of `boolean`, or `boolean` unioned only with `null` and `undefined`, on a parameter, an interface or type-literal property, a function, method, arrow or accessor return, or a function, call or index signature.
|
|
60
|
+
- Allowed: `true` or `false` literals, `boolean | string`, aliases of boolean, type predicates such as `value is Item`, inferred types, variables and class fields.
|
|
61
|
+
- All boolean signatures are reported, including predicates such as `isReady(): boolean`. Telling evaluative booleans from state is left to review.
|
|
62
|
+
|
|
63
|
+
## Example
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const render = (compact: boolean): string => "";
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Fix
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const render = (mode: "compact" | "full"): string => "";
|
|
73
|
+
```
|
|
74
|
+
Name each state in the type.
|
|
75
|
+
|
|
76
|
+
## Branch in a test
|
|
77
|
+
|
|
78
|
+
### test-body
|
|
79
|
+
|
|
80
|
+
- **Flags beyond the symptom:** unit's own API (edition 1).
|
|
81
|
+
- **Settings traced to:** the edition: backwards compatibility for adopters since the npm release.
|
|
82
|
+
|
|
83
|
+
`if` statements and ternary expressions in a test file; edition 2 adds short-circuits, optional chaining and `switch`. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
84
|
+
|
|
85
|
+
## Flags
|
|
86
|
+
Edition 1:
|
|
87
|
+
- `if` statements and ternary expressions.
|
|
88
|
+
|
|
89
|
+
Edition 2 also flags:
|
|
90
|
+
- `??`, `||` and `&&`, and their assignment forms `??=`, `||=` and `&&=`.
|
|
91
|
+
- Optional chaining: `a?.b`, `a?.[key]` and `f?.()`.
|
|
92
|
+
- `switch` statements.
|
|
93
|
+
|
|
94
|
+
## Allowed forms in a test
|
|
95
|
+
|
|
96
|
+
### Branching with if
|
|
97
|
+
```ts
|
|
98
|
+
declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
|
|
99
|
+
const parsed = parse("a");
|
|
100
|
+
if (parsed.outcome === "ok") {
|
|
101
|
+
expect(parsed.value).toBe("a");
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
Compare the whole result:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
|
|
108
|
+
expect(parse("a")).toEqual({ outcome: "ok", value: "a" });
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Or write one test per case, or one table:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
|
|
115
|
+
it.each([
|
|
116
|
+
{ text: "a", expected: { outcome: "ok", value: "a" } },
|
|
117
|
+
{ text: "", expected: { outcome: "failed" } },
|
|
118
|
+
])("parses $text", ({ text, expected }) => {
|
|
119
|
+
expect(parse(text)).toEqual(expected);
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### A ternary
|
|
124
|
+
```ts
|
|
125
|
+
declare const discountFor: (customer: { readonly tier: "premium" | "standard" }) => number;
|
|
126
|
+
const tier = "premium";
|
|
127
|
+
expect(discountFor({ tier })).toBe(tier === "premium" ? 10 : 0);
|
|
128
|
+
```
|
|
129
|
+
Write the value out, with one table row per case:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
declare const discountFor: (customer: { readonly tier: "premium" | "standard" }) => number;
|
|
133
|
+
it.each([
|
|
134
|
+
{ tier: "premium", expected: 10 },
|
|
135
|
+
{ tier: "standard", expected: 0 },
|
|
136
|
+
] as const)("gives $expected off to a $tier customer", ({ tier, expected }) => {
|
|
137
|
+
expect(discountFor({ tier })).toBe(expected);
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### A short-circuit
|
|
142
|
+
```ts
|
|
143
|
+
declare const lookup: (id: string) => { readonly name: string } | undefined;
|
|
144
|
+
const found = lookup("a");
|
|
145
|
+
expect(found !== undefined && found.name === "Ada").toBe(true);
|
|
146
|
+
```
|
|
147
|
+
Write the value a fallback gives. To narrow a value that may be missing, assert it is defined, then read it:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
declare const lookup: (id: string) => { readonly name: string } | undefined;
|
|
151
|
+
const found = lookup("a");
|
|
152
|
+
assert.isDefined(found);
|
|
153
|
+
expect(found.name).toBe("Ada");
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### An optional chain after an index
|
|
157
|
+
```ts
|
|
158
|
+
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
159
|
+
expect(listTasks()[0]?.id).toBe("a");
|
|
160
|
+
```
|
|
161
|
+
Compare the whole element:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
165
|
+
expect(listTasks()[0]).toMatchObject({ id: "a" });
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Or destructure it and assert it is defined before reading it:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
172
|
+
const [first] = listTasks();
|
|
173
|
+
assert.isDefined(first);
|
|
174
|
+
expect(first.id).toBe("a");
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### An optional chain on a mock call
|
|
178
|
+
```ts
|
|
179
|
+
declare const start: (run: (task: { readonly id: string }) => void) => void;
|
|
180
|
+
const run = vi.fn<(task: { readonly id: string }) => void>();
|
|
181
|
+
start(run);
|
|
182
|
+
expect(run.mock.calls[0]?.[0].id).toBe("a");
|
|
183
|
+
```
|
|
184
|
+
Assert that call by its position:
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
declare const start: (run: (task: { readonly id: string }) => void) => void;
|
|
188
|
+
const run = vi.fn<(task: { readonly id: string }) => void>();
|
|
189
|
+
start(run);
|
|
190
|
+
expect(run).toHaveBeenNthCalledWith(1, expect.objectContaining({ id: "a" }));
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Reading `run.mock.lastCall?.[0]` names this section too. Assert the last call:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
declare const start: (run: (task: { readonly id: string }) => void) => void;
|
|
197
|
+
const run = vi.fn<(task: { readonly id: string }) => void>();
|
|
198
|
+
start(run);
|
|
199
|
+
expect(run).toHaveBeenLastCalledWith({ id: "a" });
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### An optional chain on a mock result
|
|
203
|
+
```ts
|
|
204
|
+
declare const pricing: { readonly priceOf: (amount: number) => number };
|
|
205
|
+
declare const settle: (prices: { readonly priceOf: (amount: number) => number }) => void;
|
|
206
|
+
const priceOf = vi.spyOn(pricing, "priceOf");
|
|
207
|
+
settle(pricing);
|
|
208
|
+
expect(priceOf.mock.results[0]?.value).toBe(4);
|
|
209
|
+
```
|
|
210
|
+
Assert what that call returned, by its position:
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
declare const pricing: { readonly priceOf: (amount: number) => number };
|
|
214
|
+
declare const settle: (prices: { readonly priceOf: (amount: number) => number }) => void;
|
|
215
|
+
const priceOf = vi.spyOn(pricing, "priceOf");
|
|
216
|
+
settle(pricing);
|
|
217
|
+
expect(priceOf).toHaveNthReturnedWith(1, 4);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
`toHaveLastReturnedWith` asserts what the last call returned.
|
|
221
|
+
|
|
222
|
+
An optional chain on `mock.instances` or `mock.contexts` names [An optional chain after an index](#an-optional-chain-after-an-index).
|
|
223
|
+
|
|
224
|
+
### An optional chain on a property
|
|
225
|
+
```ts
|
|
226
|
+
declare const findUser: (id: string) => { readonly name: string } | undefined;
|
|
227
|
+
expect(findUser("a")?.name).toBe("Ada");
|
|
228
|
+
```
|
|
229
|
+
Compare the whole value:
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
declare const findUser: (id: string) => { readonly name: string } | undefined;
|
|
233
|
+
expect(findUser("a")).toMatchObject({ name: "Ada" });
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Or assert it is defined before reading it:
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
declare const findUser: (id: string) => { readonly name: string } | undefined;
|
|
240
|
+
const user = findUser("a");
|
|
241
|
+
assert.isDefined(user);
|
|
242
|
+
expect(user.name).toBe("Ada");
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### An optional call
|
|
246
|
+
```ts
|
|
247
|
+
declare const observers: { readonly enter?: (node: string) => void };
|
|
248
|
+
observers.enter?.("a");
|
|
249
|
+
```
|
|
250
|
+
Destructure the function, assert it is defined, then call it:
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
declare const observers: { readonly enter?: (node: string) => void };
|
|
254
|
+
const { enter } = observers;
|
|
255
|
+
assert.isDefined(enter);
|
|
256
|
+
enter("a");
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
A method that reads `this` loses it once taken off its object, so assert it is defined where it is and call it there:
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
declare const tracker: { readonly entered: readonly string[]; enter?(node: string): void };
|
|
263
|
+
assert.isDefined(tracker.enter);
|
|
264
|
+
tracker.enter("a");
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### A switch
|
|
268
|
+
```ts
|
|
269
|
+
declare const areaOf: (shape: { readonly kind: "square"; readonly side: number } | { readonly kind: "circle"; readonly radius: number }) => number;
|
|
270
|
+
const shape = { kind: "square", side: 2 } as const;
|
|
271
|
+
switch (shape.kind) {
|
|
272
|
+
case "square":
|
|
273
|
+
expect(areaOf(shape)).toBe(4);
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
Write one test per case, or one table:
|
|
277
|
+
|
|
278
|
+
```ts
|
|
279
|
+
declare const areaOf: (shape: { readonly kind: "square"; readonly side: number } | { readonly kind: "circle"; readonly radius: number }) => number;
|
|
280
|
+
it.each([
|
|
281
|
+
{ shape: { kind: "square", side: 2 } as const, expected: 4 },
|
|
282
|
+
{ shape: { kind: "circle", radius: 0 } as const, expected: 0 },
|
|
283
|
+
])("measures a $shape.kind", ({ shape, expected }) => {
|
|
284
|
+
expect(areaOf(shape)).toBe(expected);
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Claimed type
|
|
289
|
+
|
|
290
|
+
### cast-to-any
|
|
291
|
+
|
|
292
|
+
- **Misses:** `any` reached through an outside dependency's types.
|
|
293
|
+
- **Settings traced to:** `as const` allowed: Declared, not asserted.
|
|
294
|
+
|
|
295
|
+
A type assertion whose type contains `any`.
|
|
296
|
+
|
|
297
|
+
## Flags
|
|
298
|
+
- `.ts` and `.tsx` files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
299
|
+
- A type assertion (`x as T` or `<T>x`) whose type contains the `any` keyword at any depth: `as any`, `<any>x`, `as Array<any>`, `as Record<string, any>`, `as Map<string, any>` or `as { field: any }`. The check reads the syntax tree, so an `any` elsewhere on the line is not attributed to the cast.
|
|
300
|
+
- This check judges these before [unlisted-cast-site](symptoms/claimed-type/unlisted-cast-site.md) and has no settings; every other assertion is [unlisted-cast-site](symptoms/claimed-type/unlisted-cast-site.md)'s.
|
|
301
|
+
- A bare annotation such as `let value: any` is not flagged by this check; [explicit-any](symptoms/untyped-value/explicit-any.md) covers it.
|
|
302
|
+
|
|
303
|
+
## Example
|
|
304
|
+
```ts
|
|
305
|
+
const parsed = JSON.parse(text) as any;
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Fix
|
|
309
|
+
```ts
|
|
310
|
+
const order = orderSchema.parse(JSON.parse(text));
|
|
311
|
+
```
|
|
312
|
+
Give it a concrete type where it enters: parse it once with a schema in the adapter for whoever produced it, checked at runtime.
|
|
313
|
+
|
|
314
|
+
In a test file, edition 2 of [the test-body check](symptoms/text-past-its-reader/test-body.md#serialising-or-parsing-json) flags `JSON.parse`; edition 1, the default, does not.
|
|
315
|
+
|
|
316
|
+
### non-null-assertions
|
|
317
|
+
|
|
318
|
+
- **Misses:** `any` reached through an outside dependency's types.
|
|
319
|
+
- **Settings traced to:** `as const` allowed: Declared, not asserted.
|
|
320
|
+
|
|
321
|
+
A non-null assertion, `x!`, or a definite assignment assertion, `let x!: T` or `field!: T`.
|
|
322
|
+
|
|
323
|
+
## Flags
|
|
324
|
+
Needs ESLint adopted through the projection.
|
|
325
|
+
- Under ESLint, this is `no-restricted-syntax` with two selectors, one per form.
|
|
326
|
+
- `TSNonNullExpression` flags every non-null assertion, `x!`, wherever it sits: a read such as `user.name!`, a call such as `totals.get(key)!.toFixed(2)`, an assignment target such as `basket.total! = 0`. It is the same node typescript-eslint's `no-non-null-assertion` reports.
|
|
327
|
+
- `[definite=true]` flags every definite assignment assertion: `let total!: number` and a class field `balance!: number`.
|
|
328
|
+
- Each finding sits on the line where the asserted expression or the declared name starts.
|
|
329
|
+
- Allowed: logical not `!ready`, `!==`, an optional property `total?: number`, `??` fallbacks, and an initialised binding.
|
|
330
|
+
- There are no settings. No `audit` mechanism checks this clause, so a repository without ESLint lists it as `"not-run"`, and review owes it.
|
|
331
|
+
|
|
332
|
+
## Example
|
|
333
|
+
```ts
|
|
334
|
+
const user = response as User;
|
|
335
|
+
const name = user.name!;
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Fix
|
|
339
|
+
```ts
|
|
340
|
+
const user = userSchema.parse(response);
|
|
341
|
+
const name = user.name;
|
|
342
|
+
```
|
|
343
|
+
Parse or narrow the value so the type follows from a check rather than from an assertion. For a value that may be absent, handle the absent case with a check or an early return; for a binding assigned later, initialise it where it is declared or make it a `const` built from what it needs.
|
|
344
|
+
|
|
345
|
+
In a test file, [the test-body check](symptoms/branch-in-a-test/test-body.md) flags an `if` check at either edition, and its edition 2 flags the `??` fallback: there, `assert.isDefined` a value that may be missing before reading it, as [the allowed forms](symptoms/branch-in-a-test/test-body.md#a-short-circuit) show.
|
|
346
|
+
|
|
347
|
+
### unlisted-cast-site
|
|
348
|
+
|
|
349
|
+
- **Misses:** `any` reached through an outside dependency's types.
|
|
350
|
+
- **Settings traced to:** `as const` allowed: Declared, not asserted.
|
|
351
|
+
|
|
352
|
+
A type assertion that is not on the permitted list.
|
|
353
|
+
|
|
354
|
+
## Flags
|
|
355
|
+
- `.ts` and `.tsx` files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
356
|
+
- Every `x as T` and `<T>x` assertion except a const assertion, `as const` or `<const>x`. Assertions whose type contains `any` are [cast-to-any](symptoms/claimed-type/cast-to-any.md)'s and are not repeated here.
|
|
357
|
+
- `as unknown` and `<unknown>x` are flagged. Widening never needs an assertion: annotate instead, `const parsed: unknown = JSON.parse(text)`.
|
|
358
|
+
- A cast through `unknown`, such as `raw as unknown as User`, `(<unknown>raw) as User` or one wrapped in `!` or `satisfies`, is flagged with its own message, and so is its `unknown` half. It is the escape hatch that turns any value into any type; check the value's shape at runtime at the boundary instead.
|
|
359
|
+
- `@ts-expect-error`, `@ts-ignore` and `@ts-nocheck` in the `.ts` and `.tsx` files this clause checks are reported as `inline-disable` native exceptions of this clause, where the compiler honours them and whether or not they hide a cast. Directives in `.mts`, `.cts` and JavaScript files are not read. Each is a finding in its file: a debt or an authorised location on the file covers it, and a tracked reference on the comment ([directive-pointers](symptoms/untracked-escape/directive-pointers.md)) does not stand in for the record.
|
|
360
|
+
- Test files, test helpers and scripts are checked like any other source; a test that needs a cast needs a typed stub or a narrower port.
|
|
361
|
+
- There are no settings: a boundary that forces a cast is an exception record, as below.
|
|
362
|
+
|
|
363
|
+
## Example
|
|
364
|
+
```ts
|
|
365
|
+
const user = response as User;
|
|
366
|
+
const name = user.name!;
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## Fix
|
|
370
|
+
```ts
|
|
371
|
+
const user = userSchema.parse(response);
|
|
372
|
+
const name = user.name;
|
|
373
|
+
```
|
|
374
|
+
Parse or narrow the value so the type follows from a check rather than from an assertion. For a value that may be absent, handle the absent case with a check or an early return; for a binding assigned later, initialise it where it is declared or make it a `const` built from what it needs.
|
|
375
|
+
|
|
376
|
+
When handing a value across a boundary truly forces a cast, such as a library that types its schemas loosely or a database driver that returns unparsed rows, put the cast in the one adapter file at that boundary and record that file as an `authorised-location` with a why-chain. With clean boundaries that is one file and one record; casts scattered across many files are the sign the boundary is missing.
|
|
377
|
+
|
|
378
|
+
## Computed value in a test
|
|
379
|
+
|
|
380
|
+
### test-body
|
|
381
|
+
|
|
382
|
+
- **Flags beyond the symptom:** unit's own API (edition 1).
|
|
383
|
+
- **Settings traced to:** the edition: backwards compatibility for adopters since the npm release.
|
|
384
|
+
|
|
385
|
+
Computing and mutating string and array methods in a test file; edition 2 adds computing calls on `Object`, `Array` and `Math`. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
386
|
+
|
|
387
|
+
## Flags
|
|
388
|
+
Edition 1:
|
|
389
|
+
- A method call with a computing or mutating name, wherever it could be the string or array method of that name: `map`, `filter`, `reduce`, `find`, `forEach`, `join`, `slice`, `split`, `replace`, `includes`, `sort`, `trim`, `keys`, `values`, `push`, `pop`, `splice`, `fill` and similar string and array methods.
|
|
390
|
+
- Not flagged: a call with one of those names whose arguments no string or array method of that name accepts, which makes it the unit's own API. Either it passes an object literal where none of them takes an object, such as `paths.join({ segments: ["a", "b"] })`, or it passes more arguments than any of them takes, such as `screen.keys("x", true, true)`.
|
|
391
|
+
- Still flagged, though they look like that:
|
|
392
|
+
- a call whose receiver traces back to a built-in namespace such as `Object` or `Math`, a package or `node:` module (imported, required or loaded with `import()`), or a string or array literal. The trace follows variables declared in the test file, including names destructured from a traced module or namespace, such as `posix` after `const { posix } = path`, and a property read directly off an object literal declared there, such as `deps.path` after `const deps = { path }`;
|
|
393
|
+
- a call that spreads its arguments;
|
|
394
|
+
- an object at a position where a string or array method takes one, such as `rows.includes({ id: "a" })`, `rows.push({ id: "a" })`, `rows.reduce(sum, { total: 0 })`, `rows.find(isA, {})` or `text.split({ [Symbol.split]: splitter })`.
|
|
395
|
+
- What this check cannot know: it reads names and syntax, not types, so it cannot tell what a receiver is.
|
|
396
|
+
- It flags the unit's own method given a variable, such as `repository.find(query)`.
|
|
397
|
+
- It misses a string or array method taken off its receiver before the call.
|
|
398
|
+
- It does not trace a receiver that is a function parameter, an `it.each` row, a value from another module (even a relative module that re-exports a package), a name destructured from an object literal, or a property nested deeper in one, such as `deps.nested.path`; it reads these as the unit's own.
|
|
399
|
+
- It releases a method of another built-in or library type that shares a name, such as a stream's `values` or `reduce`, when that call passes an object or more arguments than the string or array method takes.
|
|
400
|
+
Only a check that reads types knows a receiver's identity, and Hone does not have one yet.
|
|
401
|
+
|
|
402
|
+
Edition 2 also flags:
|
|
403
|
+
- Computing calls on a built-in namespace: `Object.assign`, `Object.fromEntries`, `Array.from` and any `Math` method. `JSON.stringify` and `JSON.parse` are [text-past-its-reader#test-body](symptoms/text-past-its-reader/test-body.md).
|
|
404
|
+
|
|
405
|
+
## Allowed forms in a test
|
|
406
|
+
|
|
407
|
+
### A method that picks or tests an element
|
|
408
|
+
```ts
|
|
409
|
+
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
410
|
+
expect(listTasks().find((task) => task.id === "a")).toEqual({ id: "a", status: "open" });
|
|
411
|
+
```
|
|
412
|
+
Assert on the whole array:
|
|
413
|
+
|
|
414
|
+
```ts
|
|
415
|
+
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
416
|
+
expect(listTasks()).toContainEqual({ id: "a", status: "open" });
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
```ts
|
|
420
|
+
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
421
|
+
expect(listTasks()).toEqual(expect.arrayContaining([expect.objectContaining({ id: "a" })]));
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
The check cannot tell the unit's own method with one of these names from an array method when it is given a variable, such as `repository.find(query)`. That is a limit of the check, described under [What the check flags](#flags).
|
|
425
|
+
|
|
426
|
+
### A method that computes a value
|
|
427
|
+
```ts
|
|
428
|
+
declare const idsOf: (rows: readonly { readonly id: string }[]) => readonly string[];
|
|
429
|
+
const rows = [{ id: "a1" }, { id: "b2" }];
|
|
430
|
+
expect(idsOf(rows)).toEqual(rows.map((row) => row.id));
|
|
431
|
+
```
|
|
432
|
+
Write the expected value out:
|
|
433
|
+
|
|
434
|
+
```ts
|
|
435
|
+
declare const idsOf: (rows: readonly { readonly id: string }[]) => readonly string[];
|
|
436
|
+
expect(idsOf([{ id: "a1" }, { id: "b2" }])).toEqual(["a1", "b2"]);
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Or match the part that matters:
|
|
440
|
+
|
|
441
|
+
```ts
|
|
442
|
+
declare const receiptOf: (order: { readonly total: number }) => { readonly total: number; readonly label: string };
|
|
443
|
+
expect(receiptOf({ total: 30 })).toMatchObject({ label: expect.stringContaining("30") });
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
### A method that mutates
|
|
447
|
+
```ts
|
|
448
|
+
declare const namesOf: (team: string) => readonly string[];
|
|
449
|
+
const expected = ["Ada"];
|
|
450
|
+
expected.push("Grace");
|
|
451
|
+
expect(namesOf("core")).toEqual(expected);
|
|
452
|
+
```
|
|
453
|
+
Write the finished array out:
|
|
454
|
+
|
|
455
|
+
```ts
|
|
456
|
+
declare const namesOf: (team: string) => readonly string[];
|
|
457
|
+
expect(namesOf("core")).toEqual(["Ada", "Grace"]);
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### Merging objects
|
|
461
|
+
```ts
|
|
462
|
+
const base = { method: "POST", path: "/tasks" } as const;
|
|
463
|
+
const request = Object.assign({}, base, { body: "a" });
|
|
464
|
+
expect(request.body).toBe("a");
|
|
465
|
+
```
|
|
466
|
+
Write the object out, spreading what it copies:
|
|
467
|
+
|
|
468
|
+
```ts
|
|
469
|
+
const base = { method: "POST", path: "/tasks" } as const;
|
|
470
|
+
const request = { ...base, body: "a" };
|
|
471
|
+
expect(request.body).toBe("a");
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
A spread copies an `Error`'s own properties into a plain object, which is not an `Error`. To give an `Error` a property, assign it:
|
|
475
|
+
|
|
476
|
+
```ts
|
|
477
|
+
declare const reasonOf: (error: Error & { readonly code?: string }) => string;
|
|
478
|
+
const missing: Error & { code?: string } = new Error("ENOENT");
|
|
479
|
+
missing.code = "ENOENT";
|
|
480
|
+
expect(reasonOf(missing)).toBe("missing");
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### Building an object from entries
|
|
484
|
+
```ts
|
|
485
|
+
declare const countsOf: (words: readonly string[]) => Readonly<Record<string, number>>;
|
|
486
|
+
expect(countsOf(["a"])).toEqual(Object.fromEntries([["a", 1]]));
|
|
487
|
+
```
|
|
488
|
+
Write the object out:
|
|
489
|
+
|
|
490
|
+
```ts
|
|
491
|
+
declare const countsOf: (words: readonly string[]) => Readonly<Record<string, number>>;
|
|
492
|
+
expect(countsOf(["a"])).toEqual({ a: 1 });
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
### Building an array from a length
|
|
496
|
+
```ts
|
|
497
|
+
declare const pageOf: (rows: readonly { readonly id: number }[]) => readonly { readonly id: number }[];
|
|
498
|
+
expect(pageOf(Array.from({ length: 3 }, (_, index) => ({ id: index })))).toHaveLength(3);
|
|
499
|
+
```
|
|
500
|
+
Write a short array out:
|
|
501
|
+
|
|
502
|
+
```ts
|
|
503
|
+
declare const pageOf: (rows: readonly { readonly id: number }[]) => readonly { readonly id: number }[];
|
|
504
|
+
expect(pageOf([{ id: 0 }, { id: 1 }, { id: 2 }])).toHaveLength(3);
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
An array too long to read written out, such as one row past a page size of 1,000, has no form on this page.
|
|
508
|
+
|
|
509
|
+
### A Math call
|
|
510
|
+
```ts
|
|
511
|
+
declare const roundedOf: (amount: number) => number;
|
|
512
|
+
expect(roundedOf(2.5)).toBe(Math.round(2.5));
|
|
513
|
+
```
|
|
514
|
+
Write the number out:
|
|
515
|
+
|
|
516
|
+
```ts
|
|
517
|
+
declare const roundedOf: (amount: number) => number;
|
|
518
|
+
expect(roundedOf(2.5)).toBe(3);
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
## Date used directly
|
|
522
|
+
|
|
523
|
+
### clock-sources
|
|
524
|
+
|
|
525
|
+
- **Flags beyond the symptom:** `Date.now` in comments and strings.
|
|
526
|
+
- **Misses:** `performance.now()`.
|
|
527
|
+
- **Settings traced to:** none.
|
|
528
|
+
|
|
529
|
+
`Date.now()` and `new Date`.
|
|
530
|
+
|
|
531
|
+
## Flags
|
|
532
|
+
|
|
533
|
+
- `.ts` and `.tsx` files, including tests. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped.
|
|
534
|
+
- Any line containing `Date.now()` or `new Date`, one finding per line. Comments and strings are matched too.
|
|
535
|
+
- Other time sources (`performance.now`, timers) are not checked; they are left to review.
|
|
536
|
+
- Other generated code can be left out of the check's scope with `exclude` in disciplines.json. Hand-written code that reads the time is not out of scope; it needs the clock port.
|
|
537
|
+
|
|
538
|
+
## Example
|
|
539
|
+
|
|
540
|
+
```ts
|
|
541
|
+
const startedAt = Date.now();
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
## Fix
|
|
545
|
+
|
|
546
|
+
```ts
|
|
547
|
+
const startedAt = clock.now();
|
|
548
|
+
```
|
|
549
|
+
Accept a clock as a dependency and read time only through it. The one real implementation lives in an adapter.
|
|
550
|
+
|
|
551
|
+
## Default on a closed union
|
|
552
|
+
|
|
553
|
+
### default-arm
|
|
554
|
+
|
|
555
|
+
- **Flags beyond the symptom:** a `switch` over an open set.
|
|
556
|
+
- **Settings traced to:** none.
|
|
557
|
+
|
|
558
|
+
A `default:` arm inside a `switch`.
|
|
559
|
+
|
|
560
|
+
## Flags
|
|
561
|
+
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
562
|
+
- A line matching `default:` while inside a `switch (`, tracked line by line by counting braces. One finding per line; comment lines are ignored.
|
|
563
|
+
- Every `default:` is flagged. The check cannot tell whether the switch is over a closed union, so a switch over an open set (a plain string) needs an exception. Other `default:` text inside a switch, such as an object key, is flagged too.
|
|
564
|
+
|
|
565
|
+
## Example
|
|
566
|
+
```ts
|
|
567
|
+
switch (event.kind) {
|
|
568
|
+
case "opened": return open();
|
|
569
|
+
default: return ignore();
|
|
570
|
+
}
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
## Fix
|
|
574
|
+
```ts
|
|
575
|
+
switch (event.kind) {
|
|
576
|
+
case "opened": return open();
|
|
577
|
+
case "closed": return ignore();
|
|
578
|
+
}
|
|
579
|
+
```
|
|
580
|
+
Name each remaining variant so the compiler checks exhaustiveness.
|
|
581
|
+
|
|
582
|
+
## Double with a body
|
|
583
|
+
|
|
584
|
+
### logic-in-a-passed-function
|
|
585
|
+
|
|
586
|
+
- **Misses:** hand-written doubles.
|
|
587
|
+
- **Settings traced to:** test file is `.test.ts(x)`: Companion test file recipe.
|
|
588
|
+
|
|
589
|
+
A construct any other test-body check flags, inside a function a test passes on. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
590
|
+
|
|
591
|
+
## Flags
|
|
592
|
+
- A function a test writes as a property or method of an object literal, or gives to `vi.fn` or `mockImplementation`, holding a construct another test-body check flags at the edition that runs.
|
|
593
|
+
|
|
594
|
+
## Allowed forms in a test
|
|
595
|
+
|
|
596
|
+
### Logic inside a function the test passes on
|
|
597
|
+
```ts
|
|
598
|
+
declare const isInstalled: (fileKind: { readonly kindOf: (path: string) => "file" | "missing" }) => "installed" | "missing";
|
|
599
|
+
const installedFiles = ["bin/hone.js"];
|
|
600
|
+
expect(isInstalled({ kindOf: (path) => (installedFiles.includes(path) ? "file" : "missing") })).toBe("installed");
|
|
601
|
+
```
|
|
602
|
+
A function a test writes as a property or method of an object literal, or gives to `vi.fn` or `mockImplementation`, is passed on: to the unit, to a table row, or to a double. Any flagged construct inside it names this section. Make it a `vi.fn` spy with a written-out return, and write out what it was asked:
|
|
603
|
+
|
|
604
|
+
```ts
|
|
605
|
+
declare const isInstalled: (fileKind: { readonly kindOf: (path: string) => "file" | "missing" }) => "installed" | "missing";
|
|
606
|
+
const kindOf = vi.fn<(path: string) => "file" | "missing">().mockReturnValue("file");
|
|
607
|
+
expect(isInstalled({ kindOf })).toBe("installed");
|
|
608
|
+
expect(kindOf).toHaveBeenCalledExactlyOnceWith("bin/hone.js");
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
The recipe is [Stub with vi.fn](recipes/stub-with-vifn.md).
|
|
612
|
+
|
|
613
|
+
### stub-implementation
|
|
614
|
+
|
|
615
|
+
- **Misses:** hand-written doubles.
|
|
616
|
+
- **Settings traced to:** test file is `.test.ts(x)`: Companion test file recipe.
|
|
617
|
+
|
|
618
|
+
`vi.fn(<implementation>)` and `.mockImplementation(...)`.
|
|
619
|
+
|
|
620
|
+
## Flags
|
|
621
|
+
|
|
622
|
+
- Test files only: `*.test.ts` and `*.test.tsx`. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
623
|
+
- A `vi.fn(...)` call with any argument, and any call to a method named `mockImplementation` (on any receiver, with or without arguments).
|
|
624
|
+
- Allowed: `vi.fn()`, `.mockReturnValue(...)`, `.mockResolvedValue(...)`, `.mockReturnValueOnce(...)` and `.mockImplementationOnce(...)`.
|
|
625
|
+
- `.mockImplementationOnce(...)` is not flagged even though it takes an implementation; whether that implementation gives the double behaviour is left to review.
|
|
626
|
+
- The source rule is wider (no real I/O, no real collaborators). Whether a unit is isolated is left to review.
|
|
627
|
+
|
|
628
|
+
## Example
|
|
629
|
+
|
|
630
|
+
```ts
|
|
631
|
+
const clock = { now: vi.fn(() => 1) };
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
## Fix
|
|
635
|
+
|
|
636
|
+
```ts
|
|
637
|
+
const clock = { now: vi.fn().mockReturnValue(1) };
|
|
638
|
+
```
|
|
639
|
+
Return a canned value: that double is a stub. If the double needs logic, the seam is probably too wide.
|
|
640
|
+
|
|
641
|
+
## Drawer path
|
|
642
|
+
|
|
643
|
+
### drawer-names
|
|
644
|
+
|
|
645
|
+
- **Misses:** a drawer under an ordinary name.
|
|
646
|
+
- **Settings traced to:** drawer names: Screaming folders recipe.
|
|
647
|
+
|
|
648
|
+
A forbidden file name or folder name in a path.
|
|
649
|
+
|
|
650
|
+
## Flags
|
|
651
|
+
- `.ts` and `.tsx` files only, judged by path; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
652
|
+
- File names, exactly and in lower case, with a `.ts` extension: `types.ts interfaces.ts models.ts enums.ts utils.ts util.ts helpers.ts helper.ts common.ts lib.ts misc.ts shared.ts`.
|
|
653
|
+
- Any folder in the path named `utils`, `helpers`, `common`, `lib`, `misc`, `shared`, `scripts`, `values`, `tests`, `test` or `__tests__`. Each file under such a folder is reported once for the folder.
|
|
654
|
+
- Allowed: `account-types.ts`, `Types.ts` and `types.tsx`, which are not exact matches.
|
|
655
|
+
|
|
656
|
+
## Example
|
|
657
|
+
```text
|
|
658
|
+
src/helpers.ts
|
|
659
|
+
src/utils/format-price.ts
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
## Fix
|
|
663
|
+
```text
|
|
664
|
+
src/price-formatting.ts
|
|
665
|
+
```
|
|
666
|
+
Rename the file or folder for what it contains, or split it into files that each hold one thing.
|
|
667
|
+
|
|
668
|
+
## Inherited environment in a subprocess
|
|
669
|
+
|
|
670
|
+
### git-spawn-environment
|
|
671
|
+
|
|
672
|
+
- **Misses:** `env` built from `process.env` under an accepted name.
|
|
673
|
+
- **Settings traced to:** accepted helper names: **nothing**; `.spec`, `.js`, `.mjs` test files: **nothing**.
|
|
674
|
+
|
|
675
|
+
A git spawn in a test without a hermetic `env`.
|
|
676
|
+
|
|
677
|
+
## Flags
|
|
678
|
+
|
|
679
|
+
- Test files: `*.test.ts`, `*.test.tsx`, `*.test.mjs`, `*.test.js`, `*.spec.ts`, `*.spec.mjs`. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped; any other folder can be left out with `exclude` in disciplines.json.
|
|
680
|
+
- A line calling `spawnSync`, `spawn`, `execFileSync`, `execFile`, `execSync`, `exec`, `execa` or `execaSync` with `"git"` (or `'git'`, or a template literal) as the first argument.
|
|
681
|
+
- Allowed when, within that line and the next seven, an `env:` names `hermeticGitEnvironment`, `withoutInheritedGitBindings` or `environment`, and no nearby `env:` uses `process.env`. The environment comes from a unit of ours with its own test, not a test helper.
|
|
682
|
+
- Not detected: a command string such as `execSync("git status")`, a split call, or a non-literal command. Whether the spawn is warranted at all is left to review.
|
|
683
|
+
|
|
684
|
+
## Example
|
|
685
|
+
|
|
686
|
+
```ts
|
|
687
|
+
spawnSync("git", ["init"], { cwd: directory });
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
## Fix
|
|
691
|
+
|
|
692
|
+
```ts
|
|
693
|
+
spawnSync("git", ["init"], { cwd: directory, env: hermeticGitEnvironment() });
|
|
694
|
+
```
|
|
695
|
+
Build the environment without inherited git variables or the user's configuration, and run in a temporary directory.
|
|
696
|
+
|
|
697
|
+
## Long function
|
|
698
|
+
|
|
699
|
+
### function-length
|
|
700
|
+
|
|
701
|
+
- **Settings traced to:** 50 lines: where a broad symptom fires. "Line and complexity are symptoms that flag many things." Suite bodies not measured: "A test suite's body is a list of cases, not a coordinator.".
|
|
702
|
+
|
|
703
|
+
A function body longer than 50 lines.
|
|
704
|
+
|
|
705
|
+
## Flags
|
|
706
|
+
|
|
707
|
+
- The ESLint piece lints whatever files the team's ESLint run includes. It needs ESLint adopted through the projection; see the ESLint piece.
|
|
708
|
+
- Under ESLint, a function body may span at most 50 lines. Blank and comment lines count; lines holding only `{` or `}` do not. Getters and setters are not checked. Reported at the function.
|
|
709
|
+
- A test suite's body is not checked. A suite body is a function passed as an argument to the call that runs a suite:
|
|
710
|
+
- `describe`, `suite`, `fdescribe`, `xdescribe`, `fsuite` or `xsuite`, alone or followed only by the modifiers `each`, `for`, `only`, `skip`, `todo`, `concurrent`, `sequential`, `shuffle`, `skipIf` and `runIf`, such as `describe.each(table)(name, fn)`, `describe.each` with a template table, `describe.only.each(table)(name, fn)` or `describe.skipIf(condition)(name, fn)`;
|
|
711
|
+
- Playwright's `test.describe`, alone or followed only by `only`, `skip`, `fixme`, `serial` and `parallel`, such as `test.describe.serial.only(name, fn)`.
|
|
712
|
+
- A suite nested in a suite is not checked either.
|
|
713
|
+
- Everything else is checked as any function is:
|
|
714
|
+
- each function inside a suite's body: each `it` and `test` callback, each hook and each helper declared there;
|
|
715
|
+
- a function given to `describe.each` as a table entry;
|
|
716
|
+
- a callback on any other member of those names, such as `test.describe.configure(fn)` or `suite.add(name, fn)` on a benchmark suite;
|
|
717
|
+
- mocha's `context`, and any other suite function not listed above.
|
|
718
|
+
- The check matches names, not bindings, so a local function of the repository's own named `describe` or `suite` is treated as a suite when called that way.
|
|
719
|
+
|
|
720
|
+
## Example
|
|
721
|
+
|
|
722
|
+
```ts
|
|
723
|
+
const settle = (orders: Order[]) => {
|
|
724
|
+
for (const order of orders) {
|
|
725
|
+
if (order.paid) {
|
|
726
|
+
for (const line of order.lines) {
|
|
727
|
+
if (line.refundable && line.quantity > 0) {
|
|
728
|
+
refund(line);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
## Fix
|
|
737
|
+
|
|
738
|
+
```ts
|
|
739
|
+
const settle = (orders: Order[]) => orders.filter(isPaid).forEach(refundEligibleLines);
|
|
740
|
+
```
|
|
741
|
+
Move any computing or branching between calls into a named doer, so the orchestrator only composes calls.
|
|
742
|
+
|
|
743
|
+
## Loop keyword
|
|
744
|
+
|
|
745
|
+
### loop-statement
|
|
746
|
+
|
|
747
|
+
- **Settings traced to:** none.
|
|
748
|
+
|
|
749
|
+
`for...of`, `for await`, counted `for` and `while` loops.
|
|
750
|
+
|
|
751
|
+
## Flags
|
|
752
|
+
|
|
753
|
+
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
754
|
+
- Lines matching `for (... of ...)` (with or without `await`), `for (init; test; step)` and `while (`. This includes `do...while`. Each kind is reported once per line.
|
|
755
|
+
- Matching is on raw lines, so loop headers split over several lines are missed and the same text inside a string is flagged. Comment lines are ignored.
|
|
756
|
+
- The source rule names element and counted iteration; the check also flags `while`.
|
|
757
|
+
- Draining an `AsyncIterable` with `for await` is allowed by the rule at declared sites; record it as an `authorised-location`.
|
|
758
|
+
|
|
759
|
+
## Example
|
|
760
|
+
|
|
761
|
+
```ts
|
|
762
|
+
for (const order of orders) {
|
|
763
|
+
totals.push(order.total);
|
|
764
|
+
}
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
## Fix
|
|
768
|
+
|
|
769
|
+
```ts
|
|
770
|
+
const totals = orders.map((order) => order.total);
|
|
771
|
+
```
|
|
772
|
+
Replace a counted loop with `Array.from({ length }, (_, position) => ...)`.
|
|
773
|
+
|
|
774
|
+
In a test file, the [computed-value-in-a-test check](symptoms/computed-value-in-a-test/test-body.md) flags `map` at either edition, and its edition 2 flags `Array.from`: write the values out instead, as [the allowed forms in a test](symptoms/computed-value-in-a-test/test-body.md#allowed-forms-in-a-test) show.
|
|
775
|
+
|
|
776
|
+
## Module or global patched
|
|
777
|
+
|
|
778
|
+
### module-mock-call
|
|
779
|
+
|
|
780
|
+
- **Misses:** `vi.stubGlobal`, `process.env` set in a test.
|
|
781
|
+
- **Settings traced to:** test file is `.test.ts(x)`: Companion test file recipe.
|
|
782
|
+
|
|
783
|
+
Calls to `vi.mock`.
|
|
784
|
+
|
|
785
|
+
## Flags
|
|
786
|
+
|
|
787
|
+
- Test files only: `*.test.ts` and `*.test.tsx`. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
788
|
+
- Every call spelled `vi.mock(...)`, with or without arguments.
|
|
789
|
+
- Not detected: `vi.doMock`, `jest.mock`, `vitest.mock` and `vi["mock"]`. Those are left to review.
|
|
790
|
+
|
|
791
|
+
## Example
|
|
792
|
+
|
|
793
|
+
```ts
|
|
794
|
+
vi.mock("./store.ts");
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
## Fix
|
|
798
|
+
|
|
799
|
+
```ts
|
|
800
|
+
const subject = createSubject({ store: storeStub });
|
|
801
|
+
```
|
|
802
|
+
Pass the collaborator in as a dependency and hand the test a stub.
|
|
803
|
+
|
|
804
|
+
## Name off its casing
|
|
805
|
+
|
|
806
|
+
### filename-case
|
|
807
|
+
|
|
808
|
+
- **Settings traced to:** Hone's own casing option lists: **nothing**; casing is the adopter's own lint.
|
|
809
|
+
|
|
810
|
+
A file name that is not kebab-case or PascalCase.
|
|
811
|
+
|
|
812
|
+
## Flags
|
|
813
|
+
Needs ESLint adopted through the projection.
|
|
814
|
+
- Under ESLint, the file name before its first dot is checked, after trimming edge `_`: it must be kebab-case or PascalCase. Each later dot segment must be kebab-case, PascalCase or lowercase.
|
|
815
|
+
- One leading `.`, `+` or `$` is ignored.
|
|
816
|
+
- Route names such as `[slug].ts` and `(group).ts` pass.
|
|
817
|
+
- A bad name is reported at line 1.
|
|
818
|
+
|
|
819
|
+
### naming-convention
|
|
820
|
+
|
|
821
|
+
- **Settings traced to:** Hone's own casing option lists: **nothing**; casing is the adopter's own lint.
|
|
822
|
+
|
|
823
|
+
A name that breaks the naming convention for its kind.
|
|
824
|
+
|
|
825
|
+
## Flags
|
|
826
|
+
Needs ESLint adopted through the projection.
|
|
827
|
+
- Under ESLint, this is typescript-eslint's `naming-convention` with the option list in the piece's `piece.json`.
|
|
828
|
+
- Enum members are CONSTANT_CASE. `const` bindings are CONSTANT_CASE, camelCase or PascalCase.
|
|
829
|
+
- Object literal properties are camelCase. Type properties are camelCase or PascalCase.
|
|
830
|
+
- Other variables, functions and parameters are camelCase or PascalCase; a leading or trailing `_` or `$` is allowed.
|
|
831
|
+
- Types are PascalCase. Class members are camelCase, and static ones may also be CONSTANT_CASE.
|
|
832
|
+
- Consecutive capitals are allowed (`agentID`, `HTTPServer`).
|
|
833
|
+
- Ignored: names that need quotes, destructured bindings, imports and unused bindings whose name starts with `_`.
|
|
834
|
+
- Not checked, unlike Biome: the local name of a renamed named import (`import { a as b }`) and a `catch` parameter. typescript-eslint has no selector for either; review covers them.
|
|
835
|
+
|
|
836
|
+
## Outside import past a boundary
|
|
837
|
+
|
|
838
|
+
### import-or-require
|
|
839
|
+
|
|
840
|
+
- **Misses:** `import()`, `require`, globals.
|
|
841
|
+
- **Settings traced to:** `confinedPackages`, empty by default on purpose: the universe of outside dependencies cannot be listed, and flagging every import would catch internal packages. Telling outside from internal needs the workspace layout, which Hone can read.
|
|
842
|
+
|
|
843
|
+
Imports of the packages the repository confines, and any `node:` import.
|
|
844
|
+
|
|
845
|
+
## Flags
|
|
846
|
+
|
|
847
|
+
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
848
|
+
- A line with `from "<specifier>"` where the specifier is a package listed in the clause's `confinedPackages` setting (see [Settings](#settings)) or a subpath of one: `hono` covers `hono` and `hono/cors`, and `@scope/name` covers `@scope/name` and `@scope/name/client`. A longer name is a different package, so `hono` does not cover `honox` or `hono-extra`. With no packages listed, which is the default, no library import is flagged. Type-only imports and matches inside strings are flagged too.
|
|
849
|
+
- A `node:` specifier in an import, `export ... from`, `import("node:...")`, `import type`, `import x = require(...)` or `require("node:...")`. Unprefixed `fs` is not detected.
|
|
850
|
+
- The source rule covers every third-party dependency; the check covers only the listed packages. The rest is left to review.
|
|
163
851
|
|
|
164
852
|
## Settings
|
|
165
853
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
854
|
+
List each outside dependency the repository confines to its adapter in `disciplines.json`, then record each adapter file as an `authorised-location`:
|
|
855
|
+
|
|
856
|
+
```jsonc
|
|
857
|
+
"clauseSettings": {
|
|
858
|
+
"CD-19#import-boundaries": { "confinedPackages": ["winston", "uuid"] }
|
|
859
|
+
}
|
|
860
|
+
```
|
|
861
|
+
|
|
862
|
+
## Example
|
|
863
|
+
|
|
864
|
+
With `"confinedPackages": ["uuid"]`, both lines are flagged; with the default, only the first.
|
|
865
|
+
|
|
866
|
+
```ts
|
|
867
|
+
import { readFileSync } from "node:fs";
|
|
868
|
+
import { v4 } from "uuid";
|
|
869
|
+
```
|
|
870
|
+
|
|
871
|
+
## Fix
|
|
872
|
+
|
|
873
|
+
```ts
|
|
874
|
+
import type { FileReader } from "./file-reader.ts";
|
|
875
|
+
import type { IdGenerator } from "./id-generator.ts";
|
|
876
|
+
```
|
|
877
|
+
Import your own port and take it in the unit's argument. Only the adapter for that outside party imports the library.
|
|
878
|
+
|
|
879
|
+
## Positional parameters
|
|
880
|
+
|
|
881
|
+
### parameter-count
|
|
882
|
+
|
|
883
|
+
- **Misses:** our own functions with exactly two parameters.
|
|
884
|
+
- **Settings traced to:** `max: 2`: a recorded compromise of the check, which cannot tell the two kinds apart. "Positional parameters is 2 because it flags functions designed to be used in native APIs even inline unnamed ones for things like map/reduce. Making 1 untenable."; "The check is not right. Its unable to distinguish.".
|
|
885
|
+
|
|
886
|
+
A function with more than two parameters.
|
|
887
|
+
|
|
888
|
+
## Flags
|
|
889
|
+
|
|
890
|
+
- The ESLint piece lints whatever files the team's ESLint run includes. It needs ESLint adopted through the projection; see the ESLint piece.
|
|
891
|
+
- Under ESLint, this is typescript-eslint's `max-params` with `{ "max": 2, "countVoidThis": true }`.
|
|
892
|
+
- A function declaration, function expression, arrow function, method or constructor with more than two parameters. A `this` parameter counts.
|
|
893
|
+
- Not flagged by the check: functions with two or fewer parameters. The rule asks for one named object; a function with two parameters is left to review, where the function-first lens treats every authored function with two or more parameters as a candidate.
|
|
894
|
+
|
|
895
|
+
## Example
|
|
896
|
+
|
|
897
|
+
```ts
|
|
898
|
+
const createOrder = (customerId: string, items: Item[], currency: string) => ({ customerId, items, currency });
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
## Fix
|
|
902
|
+
|
|
903
|
+
```ts
|
|
904
|
+
const createOrder = ({ customerId, items, currency }: OrderRequest) => ({ customerId, items, currency });
|
|
905
|
+
```
|
|
906
|
+
Take one object with named fields so each call site reads as a labelled contract.
|
|
907
|
+
|
|
908
|
+
## Rebinding
|
|
909
|
+
|
|
910
|
+
### parameter-reassignment
|
|
911
|
+
|
|
912
|
+
- **Misses:** a local `let` in production.
|
|
913
|
+
- **Settings traced to:** none.
|
|
914
|
+
|
|
915
|
+
Assigning to, incrementing or destructuring into a parameter itself.
|
|
916
|
+
|
|
917
|
+
## Flags
|
|
918
|
+
|
|
919
|
+
Needs ESLint adopted through the projection; see the ESLint piece.
|
|
920
|
+
|
|
921
|
+
- Under ESLint, this is ESLint's `no-param-reassign` with `{ "props": false }`.
|
|
922
|
+
- It flags assigning to a parameter, incrementing or decrementing it, and destructuring-assigning into it.
|
|
923
|
+
- A parameter's fields are not checked here; the audit's [`parameter-mutation`](symptoms/write-into-a-parameter/parameter-mutation.md) clause covers them.
|
|
924
|
+
|
|
925
|
+
### test-body
|
|
926
|
+
|
|
927
|
+
- **Misses:** a local `let` in production.
|
|
928
|
+
- **Settings traced to:** none.
|
|
929
|
+
|
|
930
|
+
`let` declarations in a test file. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
931
|
+
|
|
932
|
+
## Flags
|
|
933
|
+
Edition 1:
|
|
934
|
+
- `let` declarations.
|
|
935
|
+
|
|
936
|
+
## Allowed forms in a test
|
|
937
|
+
|
|
938
|
+
### A let
|
|
939
|
+
```ts
|
|
940
|
+
declare const record: (store: { readonly save: (text: string) => void }) => void;
|
|
941
|
+
let saved = "";
|
|
942
|
+
record({ save: (text) => { saved = text; } });
|
|
943
|
+
expect(saved).toBe("a");
|
|
944
|
+
```
|
|
945
|
+
Record the calls with `vi.fn` and assert them:
|
|
946
|
+
|
|
947
|
+
```ts
|
|
948
|
+
declare const record: (store: { readonly save: (text: string) => void }) => void;
|
|
949
|
+
const save = vi.fn<(text: string) => void>();
|
|
950
|
+
record({ save });
|
|
951
|
+
expect(save).toHaveBeenCalledWith("a");
|
|
952
|
+
```
|
|
953
|
+
|
|
954
|
+
## Shorthand name
|
|
955
|
+
|
|
956
|
+
### identifier-names
|
|
957
|
+
|
|
958
|
+
- **Misses:** shorthand not on the list.
|
|
959
|
+
- **Settings traced to:** shorthand and filler list: Whole words recipe.
|
|
960
|
+
|
|
961
|
+
A binding named from a fixed shorthand or filler list.
|
|
962
|
+
|
|
963
|
+
## Flags
|
|
964
|
+
- `.ts` and `.tsx` files, including tests; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
965
|
+
- The declared name of a variable, a parameter, a named function declaration or a destructured binding, when the whole name is exactly one of these (case-sensitive):
|
|
966
|
+
- shorthand: `c op s cb fn tx e ev acc item k v el arr i j n obj val res req tmp temp`
|
|
967
|
+
- filler: `object obj args arguments details extra extras data info params parameters props payload body value result stuff things misc metadata`
|
|
968
|
+
- Allowed: longer names that contain these words (`accountData`), names starting with `_`, property keys and property accesses.
|
|
969
|
+
- Other poor names (`manager`, `handler`, vague nouns) are left to review.
|
|
970
|
+
|
|
971
|
+
## Example
|
|
972
|
+
```ts
|
|
973
|
+
const data = await loadAccount(id);
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
## Fix
|
|
977
|
+
```ts
|
|
978
|
+
const account = await loadAccount(id);
|
|
979
|
+
```
|
|
980
|
+
Name the value for what it is in the domain.
|
|
981
|
+
|
|
982
|
+
## Strictness weakened
|
|
983
|
+
|
|
984
|
+
### exact-optional-property-types
|
|
985
|
+
|
|
986
|
+
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
987
|
+
- **Misses:** edition 1: a base reached by `extends`.
|
|
988
|
+
- **Settings traced to:** flag list: The type checker proves it. Edition 1 flags presence, which is the Shared strict base config recipe: **traced to a recipe, not a rule**.
|
|
989
|
+
|
|
990
|
+
`exactOptionalPropertyTypes` is set in a `tsconfig.json`; edition 2 adds that it resolves to on.
|
|
991
|
+
|
|
992
|
+
## Flags
|
|
993
|
+
Each strictness-weakened check has two editions. Edition 1 runs by default. Edition 2 also judges what each `tsconfig.json` inherits, and becomes the default in the next major release; see [Settings](#settings) to run it now.
|
|
994
|
+
|
|
995
|
+
Edition 1:
|
|
996
|
+
- `tsconfig.json` files, named exactly, at any depth. `tsconfig.base.json` and other names are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
997
|
+
- For each selected clause, the matching option present in that file's `compilerOptions`. Presence is enough: `true` is flagged as well as `false`.
|
|
998
|
+
- Options in `extends`-ed files are not seen. A file that cannot be parsed, or whose root or `compilerOptions` is not an object, fails the run.
|
|
999
|
+
|
|
1000
|
+
Edition 2 also flags, for each selected option a `tsconfig.json` does not set itself, an option its resolved configuration leaves off:
|
|
1001
|
+
- The configuration is resolved by the repository's installed TypeScript, as `tsc` would resolve it: every file in the `extends` chain, a relative path, a package such as `@tsconfig/strictest` or a workspace package under `node_modules`, and an array of bases on TypeScript 5.0 or later, later bases winning. An option a base turns on and a later file turns off is off.
|
|
1002
|
+
- `strict` and `useUnknownInCatchVariables` take TypeScript's defaults: TypeScript 6 treats `strict` as on when nothing sets it, and `useUnknownInCatchVariables` follows `strict` unless it is set.
|
|
1003
|
+
- The finding names the file to edit. `= false, inherited from <base>` names each base that turns the option off. `= false, turned off in <file>` names this `tsconfig.json` when its own `"strict": false` turns `useUnknownInCatchVariables` off. `unset here and in <bases>` lists every file in the chain, none of which sets the option; `unset, and this file extends no base` says there is no chain.
|
|
1004
|
+
- A configuration TypeScript cannot resolve, such as a base file that is missing, a package that is not installed, or bases that extend each other, is flagged for each selected option the file does not set as `unknown`, followed by TypeScript's own diagnostic. An `extends` holding `${configDir}` resolves however the installed TypeScript resolves it, and is flagged the same way when TypeScript cannot find it. Fix the chain, and the options are judged.
|
|
1005
|
+
- The base files are judged through the `tsconfig.json` files that extend them, not on their own.
|
|
1006
|
+
- A `tsconfig.json` from which TypeScript would compile no file is not judged on what it resolves to, since its options apply to no file. After resolving the chain, TypeScript has no `files` entry, and no `include` entry that names a path outright or a folder or pattern it would search. Examples: an empty `files` list, its own or inherited, with no `include`, such as the solution-style root with only `references` that `npm create vite` writes; an empty `include`; an `exclude` of every file. Any non-empty `include` that names a file or a folder is still judged, such as `"include": ["vite.config.ts"]` or `["src"]`, and so is a config that sets neither `files` nor `include`, since TypeScript then includes every file. An option a skipped file sets itself is still flagged, as in edition 1. The configs it references are not judged through it; only files named `tsconfig.json` are read.
|
|
1007
|
+
|
|
1008
|
+
## Settings
|
|
1009
|
+
- `edition`: the edition this clause runs, `"1"` or `"2"`. Without it, the clause runs edition 1, or the latest edition when `checkEditions` in `disciplines.json` is `"latest"`.
|
|
1010
|
+
|
|
1011
|
+
```jsonc
|
|
1012
|
+
"clauseSettings": {
|
|
1013
|
+
"CD-3#exact-optional-property-types": { "edition": "2" }
|
|
1014
|
+
}
|
|
1015
|
+
```
|
|
1016
|
+
|
|
1017
|
+
## Example
|
|
1018
|
+
```jsonc
|
|
1019
|
+
{ "compilerOptions": { "strict": false } }
|
|
1020
|
+
```
|
|
1021
|
+
|
|
1022
|
+
## Fix
|
|
1023
|
+
```jsonc
|
|
1024
|
+
{ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "dist" } }
|
|
1025
|
+
```
|
|
1026
|
+
Put the flags in a shared base file that is not named `tsconfig.json`, and leave them out of every `tsconfig.json`. Under edition 1, that the base file turns them on is left to review. Under edition 2 the check reads the base: turn every selected flag on in it.
|
|
1027
|
+
|
|
1028
|
+
```jsonc
|
|
1029
|
+
{ "compilerOptions": { "strict": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, "noImplicitOverride": true, "noFallthroughCasesInSwitch": true, "noPropertyAccessFromIndexSignature": true, "useUnknownInCatchVariables": true } }
|
|
1030
|
+
```
|
|
1031
|
+
|
|
1032
|
+
### no-fallthrough-cases-in-switch
|
|
1033
|
+
|
|
1034
|
+
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1035
|
+
- **Misses:** edition 1: a base reached by `extends`.
|
|
1036
|
+
- **Settings traced to:** flag list: The type checker proves it. Edition 1 flags presence, which is the Shared strict base config recipe: **traced to a recipe, not a rule**.
|
|
1037
|
+
|
|
1038
|
+
`noFallthroughCasesInSwitch` is set in a `tsconfig.json`; edition 2 adds that it resolves to on.
|
|
1039
|
+
|
|
1040
|
+
## Flags
|
|
1041
|
+
Each strictness-weakened check has two editions. Edition 1 runs by default. Edition 2 also judges what each `tsconfig.json` inherits, and becomes the default in the next major release; see [Settings](#settings) to run it now.
|
|
1042
|
+
|
|
1043
|
+
Edition 1:
|
|
1044
|
+
- `tsconfig.json` files, named exactly, at any depth. `tsconfig.base.json` and other names are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1045
|
+
- For each selected clause, the matching option present in that file's `compilerOptions`. Presence is enough: `true` is flagged as well as `false`.
|
|
1046
|
+
- Options in `extends`-ed files are not seen. A file that cannot be parsed, or whose root or `compilerOptions` is not an object, fails the run.
|
|
1047
|
+
|
|
1048
|
+
Edition 2 also flags, for each selected option a `tsconfig.json` does not set itself, an option its resolved configuration leaves off:
|
|
1049
|
+
- The configuration is resolved by the repository's installed TypeScript, as `tsc` would resolve it: every file in the `extends` chain, a relative path, a package such as `@tsconfig/strictest` or a workspace package under `node_modules`, and an array of bases on TypeScript 5.0 or later, later bases winning. An option a base turns on and a later file turns off is off.
|
|
1050
|
+
- `strict` and `useUnknownInCatchVariables` take TypeScript's defaults: TypeScript 6 treats `strict` as on when nothing sets it, and `useUnknownInCatchVariables` follows `strict` unless it is set.
|
|
1051
|
+
- The finding names the file to edit. `= false, inherited from <base>` names each base that turns the option off. `= false, turned off in <file>` names this `tsconfig.json` when its own `"strict": false` turns `useUnknownInCatchVariables` off. `unset here and in <bases>` lists every file in the chain, none of which sets the option; `unset, and this file extends no base` says there is no chain.
|
|
1052
|
+
- A configuration TypeScript cannot resolve, such as a base file that is missing, a package that is not installed, or bases that extend each other, is flagged for each selected option the file does not set as `unknown`, followed by TypeScript's own diagnostic. An `extends` holding `${configDir}` resolves however the installed TypeScript resolves it, and is flagged the same way when TypeScript cannot find it. Fix the chain, and the options are judged.
|
|
1053
|
+
- The base files are judged through the `tsconfig.json` files that extend them, not on their own.
|
|
1054
|
+
- A `tsconfig.json` from which TypeScript would compile no file is not judged on what it resolves to, since its options apply to no file. After resolving the chain, TypeScript has no `files` entry, and no `include` entry that names a path outright or a folder or pattern it would search. Examples: an empty `files` list, its own or inherited, with no `include`, such as the solution-style root with only `references` that `npm create vite` writes; an empty `include`; an `exclude` of every file. Any non-empty `include` that names a file or a folder is still judged, such as `"include": ["vite.config.ts"]` or `["src"]`, and so is a config that sets neither `files` nor `include`, since TypeScript then includes every file. An option a skipped file sets itself is still flagged, as in edition 1. The configs it references are not judged through it; only files named `tsconfig.json` are read.
|
|
1055
|
+
|
|
1056
|
+
## Settings
|
|
1057
|
+
- `edition`: the edition this clause runs, `"1"` or `"2"`. Without it, the clause runs edition 1, or the latest edition when `checkEditions` in `disciplines.json` is `"latest"`.
|
|
1058
|
+
|
|
1059
|
+
```jsonc
|
|
1060
|
+
"clauseSettings": {
|
|
1061
|
+
"CD-3#no-fallthrough-cases-in-switch": { "edition": "2" }
|
|
1062
|
+
}
|
|
1063
|
+
```
|
|
1064
|
+
|
|
1065
|
+
## Example
|
|
1066
|
+
```jsonc
|
|
1067
|
+
{ "compilerOptions": { "strict": false } }
|
|
1068
|
+
```
|
|
1069
|
+
|
|
1070
|
+
## Fix
|
|
1071
|
+
```jsonc
|
|
1072
|
+
{ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "dist" } }
|
|
1073
|
+
```
|
|
1074
|
+
Put the flags in a shared base file that is not named `tsconfig.json`, and leave them out of every `tsconfig.json`. Under edition 1, that the base file turns them on is left to review. Under edition 2 the check reads the base: turn every selected flag on in it.
|
|
1075
|
+
|
|
1076
|
+
```jsonc
|
|
1077
|
+
{ "compilerOptions": { "strict": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, "noImplicitOverride": true, "noFallthroughCasesInSwitch": true, "noPropertyAccessFromIndexSignature": true, "useUnknownInCatchVariables": true } }
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1080
|
+
### no-implicit-override
|
|
1081
|
+
|
|
1082
|
+
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1083
|
+
- **Misses:** edition 1: a base reached by `extends`.
|
|
1084
|
+
- **Settings traced to:** flag list: The type checker proves it. Edition 1 flags presence, which is the Shared strict base config recipe: **traced to a recipe, not a rule**.
|
|
1085
|
+
|
|
1086
|
+
`noImplicitOverride` is set in a `tsconfig.json`; edition 2 adds that it resolves to on.
|
|
1087
|
+
|
|
1088
|
+
## Flags
|
|
1089
|
+
Each strictness-weakened check has two editions. Edition 1 runs by default. Edition 2 also judges what each `tsconfig.json` inherits, and becomes the default in the next major release; see [Settings](#settings) to run it now.
|
|
1090
|
+
|
|
1091
|
+
Edition 1:
|
|
1092
|
+
- `tsconfig.json` files, named exactly, at any depth. `tsconfig.base.json` and other names are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1093
|
+
- For each selected clause, the matching option present in that file's `compilerOptions`. Presence is enough: `true` is flagged as well as `false`.
|
|
1094
|
+
- Options in `extends`-ed files are not seen. A file that cannot be parsed, or whose root or `compilerOptions` is not an object, fails the run.
|
|
1095
|
+
|
|
1096
|
+
Edition 2 also flags, for each selected option a `tsconfig.json` does not set itself, an option its resolved configuration leaves off:
|
|
1097
|
+
- The configuration is resolved by the repository's installed TypeScript, as `tsc` would resolve it: every file in the `extends` chain, a relative path, a package such as `@tsconfig/strictest` or a workspace package under `node_modules`, and an array of bases on TypeScript 5.0 or later, later bases winning. An option a base turns on and a later file turns off is off.
|
|
1098
|
+
- `strict` and `useUnknownInCatchVariables` take TypeScript's defaults: TypeScript 6 treats `strict` as on when nothing sets it, and `useUnknownInCatchVariables` follows `strict` unless it is set.
|
|
1099
|
+
- The finding names the file to edit. `= false, inherited from <base>` names each base that turns the option off. `= false, turned off in <file>` names this `tsconfig.json` when its own `"strict": false` turns `useUnknownInCatchVariables` off. `unset here and in <bases>` lists every file in the chain, none of which sets the option; `unset, and this file extends no base` says there is no chain.
|
|
1100
|
+
- A configuration TypeScript cannot resolve, such as a base file that is missing, a package that is not installed, or bases that extend each other, is flagged for each selected option the file does not set as `unknown`, followed by TypeScript's own diagnostic. An `extends` holding `${configDir}` resolves however the installed TypeScript resolves it, and is flagged the same way when TypeScript cannot find it. Fix the chain, and the options are judged.
|
|
1101
|
+
- The base files are judged through the `tsconfig.json` files that extend them, not on their own.
|
|
1102
|
+
- A `tsconfig.json` from which TypeScript would compile no file is not judged on what it resolves to, since its options apply to no file. After resolving the chain, TypeScript has no `files` entry, and no `include` entry that names a path outright or a folder or pattern it would search. Examples: an empty `files` list, its own or inherited, with no `include`, such as the solution-style root with only `references` that `npm create vite` writes; an empty `include`; an `exclude` of every file. Any non-empty `include` that names a file or a folder is still judged, such as `"include": ["vite.config.ts"]` or `["src"]`, and so is a config that sets neither `files` nor `include`, since TypeScript then includes every file. An option a skipped file sets itself is still flagged, as in edition 1. The configs it references are not judged through it; only files named `tsconfig.json` are read.
|
|
1103
|
+
|
|
1104
|
+
## Settings
|
|
1105
|
+
- `edition`: the edition this clause runs, `"1"` or `"2"`. Without it, the clause runs edition 1, or the latest edition when `checkEditions` in `disciplines.json` is `"latest"`.
|
|
1106
|
+
|
|
1107
|
+
```jsonc
|
|
1108
|
+
"clauseSettings": {
|
|
1109
|
+
"CD-3#no-implicit-override": { "edition": "2" }
|
|
1110
|
+
}
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
## Example
|
|
1114
|
+
```jsonc
|
|
1115
|
+
{ "compilerOptions": { "strict": false } }
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
## Fix
|
|
1119
|
+
```jsonc
|
|
1120
|
+
{ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "dist" } }
|
|
1121
|
+
```
|
|
1122
|
+
Put the flags in a shared base file that is not named `tsconfig.json`, and leave them out of every `tsconfig.json`. Under edition 1, that the base file turns them on is left to review. Under edition 2 the check reads the base: turn every selected flag on in it.
|
|
1123
|
+
|
|
1124
|
+
```jsonc
|
|
1125
|
+
{ "compilerOptions": { "strict": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, "noImplicitOverride": true, "noFallthroughCasesInSwitch": true, "noPropertyAccessFromIndexSignature": true, "useUnknownInCatchVariables": true } }
|
|
1126
|
+
```
|
|
1127
|
+
|
|
1128
|
+
### no-property-access-from-index-signature
|
|
1129
|
+
|
|
1130
|
+
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1131
|
+
- **Misses:** edition 1: a base reached by `extends`.
|
|
1132
|
+
- **Settings traced to:** flag list: The type checker proves it. Edition 1 flags presence, which is the Shared strict base config recipe: **traced to a recipe, not a rule**.
|
|
1133
|
+
|
|
1134
|
+
`noPropertyAccessFromIndexSignature` is set in a `tsconfig.json`; edition 2 adds that it resolves to on.
|
|
1135
|
+
|
|
1136
|
+
## Flags
|
|
1137
|
+
Each strictness-weakened check has two editions. Edition 1 runs by default. Edition 2 also judges what each `tsconfig.json` inherits, and becomes the default in the next major release; see [Settings](#settings) to run it now.
|
|
1138
|
+
|
|
1139
|
+
Edition 1:
|
|
1140
|
+
- `tsconfig.json` files, named exactly, at any depth. `tsconfig.base.json` and other names are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1141
|
+
- For each selected clause, the matching option present in that file's `compilerOptions`. Presence is enough: `true` is flagged as well as `false`.
|
|
1142
|
+
- Options in `extends`-ed files are not seen. A file that cannot be parsed, or whose root or `compilerOptions` is not an object, fails the run.
|
|
1143
|
+
|
|
1144
|
+
Edition 2 also flags, for each selected option a `tsconfig.json` does not set itself, an option its resolved configuration leaves off:
|
|
1145
|
+
- The configuration is resolved by the repository's installed TypeScript, as `tsc` would resolve it: every file in the `extends` chain, a relative path, a package such as `@tsconfig/strictest` or a workspace package under `node_modules`, and an array of bases on TypeScript 5.0 or later, later bases winning. An option a base turns on and a later file turns off is off.
|
|
1146
|
+
- `strict` and `useUnknownInCatchVariables` take TypeScript's defaults: TypeScript 6 treats `strict` as on when nothing sets it, and `useUnknownInCatchVariables` follows `strict` unless it is set.
|
|
1147
|
+
- The finding names the file to edit. `= false, inherited from <base>` names each base that turns the option off. `= false, turned off in <file>` names this `tsconfig.json` when its own `"strict": false` turns `useUnknownInCatchVariables` off. `unset here and in <bases>` lists every file in the chain, none of which sets the option; `unset, and this file extends no base` says there is no chain.
|
|
1148
|
+
- A configuration TypeScript cannot resolve, such as a base file that is missing, a package that is not installed, or bases that extend each other, is flagged for each selected option the file does not set as `unknown`, followed by TypeScript's own diagnostic. An `extends` holding `${configDir}` resolves however the installed TypeScript resolves it, and is flagged the same way when TypeScript cannot find it. Fix the chain, and the options are judged.
|
|
1149
|
+
- The base files are judged through the `tsconfig.json` files that extend them, not on their own.
|
|
1150
|
+
- A `tsconfig.json` from which TypeScript would compile no file is not judged on what it resolves to, since its options apply to no file. After resolving the chain, TypeScript has no `files` entry, and no `include` entry that names a path outright or a folder or pattern it would search. Examples: an empty `files` list, its own or inherited, with no `include`, such as the solution-style root with only `references` that `npm create vite` writes; an empty `include`; an `exclude` of every file. Any non-empty `include` that names a file or a folder is still judged, such as `"include": ["vite.config.ts"]` or `["src"]`, and so is a config that sets neither `files` nor `include`, since TypeScript then includes every file. An option a skipped file sets itself is still flagged, as in edition 1. The configs it references are not judged through it; only files named `tsconfig.json` are read.
|
|
1151
|
+
|
|
1152
|
+
## Settings
|
|
1153
|
+
- `edition`: the edition this clause runs, `"1"` or `"2"`. Without it, the clause runs edition 1, or the latest edition when `checkEditions` in `disciplines.json` is `"latest"`.
|
|
1154
|
+
|
|
1155
|
+
```jsonc
|
|
1156
|
+
"clauseSettings": {
|
|
1157
|
+
"CD-3#no-property-access-from-index-signature": { "edition": "2" }
|
|
1158
|
+
}
|
|
1159
|
+
```
|
|
1160
|
+
|
|
1161
|
+
## Example
|
|
1162
|
+
```jsonc
|
|
1163
|
+
{ "compilerOptions": { "strict": false } }
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
## Fix
|
|
1167
|
+
```jsonc
|
|
1168
|
+
{ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "dist" } }
|
|
1169
|
+
```
|
|
1170
|
+
Put the flags in a shared base file that is not named `tsconfig.json`, and leave them out of every `tsconfig.json`. Under edition 1, that the base file turns them on is left to review. Under edition 2 the check reads the base: turn every selected flag on in it.
|
|
1171
|
+
|
|
1172
|
+
```jsonc
|
|
1173
|
+
{ "compilerOptions": { "strict": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, "noImplicitOverride": true, "noFallthroughCasesInSwitch": true, "noPropertyAccessFromIndexSignature": true, "useUnknownInCatchVariables": true } }
|
|
1174
|
+
```
|
|
1175
|
+
|
|
1176
|
+
### no-unchecked-indexed-access
|
|
1177
|
+
|
|
1178
|
+
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1179
|
+
- **Misses:** edition 1: a base reached by `extends`.
|
|
1180
|
+
- **Settings traced to:** flag list: The type checker proves it. Edition 1 flags presence, which is the Shared strict base config recipe: **traced to a recipe, not a rule**.
|
|
1181
|
+
|
|
1182
|
+
`noUncheckedIndexedAccess` is set in a `tsconfig.json`; edition 2 adds that it resolves to on.
|
|
1183
|
+
|
|
1184
|
+
## Flags
|
|
1185
|
+
Each strictness-weakened check has two editions. Edition 1 runs by default. Edition 2 also judges what each `tsconfig.json` inherits, and becomes the default in the next major release; see [Settings](#settings) to run it now.
|
|
1186
|
+
|
|
1187
|
+
Edition 1:
|
|
1188
|
+
- `tsconfig.json` files, named exactly, at any depth. `tsconfig.base.json` and other names are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1189
|
+
- For each selected clause, the matching option present in that file's `compilerOptions`. Presence is enough: `true` is flagged as well as `false`.
|
|
1190
|
+
- Options in `extends`-ed files are not seen. A file that cannot be parsed, or whose root or `compilerOptions` is not an object, fails the run.
|
|
1191
|
+
|
|
1192
|
+
Edition 2 also flags, for each selected option a `tsconfig.json` does not set itself, an option its resolved configuration leaves off:
|
|
1193
|
+
- The configuration is resolved by the repository's installed TypeScript, as `tsc` would resolve it: every file in the `extends` chain, a relative path, a package such as `@tsconfig/strictest` or a workspace package under `node_modules`, and an array of bases on TypeScript 5.0 or later, later bases winning. An option a base turns on and a later file turns off is off.
|
|
1194
|
+
- `strict` and `useUnknownInCatchVariables` take TypeScript's defaults: TypeScript 6 treats `strict` as on when nothing sets it, and `useUnknownInCatchVariables` follows `strict` unless it is set.
|
|
1195
|
+
- The finding names the file to edit. `= false, inherited from <base>` names each base that turns the option off. `= false, turned off in <file>` names this `tsconfig.json` when its own `"strict": false` turns `useUnknownInCatchVariables` off. `unset here and in <bases>` lists every file in the chain, none of which sets the option; `unset, and this file extends no base` says there is no chain.
|
|
1196
|
+
- A configuration TypeScript cannot resolve, such as a base file that is missing, a package that is not installed, or bases that extend each other, is flagged for each selected option the file does not set as `unknown`, followed by TypeScript's own diagnostic. An `extends` holding `${configDir}` resolves however the installed TypeScript resolves it, and is flagged the same way when TypeScript cannot find it. Fix the chain, and the options are judged.
|
|
1197
|
+
- The base files are judged through the `tsconfig.json` files that extend them, not on their own.
|
|
1198
|
+
- A `tsconfig.json` from which TypeScript would compile no file is not judged on what it resolves to, since its options apply to no file. After resolving the chain, TypeScript has no `files` entry, and no `include` entry that names a path outright or a folder or pattern it would search. Examples: an empty `files` list, its own or inherited, with no `include`, such as the solution-style root with only `references` that `npm create vite` writes; an empty `include`; an `exclude` of every file. Any non-empty `include` that names a file or a folder is still judged, such as `"include": ["vite.config.ts"]` or `["src"]`, and so is a config that sets neither `files` nor `include`, since TypeScript then includes every file. An option a skipped file sets itself is still flagged, as in edition 1. The configs it references are not judged through it; only files named `tsconfig.json` are read.
|
|
1199
|
+
|
|
1200
|
+
## Settings
|
|
1201
|
+
- `edition`: the edition this clause runs, `"1"` or `"2"`. Without it, the clause runs edition 1, or the latest edition when `checkEditions` in `disciplines.json` is `"latest"`.
|
|
1202
|
+
|
|
1203
|
+
```jsonc
|
|
1204
|
+
"clauseSettings": {
|
|
1205
|
+
"CD-3#no-unchecked-indexed-access": { "edition": "2" }
|
|
1206
|
+
}
|
|
1207
|
+
```
|
|
1208
|
+
|
|
1209
|
+
## Example
|
|
1210
|
+
```jsonc
|
|
1211
|
+
{ "compilerOptions": { "strict": false } }
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
## Fix
|
|
1215
|
+
```jsonc
|
|
1216
|
+
{ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "dist" } }
|
|
1217
|
+
```
|
|
1218
|
+
Put the flags in a shared base file that is not named `tsconfig.json`, and leave them out of every `tsconfig.json`. Under edition 1, that the base file turns them on is left to review. Under edition 2 the check reads the base: turn every selected flag on in it.
|
|
1219
|
+
|
|
1220
|
+
```jsonc
|
|
1221
|
+
{ "compilerOptions": { "strict": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, "noImplicitOverride": true, "noFallthroughCasesInSwitch": true, "noPropertyAccessFromIndexSignature": true, "useUnknownInCatchVariables": true } }
|
|
1222
|
+
```
|
|
1223
|
+
|
|
1224
|
+
### strict
|
|
1225
|
+
|
|
1226
|
+
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1227
|
+
- **Misses:** edition 1: a base reached by `extends`.
|
|
1228
|
+
- **Settings traced to:** flag list: The type checker proves it. Edition 1 flags presence, which is the Shared strict base config recipe: **traced to a recipe, not a rule**.
|
|
1229
|
+
|
|
1230
|
+
`strict` is set in a `tsconfig.json`; edition 2 adds that it resolves to on.
|
|
1231
|
+
|
|
1232
|
+
## Flags
|
|
1233
|
+
Each strictness-weakened check has two editions. Edition 1 runs by default. Edition 2 also judges what each `tsconfig.json` inherits, and becomes the default in the next major release; see [Settings](#settings) to run it now.
|
|
1234
|
+
|
|
1235
|
+
Edition 1:
|
|
1236
|
+
- `tsconfig.json` files, named exactly, at any depth. `tsconfig.base.json` and other names are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1237
|
+
- For each selected clause, the matching option present in that file's `compilerOptions`. Presence is enough: `true` is flagged as well as `false`.
|
|
1238
|
+
- Options in `extends`-ed files are not seen. A file that cannot be parsed, or whose root or `compilerOptions` is not an object, fails the run.
|
|
1239
|
+
|
|
1240
|
+
Edition 2 also flags, for each selected option a `tsconfig.json` does not set itself, an option its resolved configuration leaves off:
|
|
1241
|
+
- The configuration is resolved by the repository's installed TypeScript, as `tsc` would resolve it: every file in the `extends` chain, a relative path, a package such as `@tsconfig/strictest` or a workspace package under `node_modules`, and an array of bases on TypeScript 5.0 or later, later bases winning. An option a base turns on and a later file turns off is off.
|
|
1242
|
+
- `strict` and `useUnknownInCatchVariables` take TypeScript's defaults: TypeScript 6 treats `strict` as on when nothing sets it, and `useUnknownInCatchVariables` follows `strict` unless it is set.
|
|
1243
|
+
- The finding names the file to edit. `= false, inherited from <base>` names each base that turns the option off. `= false, turned off in <file>` names this `tsconfig.json` when its own `"strict": false` turns `useUnknownInCatchVariables` off. `unset here and in <bases>` lists every file in the chain, none of which sets the option; `unset, and this file extends no base` says there is no chain.
|
|
1244
|
+
- A configuration TypeScript cannot resolve, such as a base file that is missing, a package that is not installed, or bases that extend each other, is flagged for each selected option the file does not set as `unknown`, followed by TypeScript's own diagnostic. An `extends` holding `${configDir}` resolves however the installed TypeScript resolves it, and is flagged the same way when TypeScript cannot find it. Fix the chain, and the options are judged.
|
|
1245
|
+
- The base files are judged through the `tsconfig.json` files that extend them, not on their own.
|
|
1246
|
+
- A `tsconfig.json` from which TypeScript would compile no file is not judged on what it resolves to, since its options apply to no file. After resolving the chain, TypeScript has no `files` entry, and no `include` entry that names a path outright or a folder or pattern it would search. Examples: an empty `files` list, its own or inherited, with no `include`, such as the solution-style root with only `references` that `npm create vite` writes; an empty `include`; an `exclude` of every file. Any non-empty `include` that names a file or a folder is still judged, such as `"include": ["vite.config.ts"]` or `["src"]`, and so is a config that sets neither `files` nor `include`, since TypeScript then includes every file. An option a skipped file sets itself is still flagged, as in edition 1. The configs it references are not judged through it; only files named `tsconfig.json` are read.
|
|
1247
|
+
|
|
1248
|
+
## Settings
|
|
1249
|
+
- `edition`: the edition this clause runs, `"1"` or `"2"`. Without it, the clause runs edition 1, or the latest edition when `checkEditions` in `disciplines.json` is `"latest"`.
|
|
1250
|
+
|
|
1251
|
+
```jsonc
|
|
1252
|
+
"clauseSettings": {
|
|
1253
|
+
"CD-3#strict": { "edition": "2" }
|
|
1254
|
+
}
|
|
1255
|
+
```
|
|
1256
|
+
|
|
1257
|
+
## Example
|
|
1258
|
+
```jsonc
|
|
1259
|
+
{ "compilerOptions": { "strict": false } }
|
|
1260
|
+
```
|
|
1261
|
+
|
|
1262
|
+
## Fix
|
|
1263
|
+
```jsonc
|
|
1264
|
+
{ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "dist" } }
|
|
1265
|
+
```
|
|
1266
|
+
Put the flags in a shared base file that is not named `tsconfig.json`, and leave them out of every `tsconfig.json`. Under edition 1, that the base file turns them on is left to review. Under edition 2 the check reads the base: turn every selected flag on in it.
|
|
1267
|
+
|
|
1268
|
+
```jsonc
|
|
1269
|
+
{ "compilerOptions": { "strict": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, "noImplicitOverride": true, "noFallthroughCasesInSwitch": true, "noPropertyAccessFromIndexSignature": true, "useUnknownInCatchVariables": true } }
|
|
1270
|
+
```
|
|
1271
|
+
|
|
1272
|
+
### use-unknown-in-catch-variables
|
|
1273
|
+
|
|
1274
|
+
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1275
|
+
- **Misses:** edition 1: a base reached by `extends`.
|
|
1276
|
+
- **Settings traced to:** flag list: The type checker proves it. Edition 1 flags presence, which is the Shared strict base config recipe: **traced to a recipe, not a rule**.
|
|
1277
|
+
|
|
1278
|
+
`useUnknownInCatchVariables` is set in a `tsconfig.json`; edition 2 adds that it resolves to on.
|
|
1279
|
+
|
|
1280
|
+
## Flags
|
|
1281
|
+
Each strictness-weakened check has two editions. Edition 1 runs by default. Edition 2 also judges what each `tsconfig.json` inherits, and becomes the default in the next major release; see [Settings](#settings) to run it now.
|
|
1282
|
+
|
|
1283
|
+
Edition 1:
|
|
1284
|
+
- `tsconfig.json` files, named exactly, at any depth. `tsconfig.base.json` and other names are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1285
|
+
- For each selected clause, the matching option present in that file's `compilerOptions`. Presence is enough: `true` is flagged as well as `false`.
|
|
1286
|
+
- Options in `extends`-ed files are not seen. A file that cannot be parsed, or whose root or `compilerOptions` is not an object, fails the run.
|
|
1287
|
+
|
|
1288
|
+
Edition 2 also flags, for each selected option a `tsconfig.json` does not set itself, an option its resolved configuration leaves off:
|
|
1289
|
+
- The configuration is resolved by the repository's installed TypeScript, as `tsc` would resolve it: every file in the `extends` chain, a relative path, a package such as `@tsconfig/strictest` or a workspace package under `node_modules`, and an array of bases on TypeScript 5.0 or later, later bases winning. An option a base turns on and a later file turns off is off.
|
|
1290
|
+
- `strict` and `useUnknownInCatchVariables` take TypeScript's defaults: TypeScript 6 treats `strict` as on when nothing sets it, and `useUnknownInCatchVariables` follows `strict` unless it is set.
|
|
1291
|
+
- The finding names the file to edit. `= false, inherited from <base>` names each base that turns the option off. `= false, turned off in <file>` names this `tsconfig.json` when its own `"strict": false` turns `useUnknownInCatchVariables` off. `unset here and in <bases>` lists every file in the chain, none of which sets the option; `unset, and this file extends no base` says there is no chain.
|
|
1292
|
+
- A configuration TypeScript cannot resolve, such as a base file that is missing, a package that is not installed, or bases that extend each other, is flagged for each selected option the file does not set as `unknown`, followed by TypeScript's own diagnostic. An `extends` holding `${configDir}` resolves however the installed TypeScript resolves it, and is flagged the same way when TypeScript cannot find it. Fix the chain, and the options are judged.
|
|
1293
|
+
- The base files are judged through the `tsconfig.json` files that extend them, not on their own.
|
|
1294
|
+
- A `tsconfig.json` from which TypeScript would compile no file is not judged on what it resolves to, since its options apply to no file. After resolving the chain, TypeScript has no `files` entry, and no `include` entry that names a path outright or a folder or pattern it would search. Examples: an empty `files` list, its own or inherited, with no `include`, such as the solution-style root with only `references` that `npm create vite` writes; an empty `include`; an `exclude` of every file. Any non-empty `include` that names a file or a folder is still judged, such as `"include": ["vite.config.ts"]` or `["src"]`, and so is a config that sets neither `files` nor `include`, since TypeScript then includes every file. An option a skipped file sets itself is still flagged, as in edition 1. The configs it references are not judged through it; only files named `tsconfig.json` are read.
|
|
1295
|
+
|
|
1296
|
+
## Settings
|
|
1297
|
+
- `edition`: the edition this clause runs, `"1"` or `"2"`. Without it, the clause runs edition 1, or the latest edition when `checkEditions` in `disciplines.json` is `"latest"`.
|
|
1298
|
+
|
|
1299
|
+
```jsonc
|
|
1300
|
+
"clauseSettings": {
|
|
1301
|
+
"CD-3#use-unknown-in-catch-variables": { "edition": "2" }
|
|
1302
|
+
}
|
|
1303
|
+
```
|
|
1304
|
+
|
|
1305
|
+
## Example
|
|
1306
|
+
```jsonc
|
|
1307
|
+
{ "compilerOptions": { "strict": false } }
|
|
1308
|
+
```
|
|
1309
|
+
|
|
1310
|
+
## Fix
|
|
1311
|
+
```jsonc
|
|
1312
|
+
{ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "dist" } }
|
|
1313
|
+
```
|
|
1314
|
+
Put the flags in a shared base file that is not named `tsconfig.json`, and leave them out of every `tsconfig.json`. Under edition 1, that the base file turns them on is left to review. Under edition 2 the check reads the base: turn every selected flag on in it.
|
|
1315
|
+
|
|
1316
|
+
```jsonc
|
|
1317
|
+
{ "compilerOptions": { "strict": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, "noImplicitOverride": true, "noFallthroughCasesInSwitch": true, "noPropertyAccessFromIndexSignature": true, "useUnknownInCatchVariables": true } }
|
|
1318
|
+
```
|
|
1319
|
+
|
|
1320
|
+
## Tangled function
|
|
1321
|
+
|
|
1322
|
+
### cognitive-complexity
|
|
1323
|
+
|
|
1324
|
+
- **Settings traced to:** complexity 15: where a broad symptom fires (as above).
|
|
1325
|
+
|
|
1326
|
+
A function whose cognitive complexity is above 15.
|
|
1327
|
+
|
|
1328
|
+
## Flags
|
|
1329
|
+
|
|
1330
|
+
- The ESLint piece lints whatever files the team's ESLint run includes. It needs ESLint adopted through the projection; see the ESLint piece.
|
|
1331
|
+
- Under ESLint, each function's cognitive complexity must be at most 15.
|
|
1332
|
+
- An `if`, `else if`, `switch`, ternary, `catch` and each loop adds 1 plus the current nesting depth.
|
|
1333
|
+
- An `else`, a `finally`, a labelled `break` or `continue`, and each run of the same logical operator add 1.
|
|
1334
|
+
- Nesting deepens inside `if`, loops, `switch`, `catch` and ternaries.
|
|
1335
|
+
- A nested function is scored on its own, starting one level deeper, and its score is not added to its parent.
|
|
1336
|
+
- Reported at the function's name.
|
|
1337
|
+
|
|
1338
|
+
## Example
|
|
1339
|
+
|
|
1340
|
+
```ts
|
|
1341
|
+
const settle = (orders: Order[]) => {
|
|
1342
|
+
for (const order of orders) {
|
|
1343
|
+
if (order.paid) {
|
|
1344
|
+
for (const line of order.lines) {
|
|
1345
|
+
if (line.refundable && line.quantity > 0) {
|
|
1346
|
+
refund(line);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
```
|
|
1353
|
+
|
|
1354
|
+
## Fix
|
|
1355
|
+
|
|
1356
|
+
```ts
|
|
1357
|
+
const settle = (orders: Order[]) => orders.filter(isPaid).forEach(refundEligibleLines);
|
|
1358
|
+
```
|
|
1359
|
+
Move any computing or branching between calls into a named doer, so the orchestrator only composes calls.
|
|
1360
|
+
|
|
1361
|
+
## Test switched off
|
|
1362
|
+
|
|
1363
|
+
### focused-tests
|
|
1364
|
+
|
|
1365
|
+
- **Misses:** `.todo`.
|
|
1366
|
+
- **Settings traced to:** `.todo` not flagged: a miss.
|
|
1367
|
+
|
|
1368
|
+
`.only` on a test or suite, or `fdescribe`, `fit`, `ftest`, `fsuite`.
|
|
1369
|
+
|
|
1370
|
+
## Flags
|
|
1371
|
+
Needs ESLint adopted through the projection.
|
|
1372
|
+
- Under ESLint, this check flags `.only` on a `describe`, `it`, `test` or `suite` chain, including `.only.each` and `test.describe.only`, and the bare names `fdescribe`, `fit`, `ftest` and `fsuite`. It reports at the `only` token.
|
|
1373
|
+
- Not flagged: `.todo`, `.concurrent` and `.each`.
|
|
1374
|
+
|
|
1375
|
+
### skipped-tests
|
|
1376
|
+
|
|
1377
|
+
- **Misses:** `.todo`.
|
|
1378
|
+
- **Settings traced to:** `.todo` not flagged: a miss.
|
|
1379
|
+
|
|
1380
|
+
`.skip` or `.fixme` on a test or suite, or `xdescribe`, `xit`, `xtest`, `xsuite`.
|
|
1381
|
+
|
|
1382
|
+
## Flags
|
|
1383
|
+
Needs ESLint adopted through the projection.
|
|
1384
|
+
- Under ESLint, this check flags `.skip` and `.fixme` on those chains, and the bare names `xdescribe`, `xit`, `xtest` and `xsuite`.
|
|
1385
|
+
- Not flagged: `.todo`, `.concurrent` and `.each`.
|
|
1386
|
+
|
|
1387
|
+
## Text past its reader
|
|
1388
|
+
|
|
1389
|
+
### test-body
|
|
1390
|
+
|
|
1391
|
+
- **Misses:** production sites.
|
|
1392
|
+
- **Settings traced to:** the edition: backwards compatibility for adopters since the npm release.
|
|
1393
|
+
|
|
1394
|
+
Edition 2: `JSON.stringify` and `JSON.parse` in a test file. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
1395
|
+
|
|
1396
|
+
## Flags
|
|
1397
|
+
Edition 2:
|
|
1398
|
+
- `JSON.stringify` and `JSON.parse`. A finding names [Serialising or parsing JSON](#serialising-or-parsing-json).
|
|
1399
|
+
|
|
1400
|
+
## Allowed forms in a test
|
|
1401
|
+
|
|
1402
|
+
### Serialising or parsing JSON
|
|
1403
|
+
```ts
|
|
1404
|
+
declare const render: (row: { readonly id: string }) => string;
|
|
1405
|
+
expect(JSON.parse(render({ id: "a" }))).toEqual({ id: "a" });
|
|
1406
|
+
```
|
|
1407
|
+
A finding on `JSON.stringify` or `JSON.parse` names this section. Assert the object the unit gives back, written out:
|
|
1408
|
+
|
|
1409
|
+
```ts
|
|
1410
|
+
declare const rowOf: (row: { readonly id: string }) => { readonly id: string };
|
|
1411
|
+
expect(rowOf({ id: "a" })).toEqual({ id: "a" });
|
|
1412
|
+
```
|
|
1413
|
+
|
|
1414
|
+
A unit that gives back only text should hand over an object, leaving the text to the adapter at its edge.
|
|
1415
|
+
|
|
1416
|
+
## Throw or catch in a test
|
|
1417
|
+
|
|
1418
|
+
### throw-statement
|
|
1419
|
+
|
|
1420
|
+
- **Misses:** `catch`.
|
|
1421
|
+
- **Settings traced to:** none.
|
|
1422
|
+
|
|
1423
|
+
A `throw` statement in a test file.
|
|
1424
|
+
|
|
1425
|
+
## Flags
|
|
1426
|
+
- Test files only: `*.test.ts` and `*.test.tsx`. `*.spec.ts` and `.js` tests are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1427
|
+
- Every `throw` statement, wherever it sits in the file.
|
|
1428
|
+
- Allowed: assertion calls such as `expect(...)`.
|
|
1429
|
+
- The source rule also confines throwing in production code to a closed list of contexts. The check does not look at production files; that part is left to review.
|
|
1430
|
+
|
|
1431
|
+
## Example
|
|
1432
|
+
```ts
|
|
1433
|
+
it("loads the account", () => {
|
|
1434
|
+
const result = load("a1");
|
|
1435
|
+
if (result.outcome === "failed") throw new Error("load failed");
|
|
1436
|
+
});
|
|
1437
|
+
```
|
|
1438
|
+
|
|
1439
|
+
## Fix
|
|
1440
|
+
```ts
|
|
1441
|
+
it("loads the account", () => {
|
|
1442
|
+
expect(load("a1")).toEqual({ outcome: "ok", value: account });
|
|
1443
|
+
});
|
|
1444
|
+
```
|
|
1445
|
+
Assert on the whole result. Branching in tests is also reported by [the branch-in-a-test check](symptoms/branch-in-a-test/test-body.md).
|
|
1446
|
+
|
|
1447
|
+
### try-block
|
|
1448
|
+
|
|
1449
|
+
- **Misses:** `catch`.
|
|
1450
|
+
- **Settings traced to:** none.
|
|
1451
|
+
|
|
1452
|
+
`try` statements in a test file. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
1453
|
+
|
|
1454
|
+
## Flags
|
|
1455
|
+
Edition 1:
|
|
1456
|
+
- `try` statements.
|
|
1457
|
+
|
|
1458
|
+
## Allowed forms in a test
|
|
1459
|
+
|
|
1460
|
+
### A try block
|
|
1461
|
+
```ts
|
|
1462
|
+
declare const load: (path: string) => string;
|
|
1463
|
+
try {
|
|
1464
|
+
load("missing.json");
|
|
1465
|
+
} catch (error) {
|
|
1466
|
+
expect(error).toBeInstanceOf(Error);
|
|
1467
|
+
}
|
|
1468
|
+
```
|
|
1469
|
+
Assert the throw:
|
|
1470
|
+
|
|
1471
|
+
```ts
|
|
1472
|
+
declare const load: (path: string) => string;
|
|
1473
|
+
expect(() => load("missing.json")).toThrow(Error);
|
|
1474
|
+
```
|
|
1475
|
+
|
|
1476
|
+
```ts
|
|
1477
|
+
declare const loadLater: (path: string) => Promise<string>;
|
|
1478
|
+
it("refuses a missing file", async () => {
|
|
1479
|
+
await expect(loadLater("missing.json")).rejects.toThrow(Error);
|
|
1480
|
+
});
|
|
1481
|
+
```
|
|
1482
|
+
|
|
1483
|
+
## Thrown non-error
|
|
1484
|
+
|
|
1485
|
+
### throw-only-error
|
|
1486
|
+
|
|
1487
|
+
- **Settings traced to:** none.
|
|
1488
|
+
|
|
1489
|
+
A `throw` of something that is not an error object.
|
|
1490
|
+
|
|
1491
|
+
## Flags
|
|
1492
|
+
Needs ESLint adopted through the projection.
|
|
1493
|
+
- Under ESLint, a `throw` of a literal, an object literal, a binary expression, a template or tagged template, or `undefined` is flagged. It follows the thrown value through `a ? b : c`, `a || b`, assignment and sequence expressions.
|
|
1494
|
+
- Allowed: `new Error(...)`, identifiers, calls and member access.
|
|
1495
|
+
- This clause applies to every file the ESLint run includes, not only tests.
|
|
1496
|
+
|
|
1497
|
+
## Type derived from code
|
|
1498
|
+
|
|
1499
|
+
### factory-return-types
|
|
1500
|
+
|
|
1501
|
+
- **Flags beyond the symptom:** text in comments.
|
|
1502
|
+
- **Misses:** `Parameters<typeof>`, `typeof` alone.
|
|
1503
|
+
- **Settings traced to:** none.
|
|
1504
|
+
|
|
1505
|
+
A line containing `ReturnType<typeof`.
|
|
1506
|
+
|
|
1507
|
+
## Flags
|
|
1508
|
+
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1509
|
+
- Any line matching `ReturnType<typeof`, one finding per line. This includes `Awaited<ReturnType<typeof ...>>` and matches inside strings.
|
|
1510
|
+
- Lines starting with `//`, `/*` or `*` are ignored. A `ReturnType<` and `typeof` split across lines are not seen.
|
|
1511
|
+
- The source rule's carve-out, an external library symbol with no exported return type, is not detected; record it as an exception.
|
|
1512
|
+
|
|
1513
|
+
## Example
|
|
1514
|
+
```ts
|
|
1515
|
+
type Client = ReturnType<typeof createClient>;
|
|
1516
|
+
```
|
|
1517
|
+
|
|
1518
|
+
## Fix
|
|
1519
|
+
```ts
|
|
1520
|
+
export type Client = { readonly send: (message: string) => void };
|
|
1521
|
+
const createClient = (): Client => ({ send: () => undefined });
|
|
1522
|
+
```
|
|
1523
|
+
Declare and export the type, then annotate the factory with it.
|
|
1524
|
+
|
|
1525
|
+
## Unit without a running test
|
|
1526
|
+
|
|
1527
|
+
### companion-test-file
|
|
1528
|
+
|
|
1529
|
+
- **Misses:** an empty or non-running sibling.
|
|
1530
|
+
- **Settings traced to:** `__tests__` skipped by default, on purpose (noise; the practice is not adopted). `exclude` is scope.
|
|
1531
|
+
|
|
1532
|
+
A production file with a runtime export and no `.test` sibling.
|
|
1533
|
+
|
|
1534
|
+
## Flags
|
|
1535
|
+
|
|
1536
|
+
- Production `.ts` and `.tsx` files. Skipped: `*.test.ts(x)`, `.d.ts` and anything under `__tests__`. Generated folders (`node_modules`, `dist`, `build`, `coverage`, `.git`, root `vendor`) are skipped; any other folder or file can be left out with `exclude` in disciplines.json.
|
|
1537
|
+
- A file with a runtime export (`export const`, `function`, `class`, `enum`, `export default`, or `export { name }`) and no `<name>.test.ts` beside it (`<name>.test.tsx` for `.tsx`). The sibling must be in the repository's file list.
|
|
1538
|
+
- Allowed: files with only `export type`, `export interface`, `export declare`, type-only named exports or `export * from`, and files with no exports.
|
|
1539
|
+
- The source rule asks for a test beside every source file; files without runtime exports are left to review.
|
|
1540
|
+
|
|
1541
|
+
## Example
|
|
1542
|
+
|
|
1543
|
+
```ts
|
|
1544
|
+
export const price = 1;
|
|
1545
|
+
```
|
|
1546
|
+
This is `src/price.ts` with no `src/price.test.ts` beside it.
|
|
1547
|
+
|
|
1548
|
+
## Fix
|
|
1549
|
+
|
|
1550
|
+
Add `src/price.test.ts` next to the file, with at least one test of its behaviour.
|
|
1551
|
+
|
|
1552
|
+
## Untracked escape
|
|
1553
|
+
|
|
1554
|
+
### directive-pointers
|
|
1555
|
+
|
|
1556
|
+
- **Settings traced to:** reference form "need a digit": **nothing**.
|
|
1557
|
+
|
|
1558
|
+
TODOs, linter directives and `@ts-expect-error` without a tracker.
|
|
1559
|
+
|
|
1560
|
+
## Flags
|
|
1561
|
+
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1562
|
+
- `// TODO` not followed, after optional spaces, by a tracked reference, for example `// TODO(#42) ...`.
|
|
1563
|
+
- A comment starting with `biome-ignore`, `eslint-disable`, `eslint-enable`, `eslint-disable-line`, `eslint-disable-next-line`, an `oxlint-` equivalent or `eslint <config>`, unless the comment carries a tracked reference.
|
|
1564
|
+
- A TypeScript directive without a tracked reference after it, in each form the compiler honours: `@ts-expect-error` or `@ts-ignore` opening a `//` or `///` comment, or opening the last line of a block comment after any `/` and `*`; and `@ts-nocheck`, in any letter case, opening a `//` or `///` comment among the comments that start the file. As in the compiler, `@ts-ignore` and `@ts-expect-error` are matched as written, so `@ts-ignored` counts and `@Ts-Ignore` does not. Forms the compiler ignores, such as `/* @ts-nocheck */`, a directive above a block comment's closing line, or `////`, are not flagged. `@ts-check` turns checking on and is not flagged.
|
|
1565
|
+
- A tracked reference is a parenthesised token with no spaces that contains a digit, such as `(#42)`, `(PROJ-7)`, `(spec-42)` or `(https://tracker.example/issues/42)`. `()`, `(legacy)` and `(issue 42)` are not tracked references.
|
|
1566
|
+
- TODO is matched on raw lines, so the same text inside a string is flagged too; linter and type directives are read from comments only.
|
|
1567
|
+
- Ordinary explanatory comments and JSDoc are not flagged; keeping them out is left to review.
|
|
1568
|
+
|
|
1569
|
+
## Settings
|
|
1570
|
+
`trackerPatterns` narrows which tracked references count, for example to your own tracker's format. Each entry is a regular expression, as JavaScript source text, tested against each tracked reference with its parentheses; a reference counts when any entry matches. The test is an unanchored search unless the pattern anchors itself with `^` and `$`. The default, `["^\\(\\S+\\)$"]`, lets every tracked reference count.
|
|
1571
|
+
|
|
1572
|
+
```jsonc
|
|
1573
|
+
"clauseSettings": {
|
|
1574
|
+
"CD-5#comments-directives": { "trackerPatterns": ["^\\(spec-\\d+\\)$", "^\\(#\\d+\\)$"] }
|
|
1575
|
+
}
|
|
1576
|
+
```
|
|
1577
|
+
|
|
1578
|
+
The patterns only narrow: a reference must still be a parenthesised token with no spaces that contains a digit, so a pattern such as `.*` cannot make `(legacy)` count. The same measure applies to TODO, where the reference must come right after `TODO`. Each entry must be a non-empty string that compiles as a regular expression; otherwise the check stops with a piece-invalid failure naming the clause and the entry.
|
|
1579
|
+
|
|
1580
|
+
## Example
|
|
1581
|
+
```ts
|
|
1582
|
+
// biome-ignore lint/style/noNonNullAssertion: legacy
|
|
1583
|
+
const first = items[0]!;
|
|
1584
|
+
```
|
|
1585
|
+
|
|
1586
|
+
## Fix
|
|
1587
|
+
```ts
|
|
1588
|
+
const first = items[0];
|
|
1589
|
+
```
|
|
1590
|
+
Remove the need for the directive. If it must stay, add a tracked reference to the work that removes it: `// biome-ignore lint/style/noNonNullAssertion: until items is typed as non-empty (#42)`. The reference satisfies this clause only. A directive that escapes a selected clause, such as an `eslint-disable` naming a selected rule or a `@ts-expect-error` under [unlisted-cast-site](symptoms/claimed-type/unlisted-cast-site.md), still needs a file record on that clause, and that record does not satisfy this clause.
|
|
1591
|
+
|
|
1592
|
+
## Untyped value
|
|
1593
|
+
|
|
1594
|
+
### explicit-any
|
|
1595
|
+
|
|
1596
|
+
- **Settings traced to:** none.
|
|
1597
|
+
|
|
1598
|
+
An `any` type anywhere in a type position.
|
|
1599
|
+
|
|
1600
|
+
## Flags
|
|
1601
|
+
Needs ESLint adopted through the projection.
|
|
1602
|
+
- Under ESLint, this is typescript-eslint's `no-explicit-any` with default options. It flags every `any` type: annotations, type arguments such as `Map<string, any>`, and `as any`.
|
|
1603
|
+
- Allowed: `unknown`, `let total = 0` and `let total: number`.
|
|
1604
|
+
|
|
1605
|
+
### implicit-any-let
|
|
1606
|
+
|
|
1607
|
+
- **Settings traced to:** none.
|
|
1608
|
+
|
|
1609
|
+
A `let` or `var` with neither a type annotation nor an initialiser.
|
|
1610
|
+
|
|
1611
|
+
## Flags
|
|
1612
|
+
Needs ESLint adopted through the projection.
|
|
1613
|
+
- Under ESLint, this flags a `let` or `var` declaration in a `.ts` or `.tsx` file that has neither a type annotation nor an initialiser, one report per declaration at its first such binding. Declaration files (`.d.ts`), `const`, and `for-in` and `for-of` heads are not flagged.
|
|
1614
|
+
- Allowed: `unknown`, `let total = 0` and `let total: number`.
|
|
1615
|
+
|
|
1616
|
+
## Work inside a condition
|
|
1617
|
+
|
|
1618
|
+
### else-after-an-exit
|
|
1619
|
+
|
|
1620
|
+
- **Misses:** an `if` nested with no `else`.
|
|
1621
|
+
- **Settings traced to:** none.
|
|
1622
|
+
|
|
1623
|
+
An `else` after an `if` branch that always exits.
|
|
1624
|
+
|
|
1625
|
+
## Flags
|
|
1626
|
+
|
|
1627
|
+
- The ESLint piece lints whatever files the team's ESLint run includes. It needs ESLint adopted through the projection; see the ESLint piece.
|
|
1628
|
+
- Under ESLint, an `else` after an `if` branch that always exits is reported at the `else` keyword.
|
|
1629
|
+
- A branch always exits when it ends in `return`, `throw`, `continue`, or `break` outside a switch. A nested `if` exits when both of its branches do. A `switch` exits when every non-empty case does.
|
|
1630
|
+
- Along an `else if` chain whose earlier branches all exit, every `else` is reported.
|
|
1631
|
+
- Allowed: an `else` after a branch that can fall through.
|
|
1632
|
+
|
|
1633
|
+
## Example
|
|
1634
|
+
|
|
1635
|
+
```ts
|
|
1636
|
+
const label = (order: Order) => {
|
|
1637
|
+
if (order.cancelled) {
|
|
1638
|
+
return "cancelled";
|
|
1639
|
+
} else {
|
|
1640
|
+
return "active";
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
```
|
|
169
1644
|
|
|
170
|
-
|
|
1645
|
+
## Fix
|
|
171
1646
|
|
|
172
|
-
|
|
1647
|
+
```ts
|
|
1648
|
+
const label = (order: Order) => {
|
|
1649
|
+
if (order.cancelled) return "cancelled";
|
|
1650
|
+
return "active";
|
|
1651
|
+
};
|
|
1652
|
+
```
|
|
1653
|
+
Handle the unhappy path first with an early return and leave the happy path as the final return.
|
|
173
1654
|
|
|
174
|
-
|
|
175
|
-
|---|---|---|
|
|
176
|
-
| Strictness edition 1 flags a flag's presence | requires the recipe's layout, not strictness | a recipe, not a rule. "The older strictness check is probably just a flaw." |
|
|
177
|
-
| `.todo` not flagged | a test that does not run passes | a miss. "Todo not flagged is probably just a false negative." |
|
|
178
|
-
| Accepted helper names | The subprocess-environment check passes a git spawn when its `env:` option mentions one of three hard-coded identifiers: `hermeticGitEnvironment`, `withoutInheritedGitBindings` or `environment`. It matches the name, not what the value holds, so any variable called `environment` passes. | nothing; a margin of the check (it misses by name) |
|
|
179
|
-
| Casing fixed inside Hone | Today file names must be kebab-case or PascalCase, both allowed everywhere, hard-coded. Identifier casing is a fixed option list in Hone's own piece, built on typescript-eslint's naming-convention. The adopter declares neither. | nothing. "Casing should be config from adopter to declare for consistency but requires the folder nuance settings." |
|
|
180
|
-
| Tracked-reference form | which TODO counts as tracked | nothing yet |
|
|
1655
|
+
## Write into a parameter
|
|
181
1656
|
|
|
182
|
-
|
|
1657
|
+
### parameter-mutation
|
|
183
1658
|
|
|
184
|
-
|
|
185
|
-
|---|---|
|
|
186
|
-
| 50-line limit, complexity 15 | where two broad symptoms fire; they change no rule |
|
|
187
|
-
| `max-params: 2` | a recorded compromise of the check; its miss is margin |
|
|
188
|
-
| `exclude` | scope chosen by the codebase |
|
|
189
|
-
| Edition defaults | "Edition defaults would be for backwards compatability since we went npm." An existing adopter keeps the behaviour it installed. |
|
|
190
|
-
| `confinedPackages` empty by default | "packages is empty because we can't define the universe and if we just said imports at all we would catch internal packages." Seeing every outside dependency needs a way to tell it from an internal package; until then the list is the adopter's to fill. |
|
|
191
|
-
| `__tests__` skipped by default | "probably because of noise level and the fact I don't adopt that folder practice deliberately at all." |
|
|
192
|
-
| `.spec.ts` not treated as a test file by most checks | "Spec is also just not a naming practice I use." Then: "It honestly should be config for user to declare file naming structure so we can match their conventions." Hone has no such config yet; the Companion test file and Integration test suffix recipes are the convention it reads. |
|
|
193
|
-
| Generated folders skipped (`node_modules`, `dist` and the like) | not code of ours |
|
|
194
|
-
| Reading `.test.js` and `.test.mjs` in the subprocess-environment check | it widens one check, not narrows a rule |
|
|
195
|
-
| Suite-body exemption | "A test suite's body is a list of cases, not a coordinator." |
|
|
196
|
-
| Drawer names | Screaming folders |
|
|
197
|
-
| Shorthand list | Whole words |
|
|
198
|
-
| `as const` | Declared, not asserted |
|
|
199
|
-
| Integration suffix | its recipe |
|
|
1659
|
+
- **Settings traced to:** none.
|
|
200
1660
|
|
|
201
|
-
|
|
1661
|
+
Assignment to, deletion from or in-place methods on a parameter's fields.
|
|
202
1662
|
|
|
203
|
-
|
|
1663
|
+
## Flags
|
|
204
1664
|
|
|
205
|
-
|
|
206
|
-
-
|
|
207
|
-
-
|
|
1665
|
+
- `.ts` and `.tsx` files, including tests and declaration files; generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1666
|
+
- Inside a function declaration, function expression, arrow function or method, where the root name is one of its parameters (including destructured and outer-function parameters):
|
|
1667
|
+
- `parameter.field = value` and `parameter.a[0].b = value`
|
|
1668
|
+
- `delete parameter.field`
|
|
1669
|
+
- `parameter.push(...)`, `pop`, `shift`, `unshift`, `splice`, `sort`, `reverse`, `fill`, `copyWithin`
|
|
1670
|
+
- Not detected: reassigning the parameter, `+=` and `++`, `Map.set`, and mutation through an alias (`const copy = input; copy.x = 1`).
|
|
208
1671
|
|
|
209
|
-
|
|
210
|
-
- It **smooths** a second convention, by choosing which convention a check measures a folder against.
|
|
211
|
-
- It **marks generated code** as an outside party's code at a boundary, under that boundary's record.
|
|
1672
|
+
## Example
|
|
212
1673
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
1674
|
+
```ts
|
|
1675
|
+
const addTotal = (order: Order) => {
|
|
1676
|
+
order.total = 10;
|
|
1677
|
+
};
|
|
1678
|
+
```
|
|
216
1679
|
|
|
217
|
-
|
|
1680
|
+
## Fix
|
|
218
1681
|
|
|
219
|
-
|
|
1682
|
+
```ts
|
|
1683
|
+
const withTotal = (order: Order): Order => ({ ...order, total: 10 });
|
|
1684
|
+
```
|
|
1685
|
+
Copy before sorting or reversing: `[...items].sort()`.
|