@ddd-ts-kit/eslint-plugin 0.16.1 → 0.17.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 (93) hide show
  1. package/README.fr.md +3 -2
  2. package/README.md +2 -1
  3. package/dist/project/config.d.ts +8 -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 +13 -0
  7. package/dist/project/parse-config.js.map +1 -1
  8. package/dist/rules/naming-business-name.d.ts +6 -0
  9. package/dist/rules/naming-business-name.d.ts.map +1 -0
  10. package/dist/rules/naming-business-name.js +175 -0
  11. package/dist/rules/naming-business-name.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/business-names/binding-advice.d.ts +4 -0
  16. package/dist/support/business-names/binding-advice.d.ts.map +1 -0
  17. package/dist/support/business-names/binding-advice.js +12 -0
  18. package/dist/support/business-names/binding-advice.js.map +1 -0
  19. package/dist/support/business-names/binding-kind.d.ts +3 -0
  20. package/dist/support/business-names/binding-kind.d.ts.map +1 -0
  21. package/dist/support/business-names/binding-kind.js +2 -0
  22. package/dist/support/business-names/binding-kind.js.map +1 -0
  23. package/dist/support/business-names/built-class.d.ts +9 -0
  24. package/dist/support/business-names/built-class.d.ts.map +1 -0
  25. package/dist/support/business-names/built-class.js +37 -0
  26. package/dist/support/business-names/built-class.js.map +1 -0
  27. package/dist/support/business-names/called-member.d.ts +8 -0
  28. package/dist/support/business-names/called-member.d.ts.map +1 -0
  29. package/dist/support/business-names/called-member.js +10 -0
  30. package/dist/support/business-names/called-member.js.map +1 -0
  31. package/dist/support/business-names/camel.d.ts +3 -0
  32. package/dist/support/business-names/camel.d.ts.map +1 -0
  33. package/dist/support/business-names/camel.js +5 -0
  34. package/dist/support/business-names/camel.js.map +1 -0
  35. package/dist/support/business-names/collection-element.d.ts +4 -0
  36. package/dist/support/business-names/collection-element.d.ts.map +1 -0
  37. package/dist/support/business-names/collection-element.js +12 -0
  38. package/dist/support/business-names/collection-element.js.map +1 -0
  39. package/dist/support/business-names/conventional-model-name.d.ts +9 -0
  40. package/dist/support/business-names/conventional-model-name.d.ts.map +1 -0
  41. package/dist/support/business-names/conventional-model-name.js +22 -0
  42. package/dist/support/business-names/conventional-model-name.js.map +1 -0
  43. package/dist/support/business-names/generic-words.d.ts +6 -0
  44. package/dist/support/business-names/generic-words.d.ts.map +1 -0
  45. package/dist/support/business-names/generic-words.js +25 -0
  46. package/dist/support/business-names/generic-words.js.map +1 -0
  47. package/dist/support/business-names/is-name-free.d.ts +10 -0
  48. package/dist/support/business-names/is-name-free.d.ts.map +1 -0
  49. package/dist/support/business-names/is-name-free.js +26 -0
  50. package/dist/support/business-names/is-name-free.js.map +1 -0
  51. package/dist/support/business-names/judges-names.d.ts +7 -0
  52. package/dist/support/business-names/judges-names.d.ts.map +1 -0
  53. package/dist/support/business-names/judges-names.js +14 -0
  54. package/dist/support/business-names/judges-names.js.map +1 -0
  55. package/dist/support/business-names/pattern-identifiers.d.ts +4 -0
  56. package/dist/support/business-names/pattern-identifiers.d.ts.map +1 -0
  57. package/dist/support/business-names/pattern-identifiers.js +21 -0
  58. package/dist/support/business-names/pattern-identifiers.js.map +1 -0
  59. package/dist/support/business-names/plural.d.ts +3 -0
  60. package/dist/support/business-names/plural.d.ts.map +1 -0
  61. package/dist/support/business-names/plural.js +8 -0
  62. package/dist/support/business-names/plural.js.map +1 -0
  63. package/dist/support/business-names/proposed-name.d.ts +6 -0
  64. package/dist/support/business-names/proposed-name.d.ts.map +1 -0
  65. package/dist/support/business-names/proposed-name.js +2 -0
  66. package/dist/support/business-names/proposed-name.js.map +1 -0
  67. package/dist/support/business-names/rename-fix.d.ts +8 -0
  68. package/dist/support/business-names/rename-fix.d.ts.map +1 -0
  69. package/dist/support/business-names/rename-fix.js +26 -0
  70. package/dist/support/business-names/rename-fix.js.map +1 -0
  71. package/dist/support/business-names/repository-concept.d.ts +4 -0
  72. package/dist/support/business-names/repository-concept.d.ts.map +1 -0
  73. package/dist/support/business-names/repository-concept.js +10 -0
  74. package/dist/support/business-names/repository-concept.js.map +1 -0
  75. package/dist/support/business-names/singular.d.ts +3 -0
  76. package/dist/support/business-names/singular.d.ts.map +1 -0
  77. package/dist/support/business-names/singular.js +11 -0
  78. package/dist/support/business-names/singular.js.map +1 -0
  79. package/dist/support/business-names/typed-names.d.ts +13 -0
  80. package/dist/support/business-names/typed-names.d.ts.map +1 -0
  81. package/dist/support/business-names/typed-names.js +53 -0
  82. package/dist/support/business-names/typed-names.js.map +1 -0
  83. package/dist/support/business-names/words-of.d.ts +9 -0
  84. package/dist/support/business-names/words-of.d.ts.map +1 -0
  85. package/dist/support/business-names/words-of.js +8 -0
  86. package/dist/support/business-names/words-of.js.map +1 -0
  87. package/dist/version.d.ts +1 -1
  88. package/dist/version.js +1 -1
  89. package/docs/rules/authz-declared.fr.md +2 -2
  90. package/docs/rules/authz-declared.md +1 -1
  91. package/docs/rules/naming-business-name.fr.md +82 -0
  92. package/docs/rules/naming-business-name.md +81 -0
  93. package/package.json +1 -1
@@ -0,0 +1,81 @@
1
+ **English** · [Français](naming-business-name.fr.md)
2
+
3
+ # ddd-ts-kit/naming-business-name
4
+
5
+ Architecture id: `naming/business-name`. Default severity: `error`. Fixable (`eslint --fix`) where the name is known.
6
+
7
+ Applies to: `domain/` and `application/` of every context, and the shared kernel outside its `presentation/`; tests excluded. On by default, in a new project and in an existing one: a config without `businessNames` reads the default list.
8
+
9
+ ## Why
10
+
11
+ The code of the model is the ubiquitous language written down. A handler that loads an appointment and names it `target`, a loop that walks the due reminders as `item`, a parameter called `data`: each makes the reader translate the line back into the business, and hides which concept it handles. A generic name also spreads, because the next line is written by copying the last one: the command handler templates of the kit wrote `const target = X.create(..)` until 0.17, and forty handlers of the example application inherited it. Named after its concept, `appointment`, `reminder`, `delegation`, a line reads as the domain expert would say it.
12
+
13
+ ## Reported
14
+
15
+ A name that is one of the generic words, `target`, `targets`, `data`, `item`, `items`, `obj`, `object`, `thing`, `things`, `stuff`, `info`, `element`, `el`, `tmp`, `temp`, `foo`, `bar` or `baz`, given to:
16
+
17
+ - a variable, `const target = ..`;
18
+ - a loop variable, `for (const target of due)`;
19
+ - a destructured binding, `const { lines: data } = command`, at any depth;
20
+ - a parameter of a function, a method, an arrow, an abstract or overload signature, a method signature of an interface, or a function type;
21
+ - a property of a class (parameter properties included), of an interface, or of a type alias of an object.
22
+
23
+ Incorrect:
24
+
25
+ ```ts
26
+ const target = await this.appointmentRepository.findById(command.appointmentId);
27
+
28
+ for (const target of due) {
29
+ target.expire(command.at);
30
+ }
31
+ ```
32
+
33
+ Correct:
34
+
35
+ ```ts
36
+ const appointment = await this.appointmentRepository.findById(command.appointmentId);
37
+
38
+ for (const appointment of due) {
39
+ appointment.expire(command.at);
40
+ }
41
+ ```
42
+
43
+ ## The fix
44
+
45
+ A variable whose initializer says which concept it holds is renamed, with every use of it, to the name of that concept in camel case:
46
+
47
+ - `X.create(..)` and `new X(..)`, `X` a class of the file or one imported from the project (`new Map()` says nothing of the business): `const appointment = Appointment.create(..)`;
48
+ - a call on a repository: with type information (the presets of the plugin give it), the type it answers, once awaited and without `undefined`, when it is an aggregate, an entity or a value object of the project (`domain/aggregates/`, `domain/entities/`, `domain/value-objects/`, the shared kernel); `appointments` for a list. The repository is an instance of a port of `domain/repositories/`, or a binding named `<concept>Repository`. Without type information, the names decide: `this.appointmentRepository.findById(..)` (`find`, `get`, `load`, `require`, alone or with `One` or `ById`) holds an `appointment`, `findDue(..)` held by a plural word (`targets`, `items`, `things`) holds `appointments`.
49
+
50
+ A shorthand property keeps its key: `{ target }` becomes `{ target: appointment }`. The rule reports without fixing when the name is already taken (declared in the scope, shadowing between a use and the declaration, or used inside the scope for something else), when the variable is exported, and when the binding holds one element but the name says several, or the other way round. A loop variable is never fixed: the message gives the singular of its collection (`reminder` for `dueReminders`, or the element type with type information).
51
+
52
+ Upgrading a project is one command, then the reports that remain:
53
+
54
+ ```bash
55
+ npx eslint . --fix
56
+ npx eslint .
57
+ ```
58
+
59
+ ## Details
60
+
61
+ A key of an object literal follows the type it is written for and is not judged: `{ items, total }` is the shape of a `Page` of the kernel. A type literal nested in an annotation, `props: { data: string }`, is not a declaration of the model either. A catch clause is not judged.
62
+
63
+ ## Options
64
+
65
+ `words`: the generic words, in place of the default list. `allow`: words removed from the list.
66
+
67
+ ```js
68
+ 'ddd-ts-kit/naming-business-name': ['error', { allow: ['info'] }]
69
+ ```
70
+
71
+ Both options come over `businessNames` of `ddd-ts-kit.config.json`, `{ "words": [..], "allow": [..] }`, which `ddd-ts-kit check` reads too: keep the list there so that both analyzers judge the same names. `rules."naming/business-name"` set to `off` silences the rule, and `// ddd-ts-kit-disable-next-line naming/business-name -- <reason>` silences one line, exactly as for `ddd-ts-kit check`.
72
+
73
+ ## Limits
74
+
75
+ - Infrastructure, presentation, the platform and the tests are not judged: an adapter speaks the words of its library, and a spec the words of its scenario. A serializer of `presentation/` is still better named after what it serializes.
76
+ - A generic word inside a longer name (`targetDate`, `itemCount`) is not reported: it is qualified. `language/no-technical-name` judges the names of classes and use cases.
77
+ - Without type information, a repository whose method names neither one element nor several (`save`, `search`, `count`) gets no proposal.
78
+
79
+ ## With the CLI checker
80
+
81
+ `ddd-ts-kit check` reports the same id from the text of the files, with the same list and the same places, and proposes the name of the class an initializer builds or of the repository it reads. This rule is the authority, and the one that renames.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-ts-kit/eslint-plugin",
3
- "version": "0.16.1",
3
+ "version": "0.17.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
  "license": "MIT",
6
6
  "repository": {