@hailstails/hone 2.0.0-pre.3 → 2.0.0-pre.5
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 +9 -20
- package/CHANGELOG.md +104 -0
- package/MIGRATING.md +18 -9
- package/README.md +15 -17
- package/chunks/chunk-3CWFUD5B.js +38 -0
- package/chunks/chunk-4AJQHZ7I.js +191 -0
- package/chunks/chunk-5AKHEW6V.js +15 -0
- package/chunks/{chunk-L7BGRC6D.js → chunk-6LTJRJOE.js} +1 -1
- package/chunks/chunk-75XWZYNN.js +64 -0
- package/chunks/{chunk-ASUN4AVC.js → chunk-BISP2JOL.js} +73 -9
- package/chunks/chunk-COQMPHWZ.js +37 -0
- package/chunks/chunk-D6645WPB.js +6 -0
- package/chunks/chunk-DJMF6JIM.js +42 -0
- package/chunks/chunk-EBX57Z3V.js +8 -0
- package/chunks/chunk-EFUWHLZK.js +426 -0
- package/chunks/chunk-FHVNKG5Q.js +19 -0
- package/chunks/{chunk-NRIQD3PI.js → chunk-FRE5IA3C.js} +3 -5
- package/chunks/{chunk-OKLYWD2Z.js → chunk-GMLT3MHO.js} +262 -257
- package/chunks/{chunk-QP5TLOBY.js → chunk-HVZVKZPW.js} +12 -9
- package/chunks/chunk-LEFM7OPS.js +41 -0
- package/chunks/chunk-LNMDMRGQ.js +51 -0
- package/chunks/chunk-M4VSJ27S.js +139 -0
- package/chunks/{chunk-RGSHTPLA.js → chunk-MBEDAFVC.js} +3 -11
- package/chunks/chunk-ND3EOGDK.js +2350 -0
- package/chunks/chunk-ONDBACCR.js +14332 -0
- package/chunks/chunk-OO5KV7KN.js +17 -0
- package/chunks/chunk-SKDQ3QJD.js +75 -0
- package/chunks/chunk-U6W65ZOF.js +86 -0
- package/chunks/chunk-W5OIAUDW.js +18 -0
- package/chunks/{chunk-GNOMK7CR.js → chunk-WPEOCLTP.js} +495 -52
- package/chunks/chunk-X73RZUPO.js +63 -0
- package/chunks/chunk-XE2KKWYH.js +45 -0
- package/chunks/chunk-XNIXPQQ5.js +179 -0
- package/chunks/chunk-YONPKP3C.js +15 -0
- package/docs/adding-a-discipline-or-mechanism.md +1 -1
- package/docs/extending.md +7 -388
- package/methods/lenses/function-first.md +2 -2
- package/package.json +7 -6
- package/rules/README.md +7 -5
- package/rules/SPIRIT.md +1 -1
- package/rules/numbers.md +4 -4
- package/rules/principles/no-leak-across-a-boundary.md +1 -1
- package/rules/principles.md +1 -1
- package/rules/record-kinds/authorised-location.md +1 -1
- package/rules/records.md +11 -19
- package/rules/rules.md +5 -5
- package/rules/sources.md +6 -7
- package/rules/typescript/checks.md +280 -394
- package/rules/typescript/recipes/adapter-per-outside-party.md +10 -5
- package/rules/typescript/recipes/assert-to-narrow.md +114 -4
- package/rules/typescript/recipes/closure-factory.md +5 -5
- package/rules/typescript/recipes/companion-test-file.md +5 -3
- package/rules/typescript/recipes/composed-orchestrator.md +6 -4
- package/rules/typescript/recipes/composition-root.md +5 -3
- package/rules/typescript/recipes/{bounded-context-generic.md → constrained-context-generic.md} +6 -4
- package/rules/typescript/recipes/copy-never-write-in.md +6 -4
- package/rules/typescript/recipes/declared-not-bundled.md +5 -3
- package/rules/typescript/recipes/dependency-record.md +5 -3
- package/rules/typescript/recipes/domain-vocabulary-list.md +5 -3
- package/rules/typescript/recipes/entity-module.md +8 -5
- package/rules/typescript/recipes/exact-pins-and-a-lock-file.md +5 -3
- package/rules/typescript/recipes/extension-outside-the-vendored-code.md +5 -3
- package/rules/typescript/recipes/failure-asserted-as-a-value.md +44 -4
- package/rules/typescript/recipes/failure-mapping-at-the-adapter.md +8 -5
- package/rules/typescript/recipes/fix-the-declaration-not-the-value.md +5 -3
- package/rules/typescript/recipes/functional-iteration.md +8 -3
- package/rules/typescript/recipes/guard-clauses.md +5 -3
- package/rules/typescript/recipes/integration-test-owns-its-scratch.md +5 -3
- package/rules/typescript/recipes/integration-test-suffix.md +5 -3
- package/rules/typescript/recipes/it-each-over-typed-rows.md +117 -0
- package/rules/typescript/recipes/map-out-at-the-adapter.md +36 -4
- package/rules/typescript/recipes/meaning-in-names-not-comments.md +5 -5
- package/rules/typescript/recipes/named-exported-type.md +5 -3
- package/rules/typescript/recipes/narrow-ports.md +5 -3
- package/rules/typescript/recipes/one-argument-object.md +8 -3
- package/rules/typescript/recipes/{port-in-the-domain.md → port-in-a-module-of-its-own.md} +7 -5
- package/rules/typescript/recipes/ports-in-the-argument.md +5 -3
- package/rules/typescript/recipes/repo-scripts-only.md +5 -3
- package/rules/typescript/recipes/result-union.md +5 -5
- package/rules/typescript/recipes/screaming-folders.md +5 -5
- package/rules/typescript/recipes/shared-strict-base-config.md +5 -5
- package/rules/typescript/recipes/stub-with-vi-fn.md +130 -0
- package/rules/typescript/recipes/tagged-union-and-exhaustive-switch.md +5 -3
- package/rules/typescript/recipes/whole-words.md +5 -3
- package/rules/typescript/recipes/whole-written-out-expectation.md +284 -4
- package/rules/typescript/recipes/world-values-through-a-port.md +5 -3
- package/rules/typescript/recipes/zod-at-the-producers-adapter.md +8 -3
- package/rules/typescript/recipes.md +567 -21
- package/rules/typescript/symptoms/ambient-randomness/random-call.md +10 -0
- package/rules/typescript/symptoms/ambient-randomness.md +1 -1
- package/rules/typescript/symptoms/answer-set-in-a-hook/hook-answer.md +10 -0
- package/rules/typescript/symptoms/answer-set-in-a-hook.md +1 -1
- package/rules/typescript/symptoms/assertion-outside-a-test-body/assertion-site.md +10 -0
- package/rules/typescript/symptoms/assertion-outside-a-test-body.md +25 -0
- package/rules/typescript/symptoms/branch-in-a-test/test-body.md +10 -184
- package/rules/typescript/symptoms/branch-in-a-test.md +11 -1
- package/rules/typescript/symptoms/built-unit-called-in-place/call-of-a-call.md +10 -0
- package/rules/typescript/symptoms/built-unit-called-in-place.md +25 -0
- package/rules/typescript/symptoms/claimed-type/non-null-assertions.md +1 -1
- package/rules/typescript/symptoms/code-or-prose-read-as-text-in-a-test/raw-read.md +10 -0
- package/rules/typescript/symptoms/code-or-prose-read-as-text-in-a-test.md +31 -0
- package/rules/typescript/symptoms/computed-value-in-a-test/test-body.md +26 -117
- package/rules/typescript/symptoms/computed-value-in-a-test.md +1 -1
- package/rules/typescript/symptoms/date-used-directly.md +1 -1
- package/rules/typescript/symptoms/default-for-a-required-value.md +1 -1
- package/rules/typescript/symptoms/double-with-a-body/logic-in-a-passed-function.md +2 -19
- package/rules/typescript/symptoms/double-with-a-body/stub-implementation.md +2 -2
- package/rules/typescript/symptoms/double-with-a-body.md +1 -1
- package/rules/typescript/symptoms/export-from-a-test/test-file-export.md +10 -0
- package/rules/typescript/symptoms/export-from-a-test.md +33 -0
- package/rules/typescript/symptoms/failure-shaped-as-success/empty-catch.md +10 -0
- package/rules/typescript/symptoms/failure-shaped-as-success.md +1 -1
- package/rules/typescript/symptoms/floating-version/version-selector.md +10 -0
- package/rules/typescript/symptoms/inherited-environment-in-a-subprocess/git-spawn-environment.md +2 -2
- package/rules/typescript/symptoms/inner-layer-imports-outer.md +1 -1
- package/rules/typescript/symptoms/library-class-built-in-place.md +1 -1
- package/rules/typescript/symptoms/loop-keyword/loop-statement.md +1 -1
- package/rules/typescript/symptoms/many-spellings-of-one-concept/test-call-aliases.md +10 -0
- package/rules/typescript/symptoms/many-spellings-of-one-concept.md +3 -2
- package/rules/typescript/symptoms/module-or-global-patched/module-mock-call.md +4 -4
- package/rules/typescript/symptoms/no-lock-file/committed-lock-file.md +12 -0
- package/rules/typescript/symptoms/outside-import-past-a-boundary/import-or-require.md +1 -0
- package/rules/typescript/symptoms/outside-import-past-a-boundary.md +5 -4
- package/rules/typescript/symptoms/outside-type-in-a-signature.md +2 -2
- package/rules/typescript/symptoms/{port-outside-the-domain.md → port-beside-its-adapter.md} +2 -2
- package/rules/typescript/symptoms/port-named-for-a-mechanism.md +1 -1
- package/rules/typescript/symptoms/process-global-used-in-place/debugger-statement.md +10 -0
- package/rules/typescript/symptoms/process-global-used-in-place/direct-global-use.md +14 -0
- package/rules/typescript/symptoms/process-global-used-in-place.md +2 -2
- package/rules/typescript/symptoms/prose-in-code/comment-prose.md +12 -0
- package/rules/typescript/symptoms/rebinding/test-body.md +1 -18
- package/rules/typescript/symptoms/rebinding.md +11 -1
- package/rules/typescript/symptoms/schema-past-its-adapter.md +2 -2
- package/rules/typescript/symptoms/test-switched-off/skipped-tests.md +3 -6
- package/rules/typescript/symptoms/test-switched-off.md +1 -1
- package/rules/typescript/symptoms/text-past-its-reader/test-body.md +2 -17
- package/rules/typescript/symptoms/text-past-its-reader.md +1 -1
- package/rules/typescript/symptoms/throw-between-our-units/throw-statement.md +10 -0
- package/rules/typescript/symptoms/throw-or-catch-in-a-test/throw-statement.md +1 -1
- package/rules/typescript/symptoms/throw-or-catch-in-a-test/try-block.md +1 -25
- package/rules/typescript/symptoms/tool-fetched-at-run-time/fetch-command.md +10 -0
- package/rules/typescript/symptoms/type-declared-in-a-test/test-type-declaration.md +10 -0
- package/rules/typescript/symptoms/type-declared-in-a-test.md +33 -0
- package/rules/typescript/symptoms/unasserted-call.md +1 -1
- package/rules/typescript/symptoms/unit-without-a-running-test/companion-test-file.md +2 -2
- package/rules/typescript/symptoms/wide-input/unread-parameter.md +10 -0
- package/rules/typescript/symptoms/wide-input.md +3 -2
- package/rules/typescript/symptoms.md +210 -148
- package/src/application/conformance/conformance-testing-types.d.ts +13 -16
- package/src/domain/language-layer/authored-item-types.d.ts +66 -0
- package/src/domain/language-layer/catalogue-name.d.ts +5 -0
- package/src/domain/language-layer/check-address-text.d.ts +12 -0
- package/src/domain/rule-set/authored-rule-set-types.d.ts +31 -32
- package/src/domain/rule-set/clause-address-types.d.ts +4 -3
- package/src/domain/rule-set/rule-set-name-of.d.ts +10 -0
- package/src/domain/runner/check-binding.d.ts +18 -0
- package/src/domain/runner/check-observations.d.ts +39 -0
- package/src/domain/runner/conformance-types.d.ts +8 -2
- package/src/domain/runner/runner-result-types.d.ts +1 -2
- package/src/domain/settings/test-files.d.ts +7 -0
- package/src/eslint-plugin.js +45 -39
- package/src/hone.js +16 -13716
- package/src/infrastructure/disciplines-file/version-one-names.json +4 -5
- package/src/infrastructure/engines/eslint/authored-class-or-this/static-members-only/piece.json +0 -6
- package/src/infrastructure/engines/eslint/long-function/function-length/piece.json +0 -6
- package/src/infrastructure/engines/eslint/runner/pieces/eslint-piece-settings-types.d.ts +2 -0
- package/src/infrastructure/engines/eslint/runner/runner.js +1001 -1234
- package/src/infrastructure/engines/eslint/test-switched-off/focused-tests/README.md +0 -3
- package/src/infrastructure/engines/eslint/test-switched-off/focused-tests/eslint-plugin.js +33 -21
- package/src/infrastructure/engines/eslint/test-switched-off/skipped-tests/piece.json +11 -4
- package/src/infrastructure/engines/eslint/test-switched-off/skipped-tests/skipped-tests.examples.json +28 -0
- package/src/infrastructure/engines/eslint/untyped-value/implicit-any-let/piece.json +0 -2
- package/src/infrastructure/engines/eslint/wide-input/unread-parameter/eslint-plugin.js +94 -0
- package/src/infrastructure/engines/eslint/wide-input/unread-parameter/piece.json +11 -0
- package/src/infrastructure/engines/eslint/wide-input/unread-parameter/unread-parameter.examples.json +48 -0
- package/src/infrastructure/engines/walker/ambient-randomness/random-call/ambient-randomness.js +109 -0
- package/src/infrastructure/engines/walker/ambient-randomness/random-call/piece.json +9 -0
- package/src/infrastructure/engines/walker/ambient-randomness/random-call/random-call.examples.json +48 -0
- package/src/infrastructure/engines/walker/answer-set-in-a-hook/hook-answer/hook-answer.examples.json +42 -0
- package/src/infrastructure/engines/walker/answer-set-in-a-hook/hook-answer/hook-answers.js +72 -0
- package/src/infrastructure/engines/walker/answer-set-in-a-hook/hook-answer/piece.json +9 -0
- package/src/infrastructure/engines/walker/assertion-outside-a-test-body/assertion-site/assertion-site.examples.json +30 -0
- package/src/infrastructure/engines/walker/assertion-outside-a-test-body/assertion-site/assertion-site.js +123 -0
- package/src/infrastructure/engines/walker/assertion-outside-a-test-body/assertion-site/piece.json +9 -0
- package/src/infrastructure/engines/walker/authored-class-or-this/class-keyword/class-syntax.js +3 -3
- package/src/infrastructure/engines/walker/boolean-in-a-signature/boolean-annotation/boolean-signatures.js +7 -5
- package/src/infrastructure/engines/walker/branch-in-a-test/test-body/test-body-logic.js +192 -147
- package/src/infrastructure/engines/walker/built-unit-called-in-place/call-of-a-call/call-of-a-call.examples.json +24 -0
- package/src/infrastructure/engines/walker/built-unit-called-in-place/call-of-a-call/call-of-a-call.js +34 -0
- package/src/infrastructure/engines/walker/built-unit-called-in-place/call-of-a-call/piece.json +9 -0
- package/src/infrastructure/engines/walker/claimed-type/cast-to-any/any-cast.js +6 -4
- package/src/infrastructure/engines/walker/claimed-type/unlisted-cast-site/cast-expressions.js +6 -4
- package/src/infrastructure/engines/walker/code-or-prose-read-as-text-in-a-test/raw-read/piece.json +9 -0
- package/src/infrastructure/engines/walker/code-or-prose-read-as-text-in-a-test/raw-read/raw-read.examples.json +30 -0
- package/src/infrastructure/engines/walker/code-or-prose-read-as-text-in-a-test/raw-read/raw-read.js +166 -0
- package/src/infrastructure/engines/walker/computed-value-in-a-test/test-body/piece.json +0 -10
- package/src/infrastructure/engines/walker/date-used-directly/clock-sources/clock-sources.js +4 -4
- package/src/infrastructure/engines/walker/default-on-a-closed-union/default-arm/switch-defaults.js +8 -6
- package/src/infrastructure/engines/walker/double-with-a-body/logic-in-a-passed-function/piece.json +0 -10
- package/src/infrastructure/engines/walker/double-with-a-body/stub-implementation/dependency-isolation.js +9 -14
- package/src/infrastructure/engines/walker/drawer-path/drawer-names/categorical-paths.js +4 -4
- package/src/infrastructure/engines/walker/export-from-a-test/test-file-export/piece.json +9 -0
- package/src/infrastructure/engines/walker/export-from-a-test/test-file-export/test-file-export.examples.json +30 -0
- package/src/infrastructure/engines/walker/export-from-a-test/test-file-export/test-file-export.js +31 -0
- package/src/infrastructure/engines/walker/failure-shaped-as-success/empty-catch/empty-catch.examples.json +18 -0
- package/src/infrastructure/engines/walker/failure-shaped-as-success/empty-catch/empty-catch.js +32 -0
- package/src/infrastructure/engines/walker/failure-shaped-as-success/empty-catch/piece.json +9 -0
- package/src/infrastructure/engines/walker/floating-version/version-selector/piece.json +9 -0
- package/src/infrastructure/engines/walker/floating-version/version-selector/version-selector.examples.json +54 -0
- package/src/infrastructure/engines/walker/floating-version/version-selector/version-selector.js +75 -0
- package/src/infrastructure/engines/walker/inherited-environment-in-a-subprocess/git-spawn-environment/hermetic-git-spawns.js +8 -17
- package/src/infrastructure/engines/walker/loop-keyword/loop-statement/loops.js +8 -6
- package/src/infrastructure/engines/walker/many-spellings-of-one-concept/test-call-aliases/piece.json +9 -0
- package/src/infrastructure/engines/walker/many-spellings-of-one-concept/test-call-aliases/test-call-aliases.examples.json +36 -0
- package/src/infrastructure/engines/walker/many-spellings-of-one-concept/test-call-aliases/test-call-aliases.js +67 -0
- package/src/infrastructure/engines/walker/module-or-global-patched/module-mock-call/module-mock-call.examples.json +34 -0
- package/src/infrastructure/engines/walker/module-or-global-patched/module-mock-call/module-mocking.js +64 -16
- package/src/infrastructure/engines/walker/module-or-global-patched/module-mock-call/piece.json +5 -1
- package/src/infrastructure/engines/walker/no-lock-file/committed-lock-file/committed-lock-file.examples.json +24 -0
- package/src/infrastructure/engines/walker/no-lock-file/committed-lock-file/committed-lock-file.js +41 -0
- package/src/infrastructure/engines/walker/no-lock-file/committed-lock-file/piece.json +9 -0
- package/src/infrastructure/engines/walker/outside-import-past-a-boundary/import-or-require/import-boundaries.js +18 -16
- package/src/infrastructure/engines/walker/outside-import-past-a-boundary/import-or-require/piece.json +1 -1
- package/src/infrastructure/engines/walker/process-global-used-in-place/debugger-statement/debugger-statement.examples.json +18 -0
- package/src/infrastructure/engines/walker/process-global-used-in-place/debugger-statement/debugger-statement.js +17 -0
- package/src/infrastructure/engines/walker/process-global-used-in-place/debugger-statement/piece.json +9 -0
- package/src/infrastructure/engines/walker/process-global-used-in-place/direct-global-use/direct-global-use.examples.json +63 -0
- package/src/infrastructure/engines/walker/process-global-used-in-place/direct-global-use/piece.json +13 -0
- package/src/infrastructure/engines/walker/process-global-used-in-place/direct-global-use/process-global-used-in-place.js +126 -0
- package/src/infrastructure/engines/walker/prose-in-code/comment-prose/comment-prose.examples.json +42 -0
- package/src/infrastructure/engines/walker/prose-in-code/comment-prose/piece.json +16 -0
- package/src/infrastructure/engines/walker/prose-in-code/comment-prose/prose-in-code.js +90 -0
- package/src/infrastructure/engines/walker/rebinding/test-body/piece.json +0 -10
- package/src/infrastructure/engines/walker/runner/pieces/walker-piece.d.ts +7 -5
- package/src/infrastructure/engines/walker/runner/runner.js +268 -79
- package/src/infrastructure/engines/walker/runner/toolchain/typescript-parse.d.ts +3 -0
- package/src/infrastructure/engines/walker/shorthand-name/identifier-names/identifier-names.js +12 -7
- package/src/infrastructure/engines/walker/strictness-weakened/exact-optional-property-types/piece.json +0 -10
- package/src/infrastructure/engines/walker/strictness-weakened/no-fallthrough-cases-in-switch/piece.json +0 -10
- package/src/infrastructure/engines/walker/strictness-weakened/no-implicit-override/piece.json +0 -10
- package/src/infrastructure/engines/walker/strictness-weakened/no-property-access-from-index-signature/piece.json +0 -10
- package/src/infrastructure/engines/walker/strictness-weakened/no-unchecked-indexed-access/piece.json +0 -10
- package/src/infrastructure/engines/walker/strictness-weakened/strict/compiler-overrides.js +30 -52
- package/src/infrastructure/engines/walker/strictness-weakened/use-unknown-in-catch-variables/piece.json +0 -10
- package/src/infrastructure/engines/walker/text-past-its-reader/test-body/piece.json +0 -10
- package/src/infrastructure/engines/walker/throw-between-our-units/throw-statement/piece.json +9 -0
- package/src/infrastructure/engines/walker/throw-between-our-units/throw-statement/throw-statement.examples.json +36 -0
- package/src/infrastructure/engines/walker/throw-between-our-units/throw-statement/throws-in-production.js +12 -0
- package/src/infrastructure/engines/walker/throw-or-catch-in-a-test/throw-statement/throw-statement.examples.json +6 -6
- package/src/infrastructure/engines/walker/throw-or-catch-in-a-test/throw-statement/throws-in-tests.js +5 -44
- package/src/infrastructure/engines/walker/throw-or-catch-in-a-test/try-block/piece.json +0 -10
- package/src/infrastructure/engines/walker/tool-fetched-at-run-time/fetch-command/fetch-command.examples.json +42 -0
- package/src/infrastructure/engines/walker/tool-fetched-at-run-time/fetch-command/fetch-command.js +152 -0
- package/src/infrastructure/engines/walker/tool-fetched-at-run-time/fetch-command/piece.json +9 -0
- package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/piece.json +9 -0
- package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.examples.json +36 -0
- package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.js +141 -0
- package/src/infrastructure/engines/walker/type-derived-from-code/factory-return-types/factory-return-types.js +8 -6
- package/src/infrastructure/engines/walker/unit-without-a-running-test/companion-test-file/export-test-sibling.js +16 -10
- package/src/infrastructure/engines/walker/untracked-escape/directive-pointers/comments-directives.js +18 -64
- package/src/infrastructure/engines/walker/write-into-a-parameter/parameter-mutation/parameter-mutation.js +7 -5
- package/src/measure-engines.process.js +80 -0
- package/src/rule-set.d.ts +2 -1
- package/src/testing.d.ts +2 -4
- package/src/testing.js +173 -314
- package/src/{audit.d.ts → walker.d.ts} +13 -8
- package/src/walker.js +28 -0
- package/chunks/chunk-5HRMJ4O2.js +0 -608
- package/chunks/chunk-IX2VZTBO.js +0 -887
- package/chunks/chunk-K2W3D3NB.js +0 -17
- package/chunks/chunk-M6SOGWT7.js +0 -82
- package/chunks/chunk-Q62Y25WS.js +0 -843
- package/chunks/chunk-R75QELTA.js +0 -481
- package/chunks/chunk-RANAKCTW.js +0 -31
- package/chunks/chunk-TNY2PASL.js +0 -38
- package/chunks/chunk-UJONWHA4.js +0 -22
- package/docs/output-contract.md +0 -1155
- package/rules/record-kinds/boundary-record.md +0 -9
- package/rules/typescript/recipes/iteach-over-typed-rows.md +0 -18
- package/rules/typescript/recipes/stub-with-vifn.md +0 -20
- package/src/audit.js +0 -18
- package/src/domain/runner/runner-module-types.d.ts +0 -15
|
@@ -1,9 +1,40 @@
|
|
|
1
1
|
# Checks in TypeScript
|
|
2
2
|
|
|
3
|
+
## Ambient randomness
|
|
4
|
+
|
|
5
|
+
### random-call
|
|
6
|
+
|
|
7
|
+
- **Engines:** `walker`
|
|
8
|
+
- **Misses:** Local variable aliases, self.crypto, and crypto obtained through ordinary require calls or dynamic imports.
|
|
9
|
+
- **Settings traced to:** None.
|
|
10
|
+
|
|
11
|
+
Direct calls to `Math.random`, `crypto.randomUUID` and `crypto.getRandomValues`. The check follows `globalThis.crypto`, `window.crypto` and static Node crypto imports, including `import = require` and access through a module’s `webcrypto` export. Locally bound receivers from other sources pass.
|
|
12
|
+
|
|
13
|
+
## Answer set in a hook
|
|
14
|
+
|
|
15
|
+
### hook-answer
|
|
16
|
+
|
|
17
|
+
- **Engines:** `walker`
|
|
18
|
+
- **Misses:** Named hook callbacks and alias calls.
|
|
19
|
+
- **Settings traced to:** None.
|
|
20
|
+
|
|
21
|
+
Stub answers set in inline test lifecycle callbacks.
|
|
22
|
+
|
|
23
|
+
## Assertion outside a test body
|
|
24
|
+
|
|
25
|
+
### assertion-site
|
|
26
|
+
|
|
27
|
+
- **Engines:** `walker`
|
|
28
|
+
- **Misses:** Assertions called through another wrapper or a Vitest namespace import. A test registered through a shared fixture module or a mutable alias may be reported as outside a test. Asymmetric matchers and extension registration do not assert.
|
|
29
|
+
- **Settings traced to:** None.
|
|
30
|
+
|
|
31
|
+
An assertion in a hook, suite body or helper is detached from the test whose result it should determine. Put it in the test body that exercises the behaviour.
|
|
32
|
+
|
|
3
33
|
## Authored class or this
|
|
4
34
|
|
|
5
35
|
### class-keyword
|
|
6
36
|
|
|
37
|
+
- **Engines:** `walker`, `eslint`
|
|
7
38
|
- **Misses:** `this` outside a class.
|
|
8
39
|
- **Settings traced to:** none.
|
|
9
40
|
|
|
@@ -31,6 +62,7 @@ Return an object of functions from a factory that closes over its state.
|
|
|
31
62
|
|
|
32
63
|
### static-members-only
|
|
33
64
|
|
|
65
|
+
- **Engines:** `eslint`
|
|
34
66
|
- **Misses:** `this` outside a class.
|
|
35
67
|
- **Settings traced to:** none.
|
|
36
68
|
|
|
@@ -48,6 +80,7 @@ Needs ESLint adopted through the projection.
|
|
|
48
80
|
|
|
49
81
|
### boolean-annotation
|
|
50
82
|
|
|
83
|
+
- **Engines:** `walker`
|
|
51
84
|
- **Flags beyond the symptom:** a predicate's boolean return.
|
|
52
85
|
- **Settings traced to:** none.
|
|
53
86
|
|
|
@@ -77,218 +110,57 @@ Name each state in the type.
|
|
|
77
110
|
|
|
78
111
|
### test-body
|
|
79
112
|
|
|
113
|
+
- **Engines:** `walker`
|
|
114
|
+
- **Forms:** `branching-with-if`, `a-ternary`, `a-short-circuit`, `an-optional-chain-after-an-index`, `an-optional-chain-on-a-mock-call`, `an-optional-chain-on-a-mock-result`, `an-optional-chain-on-a-property`, `an-optional-call`, `a-switch`
|
|
80
115
|
- **Flags beyond the symptom:** unit's own API (edition 1).
|
|
81
116
|
- **Settings traced to:** the edition: backwards compatibility for adopters since the npm release.
|
|
82
117
|
|
|
83
|
-
|
|
118
|
+
Branches 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.
|
|
84
119
|
|
|
85
120
|
## 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
121
|
|
|
96
122
|
### Branching with if
|
|
97
|
-
|
|
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
|
-
```
|
|
123
|
+
An `if` statement. Edition 1.
|
|
122
124
|
|
|
123
125
|
### A ternary
|
|
124
|
-
|
|
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
|
-
```
|
|
126
|
+
A ternary expression. Edition 1.
|
|
140
127
|
|
|
141
128
|
### A short-circuit
|
|
142
|
-
|
|
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
|
-
```
|
|
129
|
+
`??`, `||` or `&&`, or an assignment form `??=`, `||=` or `&&=`. Edition 2 adds it.
|
|
155
130
|
|
|
156
131
|
### An optional chain after an index
|
|
157
|
-
|
|
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
|
-
```
|
|
132
|
+
Optional chaining straight after an index, as in `rows[0]?.id`, `mock.instances` and `mock.contexts` included. Edition 2 adds it.
|
|
176
133
|
|
|
177
134
|
### An optional chain on a mock call
|
|
178
|
-
|
|
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
|
-
```
|
|
135
|
+
Optional chaining after an index into `mock.calls`, or on `mock.lastCall`. Edition 2 adds it.
|
|
201
136
|
|
|
202
137
|
### An optional chain on a mock result
|
|
203
|
-
|
|
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).
|
|
138
|
+
Optional chaining after an index into `mock.results`. Edition 2 adds it.
|
|
223
139
|
|
|
224
140
|
### An optional chain on a property
|
|
225
|
-
|
|
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
|
-
```
|
|
141
|
+
Any other optional property or index, `a?.b` or `a?.[key]`. Edition 2 adds it.
|
|
244
142
|
|
|
245
143
|
### An optional call
|
|
246
|
-
|
|
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:
|
|
144
|
+
An optional call, `f?.()`. Edition 2 adds it.
|
|
251
145
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const { enter } = observers;
|
|
255
|
-
assert.isDefined(enter);
|
|
256
|
-
enter("a");
|
|
257
|
-
```
|
|
146
|
+
### A switch
|
|
147
|
+
A `switch` statement. Edition 2 adds it.
|
|
258
148
|
|
|
259
|
-
|
|
149
|
+
## Built unit called in place
|
|
260
150
|
|
|
261
|
-
|
|
262
|
-
declare const tracker: { readonly entered: readonly string[]; enter?(node: string): void };
|
|
263
|
-
assert.isDefined(tracker.enter);
|
|
264
|
-
tracker.enter("a");
|
|
265
|
-
```
|
|
151
|
+
### call-of-a-call
|
|
266
152
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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:
|
|
153
|
+
- **Engines:** `walker`
|
|
154
|
+
- **Misses:** An object passed through a variable, spread, array or type assertion.
|
|
155
|
+
- **Settings traced to:** None.
|
|
277
156
|
|
|
278
|
-
|
|
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
|
-
```
|
|
157
|
+
A call builds a unit from an object literal and immediately calls the result. Give the unit a name before calling it, or pass it to its caller.
|
|
287
158
|
|
|
288
159
|
## Claimed type
|
|
289
160
|
|
|
290
161
|
### cast-to-any
|
|
291
162
|
|
|
163
|
+
- **Engines:** `walker`
|
|
292
164
|
- **Misses:** `any` reached through an outside dependency's types.
|
|
293
165
|
- **Settings traced to:** `as const` allowed: Declared, not asserted.
|
|
294
166
|
|
|
@@ -315,6 +187,7 @@ In a test file, edition 2 of [the test-body check](symptoms/text-past-its-reader
|
|
|
315
187
|
|
|
316
188
|
### non-null-assertions
|
|
317
189
|
|
|
190
|
+
- **Engines:** `eslint`
|
|
318
191
|
- **Misses:** `any` reached through an outside dependency's types.
|
|
319
192
|
- **Settings traced to:** `as const` allowed: Declared, not asserted.
|
|
320
193
|
|
|
@@ -342,10 +215,11 @@ const name = user.name;
|
|
|
342
215
|
```
|
|
343
216
|
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
217
|
|
|
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:
|
|
218
|
+
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: read [Branch in a test](symptoms/branch-in-a-test.md) there.
|
|
346
219
|
|
|
347
220
|
### unlisted-cast-site
|
|
348
221
|
|
|
222
|
+
- **Engines:** `walker`
|
|
349
223
|
- **Misses:** `any` reached through an outside dependency's types.
|
|
350
224
|
- **Settings traced to:** `as const` allowed: Declared, not asserted.
|
|
351
225
|
|
|
@@ -375,153 +249,75 @@ Parse or narrow the value so the type follows from a check rather than from an a
|
|
|
375
249
|
|
|
376
250
|
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
251
|
|
|
252
|
+
## Code or prose read as text in a test
|
|
253
|
+
|
|
254
|
+
### raw-read
|
|
255
|
+
|
|
256
|
+
- **Engines:** `walker`
|
|
257
|
+
- **Misses:** Paths supplied through variables or another module, and file systems reached through a `require` result held in a variable.
|
|
258
|
+
- **Settings traced to:** None.
|
|
259
|
+
|
|
260
|
+
The test reads source or prose as text. Assert what the code returns or does. A test that needs to parse source to prove its syntax can record that location.
|
|
261
|
+
|
|
378
262
|
## Computed value in a test
|
|
379
263
|
|
|
380
264
|
### test-body
|
|
381
265
|
|
|
266
|
+
- **Engines:** `walker`
|
|
267
|
+
- **Forms:** `a-method-that-picks-or-tests-an-element`, `a-method-that-computes-a-value`, `a-method-that-mutates`, `merging-objects`, `building-an-object-from-entries`, `building-an-array-from-a-length`, `a-math-call`
|
|
382
268
|
- **Flags beyond the symptom:** unit's own API (edition 1).
|
|
383
269
|
- **Settings traced to:** the edition: backwards compatibility for adopters since the npm release.
|
|
384
270
|
|
|
385
|
-
|
|
271
|
+
Values computed, mutated or picked 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.
|
|
386
272
|
|
|
387
273
|
## 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
274
|
|
|
407
275
|
### A method that picks or tests an element
|
|
408
|
-
|
|
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).
|
|
276
|
+
A call named `at`, `every`, `filter`, `find`, `findIndex`, `findLast`, `findLastIndex`, `includes`, `indexOf`, `lastIndexOf` or `some`. Edition 1.
|
|
425
277
|
|
|
426
278
|
### A method that computes a value
|
|
427
|
-
|
|
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
|
-
```
|
|
279
|
+
A call named after a string or array method that gives back a new value or walks the list: `map`, `reduce`, `forEach`, `join`, `slice`, `split`, `replace`, `sort`, `trim`, `keys`, `values` and similar. Edition 1.
|
|
445
280
|
|
|
446
281
|
### A method that mutates
|
|
447
|
-
|
|
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
|
-
```
|
|
282
|
+
A call named `copyWithin`, `fill`, `pop`, `push`, `reverse`, `shift`, `splice` or `unshift`. Edition 1.
|
|
459
283
|
|
|
460
284
|
### Merging objects
|
|
461
|
-
|
|
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
|
-
```
|
|
285
|
+
`Object.assign`. Edition 2 adds it.
|
|
482
286
|
|
|
483
287
|
### Building an object from entries
|
|
484
|
-
|
|
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
|
-
```
|
|
288
|
+
`Object.fromEntries`. Edition 2 adds it.
|
|
494
289
|
|
|
495
290
|
### Building an array from a length
|
|
496
|
-
|
|
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:
|
|
291
|
+
`Array.from`. Edition 2 adds it.
|
|
501
292
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
expect(pageOf([{ id: 0 }, { id: 1 }, { id: 2 }])).toHaveLength(3);
|
|
505
|
-
```
|
|
293
|
+
### A Math call
|
|
294
|
+
Any `Math` method. Edition 2 adds it.
|
|
506
295
|
|
|
507
|
-
|
|
296
|
+
## Margin
|
|
508
297
|
|
|
509
|
-
|
|
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:
|
|
298
|
+
A method call is flagged wherever it could be the string or array method of that name.
|
|
515
299
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
300
|
+
- 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)`.
|
|
301
|
+
- Still flagged, though they look like that:
|
|
302
|
+
- 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()`) other than a `#` import or a package some `package.json` in the repository names, 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 }`;
|
|
303
|
+
- a call that spreads its arguments;
|
|
304
|
+
- 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 })`.
|
|
305
|
+
- What this check cannot know: it reads names and syntax, not types, so it cannot tell what a receiver is.
|
|
306
|
+
- It flags the unit's own method given a variable, such as `repository.find(query)`.
|
|
307
|
+
- It misses a string or array method taken off its receiver before the call.
|
|
308
|
+
- 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.
|
|
309
|
+
- 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.
|
|
310
|
+
Only a check that reads types knows a receiver's identity, and Hone does not have one yet.
|
|
311
|
+
|
|
312
|
+
An array too long to read written out, such as one row past a page size of 1,000, is flagged too. A record at the site answers it.
|
|
313
|
+
|
|
314
|
+
`JSON.stringify` and `JSON.parse` are [text-past-its-reader#test-body](symptoms/text-past-its-reader/test-body.md).
|
|
520
315
|
|
|
521
316
|
## Date used directly
|
|
522
317
|
|
|
523
318
|
### clock-sources
|
|
524
319
|
|
|
320
|
+
- **Engines:** `walker`
|
|
525
321
|
- **Flags beyond the symptom:** `Date.now` in comments and strings.
|
|
526
322
|
- **Misses:** `performance.now()`.
|
|
527
323
|
- **Settings traced to:** none.
|
|
@@ -552,6 +348,7 @@ Accept a clock as a dependency and read time only through it. The one real imple
|
|
|
552
348
|
|
|
553
349
|
### default-arm
|
|
554
350
|
|
|
351
|
+
- **Engines:** `walker`
|
|
555
352
|
- **Flags beyond the symptom:** a `switch` over an open set.
|
|
556
353
|
- **Settings traced to:** none.
|
|
557
354
|
|
|
@@ -583,43 +380,29 @@ Name each remaining variant so the compiler checks exhaustiveness.
|
|
|
583
380
|
|
|
584
381
|
### logic-in-a-passed-function
|
|
585
382
|
|
|
383
|
+
- **Engines:** `walker`
|
|
384
|
+
- **Forms:** `logic-inside-a-function-the-test-passes-on`
|
|
586
385
|
- **Misses:** hand-written doubles.
|
|
587
|
-
- **Settings traced to:** test
|
|
386
|
+
- **Settings traced to:** test files are what `testFiles` declares: the adopter's convention.
|
|
588
387
|
|
|
589
388
|
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
389
|
|
|
591
390
|
## 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
391
|
|
|
596
392
|
### Logic inside a function the test passes on
|
|
597
|
-
|
|
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).
|
|
393
|
+
A function a test writes as a property or method of an object literal, gives to `vi.fn`, `mockImplementation` or `mockImplementationOnce`, or passes straight to a function it calls in its own body, holding a construct another test-body check flags. The edition is that construct's.
|
|
612
394
|
|
|
613
395
|
### stub-implementation
|
|
614
396
|
|
|
397
|
+
- **Engines:** `walker`
|
|
615
398
|
- **Misses:** hand-written doubles.
|
|
616
|
-
- **Settings traced to:** test
|
|
399
|
+
- **Settings traced to:** test files are what `testFiles` declares: the adopter's convention.
|
|
617
400
|
|
|
618
401
|
`vi.fn(<implementation>)` and `.mockImplementation(...)`.
|
|
619
402
|
|
|
620
403
|
## Flags
|
|
621
404
|
|
|
622
|
-
- Test files only:
|
|
405
|
+
- Test files only: the `.ts` and `.tsx` files `testFiles` names. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
623
406
|
- A `vi.fn(...)` call with any argument, and any call to a method named `mockImplementation` (on any receiver, with or without arguments).
|
|
624
407
|
- Allowed: `vi.fn()`, `.mockReturnValue(...)`, `.mockResolvedValue(...)`, `.mockReturnValueOnce(...)` and `.mockImplementationOnce(...)`.
|
|
625
408
|
- `.mockImplementationOnce(...)` is not flagged even though it takes an implementation; whether that implementation gives the double behaviour is left to review.
|
|
@@ -642,6 +425,7 @@ Return a canned value: that double is a stub. If the double needs logic, the sea
|
|
|
642
425
|
|
|
643
426
|
### drawer-names
|
|
644
427
|
|
|
428
|
+
- **Engines:** `walker`
|
|
645
429
|
- **Misses:** a drawer under an ordinary name.
|
|
646
430
|
- **Settings traced to:** drawer names: Screaming folders recipe.
|
|
647
431
|
|
|
@@ -665,18 +449,49 @@ src/price-formatting.ts
|
|
|
665
449
|
```
|
|
666
450
|
Rename the file or folder for what it contains, or split it into files that each hold one thing.
|
|
667
451
|
|
|
452
|
+
## Export from a test
|
|
453
|
+
|
|
454
|
+
### test-file-export
|
|
455
|
+
|
|
456
|
+
- **Engines:** `walker`
|
|
457
|
+
- **Misses:** An ordinary source file imported exclusively by tests.
|
|
458
|
+
- **Settings traced to:** None.
|
|
459
|
+
|
|
460
|
+
A test file exports a value or type that other files can import. Keep the companion test self-contained and put reusable production code in the module that owns it.
|
|
461
|
+
|
|
462
|
+
## Failure shaped as success
|
|
463
|
+
|
|
464
|
+
### empty-catch
|
|
465
|
+
|
|
466
|
+
- **Engines:** `walker`
|
|
467
|
+
- **Misses:** A handler that returns a success-shaped default or whose body cannot be seen at the call site.
|
|
468
|
+
- **Settings traced to:** None.
|
|
469
|
+
|
|
470
|
+
An empty catch block or promise rejection handler drops the failure so callers can continue as if the operation succeeded. Return a failure value or leave handling to the boundary that can act on it.
|
|
471
|
+
|
|
472
|
+
## Floating version
|
|
473
|
+
|
|
474
|
+
### version-selector
|
|
475
|
+
|
|
476
|
+
- **Engines:** `walker`
|
|
477
|
+
- **Misses:** Versions provided through workflow matrix expressions.
|
|
478
|
+
- **Settings traced to:** None.
|
|
479
|
+
|
|
480
|
+
Floating versions the repository runs, including development dependencies, private package dependencies, package managers, and workflow tools. Published dependency and peer ranges can express compatibility.
|
|
481
|
+
|
|
668
482
|
## Inherited environment in a subprocess
|
|
669
483
|
|
|
670
484
|
### git-spawn-environment
|
|
671
485
|
|
|
486
|
+
- **Engines:** `walker`
|
|
672
487
|
- **Misses:** `env` built from `process.env` under an accepted name.
|
|
673
488
|
- **Settings traced to:** accepted helper names: **nothing**; `.spec`, `.js`, `.mjs` test files: **nothing**.
|
|
674
489
|
|
|
675
|
-
A git spawn in a test
|
|
490
|
+
A git spawn in a test whose `env` is inherited.
|
|
676
491
|
|
|
677
492
|
## Flags
|
|
678
493
|
|
|
679
|
-
- Test files:
|
|
494
|
+
- Test files: the `.ts`, `.tsx`, `.mjs` and `.js` files `testFiles` names. 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
495
|
- 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
496
|
- 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
497
|
- 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.
|
|
@@ -698,6 +513,7 @@ Build the environment without inherited git variables or the user's configuratio
|
|
|
698
513
|
|
|
699
514
|
### function-length
|
|
700
515
|
|
|
516
|
+
- **Engines:** `eslint`
|
|
701
517
|
- **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
518
|
|
|
703
519
|
A function body longer than 50 lines.
|
|
@@ -744,6 +560,7 @@ Move any computing or branching between calls into a named doer, so the orchestr
|
|
|
744
560
|
|
|
745
561
|
### loop-statement
|
|
746
562
|
|
|
563
|
+
- **Engines:** `walker`
|
|
747
564
|
- **Settings traced to:** none.
|
|
748
565
|
|
|
749
566
|
`for...of`, `for await`, counted `for` and `while` loops.
|
|
@@ -771,20 +588,31 @@ const totals = orders.map((order) => order.total);
|
|
|
771
588
|
```
|
|
772
589
|
Replace a counted loop with `Array.from({ length }, (_, position) => ...)`.
|
|
773
590
|
|
|
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`:
|
|
591
|
+
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`: read [Computed value in a test](symptoms/computed-value-in-a-test.md) there.
|
|
592
|
+
|
|
593
|
+
## Many spellings of one concept
|
|
594
|
+
|
|
595
|
+
### test-call-aliases
|
|
596
|
+
|
|
597
|
+
- **Engines:** `walker`
|
|
598
|
+
- **Misses:** Calls through a different local alias or a Vitest namespace import.
|
|
599
|
+
- **Settings traced to:** None.
|
|
600
|
+
|
|
601
|
+
In a test file, a call rooted at `test` or `suite` refers to Vitest or has no local binding. Use `it` and `describe` so tests use the same names. Local bindings with other meanings pass.
|
|
775
602
|
|
|
776
603
|
## Module or global patched
|
|
777
604
|
|
|
778
605
|
### module-mock-call
|
|
779
606
|
|
|
780
|
-
- **
|
|
781
|
-
- **
|
|
607
|
+
- **Engines:** `walker`
|
|
608
|
+
- **Misses:** Both editions miss aliased receivers and module mocks such as vi.doMock or vi["mock"]. Edition 1 leaves global patches to review. Edition 2 still misses indirect writes and global vi.spyOn calls.
|
|
609
|
+
- **Settings traced to:** test files are what `testFiles` declares: the adopter's convention.
|
|
782
610
|
|
|
783
|
-
Calls to `vi.mock`.
|
|
611
|
+
Calls to `vi.mock`. Edition 2 also flags `vi.stubGlobal`, `vi.stubEnv` and direct changes to `process.env` in test files, including assignments, deletes, increments and decrements.
|
|
784
612
|
|
|
785
613
|
## Flags
|
|
786
614
|
|
|
787
|
-
- Test files only:
|
|
615
|
+
- Test files only: the `.ts` and `.tsx` files `testFiles` names. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
788
616
|
- Every call spelled `vi.mock(...)`, with or without arguments.
|
|
789
617
|
- Not detected: `vi.doMock`, `jest.mock`, `vitest.mock` and `vi["mock"]`. Those are left to review.
|
|
790
618
|
|
|
@@ -805,6 +633,7 @@ Pass the collaborator in as a dependency and hand the test a stub.
|
|
|
805
633
|
|
|
806
634
|
### filename-case
|
|
807
635
|
|
|
636
|
+
- **Engines:** `eslint`
|
|
808
637
|
- **Settings traced to:** Hone's own casing option lists: **nothing**; casing is the adopter's own lint.
|
|
809
638
|
|
|
810
639
|
A file name that is not kebab-case or PascalCase.
|
|
@@ -818,6 +647,7 @@ Needs ESLint adopted through the projection.
|
|
|
818
647
|
|
|
819
648
|
### naming-convention
|
|
820
649
|
|
|
650
|
+
- **Engines:** `eslint`
|
|
821
651
|
- **Settings traced to:** Hone's own casing option lists: **nothing**; casing is the adopter's own lint.
|
|
822
652
|
|
|
823
653
|
A name that breaks the naming convention for its kind.
|
|
@@ -833,10 +663,23 @@ Needs ESLint adopted through the projection.
|
|
|
833
663
|
- Ignored: names that need quotes, destructured bindings, imports and unused bindings whose name starts with `_`.
|
|
834
664
|
- 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
665
|
|
|
666
|
+
## No lock file
|
|
667
|
+
|
|
668
|
+
### committed-lock-file
|
|
669
|
+
|
|
670
|
+
- **Engines:** `walker`
|
|
671
|
+
- **Misses:** Package managers with an unrecognised lock file. Workspace membership is not verified.
|
|
672
|
+
- **Settings traced to:** None.
|
|
673
|
+
|
|
674
|
+
Dependencies declared without an applicable tracked lock file.
|
|
675
|
+
|
|
676
|
+
A recognised tracked lock file covers manifests in its directory and below, including a root lock.
|
|
677
|
+
|
|
836
678
|
## Outside import past a boundary
|
|
837
679
|
|
|
838
680
|
### import-or-require
|
|
839
681
|
|
|
682
|
+
- **Engines:** `walker`
|
|
840
683
|
- **Misses:** `import()`, `require`, globals.
|
|
841
684
|
- **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
685
|
|
|
@@ -880,6 +723,7 @@ Import your own port and take it in the unit's argument. Only the adapter for th
|
|
|
880
723
|
|
|
881
724
|
### parameter-count
|
|
882
725
|
|
|
726
|
+
- **Engines:** `eslint`
|
|
883
727
|
- **Misses:** our own functions with exactly two parameters.
|
|
884
728
|
- **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
729
|
|
|
@@ -905,10 +749,45 @@ const createOrder = ({ customerId, items, currency }: OrderRequest) => ({ custom
|
|
|
905
749
|
```
|
|
906
750
|
Take one object with named fields so each call site reads as a labelled contract.
|
|
907
751
|
|
|
752
|
+
## Process global used in place
|
|
753
|
+
|
|
754
|
+
### debugger-statement
|
|
755
|
+
|
|
756
|
+
- **Engines:** `walker`
|
|
757
|
+
- **Misses:** Debugger activation through a runtime API.
|
|
758
|
+
- **Settings traced to:** None.
|
|
759
|
+
|
|
760
|
+
A `debugger` statement can pause execution through the runtime. Keep that effect at the process boundary and pass any needed diagnostic capability in through a port.
|
|
761
|
+
|
|
762
|
+
### direct-global-use
|
|
763
|
+
|
|
764
|
+
- **Engines:** `walker`
|
|
765
|
+
- **Misses:** Destructured aliases, indirect calls or references, and dialog calls through other receivers or parenthesised receivers.
|
|
766
|
+
- **Settings traced to:** The edition preserves compatibility for existing selections.
|
|
767
|
+
|
|
768
|
+
Direct reads of process globals and direct console use.
|
|
769
|
+
|
|
770
|
+
A locally supplied value with the same name passes. Reads of globals still report after an ambient declaration or a canonical Node import or require.
|
|
771
|
+
|
|
772
|
+
Edition 2 also covers unbound `alert`, `confirm`, and `prompt` calls, including calls on the unbound `window` global.
|
|
773
|
+
|
|
774
|
+
## Prose in code
|
|
775
|
+
|
|
776
|
+
### comment-prose
|
|
777
|
+
|
|
778
|
+
- **Engines:** `walker`
|
|
779
|
+
- **Misses:** Comments in JavaScript files.
|
|
780
|
+
- **Settings traced to:** `trackerPatterns` reference forms: **nothing**.
|
|
781
|
+
|
|
782
|
+
Prose in TypeScript line or block comments, including JSDoc.
|
|
783
|
+
|
|
784
|
+
A tracked TODO may contain only its pointer. `trackerPatterns` chooses which numbered references and URLs count.
|
|
785
|
+
|
|
908
786
|
## Rebinding
|
|
909
787
|
|
|
910
788
|
### parameter-reassignment
|
|
911
789
|
|
|
790
|
+
- **Engines:** `eslint`
|
|
912
791
|
- **Misses:** a local `let` in production.
|
|
913
792
|
- **Settings traced to:** none.
|
|
914
793
|
|
|
@@ -924,37 +803,23 @@ Needs ESLint adopted through the projection; see the ESLint piece.
|
|
|
924
803
|
|
|
925
804
|
### test-body
|
|
926
805
|
|
|
806
|
+
- **Engines:** `walker`
|
|
807
|
+
- **Forms:** `a-let`
|
|
927
808
|
- **Misses:** a local `let` in production.
|
|
928
809
|
- **Settings traced to:** none.
|
|
929
810
|
|
|
930
811
|
`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
812
|
|
|
932
813
|
## Flags
|
|
933
|
-
Edition 1:
|
|
934
|
-
- `let` declarations.
|
|
935
|
-
|
|
936
|
-
## Allowed forms in a test
|
|
937
814
|
|
|
938
815
|
### A let
|
|
939
|
-
|
|
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
|
-
```
|
|
816
|
+
A `let` declaration. Edition 1.
|
|
953
817
|
|
|
954
818
|
## Shorthand name
|
|
955
819
|
|
|
956
820
|
### identifier-names
|
|
957
821
|
|
|
822
|
+
- **Engines:** `walker`
|
|
958
823
|
- **Misses:** shorthand not on the list.
|
|
959
824
|
- **Settings traced to:** shorthand and filler list: Whole words recipe.
|
|
960
825
|
|
|
@@ -983,6 +848,7 @@ Name the value for what it is in the domain.
|
|
|
983
848
|
|
|
984
849
|
### exact-optional-property-types
|
|
985
850
|
|
|
851
|
+
- **Engines:** `walker`
|
|
986
852
|
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
987
853
|
- **Misses:** edition 1: a base reached by `extends`.
|
|
988
854
|
- **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**.
|
|
@@ -1031,6 +897,7 @@ Put the flags in a shared base file that is not named `tsconfig.json`, and leave
|
|
|
1031
897
|
|
|
1032
898
|
### no-fallthrough-cases-in-switch
|
|
1033
899
|
|
|
900
|
+
- **Engines:** `walker`
|
|
1034
901
|
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1035
902
|
- **Misses:** edition 1: a base reached by `extends`.
|
|
1036
903
|
- **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**.
|
|
@@ -1079,6 +946,7 @@ Put the flags in a shared base file that is not named `tsconfig.json`, and leave
|
|
|
1079
946
|
|
|
1080
947
|
### no-implicit-override
|
|
1081
948
|
|
|
949
|
+
- **Engines:** `walker`
|
|
1082
950
|
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1083
951
|
- **Misses:** edition 1: a base reached by `extends`.
|
|
1084
952
|
- **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**.
|
|
@@ -1127,6 +995,7 @@ Put the flags in a shared base file that is not named `tsconfig.json`, and leave
|
|
|
1127
995
|
|
|
1128
996
|
### no-property-access-from-index-signature
|
|
1129
997
|
|
|
998
|
+
- **Engines:** `walker`
|
|
1130
999
|
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1131
1000
|
- **Misses:** edition 1: a base reached by `extends`.
|
|
1132
1001
|
- **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**.
|
|
@@ -1175,6 +1044,7 @@ Put the flags in a shared base file that is not named `tsconfig.json`, and leave
|
|
|
1175
1044
|
|
|
1176
1045
|
### no-unchecked-indexed-access
|
|
1177
1046
|
|
|
1047
|
+
- **Engines:** `walker`
|
|
1178
1048
|
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1179
1049
|
- **Misses:** edition 1: a base reached by `extends`.
|
|
1180
1050
|
- **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**.
|
|
@@ -1223,6 +1093,7 @@ Put the flags in a shared base file that is not named `tsconfig.json`, and leave
|
|
|
1223
1093
|
|
|
1224
1094
|
### strict
|
|
1225
1095
|
|
|
1096
|
+
- **Engines:** `walker`
|
|
1226
1097
|
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1227
1098
|
- **Misses:** edition 1: a base reached by `extends`.
|
|
1228
1099
|
- **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**.
|
|
@@ -1271,6 +1142,7 @@ Put the flags in a shared base file that is not named `tsconfig.json`, and leave
|
|
|
1271
1142
|
|
|
1272
1143
|
### use-unknown-in-catch-variables
|
|
1273
1144
|
|
|
1145
|
+
- **Engines:** `walker`
|
|
1274
1146
|
- **Flags beyond the symptom:** edition 1: a flag set to `true`.
|
|
1275
1147
|
- **Misses:** edition 1: a base reached by `extends`.
|
|
1276
1148
|
- **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**.
|
|
@@ -1321,6 +1193,7 @@ Put the flags in a shared base file that is not named `tsconfig.json`, and leave
|
|
|
1321
1193
|
|
|
1322
1194
|
### cognitive-complexity
|
|
1323
1195
|
|
|
1196
|
+
- **Engines:** `eslint`
|
|
1324
1197
|
- **Settings traced to:** complexity 15: where a broad symptom fires (as above).
|
|
1325
1198
|
|
|
1326
1199
|
A function whose cognitive complexity is above 15.
|
|
@@ -1362,6 +1235,7 @@ Move any computing or branching between calls into a named doer, so the orchestr
|
|
|
1362
1235
|
|
|
1363
1236
|
### focused-tests
|
|
1364
1237
|
|
|
1238
|
+
- **Engines:** `eslint`
|
|
1365
1239
|
- **Misses:** `.todo`.
|
|
1366
1240
|
- **Settings traced to:** `.todo` not flagged: a miss.
|
|
1367
1241
|
|
|
@@ -1374,56 +1248,52 @@ Needs ESLint adopted through the projection.
|
|
|
1374
1248
|
|
|
1375
1249
|
### skipped-tests
|
|
1376
1250
|
|
|
1377
|
-
- **
|
|
1378
|
-
- **
|
|
1251
|
+
- **Engines:** `eslint`
|
|
1252
|
+
- **Misses:** Test calls made through aliased names.
|
|
1253
|
+
- **Settings traced to:** The edition preserves the published edition 1 behaviour for adopters.
|
|
1379
1254
|
|
|
1380
|
-
`.skip
|
|
1255
|
+
Edition 1 flags `.skip`, `.fixme`, `xdescribe`, `xit`, `xtest` and `xsuite`. Edition 2 also flags `.todo`, `.skipIf` and `.runIf`. A test should run wherever the suite runs.
|
|
1381
1256
|
|
|
1382
|
-
## Flags
|
|
1383
1257
|
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
1258
|
|
|
1387
1259
|
## Text past its reader
|
|
1388
1260
|
|
|
1389
1261
|
### test-body
|
|
1390
1262
|
|
|
1263
|
+
- **Engines:** `walker`
|
|
1264
|
+
- **Forms:** `serialising-or-parsing-json`
|
|
1391
1265
|
- **Misses:** production sites.
|
|
1392
1266
|
- **Settings traced to:** the edition: backwards compatibility for adopters since the npm release.
|
|
1393
1267
|
|
|
1394
|
-
|
|
1268
|
+
JSON text made or read 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
1269
|
|
|
1396
1270
|
## 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
1271
|
|
|
1402
1272
|
### Serialising or parsing JSON
|
|
1403
|
-
|
|
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:
|
|
1273
|
+
`JSON.stringify` or `JSON.parse`. Edition 2 adds it.
|
|
1408
1274
|
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1275
|
+
## Throw between our units
|
|
1276
|
+
|
|
1277
|
+
### throw-statement
|
|
1278
|
+
|
|
1279
|
+
- **Engines:** `walker`
|
|
1280
|
+
- **Misses:** A throw in a called function or a test file.
|
|
1281
|
+
- **Settings traced to:** None.
|
|
1413
1282
|
|
|
1414
|
-
A
|
|
1283
|
+
A throw statement in production TypeScript.
|
|
1415
1284
|
|
|
1416
1285
|
## Throw or catch in a test
|
|
1417
1286
|
|
|
1418
1287
|
### throw-statement
|
|
1419
1288
|
|
|
1289
|
+
- **Engines:** `walker`
|
|
1420
1290
|
- **Misses:** `catch`.
|
|
1421
1291
|
- **Settings traced to:** none.
|
|
1422
1292
|
|
|
1423
1293
|
A `throw` statement in a test file.
|
|
1424
1294
|
|
|
1425
1295
|
## Flags
|
|
1426
|
-
- Test files only:
|
|
1296
|
+
- Test files only: the `.ts` and `.tsx` files `testFiles` names. `.js` tests are not read. Generated folders such as `node_modules`, `dist`, `build` and `coverage` are skipped.
|
|
1427
1297
|
- Every `throw` statement, wherever it sits in the file.
|
|
1428
1298
|
- Allowed: assertion calls such as `expect(...)`.
|
|
1429
1299
|
- 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.
|
|
@@ -1446,44 +1316,23 @@ Assert on the whole result. Branching in tests is also reported by [the branch-i
|
|
|
1446
1316
|
|
|
1447
1317
|
### try-block
|
|
1448
1318
|
|
|
1319
|
+
- **Engines:** `walker`
|
|
1320
|
+
- **Forms:** `a-try-block`
|
|
1449
1321
|
- **Misses:** `catch`.
|
|
1450
1322
|
- **Settings traced to:** none.
|
|
1451
1323
|
|
|
1452
1324
|
`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
1325
|
|
|
1454
1326
|
## Flags
|
|
1455
|
-
Edition 1:
|
|
1456
|
-
- `try` statements.
|
|
1457
|
-
|
|
1458
|
-
## Allowed forms in a test
|
|
1459
1327
|
|
|
1460
1328
|
### A try block
|
|
1461
|
-
|
|
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
|
-
```
|
|
1329
|
+
A `try` statement. Edition 1.
|
|
1482
1330
|
|
|
1483
1331
|
## Thrown non-error
|
|
1484
1332
|
|
|
1485
1333
|
### throw-only-error
|
|
1486
1334
|
|
|
1335
|
+
- **Engines:** `eslint`
|
|
1487
1336
|
- **Settings traced to:** none.
|
|
1488
1337
|
|
|
1489
1338
|
A `throw` of something that is not an error object.
|
|
@@ -1494,10 +1343,31 @@ Needs ESLint adopted through the projection.
|
|
|
1494
1343
|
- Allowed: `new Error(...)`, identifiers, calls and member access.
|
|
1495
1344
|
- This clause applies to every file the ESLint run includes, not only tests.
|
|
1496
1345
|
|
|
1346
|
+
## Tool fetched at run time
|
|
1347
|
+
|
|
1348
|
+
### fetch-command
|
|
1349
|
+
|
|
1350
|
+
- **Engines:** `walker`
|
|
1351
|
+
- **Misses:** Indirect commands composed through aliases or variables and commands split across physical lines.
|
|
1352
|
+
- **Settings traced to:** None.
|
|
1353
|
+
|
|
1354
|
+
Direct fetch-and-run commands in package scripts, CI workflows, and shell scripts.
|
|
1355
|
+
|
|
1356
|
+
## Type declared in a test
|
|
1357
|
+
|
|
1358
|
+
### test-type-declaration
|
|
1359
|
+
|
|
1360
|
+
- **Engines:** `walker`
|
|
1361
|
+
- **Misses:** Inline type literals and declarations in ordinary source files imported only by tests.
|
|
1362
|
+
- **Settings traced to:** None.
|
|
1363
|
+
|
|
1364
|
+
A test declares a type, interface or enum of its own. Import the contract owned by the unit or its boundary so the test and the unit rely on the same type. Module and global augmentations are allowed. So is a top-level `type`, not exported, used only as the `it.each` or `describe.each` row type: one flat object or tuple, readonly or not, whose members are primitives, types imported by name, or readonly lists of imported types.
|
|
1365
|
+
|
|
1497
1366
|
## Type derived from code
|
|
1498
1367
|
|
|
1499
1368
|
### factory-return-types
|
|
1500
1369
|
|
|
1370
|
+
- **Engines:** `walker`
|
|
1501
1371
|
- **Flags beyond the symptom:** text in comments.
|
|
1502
1372
|
- **Misses:** `Parameters<typeof>`, `typeof` alone.
|
|
1503
1373
|
- **Settings traced to:** none.
|
|
@@ -1526,6 +1396,7 @@ Declare and export the type, then annotate the factory with it.
|
|
|
1526
1396
|
|
|
1527
1397
|
### companion-test-file
|
|
1528
1398
|
|
|
1399
|
+
- **Engines:** `walker`
|
|
1529
1400
|
- **Misses:** an empty or non-running sibling.
|
|
1530
1401
|
- **Settings traced to:** `__tests__` skipped by default, on purpose (noise; the practice is not adopted). `exclude` is scope.
|
|
1531
1402
|
|
|
@@ -1533,8 +1404,8 @@ A production file with a runtime export and no `.test` sibling.
|
|
|
1533
1404
|
|
|
1534
1405
|
## Flags
|
|
1535
1406
|
|
|
1536
|
-
- Production `.ts` and `.tsx` files. Skipped:
|
|
1537
|
-
- A file with a runtime export (`export const`, `function`, `class`, `enum`, `export default`, or `export { name }`) and no `<name>.
|
|
1407
|
+
- Production `.ts` and `.tsx` files. Skipped: the test files `testFiles` names, `.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.
|
|
1408
|
+
- A file with a runtime export (`export const`, `function`, `class`, `enum`, `export default`, or `export { name }`) and no `<name>.<suffix>.ts` beside it (`.tsx` for `.tsx`), for any suffix `testFiles` lists. The sibling must be in the repository's file list.
|
|
1538
1409
|
- Allowed: files with only `export type`, `export interface`, `export declare`, type-only named exports or `export * from`, and files with no exports.
|
|
1539
1410
|
- The source rule asks for a test beside every source file; files without runtime exports are left to review.
|
|
1540
1411
|
|
|
@@ -1553,6 +1424,7 @@ Add `src/price.test.ts` next to the file, with at least one test of its behaviou
|
|
|
1553
1424
|
|
|
1554
1425
|
### directive-pointers
|
|
1555
1426
|
|
|
1427
|
+
- **Engines:** `walker`
|
|
1556
1428
|
- **Settings traced to:** reference form "need a digit": **nothing**.
|
|
1557
1429
|
|
|
1558
1430
|
TODOs, linter directives and `@ts-expect-error` without a tracker.
|
|
@@ -1593,6 +1465,7 @@ Remove the need for the directive. If it must stay, add a tracked reference to t
|
|
|
1593
1465
|
|
|
1594
1466
|
### explicit-any
|
|
1595
1467
|
|
|
1468
|
+
- **Engines:** `eslint`
|
|
1596
1469
|
- **Settings traced to:** none.
|
|
1597
1470
|
|
|
1598
1471
|
An `any` type anywhere in a type position.
|
|
@@ -1604,6 +1477,7 @@ Needs ESLint adopted through the projection.
|
|
|
1604
1477
|
|
|
1605
1478
|
### implicit-any-let
|
|
1606
1479
|
|
|
1480
|
+
- **Engines:** `eslint`
|
|
1607
1481
|
- **Settings traced to:** none.
|
|
1608
1482
|
|
|
1609
1483
|
A `let` or `var` with neither a type annotation nor an initialiser.
|
|
@@ -1613,10 +1487,21 @@ Needs ESLint adopted through the projection.
|
|
|
1613
1487
|
- 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
1488
|
- Allowed: `unknown`, `let total = 0` and `let total: number`.
|
|
1615
1489
|
|
|
1490
|
+
## Wide input
|
|
1491
|
+
|
|
1492
|
+
### unread-parameter
|
|
1493
|
+
|
|
1494
|
+
- **Engines:** `eslint`
|
|
1495
|
+
- **Misses:** Leading unread parameters before a read parameter or a constructor parameter property. Functions that read arguments, unread parameter properties and fields of objects left whole. Setter parameters are required by the language.
|
|
1496
|
+
- **Settings traced to:** None.
|
|
1497
|
+
|
|
1498
|
+
The signature demands a parameter or destructured field the unit never reads. Callers build and pass input that changes nothing.
|
|
1499
|
+
|
|
1616
1500
|
## Work inside a condition
|
|
1617
1501
|
|
|
1618
1502
|
### else-after-an-exit
|
|
1619
1503
|
|
|
1504
|
+
- **Engines:** `eslint`
|
|
1620
1505
|
- **Misses:** an `if` nested with no `else`.
|
|
1621
1506
|
- **Settings traced to:** none.
|
|
1622
1507
|
|
|
@@ -1656,6 +1541,7 @@ Handle the unhappy path first with an early return and leave the happy path as t
|
|
|
1656
1541
|
|
|
1657
1542
|
### parameter-mutation
|
|
1658
1543
|
|
|
1544
|
+
- **Engines:** `walker`
|
|
1659
1545
|
- **Settings traced to:** none.
|
|
1660
1546
|
|
|
1661
1547
|
Assignment to, deletion from or in-place methods on a parameter's fields.
|