@ddd-ts-kit/eslint-plugin 0.88.0 → 0.90.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 (58) hide show
  1. package/README.fr.md +8 -2
  2. package/README.md +7 -1
  3. package/dist/rules/rules.d.ts.map +1 -1
  4. package/dist/rules/rules.js +12 -0
  5. package/dist/rules/rules.js.map +1 -1
  6. package/dist/rules/test-assertion-present.d.ts +2 -0
  7. package/dist/rules/test-assertion-present.d.ts.map +1 -0
  8. package/dist/rules/test-assertion-present.js +69 -0
  9. package/dist/rules/test-assertion-present.js.map +1 -0
  10. package/dist/rules/test-no-logic.d.ts +2 -0
  11. package/dist/rules/test-no-logic.d.ts.map +1 -0
  12. package/dist/rules/test-no-logic.js +45 -0
  13. package/dist/rules/test-no-logic.js.map +1 -0
  14. package/dist/rules/test-no-only-no-skip.d.ts +2 -0
  15. package/dist/rules/test-no-only-no-skip.d.ts.map +1 -0
  16. package/dist/rules/test-no-only-no-skip.js +53 -0
  17. package/dist/rules/test-no-only-no-skip.js.map +1 -0
  18. package/dist/rules/test-no-snapshot.d.ts +2 -0
  19. package/dist/rules/test-no-snapshot.d.ts.map +1 -0
  20. package/dist/rules/test-no-snapshot.js +37 -0
  21. package/dist/rules/test-no-snapshot.js.map +1 -0
  22. package/dist/rules/test-refusal-by-code.d.ts +2 -0
  23. package/dist/rules/test-refusal-by-code.d.ts.map +1 -0
  24. package/dist/rules/test-refusal-by-code.js +70 -0
  25. package/dist/rules/test-refusal-by-code.js.map +1 -0
  26. package/dist/rules/test-title-states-a-rule.d.ts +4 -0
  27. package/dist/rules/test-title-states-a-rule.d.ts.map +1 -0
  28. package/dist/rules/test-title-states-a-rule.js +67 -0
  29. package/dist/rules/test-title-states-a-rule.js.map +1 -0
  30. package/dist/support/descendants.d.ts +5 -2
  31. package/dist/support/descendants.d.ts.map +1 -1
  32. package/dist/support/descendants.js +7 -1
  33. package/dist/support/descendants.js.map +1 -1
  34. package/dist/support/stepdown/misplaced-functions.js +9 -1
  35. package/dist/support/stepdown/misplaced-functions.js.map +1 -1
  36. package/dist/support/tests/test-call.d.ts +20 -0
  37. package/dist/support/tests/test-call.d.ts.map +1 -0
  38. package/dist/support/tests/test-call.js +77 -0
  39. package/dist/support/tests/test-call.js.map +1 -0
  40. package/dist/support/tests/title-text.d.ts +7 -0
  41. package/dist/support/tests/title-text.d.ts.map +1 -0
  42. package/dist/support/tests/title-text.js +22 -0
  43. package/dist/support/tests/title-text.js.map +1 -0
  44. package/dist/version.d.ts +1 -1
  45. package/dist/version.js +1 -1
  46. package/docs/rules/test-assertion-present.fr.md +58 -0
  47. package/docs/rules/test-assertion-present.md +57 -0
  48. package/docs/rules/test-no-logic.fr.md +71 -0
  49. package/docs/rules/test-no-logic.md +70 -0
  50. package/docs/rules/test-no-only-no-skip.fr.md +56 -0
  51. package/docs/rules/test-no-only-no-skip.md +55 -0
  52. package/docs/rules/test-no-snapshot.fr.md +52 -0
  53. package/docs/rules/test-no-snapshot.md +51 -0
  54. package/docs/rules/test-refusal-by-code.fr.md +65 -0
  55. package/docs/rules/test-refusal-by-code.md +64 -0
  56. package/docs/rules/test-title-states-a-rule.fr.md +63 -0
  57. package/docs/rules/test-title-states-a-rule.md +62 -0
  58. package/package.json +1 -1
@@ -0,0 +1,51 @@
1
+ **English** · [Français](test-no-snapshot.fr.md)
2
+
3
+ # ddd-ts-kit/test-no-snapshot
4
+
5
+ Architecture id: `test/no-snapshot` (added by this plugin). Default severity: `error` in `recommended`, `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 snapshot records whatever the code produced the first time, and is renewed with one flag the next time it differs: it asserts nothing a reader can check against the rule, and it fails on every field the rule does not depend on. A test states the fields that matter, built in the test, so that the reader sees the cause of the outcome.
12
+
13
+ ## Reported
14
+
15
+ - `toMatchSnapshot`, `toMatchInlineSnapshot`, `toMatchFileSnapshot`
16
+ - `toThrowErrorMatchingSnapshot`, `toThrowErrorMatchingInlineSnapshot`
17
+
18
+ Incorrect:
19
+
20
+ ```ts
21
+ expect(invoice.toState()).toMatchSnapshot();
22
+ expect(() => invoice.pay(at)).toThrowErrorMatchingInlineSnapshot();
23
+ ```
24
+
25
+ Correct:
26
+
27
+ ```ts
28
+ expect(invoice.toState()).toMatchObject({ status: 'paid', paidAt: at });
29
+
30
+ given(anInvoice().paid())
31
+ .when((invoice) => invoice.pay(at))
32
+ .thenError('INVOICE_ALREADY_PAID');
33
+ ```
34
+
35
+ ## Details
36
+
37
+ The contracts the kit generates (OpenAPI, AsyncAPI, the event catalogue) are held by `ddd-ts-kit docs --check`, which compares the generated document with the committed one: that is the one place a whole document is compared, and it is not a test.
38
+
39
+ ## Options
40
+
41
+ None.
42
+
43
+ `rules."test/no-snapshot"` in `ddd-ts-kit.config.json` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line test/no-snapshot -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
44
+
45
+ ## Limits
46
+
47
+ - `toEqual` on a large object read from a fixture file is a snapshot by another name, and is not reported.
48
+
49
+ ## With the CLI checker
50
+
51
+ New with this plugin: the CLI checker has no equivalent, because reading a test needs a syntax tree.
@@ -0,0 +1,65 @@
1
+ [English](test-refusal-by-code.md) · **Français**
2
+ <!-- translation-of: test-refusal-by-code.md sha256:23f7e57668c1a946 -->
3
+
4
+ # ddd-ts-kit/test-refusal-by-code
5
+
6
+ Identifiant d'architecture : `test/refusal-by-code` (ajouté par ce *plugin*). Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : les *specs* du modèle et de l'application, `test/unit/` d'un contexte, le noyau partagé, `test/e2e/` et `test/acceptance/` (`*.spec.ts`, `*.test.ts`). Les *specs* des adaptateurs (`*.adapter.spec.ts`, `test/integration/`) et de la plateforme ne sont pas jugées.
9
+
10
+ ## Pourquoi
11
+
12
+ Un refus du modèle porte un code et ses faits (`INVOICE_ALREADY_PAID`, `{ invoiceId }`) : le client les reçoit dans le document de problème, le catalogue du contexte les liste, le lecteur du test apprend quelle règle a refusé. Un message est de la prose qu'une reformulation change sans changer la règle ; la classe d'une erreur est une implémentation que les fabriques de `domain/errors/` peuvent fondre dans une autre. Un `toThrow()` sans argument accepte n'importe quel échec, un `TypeError` du test compris.
13
+
14
+ ## Signalé
15
+
16
+ `toThrow` et `toThrowError`, après `expect(action)` ou `expect(promise).rejects`, quand leur argument est :
17
+
18
+ - rien
19
+ - une chaîne, un gabarit ou une expression régulière (un message)
20
+ - une classe, une variable ou `new Error(...)`
21
+
22
+ Incorrect :
23
+
24
+ ```ts
25
+ expect(() => invoice.pay(at)).toThrow('already paid');
26
+ expect(() => invoice.pay(at)).toThrow(InvoiceAlreadyPaid);
27
+ expect(() => Email.create(' ')).toThrow();
28
+ await expect(bus.execute(command)).rejects.toThrowError(/forbidden/);
29
+ ```
30
+
31
+ Correct :
32
+
33
+ ```ts
34
+ given(anInvoice().paid())
35
+ .when((invoice) => invoice.pay(at))
36
+ .thenError('INVOICE_ALREADY_PAID', { invoiceId: 'invoice-1' });
37
+
38
+ expectRefusal(() => Email.create(' '), 'INVALID_EMAIL', { given: ' ' });
39
+
40
+ await expect(bus.execute(command)).rejects.toMatchObject({ code: 'FORBIDDEN' });
41
+
42
+ expectProblem(response, { status: 409, code: 'SLOT_TAKEN' });
43
+ ```
44
+
45
+ ## Détails
46
+
47
+ `expect(action).not.toThrow()` dit qu'une action est acceptée et n'est pas signalé. `toThrow(expect.objectContaining({ code: 'INVOICE_ALREADY_PAID' }))` et `toThrow({ code: ... })` vérifient le code et ne sont pas signalés non plus, même si `thenError` et `expectRefusal` le disent plus court et comparent les faits.
48
+
49
+ Un échec que le test a lui-même injecté (`mailer.failNextWith(outage)`, un *middleware* qui lève) se vérifie comme lui-même, `await expect(bus.execute(command)).rejects.toBe(outage)` : c'est la preuve que cet échec, et pas un autre de même message, est remonté.
50
+
51
+ Un adaptateur, les *specs* d'intégration d'un contexte et la plateforme font face au système extérieur et à la machine : leurs échecs sont techniques (`KEYCLOAK_URL is not set`, `Keycloak answered 403`), leur message est ce qu'un opérateur lit, et c'est ce que leurs *specs* vérifient. Ils ne sont pas jugés.
52
+
53
+ ## Options
54
+
55
+ Aucune.
56
+
57
+ `rules."test/refusal-by-code"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line test/refusal-by-code -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
58
+
59
+ ## Limites
60
+
61
+ - Un *matcher* du projet qui compare un message (`expectFailure(action, 'message')`) n'est pas lu.
62
+
63
+ ## Avec le checker de la CLI
64
+
65
+ 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,64 @@
1
+ **English** · [Français](test-refusal-by-code.fr.md)
2
+
3
+ # ddd-ts-kit/test-refusal-by-code
4
+
5
+ Architecture id: `test/refusal-by-code` (added by this plugin). Default severity: `error` in `recommended`, `error` in `strict`.
6
+
7
+ Applies to: the specs of the model and of the application, `test/unit/` of a context, the shared kernel, `test/e2e/` and `test/acceptance/` (`*.spec.ts`, `*.test.ts`). The specs of the adapters (`*.adapter.spec.ts`, `test/integration/`) and of the platform are not judged.
8
+
9
+ ## Why
10
+
11
+ A refusal of the model carries a code and its facts (`INVOICE_ALREADY_PAID`, `{ invoiceId }`): the client receives them in the problem document, the catalogue of the context lists them, the reader of the test learns which rule refused. A message is prose that a rewording changes without changing the rule; the class of one error is an implementation the factories of `domain/errors/` may fold into another. A `toThrow()` without an argument accepts any failure, a `TypeError` of the test included.
12
+
13
+ ## Reported
14
+
15
+ `toThrow` and `toThrowError`, after `expect(action)` or `expect(promise).rejects`, when their argument is:
16
+
17
+ - nothing
18
+ - a string, a template or a regular expression (a message)
19
+ - a class, a variable or `new Error(...)`
20
+
21
+ Incorrect:
22
+
23
+ ```ts
24
+ expect(() => invoice.pay(at)).toThrow('already paid');
25
+ expect(() => invoice.pay(at)).toThrow(InvoiceAlreadyPaid);
26
+ expect(() => Email.create(' ')).toThrow();
27
+ await expect(bus.execute(command)).rejects.toThrowError(/forbidden/);
28
+ ```
29
+
30
+ Correct:
31
+
32
+ ```ts
33
+ given(anInvoice().paid())
34
+ .when((invoice) => invoice.pay(at))
35
+ .thenError('INVOICE_ALREADY_PAID', { invoiceId: 'invoice-1' });
36
+
37
+ expectRefusal(() => Email.create(' '), 'INVALID_EMAIL', { given: ' ' });
38
+
39
+ await expect(bus.execute(command)).rejects.toMatchObject({ code: 'FORBIDDEN' });
40
+
41
+ expectProblem(response, { status: 409, code: 'SLOT_TAKEN' });
42
+ ```
43
+
44
+ ## Details
45
+
46
+ `expect(action).not.toThrow()` says that an action is accepted and is not reported. `toThrow(expect.objectContaining({ code: 'INVOICE_ALREADY_PAID' }))` and `toThrow({ code: ... })` assert the code and are not reported either, although `thenError` and `expectRefusal` say it shorter and compare the facts.
47
+
48
+ A failure the test itself injected (`mailer.failNextWith(outage)`, a middleware that throws) is asserted as itself, `await expect(bus.execute(command)).rejects.toBe(outage)`: the proof that this failure, and not another with the same message, came through.
49
+
50
+ An adapter, the integration specs of a context and the platform face the outside system and the machine: their failures are technical (`KEYCLOAK_URL is not set`, `Keycloak answered 403`), their message is what an operator reads, and it is what their specs assert. They are not judged.
51
+
52
+ ## Options
53
+
54
+ None.
55
+
56
+ `rules."test/refusal-by-code"` in `ddd-ts-kit.config.json` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line test/refusal-by-code -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
57
+
58
+ ## Limits
59
+
60
+ - A matcher of the project that compares a message (`expectFailure(action, 'message')`) is not read.
61
+
62
+ ## With the CLI checker
63
+
64
+ New with this plugin: the CLI checker has no equivalent, because reading a test needs a syntax tree.
@@ -0,0 +1,63 @@
1
+ [English](test-title-states-a-rule.md) · **Français**
2
+ <!-- translation-of: test-title-states-a-rule.md sha256:e38c7696227c6f45 -->
3
+
4
+ # ddd-ts-kit/test-title-states-a-rule
5
+
6
+ Identifiant d'architecture : `test/title-states-a-rule` (ajouté par ce *plugin*). Sévérité par défaut : `error` dans `recommended`, `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
+ Les titres d'une *spec* en sont la seule partie que toute l'équipe lit : le rapport d'une exécution en échec, la liste qu'imprime `npm test`, la revue. Écrits comme des règles, dans les mots du métier, ils sont la spécification de l'unité, et un nouveau test s'écrit en énonçant une règle de plus. Écrits `should ...`, `test ...` ou d'après une méthode, ils disent que quelque chose est testé sans dire ce qui est vrai, et le lecteur ouvre le corps pour le savoir.
13
+
14
+ ## Signalé
15
+
16
+ Sur un `it` ou un `test`, après les *rows* et le critère que le titre cite (`#US5.02 AC1 ...`, `AC1 ...`, `#FIX-412 ...`) :
17
+
18
+ - un mot qui dit que le test est un test : `should`, `test`, `tests`, `testing`, `works`, `correctly`, `properly`, `successfully`, `as expected`, `make sure`, `ensures that`, `verifies that`, `checks that`
19
+ - un nom de code : un appel (`execute()`, `pay(at)`), un premier mot en camelCase (`issueInvoice`)
20
+ - un premier mot qui ne commence pas par une minuscule (`Refuses`, `The invoice`), sauf s'il est le paramètre d'un titre piloté par une table (`%s`, `$kind`)
21
+ - un titre vide
22
+
23
+ Sur un `describe` : un titre nommé d'après les tests (`tests`, `spec`, `suite`, `should`, un suffixe `Spec` ou `Test`) ou vide.
24
+
25
+ Incorrect :
26
+
27
+ ```ts
28
+ describe('Invoice tests', () => {
29
+ it('should refuse a second payment', () => { ... });
30
+ it('execute() saves the invoice', () => { ... });
31
+ it('Pays the invoice correctly', () => { ... });
32
+ });
33
+ ```
34
+
35
+ Correct :
36
+
37
+ ```ts
38
+ describe('Invoice', () => {
39
+ it('refuses to pay an invoice twice', () => { ... });
40
+ it('saves the invoice and answers its identifier', () => { ... });
41
+ it('#US5.02 AC1 a customer places an order', pending(async () => { ... }));
42
+ it.each(kinds)('%s announces an appointment to come', (kind) => { ... });
43
+ });
44
+ ```
45
+
46
+ ## Détails
47
+
48
+ Un titre tenu dans une variable n'est pas jugé. Un titre en gabarit est lu avec ses expressions comme paramètres : `` `answers ${status} to a caller` `` passe, et de même un titre qui commence par une expression. `describe` prend l'unité sous test, l'agrégat (`Invoice`), le cas d'usage (`Issue invoice`), la route (`POST /invoices`), un fait (`When scheduling publishes scheduling.appointment.booked`) : un nom, dans la casse qu'il a.
49
+
50
+ ## Options
51
+
52
+ Aucune.
53
+
54
+ `rules."test/title-states-a-rule"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line test/title-states-a-rule -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
55
+
56
+ ## Limites
57
+
58
+ - La règle lit la forme d'un titre, pas son sens : `records the payment` passe, que le test enregistre un paiement ou non. La revue lit le corps.
59
+ - Un verbe est reconnu à sa casse, pas à un dictionnaire : `the invoice is paid` passe.
60
+
61
+ ## Avec le checker de la CLI
62
+
63
+ 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,62 @@
1
+ **English** · [Français](test-title-states-a-rule.fr.md)
2
+
3
+ # ddd-ts-kit/test-title-states-a-rule
4
+
5
+ Architecture id: `test/title-states-a-rule` (added by this plugin). Default severity: `error` in `recommended`, `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
+ The titles of a spec are the only part of it the whole team reads: the report of a failed run, the list `npm test` prints, the review. Written as rules, in the words of the business, they are the specification of the unit, and a new test is written by stating one more rule. Written as `should ...`, `test ...` or after a method, they say that something is tested without saying what is true, and the reader opens the body to find out.
12
+
13
+ ## Reported
14
+
15
+ On an `it` or a `test`, after the rows and the criterion the title cites (`#US5.02 AC1 ...`, `AC1 ...`, `#FIX-412 ...`):
16
+
17
+ - a word that says the test is a test: `should`, `test`, `tests`, `testing`, `works`, `correctly`, `properly`, `successfully`, `as expected`, `make sure`, `ensures that`, `verifies that`, `checks that`
18
+ - a name of code: a call (`execute()`, `pay(at)`), a first word in camelCase (`issueInvoice`)
19
+ - a first word that does not start with a lower-case letter (`Refuses`, `The invoice`), unless it is the placeholder of a table-driven title (`%s`, `$kind`)
20
+ - an empty title
21
+
22
+ On a `describe`: a title named after the tests (`tests`, `spec`, `suite`, `should`, a `Spec` or `Test` suffix) or empty.
23
+
24
+ Incorrect:
25
+
26
+ ```ts
27
+ describe('Invoice tests', () => {
28
+ it('should refuse a second payment', () => { ... });
29
+ it('execute() saves the invoice', () => { ... });
30
+ it('Pays the invoice correctly', () => { ... });
31
+ });
32
+ ```
33
+
34
+ Correct:
35
+
36
+ ```ts
37
+ describe('Invoice', () => {
38
+ it('refuses to pay an invoice twice', () => { ... });
39
+ it('saves the invoice and answers its identifier', () => { ... });
40
+ it('#US5.02 AC1 a customer places an order', pending(async () => { ... }));
41
+ it.each(kinds)('%s announces an appointment to come', (kind) => { ... });
42
+ });
43
+ ```
44
+
45
+ ## Details
46
+
47
+ A title held in a variable is not judged. A template title is read with its expressions as placeholders: `` `answers ${status} to a caller` `` passes, and so does one that starts with an expression. `describe` takes the unit under test, the aggregate (`Invoice`), the use case (`Issue invoice`), the route (`POST /invoices`), a fact (`When scheduling publishes scheduling.appointment.booked`): a noun, in any case.
48
+
49
+ ## Options
50
+
51
+ None.
52
+
53
+ `rules."test/title-states-a-rule"` in `ddd-ts-kit.config.json` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line test/title-states-a-rule -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
54
+
55
+ ## Limits
56
+
57
+ - The rule reads the form of a title, not its meaning: `records the payment` passes whether or not the test records a payment. The review reads the body.
58
+ - A verb is recognised by its case, not by a dictionary: `the invoice is paid` passes.
59
+
60
+ ## With the CLI checker
61
+
62
+ New with this plugin: the CLI checker has no equivalent, because reading a test needs a syntax tree.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-ts-kit/eslint-plugin",
3
- "version": "0.88.0",
3
+ "version": "0.90.0",
4
4
  "description": "AST-accurate ESLint rules for DDD and Clean Architecture in TypeScript: layer and context isolation, domain purity, clean code ordering.",
5
5
  "keywords": [
6
6
  "ddd",