@ddd-ts-kit/eslint-plugin 0.15.0 → 0.16.1

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 (209) hide show
  1. package/README.fr.md +464 -0
  2. package/README.md +149 -9
  3. package/dist/project/config.d.ts +2 -0
  4. package/dist/project/config.d.ts.map +1 -1
  5. package/dist/project/parse-config.d.ts.map +1 -1
  6. package/dist/project/parse-config.js +2 -0
  7. package/dist/project/parse-config.js.map +1 -1
  8. package/dist/rules/domain-value-object-class.d.ts +4 -0
  9. package/dist/rules/domain-value-object-class.d.ts.map +1 -0
  10. package/dist/rules/domain-value-object-class.js +85 -0
  11. package/dist/rules/domain-value-object-class.js.map +1 -0
  12. package/dist/rules/rules.d.ts.map +1 -1
  13. package/dist/rules/rules.js +2 -0
  14. package/dist/rules/rules.js.map +1 -1
  15. package/dist/support/values/answered-objects.d.ts +8 -0
  16. package/dist/support/values/answered-objects.d.ts.map +1 -0
  17. package/dist/support/values/answered-objects.js +34 -0
  18. package/dist/support/values/answered-objects.js.map +1 -0
  19. package/dist/support/values/entry-role.d.ts +11 -0
  20. package/dist/support/values/entry-role.d.ts.map +1 -0
  21. package/dist/support/values/entry-role.js +45 -0
  22. package/dist/support/values/entry-role.js.map +1 -0
  23. package/dist/support/values/exported-bindings.d.ts +21 -0
  24. package/dist/support/values/exported-bindings.d.ts.map +1 -0
  25. package/dist/support/values/exported-bindings.js +76 -0
  26. package/dist/support/values/exported-bindings.js.map +1 -0
  27. package/dist/support/values/extends-value-object.d.ts +10 -0
  28. package/dist/support/values/extends-value-object.d.ts.map +1 -0
  29. package/dist/support/values/extends-value-object.js +36 -0
  30. package/dist/support/values/extends-value-object.js.map +1 -0
  31. package/dist/support/values/is-model-path.d.ts +8 -0
  32. package/dist/support/values/is-model-path.d.ts.map +1 -0
  33. package/dist/support/values/is-model-path.js +16 -0
  34. package/dist/support/values/is-model-path.js.map +1 -0
  35. package/dist/support/values/is-value-object-path.d.ts +7 -0
  36. package/dist/support/values/is-value-object-path.d.ts.map +1 -0
  37. package/dist/support/values/is-value-object-path.js +15 -0
  38. package/dist/support/values/is-value-object-path.js.map +1 -0
  39. package/dist/support/values/javascript-globals.d.ts +3 -0
  40. package/dist/support/values/javascript-globals.d.ts.map +1 -0
  41. package/dist/support/values/javascript-globals.js +22 -0
  42. package/dist/support/values/javascript-globals.js.map +1 -0
  43. package/dist/support/values/local-binding.d.ts +5 -0
  44. package/dist/support/values/local-binding.d.ts.map +1 -0
  45. package/dist/support/values/local-binding.js +23 -0
  46. package/dist/support/values/local-binding.js.map +1 -0
  47. package/dist/support/values/returns-package-type.d.ts +9 -0
  48. package/dist/support/values/returns-package-type.d.ts.map +1 -0
  49. package/dist/support/values/returns-package-type.js +28 -0
  50. package/dist/support/values/returns-package-type.js.map +1 -0
  51. package/dist/support/values/root-name.d.ts +4 -0
  52. package/dist/support/values/root-name.d.ts.map +1 -0
  53. package/dist/support/values/root-name.js +23 -0
  54. package/dist/support/values/root-name.js.map +1 -0
  55. package/dist/support/values/stands-for-a-value.d.ts +10 -0
  56. package/dist/support/values/stands-for-a-value.d.ts.map +1 -0
  57. package/dist/support/values/stands-for-a-value.js +31 -0
  58. package/dist/support/values/stands-for-a-value.js.map +1 -0
  59. package/dist/support/values/unwrapped.d.ts +4 -0
  60. package/dist/support/values/unwrapped.d.ts.map +1 -0
  61. package/dist/support/values/unwrapped.js +11 -0
  62. package/dist/support/values/unwrapped.js.map +1 -0
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +1 -1
  65. package/docs/rules/application-command-query-separation.fr.md +57 -0
  66. package/docs/rules/application-command-query-separation.md +2 -0
  67. package/docs/rules/application-handler-shape.fr.md +55 -0
  68. package/docs/rules/application-handler-shape.md +2 -0
  69. package/docs/rules/aspects-outside-in.fr.md +57 -0
  70. package/docs/rules/aspects-outside-in.md +2 -0
  71. package/docs/rules/authz-actor-explicit.fr.md +73 -0
  72. package/docs/rules/authz-actor-explicit.md +2 -0
  73. package/docs/rules/authz-declared.fr.md +90 -0
  74. package/docs/rules/authz-declared.md +2 -0
  75. package/docs/rules/authz-fields-by-schema.fr.md +54 -0
  76. package/docs/rules/authz-fields-by-schema.md +2 -0
  77. package/docs/rules/authz-in-application.fr.md +91 -0
  78. package/docs/rules/authz-in-application.md +2 -0
  79. package/docs/rules/clean-blank-lines.fr.md +90 -0
  80. package/docs/rules/clean-blank-lines.md +2 -0
  81. package/docs/rules/clean-braces.fr.md +64 -0
  82. package/docs/rules/clean-braces.md +2 -0
  83. package/docs/rules/clean-file-size.fr.md +46 -0
  84. package/docs/rules/clean-file-size.md +2 -0
  85. package/docs/rules/clean-formatted.fr.md +35 -0
  86. package/docs/rules/clean-formatted.md +2 -0
  87. package/docs/rules/clean-function-ceiling.fr.md +56 -0
  88. package/docs/rules/clean-function-ceiling.md +2 -0
  89. package/docs/rules/clean-function-size.fr.md +48 -0
  90. package/docs/rules/clean-function-size.md +2 -0
  91. package/docs/rules/clean-no-commented-out-code.fr.md +51 -0
  92. package/docs/rules/clean-no-commented-out-code.md +2 -0
  93. package/docs/rules/clean-no-escape-hatch.fr.md +83 -0
  94. package/docs/rules/clean-no-escape-hatch.md +2 -0
  95. package/docs/rules/clean-no-flag-argument.fr.md +53 -0
  96. package/docs/rules/clean-no-flag-argument.md +2 -0
  97. package/docs/rules/clean-no-hash-private.fr.md +66 -0
  98. package/docs/rules/clean-no-hash-private.md +2 -0
  99. package/docs/rules/clean-no-magic-number.fr.md +62 -0
  100. package/docs/rules/clean-no-magic-number.md +2 -0
  101. package/docs/rules/clean-no-noise-comment.fr.md +58 -0
  102. package/docs/rules/clean-no-noise-comment.md +2 -0
  103. package/docs/rules/clean-one-export-per-file.fr.md +91 -0
  104. package/docs/rules/clean-one-export-per-file.md +2 -0
  105. package/docs/rules/clean-stepdown.fr.md +63 -0
  106. package/docs/rules/clean-stepdown.md +2 -0
  107. package/docs/rules/context-declared-relationship.fr.md +52 -0
  108. package/docs/rules/context-declared-relationship.md +2 -0
  109. package/docs/rules/context-extractable.fr.md +112 -0
  110. package/docs/rules/context-extractable.md +2 -0
  111. package/docs/rules/context-published-language-is-a-contract.fr.md +50 -0
  112. package/docs/rules/context-published-language-is-a-contract.md +2 -0
  113. package/docs/rules/context-published-language-only.fr.md +50 -0
  114. package/docs/rules/context-published-language-only.md +2 -0
  115. package/docs/rules/declarations-constructor-injection.fr.md +92 -0
  116. package/docs/rules/declarations-constructor-injection.md +2 -0
  117. package/docs/rules/declarations-role-declared.fr.md +118 -0
  118. package/docs/rules/declarations-role-declared.md +2 -0
  119. package/docs/rules/domain-aggregate-encapsulation.fr.md +66 -0
  120. package/docs/rules/domain-aggregate-encapsulation.md +2 -0
  121. package/docs/rules/domain-events-dispatched-on-save.fr.md +86 -0
  122. package/docs/rules/domain-events-dispatched-on-save.md +2 -0
  123. package/docs/rules/domain-events-transactional-before-commit.fr.md +95 -0
  124. package/docs/rules/domain-events-transactional-before-commit.md +2 -0
  125. package/docs/rules/domain-no-generic-error.fr.md +43 -0
  126. package/docs/rules/domain-no-generic-error.md +2 -0
  127. package/docs/rules/domain-value-object-class.fr.md +177 -0
  128. package/docs/rules/domain-value-object-class.md +167 -0
  129. package/docs/rules/domain-value-object-immutability.fr.md +55 -0
  130. package/docs/rules/domain-value-object-immutability.md +2 -0
  131. package/docs/rules/errors-constructor-not-public.fr.md +56 -0
  132. package/docs/rules/errors-constructor-not-public.md +2 -0
  133. package/docs/rules/errors-factory-name.fr.md +53 -0
  134. package/docs/rules/errors-factory-name.md +2 -0
  135. package/docs/rules/errors-through-factory.fr.md +48 -0
  136. package/docs/rules/errors-through-factory.md +2 -0
  137. package/docs/rules/event-sourcing-past-tense.fr.md +43 -0
  138. package/docs/rules/event-sourcing-past-tense.md +2 -0
  139. package/docs/rules/event-sourcing-projection-never-appends.fr.md +52 -0
  140. package/docs/rules/event-sourcing-projection-never-appends.md +2 -0
  141. package/docs/rules/event-sourcing-state-in-apply.fr.md +54 -0
  142. package/docs/rules/event-sourcing-state-in-apply.md +2 -0
  143. package/docs/rules/event-sourcing-store-behind-repository.fr.md +42 -0
  144. package/docs/rules/event-sourcing-store-behind-repository.md +2 -0
  145. package/docs/rules/event-sourcing-upcaster-required.fr.md +58 -0
  146. package/docs/rules/event-sourcing-upcaster-required.md +2 -0
  147. package/docs/rules/events-consumer-idempotent.fr.md +71 -0
  148. package/docs/rules/events-consumer-idempotent.md +2 -0
  149. package/docs/rules/events-name-format.fr.md +57 -0
  150. package/docs/rules/events-name-format.md +2 -0
  151. package/docs/rules/events-outbox-required.fr.md +60 -0
  152. package/docs/rules/events-outbox-required.md +2 -0
  153. package/docs/rules/governance-recorded-deviation.fr.md +58 -0
  154. package/docs/rules/governance-recorded-deviation.md +2 -0
  155. package/docs/rules/imports-alias-only.fr.md +77 -0
  156. package/docs/rules/imports-alias-only.md +2 -0
  157. package/docs/rules/imports-extension.fr.md +86 -0
  158. package/docs/rules/imports-extension.md +2 -0
  159. package/docs/rules/language-declared-vocabulary.fr.md +67 -0
  160. package/docs/rules/language-declared-vocabulary.md +2 -0
  161. package/docs/rules/layer-application-inward.fr.md +65 -0
  162. package/docs/rules/layer-application-inward.md +4 -2
  163. package/docs/rules/layer-domain-purity.fr.md +63 -0
  164. package/docs/rules/layer-domain-purity.md +4 -2
  165. package/docs/rules/layer-infrastructure-no-presentation.fr.md +49 -0
  166. package/docs/rules/layer-infrastructure-no-presentation.md +2 -0
  167. package/docs/rules/layer-presentation-no-infrastructure.fr.md +49 -0
  168. package/docs/rules/layer-presentation-no-infrastructure.md +2 -0
  169. package/docs/rules/lifecycle-status-through-machine.fr.md +72 -0
  170. package/docs/rules/lifecycle-status-through-machine.md +2 -0
  171. package/docs/rules/ports-abstract-class.fr.md +73 -0
  172. package/docs/rules/ports-abstract-class.md +2 -0
  173. package/docs/rules/ports-implements-never-extends.fr.md +56 -0
  174. package/docs/rules/ports-implements-never-extends.md +2 -0
  175. package/docs/rules/ports-no-concrete-dependency.fr.md +56 -0
  176. package/docs/rules/ports-no-concrete-dependency.md +2 -0
  177. package/docs/rules/ports-no-token-constant.fr.md +60 -0
  178. package/docs/rules/ports-no-token-constant.md +2 -0
  179. package/docs/rules/ports-value-import.fr.md +58 -0
  180. package/docs/rules/ports-value-import.md +2 -0
  181. package/docs/rules/presentation-controller-delegates.fr.md +60 -0
  182. package/docs/rules/presentation-controller-delegates.md +2 -0
  183. package/docs/rules/presentation-controller-shape.fr.md +53 -0
  184. package/docs/rules/presentation-controller-shape.md +2 -0
  185. package/docs/rules/presentation-guard-at-the-edge.fr.md +58 -0
  186. package/docs/rules/presentation-guard-at-the-edge.md +2 -0
  187. package/docs/rules/presentation-shared-cache-varies.fr.md +57 -0
  188. package/docs/rules/presentation-shared-cache-varies.md +2 -0
  189. package/docs/rules/process-sends-commands-only.fr.md +67 -0
  190. package/docs/rules/process-sends-commands-only.md +2 -0
  191. package/docs/rules/purity-no-ambient-randomness.fr.md +46 -0
  192. package/docs/rules/purity-no-ambient-randomness.md +2 -0
  193. package/docs/rules/purity-no-environment.fr.md +48 -0
  194. package/docs/rules/purity-no-environment.md +2 -0
  195. package/docs/rules/purity-no-system-clock.fr.md +52 -0
  196. package/docs/rules/purity-no-system-clock.md +2 -0
  197. package/docs/rules/scheduling-job-name.fr.md +60 -0
  198. package/docs/rules/scheduling-job-name.md +2 -0
  199. package/docs/rules/scheduling-job-triggers-use-case.fr.md +74 -0
  200. package/docs/rules/scheduling-job-triggers-use-case.md +2 -0
  201. package/docs/rules/schema-presentation-only.fr.md +48 -0
  202. package/docs/rules/schema-presentation-only.md +2 -0
  203. package/docs/rules/standard-no-parallel-interface.fr.md +100 -0
  204. package/docs/rules/standard-no-parallel-interface.md +2 -0
  205. package/docs/rules/test-no-mocks.fr.md +50 -0
  206. package/docs/rules/test-no-mocks.md +2 -0
  207. package/docs/rules/tracing-platform-only.fr.md +68 -0
  208. package/docs/rules/tracing-platform-only.md +2 -0
  209. package/package.json +1 -1
@@ -0,0 +1,167 @@
1
+ **English** · [Français](domain-value-object-class.fr.md)
2
+
3
+ # ddd-ts-kit/domain-value-object-class
4
+
5
+ Architecture id: `domain/value-object-class`. Default severity: `error` in `recommended`, `error` in `strict`.
6
+
7
+ Applies to: a project whose config says `"stack.values": "classes"`, which `init` writes (a
8
+ config that does not say is `free`, and the rule is silent: [CONFIG.md](../../../../docs/CONFIG.md#stack)
9
+ gives the steps to move). There, the value object files, `domain/value-objects/*` of a context
10
+ and the `*.vo.ts` of the shared kernel outside its `presentation/`, and every other file of
11
+ `domain/` of a context and of the shared kernel outside its `presentation/`, specs aside.
12
+
13
+ ## Why
14
+
15
+ A value of the model is a class extending `ValueObject` of `@ddd-ts-kit/kernel`, never a function
16
+ that builds a plain object. The class gives what the function cannot:
17
+
18
+ - **equality without identity**: `equals` compares the props, two equal values are interchangeable;
19
+ - **invariants checked once**: the constructor is private, the static factory is the only way in,
20
+ so a value that exists is a valid one and no caller validates it again;
21
+ - **behaviour next to the data**: `add`, `overlaps`, `isWithin` are methods of the type they
22
+ concern, not helpers repeated wherever two fields meet;
23
+ - **refusals from static factories**: `Money.of(..)` throws (or returns) the refusal of the concept,
24
+ `InvoiceError.invalidAmount(..)`;
25
+ - **immutability**: the props are frozen, an operation returns a new instance;
26
+ - **`instanceof` in the boundary mappers**: a mapper or a serializer recognises the value and
27
+ writes it, which a structural object never allows.
28
+
29
+ ## Reported
30
+
31
+ In a value object file:
32
+
33
+ - no exported class, or a second one;
34
+ - an exported class that extends neither `ValueObject` nor another value object of the project
35
+ (a class of the same file that does, or a class imported from a value object file);
36
+ - a public constructor, declared without `private` or `protected` (a class that declares none
37
+ inherits the protected constructor of `ValueObject`);
38
+ - a concrete class without a static method that is not private: nothing can build it;
39
+ - an exported function, an exported constant bound to an arrow or a function expression, and an
40
+ exported object literal (parenthesized, `as const` and `satisfies` included), whether exported
41
+ inline, by an export list (`export { zero }`) or by default.
42
+
43
+ The exported types and interfaces of its props are allowed.
44
+
45
+ In the other files of `domain/` and of the shared kernel: an exported function (declared, bound
46
+ to a constant, exported by a list or by default) that answers a **record of data**, in the
47
+ expression of an arrow or in a `return` of its own body. Each entry of the object literal is
48
+ read for what it holds:
49
+
50
+ | Entry | Reads as | Examples |
51
+ |---|---|---|
52
+ | a literal, a parameter, an operation on them, a call of the language | data | `amount`, `'EUR'`, `cents * 100`, `Math.round(cents)`, `new Date(at)` |
53
+ | any other call or `new`, or a name bound to one in the module | built by the model | `Money.of(1)`, `total.add(tax)`, `new Slot(..)` |
54
+ | a function, a method, or a name bound to one in the module | behaviour | `isSatisfiedBy: (x) => ..`, `describe() {}`, `{ isSatisfiedBy }` |
55
+ | `...state` | derived | `{ ...state, status }` |
56
+
57
+ The object is a record of data, and the function is reported, when it holds data, nothing built
58
+ by the model and no spread. A function that declares a return type of a package
59
+ (`): EventStamp` of the kernel) is not judged: the shape is the library's.
60
+
61
+ Incorrect:
62
+
63
+ ```ts
64
+ // domain/value-objects/money.vo.ts
65
+ export type Money = { readonly amount: number; readonly currency: string };
66
+
67
+ export const money = (amount: number, currency: string): Money => ({ amount, currency });
68
+ ```
69
+
70
+ Correct:
71
+
72
+ ```ts
73
+ // domain/value-objects/money.vo.ts (npx ddd-ts-kit generate value-object billing Money)
74
+ import { ValueObject } from '@ddd-ts-kit/kernel';
75
+
76
+ export type MoneyProps = { readonly amount: number; readonly currency: string };
77
+
78
+ export class Money extends ValueObject<MoneyProps> {
79
+ private constructor(props: MoneyProps) {
80
+ super(props);
81
+ }
82
+
83
+ static of(amount: number, currency: string): Money {
84
+ if (!Number.isInteger(amount)) {
85
+ throw InvoiceError.invalidAmount(amount);
86
+ }
87
+
88
+ return new Money({ amount, currency });
89
+ }
90
+
91
+ add(other: Money): Money {
92
+ return Money.of(this.props.amount + other.props.amount, this.props.currency);
93
+ }
94
+ }
95
+ ```
96
+
97
+ ## Details
98
+
99
+ What is not reported:
100
+
101
+ ```ts
102
+ // a state machine: the result of a call, not a function
103
+ export const invoiceLifecycle = defineStateMachine({ states: ['draft', 'issued'] /* .. */ });
104
+
105
+ // a domain service: a class
106
+ export class InvoiceTotalService {
107
+ total(lines: readonly Money[]): Money { /* .. */ }
108
+ }
109
+
110
+ // a specification: a boolean, or functions only, literal or local closures
111
+ export const isOverdue = (invoice: Invoice, now: Date): boolean => invoice.dueAt < now;
112
+ export const dueBefore = (day: Date) => {
113
+ const isSatisfiedBy = (invoice: Invoice): boolean => invoice.dueAt < day;
114
+
115
+ return { isSatisfiedBy };
116
+ };
117
+
118
+ // an operation of the model: value objects it builds
119
+ export const split = (total: Money) => ({ first: Money.of(1), rest: total.subtract(Money.of(1)) });
120
+
121
+ // a reducer: derives a record that exists
122
+ export const evolve = (state: InvoiceState, status: string): InvoiceState => ({ ...state, status });
123
+ ```
124
+
125
+ What is reported, and decided so:
126
+
127
+ ```ts
128
+ // a decision answered as a record: throw the refusal from a factory
129
+ // (`throw InvoiceError.refused(reason)`), or make it a value object (`Decision.refused(reason)`)
130
+ export const decide = (reason: string) => ({ kind: 'refused' as const, reason });
131
+
132
+ // a record of data with closures: a value with behaviour, which is a class
133
+ export const money = (cents: number) => ({ cents, doubled: (): number => cents * 2 });
134
+
135
+ // a record that only gathers parameters, value objects included: a pair that means something
136
+ // is a value with a name
137
+ export const period = (start: Instant, end: Instant) => ({ start, end });
138
+ ```
139
+
140
+ ## Options
141
+
142
+ None.
143
+
144
+ `rules."domain/value-object-class"` in `ddd-ts-kit.config.json` set to `warn` or `off` relaxes the
145
+ rule, and `// ddd-ts-kit-disable-next-line domain/value-object-class -- <reason>` silences one
146
+ line, exactly as for `ddd-ts-kit check`. The rule defaults to `error`: relaxing it is a deviation,
147
+ recorded under `deviations` with the ADR that says why and until when
148
+ (`governance/recorded-deviation`). A project not ready for the rule keeps `"stack.values": "free"`
149
+ instead, which records nothing.
150
+
151
+ ## Limits
152
+
153
+ The rule reads the text and the syntax of one file, without the types. What it does not follow:
154
+
155
+ - an object built in a variable first, then returned (`const value = { .. }; return value;`);
156
+ - an object answered through a condition (`cond ? { .. } : { .. }`), inside an array, or as the
157
+ argument of a call;
158
+ - a name is resolved by its first declaration in the module, whatever its scope: a parameter
159
+ named like a function of the module reads as that function;
160
+ - a call is read by the name it starts from: `name.trim()` on a parameter reads as built by the
161
+ model, so a record holding it is not reported;
162
+ - the package exemption reads the name the declared return type starts with, not an inferred one;
163
+ - a superclass imported from a value object file is trusted: that file is judged on its own.
164
+
165
+ ## With the CLI checker
166
+
167
+ `ddd-ts-kit check` reports the same id from the text of the files, with the same table of files.
@@ -0,0 +1,55 @@
1
+ [English](domain-value-object-immutability.md) · **Français**
2
+ <!-- translation-of: domain-value-object-immutability.md sha256:5522b9c36f5b70cf -->
3
+
4
+ # ddd-ts-kit/domain-value-object-immutability
5
+
6
+ Identifiant d'architecture : `domain/value-object-immutability` (ajouté par ce *plugin*). Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : `domain/value-objects/` d'un contexte, tests exclus.
9
+
10
+ ## Pourquoi
11
+
12
+ Un objet-valeur est sa valeur. S'il peut changer, deux détenteurs de la même instance ne sont plus d'accord sur ce qu'ils détiennent, et l'égalité par valeur ne veut plus rien dire.
13
+
14
+ ## Signalé
15
+
16
+ - une propriété ou une propriété-paramètre du constructeur sans `readonly` (privées et `#private` comprises)
17
+ - un accesseur `set`
18
+ - hors du constructeur, une affectation ou une incrémentation qui part de `this` (`this.props.cents += 1`)
19
+ - hors du constructeur, une méthode de modification de tableau appelée sur quelque chose de `this` (`push`, `pop`, `shift`, `unshift`, `splice`, `sort`, `reverse`, `fill`, `copyWithin`)
20
+
21
+ Incorrect :
22
+
23
+ ```ts
24
+ export class Amount {
25
+ constructor(private cents: number) {}
26
+ add(other: Amount): void {
27
+ this.cents += other.cents;
28
+ }
29
+ }
30
+ ```
31
+
32
+ Correct :
33
+
34
+ ```ts
35
+ export class Amount extends ValueObject<AmountProps> {
36
+ add(other: Amount): Amount {
37
+ return new Amount({ cents: this.props.cents + other.props.cents });
38
+ }
39
+ }
40
+ ```
41
+
42
+ ## Options
43
+
44
+ Aucune.
45
+
46
+ `rules."domain/value-object-immutability"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line domain/value-object-immutability -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
47
+
48
+ ## Limites
49
+
50
+ - L'immuabilité profonde de ce que contient une propriété (`readonly items: string[]`) n'est pas vérifiée : préférez `readonly string[]`.
51
+ - La modification d'une `Map`, d'un `Set` ou d'un objet par des appels de méthode n'est pas vue.
52
+
53
+ ## Avec le checker de la CLI
54
+
55
+ Nouveau avec ce *plugin* : le *checker* de la CLI n'a pas d'équivalent, car la forme d'une classe demande un arbre syntaxique.
@@ -1,3 +1,5 @@
1
+ **English** · [Français](domain-value-object-immutability.fr.md)
2
+
1
3
  # ddd-ts-kit/domain-value-object-immutability
2
4
 
3
5
  Architecture id: `domain/value-object-immutability` (added by this plugin). Default severity: `error` in `recommended`, `error` in `strict`.
@@ -0,0 +1,56 @@
1
+ [English](errors-constructor-not-public.md) · **Français**
2
+ <!-- translation-of: errors-constructor-not-public.md sha256:900f7905c250d239 -->
3
+
4
+ # ddd-ts-kit/errors-constructor-not-public
5
+
6
+ Identifiant d'architecture : `errors/constructor-not-public`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : les fichiers de production de `domain/errors/` d'un contexte, dans un projet dont la configuration dit `"stack.refusals": "factories"`.
9
+
10
+ ## Pourquoi
11
+
12
+ Un constructeur public permet à n'importe quel appelant de construire un refus avec un code et un message de son cru. `ConceptError` de `@ddd-ts-kit/kernel` a un constructeur protégé, et une classe qui l'étend n'en déclare aucun : un refus n'existe alors que par une fabrique statique.
13
+
14
+ ## Signalé
15
+
16
+ - une classe qui en étend une autre et déclare un constructeur public
17
+ - une classe qui étend `DomainError` et ne déclare pas de constructeur : elle en hérite un public
18
+
19
+ Une classe abstraite n'est pas jugée.
20
+
21
+ Incorrect :
22
+
23
+ ```ts
24
+ export class SlotTakenError extends DomainError {
25
+ readonly code = 'SLOT_TAKEN';
26
+
27
+ constructor(calendarId: string) {
28
+ super(`The slot on calendar ${calendarId} is already held.`);
29
+ }
30
+ }
31
+ ```
32
+
33
+ Correct :
34
+
35
+ ```ts
36
+ export class AppointmentError extends ConceptError {
37
+ static slotTaken(calendarId: string) {
38
+ return AppointmentError.refusal('SLOT_TAKEN', `The slot on calendar ${calendarId} is already held.`, { calendarId });
39
+ }
40
+ }
41
+ ```
42
+
43
+ ## Options
44
+
45
+ Aucune.
46
+
47
+ `rules."errors/constructor-not-public"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line errors/constructor-not-public -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
48
+
49
+ ## Limites
50
+
51
+ - Une classe qui étend une base du projet et ne déclare pas de constructeur est présumée correcte : la visibilité dont elle hérite est dans un autre fichier.
52
+ - Rien n'est corrigé : rendre un constructeur privé casse chaque `new` de la classe. `ddd-ts-kit error-factories` fait passer un projet entier aux fabriques.
53
+
54
+ ## Avec le checker de la CLI
55
+
56
+ Tenue par ce *plugin* seul : la forme d'une classe demande un arbre syntaxique.
@@ -1,3 +1,5 @@
1
+ **English** · [Français](errors-constructor-not-public.fr.md)
2
+
1
3
  # ddd-ts-kit/errors-constructor-not-public
2
4
 
3
5
  Architecture id: `errors/constructor-not-public`. Default severity: `error` in `recommended`, `error` in `strict`.
@@ -0,0 +1,53 @@
1
+ [English](errors-factory-name.md) · **Français**
2
+ <!-- translation-of: errors-factory-name.md sha256:315ae3f24362c50b -->
3
+
4
+ # ddd-ts-kit/errors-factory-name
5
+
6
+ Identifiant d'architecture : `errors/factory-name`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : les fichiers de production de `domain/errors/` d'un contexte, dans un projet dont la configuration dit `"stack.refusals": "factories"`.
9
+
10
+ ## Pourquoi
11
+
12
+ La fabrique est lue par le développeur qui refuse, le code par le client, le *mapper*, le journal d'audit et les tests. Ils doivent rencontrer les mêmes mots, et ces mots sont ceux du métier : `slotTaken` et `SLOT_TAKEN`, jamais `create` et `BOOKING_FAILED`.
13
+
14
+ ## Signalé
15
+
16
+ Une fabrique (factory) est une méthode statique publique d'une classe d'erreur qui appelle `refusal(...)`.
17
+
18
+ - un nom qui dit qu'une erreur est construite et non quelle règle a refusé : `create`, `make`, `of`, `from`, `build`, `new`, `error`, `failure`, `fail`, `refusal`, `refuse`, ou un nom qui contient un chiffre (`error1`)
19
+ - un code qui n'est pas un littéral de chaîne, ou qui n'est pas en constant case (majuscules et tirets bas)
20
+ - un code qui n'est pas le nom de la fabrique en constant case, seul ou avec le nom du concept avant ou après : `AppointmentError.notFound` pose `NOT_FOUND`, `APPOINTMENT_NOT_FOUND` ou `NOT_FOUND_APPOINTMENT`
21
+
22
+ Incorrect :
23
+
24
+ ```ts
25
+ static slotTaken(calendarId: string) {
26
+ return AppointmentError.refusal('BOOKING_FAILED', 'The slot is already held.', { calendarId });
27
+ }
28
+ ```
29
+
30
+ Correct :
31
+
32
+ ```ts
33
+ static slotTaken(calendarId: string) {
34
+ return AppointmentError.refusal('SLOT_TAKEN', 'The slot is already held.', { calendarId });
35
+ }
36
+ ```
37
+
38
+ ## Options
39
+
40
+ Aucune.
41
+
42
+ `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`.
43
+
44
+ Un code déjà publié sous d'autres mots ne peut pas changer : renommez la fabrique d'après lui, ou gardez le nom et désactivez cette ligne avec la raison.
45
+
46
+ ## Limites
47
+
48
+ - Un outil ne peut pas décider si un nom est une expression métier : seuls les noms qui ne le sont certainement pas sont refusés. `language/glossary-term` tient le nom de la classe.
49
+ - Le premier appel `refusal(...)` de la méthode est celui qui est lu.
50
+
51
+ ## Avec le checker de la CLI
52
+
53
+ Tenue par ce *plugin* seul. Qu'un code soit unique dans son contexte relève de `errors/code-unique`, tenue par le *checker*.
@@ -1,3 +1,5 @@
1
+ **English** · [Français](errors-factory-name.fr.md)
2
+
1
3
  # ddd-ts-kit/errors-factory-name
2
4
 
3
5
  Architecture id: `errors/factory-name`. Default severity: `error` in `recommended`, `error` in `strict`.
@@ -0,0 +1,48 @@
1
+ [English](errors-through-factory.md) · **Français**
2
+ <!-- translation-of: errors-through-factory.md sha256:e552fc0b412b196c -->
3
+
4
+ # ddd-ts-kit/errors-through-factory
5
+
6
+ Identifiant d'architecture : `errors/through-factory`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : chaque fichier d'un contexte, tests compris, dans un projet dont la configuration dit `"stack.refusals": "factories"`. Une configuration sans cette clé a été écrite quand une erreur était une classe construite avec `new` : rien n'y est signalé.
9
+
10
+ ## Pourquoi
11
+
12
+ Le code qui refuse se lit comme une phrase, et les refus d'un concept vivent dans une classe : `throw AppointmentError.slotTaken(calendar.id, slot.startsAt)`. La fabrique (factory) écrit une fois le code, le message et les faits. Un `new` hors de la classe est un refus dont le code et le message sont ce que l'appelant a bien voulu écrire.
13
+
14
+ ## Signalé
15
+
16
+ - `new X(...)` où `X` est importé d'un fichier de `domain/errors/`
17
+
18
+ Incorrect :
19
+
20
+ ```ts
21
+ import { SlotTakenError } from '@/contexts/scheduling/domain/errors/slot-taken.error';
22
+
23
+ throw new SlotTakenError(calendar.id, slot.startsAt);
24
+ ```
25
+
26
+ Correct :
27
+
28
+ ```ts
29
+ import { AppointmentError } from '@/contexts/scheduling/domain/errors/appointment.error';
30
+
31
+ throw AppointmentError.slotTaken(calendar.id, slot.startsAt);
32
+ ```
33
+
34
+ ## Options
35
+
36
+ Aucune.
37
+
38
+ `rules."errors/through-factory"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line errors/through-factory -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
39
+
40
+ ## Limites
41
+
42
+ - Une classe d'erreur est reconnue à l'endroit d'où elle est importée : une classe déclarée ailleurs que dans `domain/errors/` n'est pas vue (`naming/suffix` y garde les erreurs).
43
+ - Les erreurs du kit (`NotFoundError`, `InvariantViolation`, `ValidationError`...) sont chacune un refus au code fixe et restent construites avec `new`.
44
+ - Rien n'est corrigé : quelle fabrique remplace un constructeur est une décision. `ddd-ts-kit error-factories` écrit le plan d'une migration et l'applique.
45
+
46
+ ## Avec le checker de la CLI
47
+
48
+ Tenue par ce *plugin* seul : le *checker* liste la règle et ne juge rien. Le compilateur refuse la même chose dès que la classe étend `ConceptError`, dont le constructeur est protégé.
@@ -1,3 +1,5 @@
1
+ **English** · [Français](errors-through-factory.fr.md)
2
+
1
3
  # ddd-ts-kit/errors-through-factory
2
4
 
3
5
  Architecture id: `errors/through-factory`. Default severity: `error` in `recommended`, `error` in `strict`.
@@ -0,0 +1,43 @@
1
+ [English](event-sourcing-past-tense.md) · **Français**
2
+ <!-- translation-of: event-sourcing-past-tense.md sha256:d60df389a9575103 -->
3
+
4
+ # ddd-ts-kit/event-sourcing-past-tense
5
+
6
+ Identifiant d'architecture : `event-sourcing/past-tense`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : `domain/aggregates/` d'un contexte, tests exclus : les fichiers qui déclarent une classe étendant `EventSourcedAggregate`.
9
+
10
+ ## Pourquoi
11
+
12
+ Un événement stocké est un fait, gardé et rejoué aussi longtemps que vit l'agrégat, lu par des personnes et par des projections qui ne sont pas encore écrites. Un nom au présent ou à l'impératif se lit comme une demande qui peut encore être refusée.
13
+
14
+ ## Signalé
15
+
16
+ - un nom importé de `domain/events/`, tel que le fichier l'écrit (le nom local d'un import renommé), dont le fait ne contient aucun participe passé. Le fait est le nom qui suit le nom de l'agrégat (`ScheduledVisitCancel` de `ScheduledVisit` : `Cancel`), ou le nom entier quand il ne commence pas par lui. Un participe passé est un mot qui se termine par `-ed`, ou un participe irrégulier courant (`paid`, `held`, `taken`, `withdrawn`, `set`, `made`, `done`, `lost`, `won`...) ; un participe qui s'écrit comme son impératif (`set`, `put`, `read`, `run`, `cut`, `found`, `left`...) ne compte pas en tête du fait, où il se lit comme un ordre (`SetPrice`, `ReadInvoice`), et compte après un nom (`InvoicePriceSet`)
17
+
18
+ Incorrect :
19
+
20
+ ```ts
21
+ import { NoteNoShow } from '@/contexts/scheduling/domain/events/note-no-show.event';
22
+ ```
23
+
24
+ Correct :
25
+
26
+ ```ts
27
+ import { NoShowNoted } from '@/contexts/scheduling/domain/events/no-show-noted.event';
28
+ ```
29
+
30
+ ## Options
31
+
32
+ Aucune.
33
+
34
+ `rules."event-sourcing/past-tense"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line event-sourcing/past-tense -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
35
+
36
+ ## Limites
37
+
38
+ - Un mot qui se termine par `-ed` sans être un participe (`Need`, `Seed`) passe.
39
+ - Un participe irrégulier absent de la liste est signalé : désactivez cette ligne avec une raison.
40
+
41
+ ## Avec le checker de la CLI
42
+
43
+ `ddd-ts-kit check` signale le même identifiant, à partir des noms que lient les instructions d'import. Les deux tiennent les mêmes listes de participes, et `generate domain-event` aussi ; un test de la CLI garde les copies identiques.
@@ -1,3 +1,5 @@
1
+ **English** · [Français](event-sourcing-past-tense.fr.md)
2
+
1
3
  # ddd-ts-kit/event-sourcing-past-tense
2
4
 
3
5
  Architecture id: `event-sourcing/past-tense`. Default severity: `error` in `recommended`, `error` in `strict`.
@@ -0,0 +1,52 @@
1
+ [English](event-sourcing-projection-never-appends.md) · **Français**
2
+ <!-- translation-of: event-sourcing-projection-never-appends.md sha256:d3f1dff5870e7a18 -->
3
+
4
+ # ddd-ts-kit/event-sourcing-projection-never-appends
5
+
6
+ Identifiant d'architecture : `event-sourcing/projection-never-appends`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : `application/projections/` d'un contexte, et tout fichier d'un contexte qui déclare une classe avec `@Projection`, tests exclus.
9
+
10
+ ## Pourquoi
11
+
12
+ Une projection transforme des faits en modèle de lecture et se rejoue depuis la position zéro à chaque reconstruction. Une projection qui ajoute à un flux d'événements y ajouterait de nouveau à chaque reconstruction, et fait décider des faits par le côté lecture.
13
+
14
+ ## Signalé
15
+
16
+ - un import de `EventStore` ou de `EventSourcedRepository` depuis `@ddd-ts-kit/kernel`, dans toute projection
17
+ - un import de quoi que ce soit de `domain/repositories/`, dans une projection déclarée `@Projection(name, { feed: 'event-store' })`
18
+
19
+ Une projection alimentée par le répartiteur (dispatcher) peut toujours nommer un port de *repository*, comme elle le pouvait avant l'*event sourcing* : elle n'est pas rejouée depuis la position zéro, et un projet qui n'opte pas pour l'*event sourcing* ne voit aucun nouveau constat.
20
+
21
+ Incorrect :
22
+
23
+ ```ts
24
+ @Projection('scheduling.attendance-history', { feed: 'event-store' })
25
+ export class AttendanceHistoryProjection {
26
+ constructor(private readonly history: AttendanceHistory, private readonly records: AttendanceRecordRepository) {}
27
+ }
28
+ ```
29
+
30
+ Correct :
31
+
32
+ ```ts
33
+ @Projection('scheduling.attendance-history', { feed: 'event-store' })
34
+ export class AttendanceHistoryProjection {
35
+ constructor(private readonly history: AttendanceHistory) {}
36
+ }
37
+ ```
38
+
39
+ ## Options
40
+
41
+ Aucune.
42
+
43
+ `rules."event-sourcing/projection-never-appends"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line event-sourcing/projection-never-appends -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
44
+
45
+ ## Limites
46
+
47
+ - Un agrégat atteint par un port de `application/ports/` n'est pas reconnu.
48
+ - On sait qu'une projection est alimentée par le *store* seulement par le littéral `feed: 'event-store'` de son `@Projection` ; une projection branchée sur une `CatchUpSubscription` sans lui est jugée comme alimentée par le répartiteur.
49
+
50
+ ## Avec le checker de la CLI
51
+
52
+ `ddd-ts-kit check` signale le même identifiant à partir des instructions d'import et du texte `@Projection(`.
@@ -1,3 +1,5 @@
1
+ **English** · [Français](event-sourcing-projection-never-appends.fr.md)
2
+
1
3
  # ddd-ts-kit/event-sourcing-projection-never-appends
2
4
 
3
5
  Architecture id: `event-sourcing/projection-never-appends`. Default severity: `error` in `recommended`, `error` in `strict`.
@@ -0,0 +1,54 @@
1
+ [English](event-sourcing-state-in-apply.md) · **Français**
2
+ <!-- translation-of: event-sourcing-state-in-apply.md sha256:08fa13535cd9d1e5 -->
3
+
4
+ # ddd-ts-kit/event-sourcing-state-in-apply
5
+
6
+ Identifiant d'architecture : `event-sourcing/state-in-apply`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : `domain/aggregates/` d'un contexte, tests exclus : les classes qui étendent `EventSourcedAggregate`.
9
+
10
+ ## Pourquoi
11
+
12
+ Un agrégat en *event sourcing* se reconstruit en rejouant ses événements à travers ses méthodes d'application (apply). Une commande qui écrit aussi l'état elle-même laisse un état qu'aucun rejeu ne reconstruit : l'agrégat se comporte d'une façon juste après la commande et d'une autre une fois rechargé.
13
+
14
+ ## Signalé
15
+
16
+ - hors du constructeur, des méthodes statiques et des méthodes d'application (`apply<Fact>`, et `restore` pour un *snapshot*), une affectation ou une incrémentation qui part de `this`
17
+ - au même endroit, un appel qui modifie quelque chose de `this` (`push`, `splice`, `sort`, `set`, `add`, `delete`, `clear`...)
18
+ - dans une méthode d'application, `this.record(..)` : un rejeu enregistrerait l'événement une seconde fois
19
+
20
+ Incorrect :
21
+
22
+ ```ts
23
+ noteNoShow(appointmentId: string, now: Date): void {
24
+ this.state = { noShows: this.state.noShows + 1 };
25
+ this.record(new NoShowNoted(this.id, now, appointmentId));
26
+ }
27
+ ```
28
+
29
+ Correct :
30
+
31
+ ```ts
32
+ noteNoShow(appointmentId: string, now: Date): void {
33
+ this.record(new NoShowNoted(this.id, now, appointmentId));
34
+ }
35
+
36
+ private applyNoShowNoted(event: NoShowNoted): void {
37
+ this.state = { noShows: this.state.noShows + 1 };
38
+ }
39
+ ```
40
+
41
+ ## Options
42
+
43
+ Aucune.
44
+
45
+ `rules."event-sourcing/state-in-apply"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line event-sourcing/state-in-apply -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
46
+
47
+ ## Limites
48
+
49
+ - Une écriture par un alias local (`const state = this.state; state.items.push(x)`) n'est pas suivie.
50
+ - Une classe qui étend `EventSourcedAggregate` sous un autre nom (un alias, une classe de base du projet) n'est pas reconnue.
51
+
52
+ ## Avec le checker de la CLI
53
+
54
+ `ddd-ts-kit check` signale le même identifiant à partir du texte des fichiers : les écritures qu'il trouve dans le corps des méthodes d'une classe dont la superclasse s'écrit `EventSourcedAggregate`. Cette règle fait autorité.
@@ -1,3 +1,5 @@
1
+ **English** · [Français](event-sourcing-state-in-apply.fr.md)
2
+
1
3
  # ddd-ts-kit/event-sourcing-state-in-apply
2
4
 
3
5
  Architecture id: `event-sourcing/state-in-apply`. Default severity: `error` in `recommended`, `error` in `strict`.
@@ -0,0 +1,42 @@
1
+ [English](event-sourcing-store-behind-repository.md) · **Français**
2
+ <!-- translation-of: event-sourcing-store-behind-repository.md sha256:2790cec1cc8acf16 -->
3
+
4
+ # ddd-ts-kit/event-sourcing-store-behind-repository
5
+
6
+ Identifiant d'architecture : `event-sourcing/store-behind-repository`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
7
+
8
+ S'applique à : `domain/` et `application/` d'un contexte, tests exclus.
9
+
10
+ ## Pourquoi
11
+
12
+ Le domaine et les cas d'usage voient un agrégat en *event sourcing* comme n'importe quel autre : chargé par son port de *repository*, changé par ses méthodes, enregistré par le même port. Un gestionnaire (handler) qui lit lui-même un flux d'événements décide de la façon dont les événements deviennent un état, ce qui est le travail de l'agrégat, et attache le cas d'usage à une technique de stockage.
13
+
14
+ ## Signalé
15
+
16
+ - un import de `EventStore`, `SnapshotStore`, `CheckpointStore`, `EventSourcedRepository`, `EventSerializer`, `CatchUpSubscription` ou `InMemoryEventStore` depuis `@ddd-ts-kit/kernel`
17
+
18
+ Incorrect :
19
+
20
+ ```ts
21
+ constructor(private readonly store: EventStore) {}
22
+ ```
23
+
24
+ Correct :
25
+
26
+ ```ts
27
+ constructor(private readonly records: AttendanceRecordRepository) {}
28
+ ```
29
+
30
+ ## Options
31
+
32
+ Aucune.
33
+
34
+ `rules."event-sourcing/store-behind-repository"` à `off` dans `ddd-ts-kit.config.json` désactive la règle, et `// ddd-ts-kit-disable-next-line event-sourcing/store-behind-repository -- <reason>` désactive une ligne, exactement comme pour `ddd-ts-kit check`.
35
+
36
+ ## Limites
37
+
38
+ - Le *store* atteint par un port du projet qui l'enveloppe n'est pas reconnu : c'est alors ce port qu'il faut regarder.
39
+
40
+ ## Avec le checker de la CLI
41
+
42
+ `ddd-ts-kit check` signale le même identifiant à partir des instructions d'import.
@@ -1,3 +1,5 @@
1
+ **English** · [Français](event-sourcing-store-behind-repository.fr.md)
2
+
1
3
  # ddd-ts-kit/event-sourcing-store-behind-repository
2
4
 
3
5
  Architecture id: `event-sourcing/store-behind-repository`. Default severity: `error` in `recommended`, `error` in `strict`.