@ddd-ts-kit/eslint-plugin 0.87.0 → 0.89.0

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.
Files changed (66) hide show
  1. package/README.fr.md +8 -2
  2. package/README.md +7 -1
  3. package/dist/presets/create-ddd-ts-kit.js +10 -2
  4. package/dist/presets/create-ddd-ts-kit.js.map +1 -1
  5. package/dist/project/config.d.ts +1 -1
  6. package/dist/project/config.d.ts.map +1 -1
  7. package/dist/project/locate.js +46 -11
  8. package/dist/project/locate.js.map +1 -1
  9. package/dist/rules/rules.d.ts.map +1 -1
  10. package/dist/rules/rules.js +12 -0
  11. package/dist/rules/rules.js.map +1 -1
  12. package/dist/rules/test-assertion-present.d.ts +2 -0
  13. package/dist/rules/test-assertion-present.d.ts.map +1 -0
  14. package/dist/rules/test-assertion-present.js +70 -0
  15. package/dist/rules/test-assertion-present.js.map +1 -0
  16. package/dist/rules/test-no-logic.d.ts +2 -0
  17. package/dist/rules/test-no-logic.d.ts.map +1 -0
  18. package/dist/rules/test-no-logic.js +46 -0
  19. package/dist/rules/test-no-logic.js.map +1 -0
  20. package/dist/rules/test-no-only-no-skip.d.ts +2 -0
  21. package/dist/rules/test-no-only-no-skip.d.ts.map +1 -0
  22. package/dist/rules/test-no-only-no-skip.js +53 -0
  23. package/dist/rules/test-no-only-no-skip.js.map +1 -0
  24. package/dist/rules/test-no-snapshot.d.ts +2 -0
  25. package/dist/rules/test-no-snapshot.d.ts.map +1 -0
  26. package/dist/rules/test-no-snapshot.js +37 -0
  27. package/dist/rules/test-no-snapshot.js.map +1 -0
  28. package/dist/rules/test-refusal-by-code.d.ts +2 -0
  29. package/dist/rules/test-refusal-by-code.d.ts.map +1 -0
  30. package/dist/rules/test-refusal-by-code.js +71 -0
  31. package/dist/rules/test-refusal-by-code.js.map +1 -0
  32. package/dist/rules/test-title-states-a-rule.d.ts +4 -0
  33. package/dist/rules/test-title-states-a-rule.d.ts.map +1 -0
  34. package/dist/rules/test-title-states-a-rule.js +68 -0
  35. package/dist/rules/test-title-states-a-rule.js.map +1 -0
  36. package/dist/support/descendants.d.ts +5 -2
  37. package/dist/support/descendants.d.ts.map +1 -1
  38. package/dist/support/descendants.js +7 -1
  39. package/dist/support/descendants.js.map +1 -1
  40. package/dist/support/stepdown/misplaced-functions.js +9 -1
  41. package/dist/support/stepdown/misplaced-functions.js.map +1 -1
  42. package/dist/support/tests/test-call.d.ts +20 -0
  43. package/dist/support/tests/test-call.d.ts.map +1 -0
  44. package/dist/support/tests/test-call.js +77 -0
  45. package/dist/support/tests/test-call.js.map +1 -0
  46. package/dist/support/tests/title-text.d.ts +7 -0
  47. package/dist/support/tests/title-text.d.ts.map +1 -0
  48. package/dist/support/tests/title-text.js +22 -0
  49. package/dist/support/tests/title-text.js.map +1 -0
  50. package/dist/version.d.ts +1 -1
  51. package/dist/version.js +1 -1
  52. package/docs/rules/errors-factory-name.fr.md +4 -4
  53. package/docs/rules/errors-factory-name.md +3 -3
  54. package/docs/rules/test-assertion-present.fr.md +58 -0
  55. package/docs/rules/test-assertion-present.md +57 -0
  56. package/docs/rules/test-no-logic.fr.md +71 -0
  57. package/docs/rules/test-no-logic.md +70 -0
  58. package/docs/rules/test-no-only-no-skip.fr.md +56 -0
  59. package/docs/rules/test-no-only-no-skip.md +55 -0
  60. package/docs/rules/test-no-snapshot.fr.md +52 -0
  61. package/docs/rules/test-no-snapshot.md +51 -0
  62. package/docs/rules/test-refusal-by-code.fr.md +65 -0
  63. package/docs/rules/test-refusal-by-code.md +64 -0
  64. package/docs/rules/test-title-states-a-rule.fr.md +63 -0
  65. package/docs/rules/test-title-states-a-rule.md +62 -0
  66. package/package.json +1 -1
@@ -0,0 +1,71 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ import { propertyName } from '../support/globals/property-name.js';
3
+ import { defineRule } from '../support/rule/define-rule.js';
4
+ const THROW_MATCHERS = new Set(['toThrow', 'toThrowError']);
5
+ /** The spec of an adapter, wherever it sits: what it asserts about the outside system is technical. */
6
+ const ADAPTER_SPEC = /\.adapter\.(?:spec|test)\.ts$/;
7
+ export const testRefusalByCode = defineRule({
8
+ id: 'test/refusal-by-code',
9
+ type: 'suggestion',
10
+ recommended: 'warn',
11
+ transition: '0.90.0',
12
+ description: 'A refusal of the model or of the application is asserted by its code and its facts, never by its message or the class of one error: `thenError`, `expectRefusal`, `rejects.toMatchObject({ code })`, `expectProblem`; `toThrow` with a message, a class or nothing is reported, outside the specs of the adapters and of the platform.',
13
+ messages: {
14
+ by: "`{{matcher}}` asserts a refusal by {{by}}. A refusal is asserted by its code and its facts, which a client and a reader rely on, never by a message or the class of one error: on an aggregate `given(...).when(...).thenError('INVOICE_ALREADY_PAID', facts)`, on an action `expectRefusal(() => Email.create(raw), 'INVALID_EMAIL', facts)`, through the bus `await expect(bus.execute(command)).rejects.toMatchObject({ code: 'FORBIDDEN' })`, end to end `expectProblem(response, { status: 409, code: 'SLOT_TAKEN' })`; a failure the test injected (`mailer.failNextWith(outage)`) is asserted as itself, `rejects.toBe(outage)`.",
15
+ },
16
+ create({ file, report }) {
17
+ if (!file.isTest || isTechnical(file)) {
18
+ return {};
19
+ }
20
+ return {
21
+ CallExpression(node) {
22
+ const { callee } = node;
23
+ if (callee.type !== AST_NODE_TYPES.MemberExpression) {
24
+ return;
25
+ }
26
+ const matcher = propertyName(callee) ?? '';
27
+ if (!THROW_MATCHERS.has(matcher) || isNegated(callee.object)) {
28
+ return;
29
+ }
30
+ const by = comparedBy(node.arguments[0]);
31
+ if (by !== undefined) {
32
+ report({ node: callee.property, messageId: 'by', data: { matcher, by } });
33
+ }
34
+ },
35
+ };
36
+ },
37
+ });
38
+ /** The platform, an adapter and the integration specs of a context assert technical failures, whose message is what an operator reads. */
39
+ function isTechnical(file) {
40
+ const { location } = file;
41
+ if (location.area === 'platform' || ADAPTER_SPEC.test(file.path)) {
42
+ return true;
43
+ }
44
+ return location.area === 'context' && location.layer === 'test' && location.inside[0] === 'integration';
45
+ }
46
+ /** `expect(action).not.toThrow()` asserts that the action is accepted: not a refusal. */
47
+ function isNegated(object) {
48
+ let current = object;
49
+ while (current.type === AST_NODE_TYPES.MemberExpression) {
50
+ if (propertyName(current) === 'not') {
51
+ return true;
52
+ }
53
+ current = current.object;
54
+ }
55
+ return false;
56
+ }
57
+ /** Nothing for an object or a matcher (`expect.objectContaining({ code })`), which may well name the code. */
58
+ function comparedBy(argument) {
59
+ if (argument === undefined) {
60
+ return 'nothing';
61
+ }
62
+ if (argument.type === AST_NODE_TYPES.Literal || argument.type === AST_NODE_TYPES.TemplateLiteral) {
63
+ return 'its message';
64
+ }
65
+ return argument.type === AST_NODE_TYPES.Identifier ||
66
+ argument.type === AST_NODE_TYPES.MemberExpression ||
67
+ argument.type === AST_NODE_TYPES.NewExpression
68
+ ? 'its class'
69
+ : undefined;
70
+ }
71
+ //# sourceMappingURL=test-refusal-by-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-refusal-by-code.js","sourceRoot":"","sources":["../../src/rules/test-refusal-by-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;AAE5D,uGAAuG;AACvG,MAAM,YAAY,GAAG,+BAA+B,CAAC;AAKrD,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAO;IAChD,EAAE,EAAE,sBAAsB;IAC1B,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,MAAM;IACnB,UAAU,EAAE,QAAQ;IACpB,WAAW,EACT,wUAAwU;IAC1U,QAAQ,EAAE;QACR,EAAE,EAAE,ymBAAymB;KAC9mB;IACD,MAAM,CAAC,EAAE,IAAI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a,CAAC;AAC1G,CAAC;AAED,yFAAyF;AACzF,SAAS,SAAS,CAAC,MAA2B;IAC5C,IAAI,OAAO,GAAwB,MAAM,CAAC;IAE1C,OAAO,OAAO,CAAC,IAAI,KAAK,cAAc,CAAC,gBAAgB,EAAE,CAAC;QACxD,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,KAAK,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,8GAA8G;AAC9G,SAAS,UAAU,CAAC,QAAqD;IACvE,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,eAAe,EAAE,CAAC;QACjG,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU;QAChD,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,gBAAgB;QACjD,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,aAAa;QAC9C,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
@@ -0,0 +1,4 @@
1
+ type MessageId = 'rule' | 'word' | 'code' | 'group' | 'empty';
2
+ export declare const testTitleStatesARule: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageId, [], import("../index.js").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
3
+ export {};
4
+ //# sourceMappingURL=test-title-states-a-rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-title-states-a-rule.d.ts","sourceRoot":"","sources":["../../src/rules/test-title-states-a-rule.ts"],"names":[],"mappings":"AAqBA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE9D,eAAO,MAAM,oBAAoB,0JAsC/B,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { defineRule } from '../support/rule/define-rule.js';
2
+ import { testCall } from '../support/tests/test-call.js';
3
+ import { titleText } from '../support/tests/title-text.js';
4
+ /** What a title cites before the rule: the rows that make a scenario pass and its criterion, `#US5.02 AC1`, a criterion alone, `AC1`, a fix, `#FIX-412`. */
5
+ const CITATIONS = /^(?:#\S+\s+)*(?:AC\d+(?:\s*,\s*AC\d+)*\s+)?/;
6
+ /** The words that say a test is a test instead of saying what is true. */
7
+ const META = /\b(?:should|tests?|testing|tested|works|correctly|properly|successfully|as expected|makes? sure|ensures? that|verif(?:y|ies) that|checks? that)\b/i;
8
+ /** A word that names code: `execute()`, `execute(command)`, a first word in camelCase (`issueInvoice`). */
9
+ const CODE = /(?:[\w$]+\([^)]*\)|^[a-z]+[A-Z]\w*)/;
10
+ /** The first word of a table-driven title stands for a row: `%s is refused`, `$kind announces an appointment`. */
11
+ const PLACEHOLDER = /^[%$]/;
12
+ /** A group named after its tests instead of its subject. */
13
+ const GROUP_META = /\b(?:tests?|specs?|suite|should)\b|(?:Spec|Specs|Test|Tests)$/i;
14
+ export const testTitleStatesARule = defineRule({
15
+ id: 'test/title-states-a-rule',
16
+ type: 'suggestion',
17
+ recommended: 'warn',
18
+ transition: '0.90.0',
19
+ description: 'The title of a test states the rule it proves: in lower case, what the subject does, after the rows and the criterion it cites; never `should`, `test`, `works`, nor the name of a method or a class. A `describe` names the unit.',
20
+ messages: {
21
+ rule: 'The title "{{title}}" does not state the rule the test proves. A title says what the subject does, in the present tense and in lower case (`refuses to pay an invoice twice`, `saves the invoice and answers its identifier`), after the rows and the criterion it cites (`#US5.02 AC1 ...`).',
22
+ word: 'The title "{{title}}" says "{{word}}": a title states the behaviour, not that it is tested. Write what is true afterwards, `records the payment of an invoice`, not `should record` or `works correctly`.',
23
+ code: 'The title "{{title}}" names code (`{{code}}`). A title is in the words of the business, never the name of a method or a class: the reader learns the rule, and finds the code below.',
24
+ group: 'The group "{{title}}" is named after its tests. `describe` names the unit under test, the aggregate (`Invoice`), the use case (`Issue invoice`) or the route (`POST /invoices`), and each `it` states one of its rules.',
25
+ empty: 'The title is empty: a test is named after the rule it proves, a group after the unit it tests.',
26
+ },
27
+ create({ file, sourceCode, report }) {
28
+ if (!file.isTest) {
29
+ return {};
30
+ }
31
+ return {
32
+ CallExpression(node) {
33
+ const call = testCall(sourceCode, node);
34
+ const text = titleText(call?.title);
35
+ if (call === undefined || text === undefined) {
36
+ return;
37
+ }
38
+ const title = call.title ?? call.head;
39
+ const problem = call.kind === 'group' ? groupProblem(text) : testProblem(text);
40
+ if (problem !== undefined) {
41
+ report({ node: title, messageId: problem.messageId, data: { title: text.trim(), ...problem.data } });
42
+ }
43
+ },
44
+ };
45
+ },
46
+ });
47
+ function testProblem(text) {
48
+ const rule = text.replace(CITATIONS, '').trim();
49
+ if (rule === '') {
50
+ return { messageId: 'empty' };
51
+ }
52
+ const meta = META.exec(rule);
53
+ if (meta !== null) {
54
+ return { messageId: 'word', data: { word: meta[0] } };
55
+ }
56
+ const code = CODE.exec(rule);
57
+ if (code !== null) {
58
+ return { messageId: 'code', data: { code: code[0] } };
59
+ }
60
+ return PLACEHOLDER.test(rule) || /^[a-z]/.test(rule) ? undefined : { messageId: 'rule' };
61
+ }
62
+ function groupProblem(text) {
63
+ if (text.trim() === '') {
64
+ return { messageId: 'empty' };
65
+ }
66
+ return GROUP_META.test(text.trim()) ? { messageId: 'group' } : undefined;
67
+ }
68
+ //# sourceMappingURL=test-title-states-a-rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-title-states-a-rule.js","sourceRoot":"","sources":["../../src/rules/test-title-states-a-rule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,C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AAC3F,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACvB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;IAChC,CAAC;IAED,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC"}
@@ -1,4 +1,7 @@
1
1
  import type { TSESTree } from '@typescript-eslint/utils';
2
- /** `node` and every node below it, in source order, without a visitor: for a tree read once. */
3
- export declare function descendants(node: TSESTree.Node): Generator<TSESTree.Node>;
2
+ /**
3
+ * `node` and every node below it, in source order, without a visitor: for a tree read once. Nothing
4
+ * for what is not a node: a body a parser leaves null, as the JS plugin API of Oxlint does.
5
+ */
6
+ export declare function descendants(node: TSESTree.Node | null | undefined): Generator<TSESTree.Node>;
4
7
  //# sourceMappingURL=descendants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"descendants.d.ts","sourceRoot":"","sources":["../../src/support/descendants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGzD,gGAAgG;AAChG,wBAAiB,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAkB1E"}
1
+ {"version":3,"file":"descendants.d.ts","sourceRoot":"","sources":["../../src/support/descendants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGzD;;;GAGG;AACH,wBAAiB,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAsB7F"}
@@ -1,6 +1,12 @@
1
1
  import { isRecord } from '../project/is-record.js';
2
- /** `node` and every node below it, in source order, without a visitor: for a tree read once. */
2
+ /**
3
+ * `node` and every node below it, in source order, without a visitor: for a tree read once. Nothing
4
+ * for what is not a node: a body a parser leaves null, as the JS plugin API of Oxlint does.
5
+ */
3
6
  export function* descendants(node) {
7
+ if (node === null || node === undefined) {
8
+ return;
9
+ }
4
10
  yield node;
5
11
  const entries = Object.entries(node);
6
12
  for (const [key, value] of entries) {
@@ -1 +1 @@
1
- {"version":3,"file":"descendants.js","sourceRoot":"","sources":["../../src/support/descendants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,gGAAgG;AAChG,MAAM,SAAS,CAAC,CAAC,WAAW,CAAC,IAAmB;IAC9C,MAAM,IAAI,CAAC;IAEX,MAAM,OAAO,GAAwB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACnC,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrB,SAAS;QACX,CAAC;QAED,MAAM,QAAQ,GAAuB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAE5E,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClB,KAAK,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/F,CAAC"}
1
+ {"version":3,"file":"descendants.js","sourceRoot":"","sources":["../../src/support/descendants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD;;;GAGG;AACH,MAAM,SAAS,CAAC,CAAC,WAAW,CAAC,IAAsC;IACjE,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxC,OAAO;IACT,CAAC;IAED,MAAM,IAAI,CAAC;IAEX,MAAM,OAAO,GAAwB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACnC,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrB,SAAS;QACX,CAAC;QAED,MAAM,QAAQ,GAAuB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAE5E,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClB,KAAK,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/F,CAAC"}
@@ -36,12 +36,20 @@ function describe(declared, sourceCode) {
36
36
  const variable = sourceCode
37
37
  .getDeclaredVariables(declared.extent)
38
38
  .find((candidate) => candidate.identifiers.includes(declared.id));
39
- const references = variable?.references.filter((reference) => !reference.init && reference.isValueReference) ?? [];
39
+ const references = variable?.references.filter((reference) => !reference.init && isValue(reference)) ?? [];
40
40
  return {
41
41
  ...declared,
42
42
  uses: references.map((reference) => reference.identifier).filter((use) => !isInside(use, declared.extent)),
43
43
  };
44
44
  }
45
+ /**
46
+ * A reference to the value of the function, not to its type. The scope manager of typescript-eslint
47
+ * says which is which; the one of the default parser of ESLint, which lints a script, says nothing,
48
+ * and a script has no types: every reference it holds is a value.
49
+ */
50
+ function isValue(reference) {
51
+ return Reflect.has(reference, 'isValueReference') ? reference.isValueReference : true;
52
+ }
45
53
  function callGraph(declared) {
46
54
  const graph = new CallGraph();
47
55
  for (const callee of declared) {
@@ -1 +1 @@
1
- {"version":3,"file":"misplaced-functions.js","sourceRoot":"","sources":["../../../src/support/stepdown/misplaced-functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAgC,MAAM,0BAA0B,CAAC;AACxF,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAiBpD,0EAA0E;AAC1E,MAAM,UAAU,kBAAkB,CAChC,OAAyB,EACzB,UAAyC;IAEzC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;IACxF,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAElC,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACjC,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YACvG,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAA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C,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAE7E,OAAO,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,QAAQ,CAAC,GAAkB;IAClC,OAAO,CACL,GAAG,CAAC,MAAM,EAAE,IAAI,KAAK,cAAc,CAAC,eAAe,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,KAAK,cAAc,CAAC,wBAAwB,CACpH,CAAC;AACJ,CAAC;AAED,gGAAgG;AAChG,SAAS,UAAU,CAAC,GAAkB;IACpC,KAAK,MAAM,QAAQ,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,mBAAmB,EAAE,CAAC;YACjF,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,kBAAkB,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC5E,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,IAAmB,EAAE,SAAwB;IAC7D,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpF,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type TSESLint, type TSESTree } from '@typescript-eslint/utils';
2
+ /** A test or a group of tests a call declares. */
3
+ export interface TestCall {
4
+ readonly kind: 'test' | 'group';
5
+ /** The function of the runner the call is made under: `it`, `test`, `describe`, `suite`, `fit`, `xit`, `xdescribe`. */
6
+ readonly root: string;
7
+ /** The modifiers chained on it, in order: `['concurrent', 'only']`, `['each']`. */
8
+ readonly modifiers: readonly string[];
9
+ /** Where a report on the declaration points: `it.only`, `describe.each(rows)`. */
10
+ readonly head: TSESTree.Node;
11
+ readonly title: TSESTree.CallExpressionArgument | undefined;
12
+ readonly body: TSESTree.CallExpressionArgument | undefined;
13
+ }
14
+ /**
15
+ * The test or the group `node` declares, when it is one: `it(title, fn)`, `describe.each(rows)(title, fn)`,
16
+ * `test.todo(title)`, `xit(title, fn)`. Nothing for `it.each(rows)` alone, whose own call declares
17
+ * the test, nor when `it` is a local of the file instead of the runner's.
18
+ */
19
+ export declare function testCall(sourceCode: Readonly<TSESLint.SourceCode>, node: TSESTree.CallExpression): TestCall | undefined;
20
+ //# sourceMappingURL=test-call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-call.d.ts","sourceRoot":"","sources":["../../../src/support/tests/test-call.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AA+BxF,kDAAkD;AAClD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,uHAAuH;IACvH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mFAAmF;IACnF,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,sBAAsB,GAAG,SAAS,CAAC;IAC5D,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,sBAAsB,GAAG,SAAS,CAAC;CAC5D;AAOD;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,EACzC,IAAI,EAAE,QAAQ,CAAC,cAAc,GAC5B,QAAQ,GAAG,SAAS,CAiBtB"}
@@ -0,0 +1,77 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ import { ambientName } from '../globals/ambient-name.js';
3
+ import { propertyName } from '../globals/property-name.js';
4
+ /** The functions of a test runner that declare a test, Vitest and Jest alike. */
5
+ const TESTS = new Set(['it', 'test']);
6
+ /** The functions that declare a group of tests. */
7
+ const GROUPS = new Set(['describe', 'suite']);
8
+ /** The focused and the skipped forms Jest kept from Jasmine: `fit`, `xit`, `xdescribe`. */
9
+ const PREFIXED = /^[fx](it|test|describe)$/;
10
+ /** What a runner chains on `it` or `describe` before the title: `it.each(rows)(title, fn)`, `describe.skip(title, fn)`. */
11
+ const MODIFIERS = new Set([
12
+ 'each',
13
+ 'for',
14
+ 'skip',
15
+ 'only',
16
+ 'todo',
17
+ 'concurrent',
18
+ 'sequential',
19
+ 'shuffle',
20
+ 'skipIf',
21
+ 'runIf',
22
+ 'fails',
23
+ ]);
24
+ /** The modifiers that take their own arguments first, the title and the body coming in a second call. */
25
+ const CURRIED = new Set(['each', 'for', 'skipIf', 'runIf']);
26
+ /**
27
+ * The test or the group `node` declares, when it is one: `it(title, fn)`, `describe.each(rows)(title, fn)`,
28
+ * `test.todo(title)`, `xit(title, fn)`. Nothing for `it.each(rows)` alone, whose own call declares
29
+ * the test, nor when `it` is a local of the file instead of the runner's.
30
+ */
31
+ export function testCall(sourceCode, node) {
32
+ const head = headOf(node.callee);
33
+ if (head === undefined) {
34
+ return undefined;
35
+ }
36
+ const { root, modifiers } = head;
37
+ const kind = kindOf(root.name);
38
+ if (kind === undefined || ambientName(sourceCode, root) !== root.name) {
39
+ return undefined;
40
+ }
41
+ const [title, body] = node.arguments;
42
+ return { kind, root: root.name, modifiers, head: node.callee, title, body };
43
+ }
44
+ /** The runner function and the modifiers a callee chains, or nothing when the chain holds anything else. */
45
+ function headOf(callee) {
46
+ if (callee.type === AST_NODE_TYPES.Identifier) {
47
+ return { root: callee, modifiers: [] };
48
+ }
49
+ if (callee.type === AST_NODE_TYPES.CallExpression) {
50
+ const inner = chainOf(callee.callee);
51
+ return inner !== undefined && CURRIED.has(inner.modifiers.at(-1) ?? '') ? inner : undefined;
52
+ }
53
+ const chain = chainOf(callee);
54
+ return chain !== undefined && !CURRIED.has(chain.modifiers.at(-1) ?? '') ? chain : undefined;
55
+ }
56
+ /** `it.concurrent.only` read as its root and its modifiers. */
57
+ function chainOf(callee) {
58
+ const modifiers = [];
59
+ let current = callee;
60
+ while (current.type === AST_NODE_TYPES.MemberExpression) {
61
+ const name = propertyName(current);
62
+ if (name === undefined || !MODIFIERS.has(name)) {
63
+ return undefined;
64
+ }
65
+ modifiers.unshift(name);
66
+ current = current.object;
67
+ }
68
+ return current.type === AST_NODE_TYPES.Identifier ? { root: current, modifiers } : undefined;
69
+ }
70
+ function kindOf(root) {
71
+ const bare = PREFIXED.exec(root)?.[1] ?? root;
72
+ if (TESTS.has(bare)) {
73
+ return 'test';
74
+ }
75
+ return GROUPS.has(bare) ? 'group' : undefined;
76
+ }
77
+ //# sourceMappingURL=test-call.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-call.js","sourceRoot":"","sources":["../../../src/support/tests/test-call.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAgC,MAAM,0BAA0B,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,iFAAiF;AACjF,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAEtC,mDAAmD;AACnD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;AAE9C,2FAA2F;AAC3F,MAAM,QAAQ,GAAG,0BAA0B,CAA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ED,SAAS,MAAM,CAAC,IAAY;IAC1B,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAE9C,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAChD,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type TSESTree } from '@typescript-eslint/utils';
2
+ /**
3
+ * The text of a title: a string literal, or a template whose expressions read as placeholders, the way
4
+ * `it.each` fills `%s` and `$name`. Nothing for a title held in a variable, which is not judged.
5
+ */
6
+ export declare function titleText(node: TSESTree.CallExpressionArgument | undefined): string | undefined;
7
+ //# sourceMappingURL=title-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"title-text.d.ts","sourceRoot":"","sources":["../../../src/support/tests/title-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAKzE;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,sBAAsB,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAgB/F"}
@@ -0,0 +1,22 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/utils';
2
+ /** How an expression of a template title is read: as the placeholder of a table-driven title. */
3
+ const PLACEHOLDER = '$value';
4
+ /**
5
+ * The text of a title: a string literal, or a template whose expressions read as placeholders, the way
6
+ * `it.each` fills `%s` and `$name`. Nothing for a title held in a variable, which is not judged.
7
+ */
8
+ export function titleText(node) {
9
+ if (node === undefined) {
10
+ return undefined;
11
+ }
12
+ if (node.type === AST_NODE_TYPES.Literal) {
13
+ return typeof node.value === 'string' ? node.value : undefined;
14
+ }
15
+ if (node.type !== AST_NODE_TYPES.TemplateLiteral) {
16
+ return undefined;
17
+ }
18
+ return node.quasis
19
+ .map((quasi, index) => (quasi.value.cooked ?? '') + (index < node.expressions.length ? PLACEHOLDER : ''))
20
+ .join('');
21
+ }
22
+ //# sourceMappingURL=title-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"title-text.js","sourceRoot":"","sources":["../../../src/support/tests/title-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AAEzE,iGAAiG;AACjG,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAiD;IACzE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,OAAO,EAAE,CAAC;QACzC,OAAO,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,eAAe,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,IAAI,CAAC,MAAM;SACf,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACxG,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.87.0";
1
+ export declare const VERSION = "0.89.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.87.0';
1
+ export const VERSION = '0.89.0';
2
2
  //# sourceMappingURL=version.js.map
@@ -1,5 +1,5 @@
1
1
  [English](errors-factory-name.md) · **Français**
2
- <!-- translation-of: errors-factory-name.md sha256:258dda2c58b2caff -->
2
+ <!-- translation-of: errors-factory-name.md sha256:605131b1f3540fac -->
3
3
 
4
4
  # ddd-ts-kit/errors-factory-name
5
5
 
@@ -21,7 +21,7 @@ Sous `named` :
21
21
  - une fabrique dont le nom ne commence pas par `for`, `with`, `because`, `on` ou `at` suivi d'une majuscule (`forAccountId`, `withNotice`, `becauseOf`, `onDate`, `atStart`) : `slotTaken`, `create`, `format` et `onboard` sont signalés, et le message propose `for` devant le nom
22
22
  - une fabrique dont le nom contient un chiffre (`forAccount2`)
23
23
 
24
- Le code n'est pas lu ici : sous `named`, une classe lit son code dans le `codes.ts` de son contexte, ce que tient `errors/code-listed` du *checker*.
24
+ Le code n'est pas lu ici : sous `named`, une classe lit son code dans le `<context>.codes.ts` de son contexte, ce que tient `errors/code-listed` du *checker*.
25
25
 
26
26
  Incorrect, sous `named` :
27
27
 
@@ -75,7 +75,7 @@ Aucune.
75
75
 
76
76
  `rules."errors/factory-name"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line errors/factory-name -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
77
77
 
78
- Un code déjà publié sous d'autres mots ne peut pas changer. Sous `named`, rien n'a à céder : le code est écrit dans `codes.ts`, à part des noms de la classe et de ses fabriques, et un projet migré y garde ses codes publiés. Sous `factories`, renommez la fabrique d'après le code, ou gardez le nom et désactivez cette ligne avec la raison.
78
+ Un code déjà publié sous d'autres mots ne peut pas changer. Sous `named`, rien n'a à céder : le code est écrit dans `<context>.codes.ts`, à part des noms de la classe et de ses fabriques, et un projet migré y garde ses codes publiés. Sous `factories`, renommez la fabrique d'après le code, ou gardez le nom et désactivez cette ligne avec la raison.
79
79
 
80
80
  ## Limites
81
81
 
@@ -84,4 +84,4 @@ Un code déjà publié sous d'autres mots ne peut pas changer. Sous `named`, rie
84
84
 
85
85
  ## Avec le checker de la CLI
86
86
 
87
- Tenue par ce *plugin* seul. Qu'un code soit unique dans son contexte relève de `errors/code-unique`, et sous `named` qu'une classe lise son code dans le `codes.ts` de son contexte relève de `errors/code-listed`, toutes deux tenues par le *checker*.
87
+ Tenue par ce *plugin* seul. Qu'un code soit unique dans son contexte relève de `errors/code-unique`, et sous `named` qu'une classe lise son code dans le `<context>.codes.ts` de son contexte relève de `errors/code-listed`, toutes deux tenues par le *checker*.
@@ -20,7 +20,7 @@ Under `named`:
20
20
  - a factory whose name does not start with `for`, `with`, `because`, `on` or `at` followed by an upper-case letter (`forAccountId`, `withNotice`, `becauseOf`, `onDate`, `atStart`): `slotTaken`, `create`, `format` and `onboard` are reported, and the message proposes `for` before the name
21
21
  - a factory whose name holds a digit (`forAccount2`)
22
22
 
23
- The code is not read here: under `named` a class reads its code from the `codes.ts` of its context, which `errors/code-listed` of the checker holds.
23
+ The code is not read here: under `named` a class reads its code from the `<context>.codes.ts` of its context, which `errors/code-listed` of the checker holds.
24
24
 
25
25
  Incorrect, under `named`:
26
26
 
@@ -74,7 +74,7 @@ None.
74
74
 
75
75
  `rules."errors/factory-name"` in `ddd-ts-kit.config.json` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line errors/factory-name -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
76
76
 
77
- A code already published under other words cannot change. Under `named` nothing has to give: the code is written in `codes.ts`, apart from the names of the class and its factories, and a migrated project keeps its published codes there. Under `factories`, rename the factory after the code, or keep the name and silence that line with the reason.
77
+ A code already published under other words cannot change. Under `named` nothing has to give: the code is written in `<context>.codes.ts`, apart from the names of the class and its factories, and a migrated project keeps its published codes there. Under `factories`, rename the factory after the code, or keep the name and silence that line with the reason.
78
78
 
79
79
  ## Limits
80
80
 
@@ -83,4 +83,4 @@ A code already published under other words cannot change. Under `named` nothing
83
83
 
84
84
  ## With the CLI checker
85
85
 
86
- Held by this plugin alone. That a code is unique in its context is `errors/code-unique`, and under `named` that a class reads its code from the `codes.ts` of its context is `errors/code-listed`, both held by the checker.
86
+ Held by this plugin alone. That a code is unique in its context is `errors/code-unique`, and under `named` that a class reads its code from the `<context>.codes.ts` of its context is `errors/code-listed`, both held by the checker.
@@ -0,0 +1,58 @@
1
+ [English](test-assertion-present.md) · **Français**
2
+ <!-- translation-of: test-assertion-present.md sha256:1047d2cf38c27c16 -->
3
+
4
+ # ddd-ts-kit/test-assertion-present
5
+
6
+ Identifiant d'architecture : `test/assertion-present` (ajouté par ce *plugin*). Sévérité par défaut : `warn` dans `recommended` (une erreur à partir de 0.90.0 : `ddd-ts-kit lint` montre ses avertissements sans échouer dessus jusque-là), `error` dans `strict`.
7
+
8
+ S'applique à : chaque fichier de test du projet (`*.spec.ts`, `*.test.ts`, le `test/` d'un contexte).
9
+
10
+ ## Pourquoi
11
+
12
+ Un test qui ne vérifie rien passe quoi que fasse le code, et fait monter le taux de couverture sans rien prouver : c'est le trou que `test/coverage-governed` ne peut pas voir. Le kit vérifie des résultats : l'état d'un *fake*, les faits enregistrés, le refus par son code, la réponse d'une route.
13
+
14
+ ## Signalé
15
+
16
+ - un `it` ou un `test` dont le corps ne contient aucun appel à `expect`, à une fonction nommée `expect...` ou `assert...` (`expectRefusal`, `expectProblem`, `expectStatus`, `expectSpanTree`, un *helper* du projet), ni au résultat d'un scénario de `@ddd-ts-kit/testing` (`thenEvents`, `thenEventNames`, `thenError`, `thenState`, `thenNoEvent`)
17
+ - un `it` ou un `test` avec un titre et sans corps, que Vitest compte comme un *todo* et que Jest refuse
18
+
19
+ Incorrect :
20
+
21
+ ```ts
22
+ it('issues the invoice', async () => {
23
+ await application.commandBus.execute(new IssueInvoiceCommand(holder, 'customer-1'));
24
+ });
25
+
26
+ it('refuses a second payment');
27
+ ```
28
+
29
+ Correct :
30
+
31
+ ```ts
32
+ it('issues the invoice and answers its identifier', async () => {
33
+ const id = await application.commandBus.execute(new IssueInvoiceCommand(holder, 'customer-1'));
34
+
35
+ expect(await invoiceRepository.findById(id)).toBeDefined();
36
+ });
37
+
38
+ it.todo('refuses a second payment');
39
+ ```
40
+
41
+ ## Détails
42
+
43
+ Le corps est lu en entier, scénario enveloppé par `pending(...)` compris, de sorte qu'un scénario d'acceptation qui attend son code est jugé comme les autres. Un *helper* qui vérifie pour plusieurs tests se nomme `expect...` ou `assert...` : la règle le voit alors, et le lecteur aussi.
44
+
45
+ ## Options
46
+
47
+ Aucune.
48
+
49
+ `rules."test/assertion-present"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line test/assertion-present -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
50
+
51
+ ## Limites
52
+
53
+ - La règle voit qu'une vérification est faite, pas qu'elle porte sur le résultat : `expect(true).toBe(true)` passe. La revue lit ce qui est vérifié.
54
+ - Un `.then(...)` sur une promesse n'est pas le résultat d'un scénario.
55
+
56
+ ## Avec le checker de la CLI
57
+
58
+ Nouveau avec ce *plugin* : le *checker* de la CLI n'a pas d'équivalent, car lire un test demande un arbre syntaxique.
@@ -0,0 +1,57 @@
1
+ **English** · [Français](test-assertion-present.fr.md)
2
+
3
+ # ddd-ts-kit/test-assertion-present
4
+
5
+ Architecture id: `test/assertion-present` (added by this plugin). Default severity: `warn` in `recommended` (an error from 0.90.0: `ddd-ts-kit lint` shows its warnings without failing on them until then), `error` in `strict`.
6
+
7
+ Applies to: every test file of the project (`*.spec.ts`, `*.test.ts`, the `test/` of a context).
8
+
9
+ ## Why
10
+
11
+ A test that asserts nothing passes whatever the code does, and raises the coverage rate while proving nothing: it is the gap `test/coverage-governed` cannot see. The kit asserts outcomes: the state of a fake, the facts recorded, the refusal by its code, the answer of a route.
12
+
13
+ ## Reported
14
+
15
+ - an `it` or a `test` whose body holds no call to `expect`, to a function named `expect...` or `assert...` (`expectRefusal`, `expectProblem`, `expectStatus`, `expectSpanTree`, a helper of the project), or to the outcome of a scenario of `@ddd-ts-kit/testing` (`thenEvents`, `thenEventNames`, `thenError`, `thenState`, `thenNoEvent`)
16
+ - an `it` or a `test` with a title and no body, which Vitest counts as a todo and Jest refuses
17
+
18
+ Incorrect:
19
+
20
+ ```ts
21
+ it('issues the invoice', async () => {
22
+ await application.commandBus.execute(new IssueInvoiceCommand(holder, 'customer-1'));
23
+ });
24
+
25
+ it('refuses a second payment');
26
+ ```
27
+
28
+ Correct:
29
+
30
+ ```ts
31
+ it('issues the invoice and answers its identifier', async () => {
32
+ const id = await application.commandBus.execute(new IssueInvoiceCommand(holder, 'customer-1'));
33
+
34
+ expect(await invoiceRepository.findById(id)).toBeDefined();
35
+ });
36
+
37
+ it.todo('refuses a second payment');
38
+ ```
39
+
40
+ ## Details
41
+
42
+ The body is read whole, the scenario `pending(...)` wraps included, so an acceptance scenario waiting for its code is judged like any other. A helper that asserts for several tests is named `expect...` or `assert...`: the rule then sees it, and so does the reader.
43
+
44
+ ## Options
45
+
46
+ None.
47
+
48
+ `rules."test/assertion-present"` in `ddd-ts-kit.config.json` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line test/assertion-present -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
49
+
50
+ ## Limits
51
+
52
+ - The rule sees that an assertion is made, not that it bears on the outcome: `expect(true).toBe(true)` passes. The review reads what is asserted.
53
+ - A `.then(...)` on a promise is not an outcome of a scenario.
54
+
55
+ ## With the CLI checker
56
+
57
+ New with this plugin: the CLI checker has no equivalent, because reading a test needs a syntax tree.