@ddd-ts-kit/eslint-plugin 0.27.0 → 0.83.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.
- package/README.fr.md +4 -4
- package/README.md +3 -3
- package/dist/project/config.d.ts +1 -1
- package/dist/project/config.d.ts.map +1 -1
- package/dist/project/parse-config.js +1 -1
- package/dist/project/parse-config.js.map +1 -1
- package/dist/rules/errors-constructor-not-public.d.ts +3 -1
- package/dist/rules/errors-constructor-not-public.d.ts.map +1 -1
- package/dist/rules/errors-constructor-not-public.js +11 -3
- package/dist/rules/errors-constructor-not-public.js.map +1 -1
- package/dist/rules/errors-factory-name.d.ts +2 -1
- package/dist/rules/errors-factory-name.d.ts.map +1 -1
- package/dist/rules/errors-factory-name.js +38 -1
- package/dist/rules/errors-factory-name.js.map +1 -1
- package/dist/rules/errors-through-factory.d.ts +1 -1
- package/dist/rules/errors-through-factory.d.ts.map +1 -1
- package/dist/rules/errors-through-factory.js +25 -7
- package/dist/rules/errors-through-factory.js.map +1 -1
- package/dist/support/errors/has-factory-prefix.d.ts +3 -0
- package/dist/support/errors/has-factory-prefix.d.ts.map +1 -0
- package/dist/support/errors/has-factory-prefix.js +7 -0
- package/dist/support/errors/has-factory-prefix.js.map +1 -0
- package/dist/support/errors/is-error-file.d.ts +4 -1
- package/dist/support/errors/is-error-file.d.ts.map +1 -1
- package/dist/support/errors/is-error-file.js +5 -2
- package/dist/support/errors/is-error-file.js.map +1 -1
- package/dist/support/errors/is-refusal-class.d.ts +4 -0
- package/dist/support/errors/is-refusal-class.d.ts.map +1 -0
- package/dist/support/errors/is-refusal-class.js +6 -0
- package/dist/support/errors/is-refusal-class.js.map +1 -0
- package/dist/support/errors/prefixed-name.d.ts +3 -0
- package/dist/support/errors/prefixed-name.d.ts.map +1 -0
- package/dist/support/errors/prefixed-name.js +5 -0
- package/dist/support/errors/prefixed-name.js.map +1 -0
- package/dist/support/rule/define-rule.d.ts +2 -0
- package/dist/support/rule/define-rule.d.ts.map +1 -1
- package/dist/support/rule/define-rule.js +4 -1
- package/dist/support/rule/define-rule.js.map +1 -1
- package/dist/support/rule/rule-docs.d.ts +5 -0
- package/dist/support/rule/rule-docs.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/rules/errors-constructor-not-public.fr.md +19 -5
- package/docs/rules/errors-constructor-not-public.md +18 -4
- package/docs/rules/errors-factory-name.fr.md +43 -9
- package/docs/rules/errors-factory-name.md +42 -8
- package/docs/rules/errors-through-factory.fr.md +23 -6
- package/docs/rules/errors-through-factory.md +22 -5
- package/package.json +1 -1
package/README.fr.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[English](README.md) · **Français**
|
|
2
|
-
<!-- translation-of: README.md sha256:
|
|
2
|
+
<!-- translation-of: README.md sha256:fa83df3df6d355f5 -->
|
|
3
3
|
|
|
4
4
|
# @ddd-ts-kit/eslint-plugin
|
|
5
5
|
|
|
@@ -234,9 +234,9 @@ chaque règle à `error`.
|
|
|
234
234
|
| [`domain/value-object-immutability`](docs/rules/domain-value-object-immutability.fr.md) | `ddd-ts-kit/domain-value-object-immutability` | objets-valeurs : chaque propriété `readonly`, pas de *setter*, pas d'écriture dans `this` | `error` | maison |
|
|
235
235
|
| [`domain/value-object-class`](docs/rules/domain-value-object-class.fr.md) | `ddd-ts-kit/domain-value-object-class` | sous `"stack.values": "classes"` : un fichier d'objet-valeur exporte une classe qui étend `ValueObject`, au constructeur privé ou protégé, avec des fabriques statiques, sans fonction ni objet littéral ; aucune fonction exportée de `domain/` ou du noyau partagé ne répond un enregistrement de données | `error` | maison |
|
|
236
236
|
| [`domain/no-generic-error`](docs/rules/domain-no-generic-error.fr.md) | `ddd-ts-kit/domain-no-generic-error` | pas de `throw new Error(...)` dans `domain/` et `application/` | `error` | maison |
|
|
237
|
-
| [`errors/through-factory`](docs/rules/errors-through-factory.fr.md) | `ddd-ts-kit/errors-through-factory` | sous `"stack.refusals": "factories"`, pas de `new` d'une classe importée de `domain/errors
|
|
238
|
-
| [`errors/constructor-not-public`](docs/rules/errors-constructor-not-public.fr.md) | `ddd-ts-kit/errors-constructor-not-public` | sous `"stack.refusals": "factories"`, une classe d'erreur de `domain/errors/` n'a pas de constructeur public, déclaré ou hérité de `DomainError` | `error` | maison |
|
|
239
|
-
| [`errors/factory-name`](docs/rules/errors-factory-name.fr.md) | `ddd-ts-kit/errors-factory-name` | sous `"stack.refusals": "factories"`, une fabrique ne s'appelle pas `create`, `make`, `of` ou `error1`, et son code est son nom en casse constante, seul ou avec le nom du concept | `error` | maison |
|
|
237
|
+
| [`errors/through-factory`](docs/rules/errors-through-factory.fr.md) | `ddd-ts-kit/errors-through-factory` | sous `"stack.refusals": "named"` ou `"factories"`, pas de `new` d'une classe importée de `domain/errors/`, ni sous `named` d'une classe qui étend `DomainRefusal` : un refus se construit par une fabrique statique de sa classe | `error` | maison |
|
|
238
|
+
| [`errors/constructor-not-public`](docs/rules/errors-constructor-not-public.fr.md) | `ddd-ts-kit/errors-constructor-not-public` | sous `"stack.refusals": "named"` ou `"factories"`, une classe d'erreur de `domain/errors/` n'a pas de constructeur public, déclaré ou hérité de `DomainError` | `error` | maison |
|
|
239
|
+
| [`errors/factory-name`](docs/rules/errors-factory-name.fr.md) | `ddd-ts-kit/errors-factory-name` | sous `"stack.refusals": "named"`, une classe de refus ne s'appelle pas `...Error` et une fabrique commence par `for`, `with`, `because`, `on` ou `at` puis une majuscule, sans chiffre ; sous `"factories"`, une fabrique ne s'appelle pas `create`, `make`, `of` ou `error1`, et son code est son nom en casse constante, seul ou avec le nom du concept | `error` | maison |
|
|
240
240
|
| [`application/handler-shape`](docs/rules/application-handler-shape.fr.md) | `ddd-ts-kit/application-handler-shape` | un `*.handler.ts` exporte une classe dont la seule méthode publique est `execute` | `error` | maison |
|
|
241
241
|
| [`presentation/controller-shape`](docs/rules/presentation-controller-shape.fr.md) | `ddd-ts-kit/presentation-controller-shape` | un `*.controller.ts` portant `@Controller` exporte une classe dont la seule méthode publique est `handle` | `error` | maison |
|
|
242
242
|
| [`presentation/controller-delegates`](docs/rules/presentation-controller-delegates.fr.md) | `ddd-ts-kit/presentation-controller-delegates` | un contrôleur reçoit le bus de sa méthode, un *mapper* de requête HTTP et un sérialiseur, rien d'autre | `error` | maison |
|
package/README.md
CHANGED
|
@@ -230,9 +230,9 @@ is an error whatever the configured limit). `strict` sets every rule to `error`.
|
|
|
230
230
|
| [`domain/value-object-immutability`](docs/rules/domain-value-object-immutability.md) | `ddd-ts-kit/domain-value-object-immutability` | value objects: every property `readonly`, no setter, no write to `this` | `error` | custom |
|
|
231
231
|
| [`domain/value-object-class`](docs/rules/domain-value-object-class.md) | `ddd-ts-kit/domain-value-object-class` | under `"stack.values": "classes"`: a value object file exports one class extending `ValueObject`, private or protected constructor, static factories, no function nor object literal; no exported function of `domain/` or of the shared kernel answers a record of data | `error` | custom |
|
|
232
232
|
| [`domain/no-generic-error`](docs/rules/domain-no-generic-error.md) | `ddd-ts-kit/domain-no-generic-error` | no `throw new Error(...)` in `domain/` and `application/` | `error` | custom |
|
|
233
|
-
| [`errors/through-factory`](docs/rules/errors-through-factory.md) | `ddd-ts-kit/errors-through-factory` | under `"stack.refusals": "factories"`, no `new` of a class imported from `domain/errors
|
|
234
|
-
| [`errors/constructor-not-public`](docs/rules/errors-constructor-not-public.md) | `ddd-ts-kit/errors-constructor-not-public` | under `"stack.refusals": "factories"`, an error class of `domain/errors/` has no public constructor, declared or inherited from `DomainError` | `error` | custom |
|
|
235
|
-
| [`errors/factory-name`](docs/rules/errors-factory-name.md) | `ddd-ts-kit/errors-factory-name` | under `"stack.refusals": "factories"`, a factory is not named `create`, `make`, `of` or `error1`, and its code is its name in constant case, alone or with the name of the concept | `error` | custom |
|
|
233
|
+
| [`errors/through-factory`](docs/rules/errors-through-factory.md) | `ddd-ts-kit/errors-through-factory` | under `"stack.refusals": "named"` or `"factories"`, no `new` of a class imported from `domain/errors/`, nor under `named` of a class extending `DomainRefusal`: a refusal is built by a static factory of its class | `error` | custom |
|
|
234
|
+
| [`errors/constructor-not-public`](docs/rules/errors-constructor-not-public.md) | `ddd-ts-kit/errors-constructor-not-public` | under `"stack.refusals": "named"` or `"factories"`, an error class of `domain/errors/` has no public constructor, declared or inherited from `DomainError` | `error` | custom |
|
|
235
|
+
| [`errors/factory-name`](docs/rules/errors-factory-name.md) | `ddd-ts-kit/errors-factory-name` | under `"stack.refusals": "named"`, a refusal class is not named `...Error` and a factory starts with `for`, `with`, `because`, `on` or `at` then an upper-case letter, no digit; under `"factories"`, a factory is not named `create`, `make`, `of` or `error1`, and its code is its name in constant case, alone or with the name of the concept | `error` | custom |
|
|
236
236
|
| [`application/handler-shape`](docs/rules/application-handler-shape.md) | `ddd-ts-kit/application-handler-shape` | a `*.handler.ts` exports one class whose single public method is `execute` | `error` | custom |
|
|
237
237
|
| [`presentation/controller-shape`](docs/rules/presentation-controller-shape.md) | `ddd-ts-kit/presentation-controller-shape` | a `*.controller.ts` carrying `@Controller` exports one class whose single public method is `handle` | `error` | custom |
|
|
238
238
|
| [`presentation/controller-delegates`](docs/rules/presentation-controller-delegates.md) | `ddd-ts-kit/presentation-controller-delegates` | a controller is given the bus of its method, a request mapper and a serializer, nothing else | `error` | custom |
|
package/dist/project/config.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface Stack {
|
|
|
27
27
|
/** Where a declared class states what it depends on: its constructor signature, or the list of its decorator. A config that does not say is `listed`. */
|
|
28
28
|
readonly dependencies: 'signature' | 'listed';
|
|
29
29
|
/** How a domain error is written: static factories on one class per concept, or a class per error. A config that does not say is `classes`. */
|
|
30
|
-
readonly refusals: 'factories' | 'classes';
|
|
30
|
+
readonly refusals: 'named' | 'factories' | 'classes';
|
|
31
31
|
/** How the schemas of the HTTP contract are written: a shape declared once and shared, or one per route. A config that does not say is `per-route`. */
|
|
32
32
|
readonly schemas: 'shared' | 'per-route';
|
|
33
33
|
/** `named`: a value of a declared vocabulary and a number of the model are read through a name. A config that does not say is `free`, and both rules are silent. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/project/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAEhD,wHAAwH;AACxH,UAAU,eAAe;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,wFAAwF;AACxF,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,eAAe,CAAC;AAEnD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IACxC,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED,MAAM,MAAM,KAAK,GAAG,UAAU,GAAG,UAAU,CAAC;AAE5C,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE9C,6EAA6E;AAC7E,MAAM,WAAW,KAAK;IACpB,qIAAqI;IACrI,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,iHAAiH;IACjH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,yJAAyJ;IACzJ,QAAQ,CAAC,YAAY,EAAE,WAAW,GAAG,QAAQ,CAAC;IAC9C,+IAA+I;IAC/I,QAAQ,CAAC,QAAQ,EAAE,WAAW,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/project/config.ts"],"names":[],"mappings":"AAAA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gCAAgC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,kGAAkG;IAClG,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,gJAAgJ;IAChJ,QAAQ,CAAC,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC;IACtE,yFAAyF;IACzF,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,uIAAuI;IACvI,QAAQ,CAAC,GAAG,EAAE,SAAS,GAAG,SAAS,CAAC;CACrC;AAED,uGAAuG;AACvG,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -7,7 +7,7 @@ export const FUNCTION_LINES_CEILING = 100;
|
|
|
7
7
|
const STYLES = ['declared', 'explicit'];
|
|
8
8
|
const ASSEMBLIES = ['barrel', 'discovery'];
|
|
9
9
|
const DEPENDENCY_STATEMENTS = ['signature', 'listed'];
|
|
10
|
-
const REFUSAL_FORMS = ['factories', 'classes'];
|
|
10
|
+
const REFUSAL_FORMS = ['named', 'factories', 'classes'];
|
|
11
11
|
const SCHEMA_FORMS = ['shared', 'per-route'];
|
|
12
12
|
const LITERAL_FORMS = ['named', 'free'];
|
|
13
13
|
const VALUE_FORMS = ['classes', 'free'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-config.js","sourceRoot":"","sources":["../../src/project/parse-config.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,cAAc,GAAW,EAAE,aAAa,EAAE,CAAC,EAAE,gBA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jE,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACrH,CAAC;AAED,SAAS,OAAO,CAAC,KAAc,EAAE,QAA2B;IAC1D,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC5F,CAAC;AAED,SAAS,KAAK,CAAmB,MAAoB,EAAE,SAAkB,EAAE,QAAW;IACpF,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,IAAI,QAAQ,CAAC;AACjE,CAAC;AAED,SAAS,IAAI,CAAC,KAAc,EAAE,QAAgB;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;AACtD,CAAC"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type MessageId = 'publicConstructor' | 'inheritedPublic' | 'publicRefusalConstructor' | 'inheritedPublicRefusal';
|
|
2
|
+
export declare const errorsConstructorNotPublic: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageId, [], import("../index.js").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
3
|
+
export {};
|
|
2
4
|
//# sourceMappingURL=errors-constructor-not-public.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-constructor-not-public.d.ts","sourceRoot":"","sources":["../../src/rules/errors-constructor-not-public.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,0BAA0B,
|
|
1
|
+
{"version":3,"file":"errors-constructor-not-public.d.ts","sourceRoot":"","sources":["../../src/rules/errors-constructor-not-public.ts"],"names":[],"mappings":"AAQA,KAAK,SAAS,GAAG,mBAAmB,GAAG,iBAAiB,GAAG,0BAA0B,GAAG,wBAAwB,CAAC;AAQjH,eAAO,MAAM,0BAA0B,mKAgDrC,CAAC"}
|
|
@@ -5,19 +5,27 @@ import { visibilityOf } from '../support/classes/visibility-of.js';
|
|
|
5
5
|
import { isErrorClass } from '../support/errors/is-error-class.js';
|
|
6
6
|
import { isErrorFile } from '../support/errors/is-error-file.js';
|
|
7
7
|
import { defineRule } from '../support/rule/define-rule.js';
|
|
8
|
+
/** The messages of each form: a concept class extends `ConceptError`, a named refusal `DomainRefusal`. */
|
|
9
|
+
const MESSAGES = {
|
|
10
|
+
factories: { declared: 'publicConstructor', inherited: 'inheritedPublic' },
|
|
11
|
+
named: { declared: 'publicRefusalConstructor', inherited: 'inheritedPublicRefusal' },
|
|
12
|
+
};
|
|
8
13
|
export const errorsConstructorNotPublic = defineRule({
|
|
9
14
|
id: 'errors/constructor-not-public',
|
|
10
15
|
type: 'problem',
|
|
11
16
|
recommended: 'error',
|
|
12
|
-
description: 'Under "stack.refusals": "factories", the constructor of an error class of domain/errors/ is not public: the class extends ConceptError and declares none, or declares it private or protected.',
|
|
17
|
+
description: 'Under "stack.refusals": "factories" or "named", the constructor of an error class of domain/errors/ is not public: the class extends ConceptError or DomainRefusal and declares none, or declares it private or protected.',
|
|
13
18
|
messages: {
|
|
14
19
|
publicConstructor: 'The constructor of {{className}} is public: anyone can build a refusal with a code and a message of their own. Extend ConceptError of @ddd-ts-kit/kernel and remove the constructor (its own is protected), then build each refusal in a static factory with `{{className}}.refusal(code, message, facts)`.',
|
|
15
20
|
inheritedPublic: '{{className}} extends DomainError and declares no constructor, so it inherits a public one. Extend ConceptError of @ddd-ts-kit/kernel, whose constructor is protected, and build each refusal in a static factory with `{{className}}.refusal(code, message, facts)`.',
|
|
21
|
+
publicRefusalConstructor: 'The constructor of {{className}} is public: anyone can build this refusal with a message of their own. Remove it: DomainRefusal of @ddd-ts-kit/kernel has a protected one, and each factory builds the refusal with `{{className}}.refusal(message, facts)`.',
|
|
22
|
+
inheritedPublicRefusal: '{{className}} extends DomainError and declares no constructor, so it inherits a public one. Extend DomainRefusal of @ddd-ts-kit/kernel, whose constructor is protected, and build the refusal in static factories with `{{className}}.refusal(message, facts)`.',
|
|
16
23
|
},
|
|
17
24
|
create({ file, report }) {
|
|
18
25
|
if (!isErrorFile(file)) {
|
|
19
26
|
return {};
|
|
20
27
|
}
|
|
28
|
+
const messages = file.config.stack.refusals === 'named' ? MESSAGES.named : MESSAGES.factories;
|
|
21
29
|
return {
|
|
22
30
|
ClassBody(body) {
|
|
23
31
|
const owner = body.parent;
|
|
@@ -27,12 +35,12 @@ export const errorsConstructorNotPublic = defineRule({
|
|
|
27
35
|
const constructor = constructorOf(body);
|
|
28
36
|
const data = { className: className(owner) };
|
|
29
37
|
if (constructor !== undefined && visibilityOf(constructor) === 'public') {
|
|
30
|
-
report({ node: constructor.key, messageId:
|
|
38
|
+
report({ node: constructor.key, messageId: messages.declared, data });
|
|
31
39
|
}
|
|
32
40
|
if (constructor === undefined &&
|
|
33
41
|
owner.superClass?.type === AST_NODE_TYPES.Identifier &&
|
|
34
42
|
owner.superClass.name === 'DomainError') {
|
|
35
|
-
report({ node: owner.id ?? owner, messageId:
|
|
43
|
+
report({ node: owner.id ?? owner, messageId: messages.inherited, data });
|
|
36
44
|
}
|
|
37
45
|
},
|
|
38
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-constructor-not-public.js","sourceRoot":"","sources":["../../src/rules/errors-constructor-not-public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,E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 +1,5 @@
|
|
|
1
|
-
type MessageId = 'vagueName' | 'codeNotLiteral' | 'codeFormat' | 'mismatch';
|
|
1
|
+
type MessageId = 'vagueName' | 'codeNotLiteral' | 'codeFormat' | 'mismatch' | NamedMessageId;
|
|
2
|
+
type NamedMessageId = 'unprefixed' | 'digitInName' | 'errorSuffix';
|
|
2
3
|
export declare const errorsFactoryName: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageId, [], import("../index.js").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
3
4
|
export {};
|
|
4
5
|
//# sourceMappingURL=errors-factory-name.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-factory-name.d.ts","sourceRoot":"","sources":["../../src/rules/errors-factory-name.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors-factory-name.d.ts","sourceRoot":"","sources":["../../src/rules/errors-factory-name.ts"],"names":[],"mappings":"AAYA,KAAK,SAAS,GAAG,WAAW,GAAG,gBAAgB,GAAG,YAAY,GAAG,UAAU,GAAG,cAAc,CAAC;AAC7F,KAAK,cAAc,GAAG,YAAY,GAAG,aAAa,GAAG,aAAa,CAAC;AAanE,eAAO,MAAM,iBAAiB,mKAmD5B,CAAC"}
|
|
@@ -4,27 +4,42 @@ import { memberName } from '../support/classes/member-name.js';
|
|
|
4
4
|
import { visibilityOf } from '../support/classes/visibility-of.js';
|
|
5
5
|
import { descendants } from '../support/descendants.js';
|
|
6
6
|
import { constantCase } from '../support/errors/constant-case.js';
|
|
7
|
+
import { hasFactoryPrefix } from '../support/errors/has-factory-prefix.js';
|
|
8
|
+
import { prefixedName } from '../support/errors/prefixed-name.js';
|
|
7
9
|
import { isErrorClass } from '../support/errors/is-error-class.js';
|
|
8
10
|
import { isErrorFile } from '../support/errors/is-error-file.js';
|
|
9
11
|
import { defineRule } from '../support/rule/define-rule.js';
|
|
10
12
|
/** Names that say an error is being made, never which rule of the business refused. */
|
|
11
13
|
const VAGUE_NAMES = ['create', 'make', 'of', 'from', 'build', 'new', 'error', 'failure', 'fail', 'refusal', 'refuse'];
|
|
12
14
|
const ERROR_CODE = /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/;
|
|
15
|
+
const ERROR_SUFFIX = /^(.+)Error$/;
|
|
13
16
|
export const errorsFactoryName = defineRule({
|
|
14
17
|
id: 'errors/factory-name',
|
|
15
18
|
type: 'problem',
|
|
16
19
|
recommended: 'error',
|
|
17
|
-
description: 'Under "stack.refusals": "factories", a static factory of an error class is named after the refusal, in the words of the business, and its code is that name in constant case, alone or with the name of the concept.',
|
|
20
|
+
description: 'Under "stack.refusals": "factories", a static factory of an error class is named after the refusal, in the words of the business, and its code is that name in constant case, alone or with the name of the concept. Under "named", the class is named after the refusal, never `...Error`, and a factory after what the refusal is about: for, with, because, on or at, then an upper-case letter, no digit.',
|
|
18
21
|
messages: {
|
|
19
22
|
vagueName: '`{{className}}.{{name}}` says that an error is built, not which rule refused. Name the factory after the refusal, as a domain expert would say it: `slotTaken`, `alreadyConfirmed`, `notFound`.',
|
|
20
23
|
codeNotLiteral: 'The code `{{className}}.{{name}}` gives to `refusal(...)` is not a string literal. Write it in place, in constant case: the code is the contract of the refusal, read by the HTTP mapping, the OpenAPI document, the audit trail and the tests.',
|
|
21
24
|
codeFormat: 'The code "{{code}}" of `{{className}}.{{name}}` is not in constant case. Write upper-case words separated by underscores, for example {{expected}}.',
|
|
22
25
|
mismatch: 'The factory `{{className}}.{{name}}` sets the code "{{code}}", which says something else. Write {{expected}}, or rename the factory after the code: a reader of the code that refuses and a reader of the contract must meet the same words.',
|
|
26
|
+
unprefixed: '`{{className}}.{{name}}` does not say what the refusal is about: the class already says what is refused. Start the factory with for, with, because, on or at, followed by an upper-case letter: `{{expected}}`, `forAccountId`, `becauseOf`, `atStart`.',
|
|
27
|
+
digitInName: '`{{className}}.{{name}}` holds a digit, which tells one factory from another and not what the refusal is about. Name it after its subject, with for, with, because, on or at: `forAccountId`, `withNotice`, `atStart`.',
|
|
28
|
+
errorSuffix: 'The refusal class {{className}} ends with Error. A refusal is named after what is refused, as a domain expert says it: name it {{expected}}, and its file after it.',
|
|
23
29
|
},
|
|
24
30
|
create({ file, report }) {
|
|
25
31
|
if (!isErrorFile(file)) {
|
|
26
32
|
return {};
|
|
27
33
|
}
|
|
34
|
+
if (file.config.stack.refusals === 'named') {
|
|
35
|
+
return {
|
|
36
|
+
ClassBody(body) {
|
|
37
|
+
if (isErrorClass(body.parent)) {
|
|
38
|
+
judgeNamed(body.parent, body.body.filter(isFactory), report);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
28
43
|
return {
|
|
29
44
|
ClassBody(body) {
|
|
30
45
|
if (!isErrorClass(body.parent)) {
|
|
@@ -85,4 +100,26 @@ function expectedCodes({ name, concept }) {
|
|
|
85
100
|
const subject = constantCase(concept.replace(/Error$/, ''));
|
|
86
101
|
return subject === '' ? [refusal] : [refusal, `${subject}_${refusal}`, `${refusal}_${subject}`];
|
|
87
102
|
}
|
|
103
|
+
/** Under `named`: `SlotTaken.forCalendar`, never `SlotTakenError.slotTaken`. The code is held by `errors/code-listed`. */
|
|
104
|
+
function judgeNamed(owner, factories, report) {
|
|
105
|
+
const refusal = className(owner);
|
|
106
|
+
const suffixed = ERROR_SUFFIX.exec(refusal);
|
|
107
|
+
if (suffixed !== null) {
|
|
108
|
+
report({ node: owner.id ?? owner, messageId: 'errorSuffix', data: { className: refusal, expected: suffixed[1] } });
|
|
109
|
+
}
|
|
110
|
+
for (const method of factories) {
|
|
111
|
+
judgeNamedFactory(refusal, method, report);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function judgeNamedFactory(refusal, method, report) {
|
|
115
|
+
const name = memberName(method) ?? '';
|
|
116
|
+
const data = { className: refusal, name };
|
|
117
|
+
if (/\d/.test(name)) {
|
|
118
|
+
report({ node: method.key, messageId: 'digitInName', data });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!hasFactoryPrefix(name)) {
|
|
122
|
+
report({ node: method.key, messageId: 'unprefixed', data: { ...data, expected: prefixedName(name) } });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
88
125
|
//# sourceMappingURL=errors-factory-name.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-factory-name.js","sourceRoot":"","sources":["../../src/rules/errors-factory-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AACzE,OAAO,
|
|
1
|
+
{"version":3,"file":"errors-factory-name.js","sourceRoot":"","sources":["../../src/rules/errors-factory-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAkB,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAe,MAAM,gCAAgC,CAAC;AAKzE,uFAAuF;AACvF,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AACtH,MAAM,UAAU,GAAG,+BAA+B,CAAC;AACnD,MAAM,YA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UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAE1C,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QAE7D,OAAO;IACT,CAAC;IAED,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IACzG,CAAC;AACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const errorsThroughFactory: import("@typescript-eslint/utils/ts-eslint").RuleModule<"constructed", [], import("../index.js").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
1
|
+
export declare const errorsThroughFactory: import("@typescript-eslint/utils/ts-eslint").RuleModule<"constructed" | "constructedRefusal", [], import("../index.js").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
2
2
|
//# sourceMappingURL=errors-through-factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-through-factory.d.ts","sourceRoot":"","sources":["../../src/rules/errors-through-factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors-through-factory.d.ts","sourceRoot":"","sources":["../../src/rules/errors-through-factory.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,oBAAoB,8LA8C/B,CAAC"}
|
|
@@ -1,36 +1,54 @@
|
|
|
1
1
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
import { isRefusalClass } from '../support/errors/is-refusal-class.js';
|
|
2
3
|
import { defineRule } from '../support/rule/define-rule.js';
|
|
3
4
|
const ERRORS_DIRECTORY = /(^|\/)domain\/errors\//;
|
|
4
5
|
export const errorsThroughFactory = defineRule({
|
|
5
6
|
id: 'errors/through-factory',
|
|
6
7
|
type: 'problem',
|
|
7
8
|
recommended: 'error',
|
|
8
|
-
description: 'Under "stack.refusals": "factories", a domain error is built by a static factory of its
|
|
9
|
+
description: 'Under "stack.refusals": "factories" or "named", a domain error is built by a static factory of its class: no `new` of a class of domain/errors/ outside that class, nor of a class extending DomainRefusal.',
|
|
9
10
|
messages: {
|
|
10
11
|
constructed: '`new {{name}}(...)` builds a refusal outside its error class, with whatever code and message the caller writes. Call the static factory named after the refusal, `throw <Concept>Error.<refusal>(...)`, and add it when it is missing: `ddd-ts-kit generate error {{context}} <Concept> <refusal>`.',
|
|
12
|
+
constructedRefusal: '`new {{name}}(...)` builds a refusal without its factory, with whatever message the caller writes. Call a static factory named after what the refusal is about, `throw {{name}}.for<Subject>(...)`, and add it when it is missing: `ddd-ts-kit generate error {{context}} {{name}} for<Subject>`.',
|
|
11
13
|
},
|
|
12
14
|
create({ file, report }) {
|
|
13
15
|
const { location } = file;
|
|
14
|
-
|
|
16
|
+
const form = file.config.stack.refusals;
|
|
17
|
+
if (form === 'classes' || location.area !== 'context') {
|
|
15
18
|
return {};
|
|
16
19
|
}
|
|
17
20
|
const errors = new Set();
|
|
21
|
+
const constructions = [];
|
|
22
|
+
const messageId = form === 'named' ? 'constructedRefusal' : 'constructed';
|
|
18
23
|
return {
|
|
19
24
|
ImportDeclaration(node) {
|
|
20
25
|
if (ERRORS_DIRECTORY.test(node.source.value)) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
importedNames(node).forEach((name) => errors.add(name));
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
// A named refusal is built by `refusal(...)`, in its own factories too: `new` of it is refused everywhere.
|
|
30
|
+
'ClassDeclaration, ClassExpression'(node) {
|
|
31
|
+
if (form === 'named' && node.id !== null && isRefusalClass(node)) {
|
|
32
|
+
errors.add(node.id.name);
|
|
24
33
|
}
|
|
25
34
|
},
|
|
26
35
|
NewExpression(node) {
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
constructions.push(node);
|
|
37
|
+
},
|
|
38
|
+
'Program:exit'() {
|
|
39
|
+
for (const node of constructions.filter((construction) => builds(construction, errors))) {
|
|
40
|
+
report({ node, messageId, data: { name: calleeName(node), context: location.context } });
|
|
29
41
|
}
|
|
30
42
|
},
|
|
31
43
|
};
|
|
32
44
|
},
|
|
33
45
|
});
|
|
46
|
+
function builds(node, errors) {
|
|
47
|
+
return errors.has(calleeName(node));
|
|
48
|
+
}
|
|
49
|
+
function calleeName(node) {
|
|
50
|
+
return node.callee.type === AST_NODE_TYPES.Identifier ? node.callee.name : '';
|
|
51
|
+
}
|
|
34
52
|
function importedNames(node) {
|
|
35
53
|
return node.specifiers
|
|
36
54
|
.filter((specifier) => specifier.type === AST_NODE_TYPES.ImportSpecifier)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-through-factory.js","sourceRoot":"","sources":["../../src/rules/errors-through-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAElD,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"errors-through-factory.js","sourceRoot":"","sources":["../../src/rules/errors-through-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,MAAM,gBAAgB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IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The words a factory of a named refusal starts with: what the refusal is about, `forAccountId`, `becauseOf`. */
|
|
2
|
+
const PREFIXED = /^(for|with|because|on|at)[A-Z]/;
|
|
3
|
+
/** `forCalendar` and `atStart` carry a prefix; `slotTaken`, `format` and `onboard` do not. */
|
|
4
|
+
export function hasFactoryPrefix(name) {
|
|
5
|
+
return PREFIXED.test(name);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=has-factory-prefix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-factory-prefix.js","sourceRoot":"","sources":["../../../src/support/errors/has-factory-prefix.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,MAAM,QAAQ,GAAG,gCAAgC,CAAC;AAElD,8FAA8F;AAC9F,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { LintedFile } from '../../project/linted-file.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* A production file of `domain/errors/` of a context, in a project that builds its refusals through
|
|
4
|
+
* factories: on one class per concept (`factories`) or on one class per refusal (`named`).
|
|
5
|
+
*/
|
|
3
6
|
export declare function isErrorFile(file: LintedFile): boolean;
|
|
4
7
|
//# sourceMappingURL=is-error-file.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-error-file.d.ts","sourceRoot":"","sources":["../../../src/support/errors/is-error-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D
|
|
1
|
+
{"version":3,"file":"is-error-file.d.ts","sourceRoot":"","sources":["../../../src/support/errors/is-error-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAUrD"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* A production file of `domain/errors/` of a context, in a project that builds its refusals through
|
|
3
|
+
* factories: on one class per concept (`factories`) or on one class per refusal (`named`).
|
|
4
|
+
*/
|
|
2
5
|
export function isErrorFile(file) {
|
|
3
6
|
const { location } = file;
|
|
4
|
-
return (file.config.stack.refusals
|
|
7
|
+
return (file.config.stack.refusals !== 'classes' &&
|
|
5
8
|
location.area === 'context' &&
|
|
6
9
|
location.layer === 'domain' &&
|
|
7
10
|
location.inside[0] === 'errors' &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-error-file.js","sourceRoot":"","sources":["../../../src/support/errors/is-error-file.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"is-error-file.js","sourceRoot":"","sources":["../../../src/support/errors/is-error-file.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAAgB;IAC1C,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAE1B,OAAO,CACL,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS;QACxC,QAAQ,CAAC,IAAI,KAAK,SAAS;QAC3B,QAAQ,CAAC,KAAK,KAAK,QAAQ;QAC3B,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ;QAC/B,CAAC,IAAI,CAAC,MAAM,CACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ClassNode } from '../classes/class-name.js';
|
|
2
|
+
/** A class that extends `DomainRefusal` of the kernel: one refusal, named after what is refused. */
|
|
3
|
+
export declare function isRefusalClass(node: ClassNode): boolean;
|
|
4
|
+
//# sourceMappingURL=is-refusal-class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-refusal-class.d.ts","sourceRoot":"","sources":["../../../src/support/errors/is-refusal-class.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D,oGAAoG;AACpG,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAEvD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
/** A class that extends `DomainRefusal` of the kernel: one refusal, named after what is refused. */
|
|
3
|
+
export function isRefusalClass(node) {
|
|
4
|
+
return node.superClass?.type === AST_NODE_TYPES.Identifier && node.superClass.name === 'DomainRefusal';
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=is-refusal-class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-refusal-class.js","sourceRoot":"","sources":["../../../src/support/errors/is-refusal-class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,oGAAoG;AACpG,MAAM,UAAU,cAAc,CAAC,IAAe;IAC5C,OAAO,IAAI,CAAC,UAAU,EAAE,IAAI,KAAK,cAAc,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,eAAe,CAAC;AACzG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefixed-name.d.ts","sourceRoot":"","sources":["../../../src/support/errors/prefixed-name.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefixed-name.js","sourceRoot":"","sources":["../../../src/support/errors/prefixed-name.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAC9D,CAAC"}
|
|
@@ -19,6 +19,8 @@ export interface RuleDefinition<MessageIds extends string, Options extends reado
|
|
|
19
19
|
readonly type: 'problem' | 'suggestion';
|
|
20
20
|
readonly description: string;
|
|
21
21
|
readonly recommended: 'error' | 'warn';
|
|
22
|
+
/** A new rule, or what a rule judges more, is a warning first: the version in which it becomes an error. */
|
|
23
|
+
readonly transition?: string;
|
|
22
24
|
readonly messages: Readonly<Record<MessageIds, string>>;
|
|
23
25
|
readonly schema?: readonly JSONSchema.JSONSchema4[];
|
|
24
26
|
readonly defaultOptions?: Options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-rule.d.ts","sourceRoot":"","sources":["../../../src/support/rule/define-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGvF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,MAAM,MAAM,MAAM,CAAC,UAAU,SAAS,MAAM,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,gBAAgB,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;AAE5G,UAAU,OAAO,CAAC,UAAU,SAAS,MAAM,EAAE,OAAO,SAAS,SAAS,OAAO,EAAE;IAC7E,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IACtE,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IACnD,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M,CAAC;IACvC,4GAA4G;IAC5G,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;IACxD,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,UAAU,CAAC,WAAW,EAAE,CAAC;IACpD,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC;CAClE;AAID,eAAO,MAAM,UAAU,WAAY,MAAM,KAAG,MAAkC,CAAC;AAE/E,wBAAgB,UAAU,CAAC,UAAU,SAAS,MAAM,EAAE,OAAO,SAAS,SAAS,OAAO,EAAE,GAAG,EAAE,EAC3F,UAAU,EAAE,cAAc,CAAC,UAAU,EAAE,OAAO,CAAC,GAC9C,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CA6BpD"}
|
|
@@ -11,7 +11,7 @@ export function defineRule(definition) {
|
|
|
11
11
|
name,
|
|
12
12
|
meta: {
|
|
13
13
|
type: definition.type,
|
|
14
|
-
docs:
|
|
14
|
+
docs: docsOfDefinition(definition, name),
|
|
15
15
|
messages: definition.messages,
|
|
16
16
|
schema: definition.schema ?? [],
|
|
17
17
|
...(definition.fixable === undefined ? {} : { fixable: definition.fixable }),
|
|
@@ -32,6 +32,9 @@ export function defineRule(definition) {
|
|
|
32
32
|
},
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
+
function docsOfDefinition({ description, id, recommended, transition }, name) {
|
|
36
|
+
return { description, ruleId: id, name, recommended, ...(transition === undefined ? {} : { transition }) };
|
|
37
|
+
}
|
|
35
38
|
function reporter(context, ruleId) {
|
|
36
39
|
let suppressed;
|
|
37
40
|
return (descriptor) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-rule.js","sourceRoot":"","sources":["../../../src/support/rule/define-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkC,MAAM,0BAA0B,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAGtE,MAAM,IAAI,GAAG,qFAAqF,CAAC;
|
|
1
|
+
{"version":3,"file":"define-rule.js","sourceRoot":"","sources":["../../../src/support/rule/define-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkC,MAAM,0BAA0B,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAGtE,MAAM,IAAI,GAAG,qFAAqF,CAAC;AA8BnG,MAAM,eAAe,GAAG,WAAW,CAAC,WAAW,CAAW,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,IAAI,KAAK,CAAC,CAAC;AAE1F,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAc,EAAU,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAE/E,MAAM,UAAU,UAAU,CACxB,UAA+C;IAE/C,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAE1D,OAAO,eAAe,CAAsB;QAC1C,IAAI;QACJ,IAAI,EAAE;YACJ,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,IAAI,EAAE,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC;YACxC,QAAQ,EAAE,UAAU,CAAC,QAAQ;YAC7B,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C,UAAU,EAAE,MAAM,CAAC,CAAC;QAE3D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YACxC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,UAA6C;IAC3D,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAE5F,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,CAAC,CAAC;IACX,CAAC;IAED,OAAO,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;AACnE,CAAC"}
|
|
@@ -5,5 +5,10 @@ export interface RuleDocs {
|
|
|
5
5
|
/** The name of the rule in ESLint, without the plugin prefix. */
|
|
6
6
|
readonly name: string;
|
|
7
7
|
readonly recommended: 'error' | 'warn';
|
|
8
|
+
/**
|
|
9
|
+
* The version of the kit in which this rule, a warning while projects upgrade, becomes an error.
|
|
10
|
+
* `ddd-ts-kit lint` shows its warnings without failing on them until then.
|
|
11
|
+
*/
|
|
12
|
+
readonly transition?: string;
|
|
8
13
|
}
|
|
9
14
|
//# sourceMappingURL=rule-docs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-docs.d.ts","sourceRoot":"","sources":["../../../src/support/rule/rule-docs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"rule-docs.d.ts","sourceRoot":"","sources":["../../../src/support/rule/rule-docs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,CAAC;IACvC;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.83.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.83.1';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
[English](errors-constructor-not-public.md) · **Français**
|
|
2
|
-
<!-- translation-of: errors-constructor-not-public.md sha256:
|
|
2
|
+
<!-- translation-of: errors-constructor-not-public.md sha256:b0eb0ec4c37d5db0 -->
|
|
3
3
|
|
|
4
4
|
# ddd-ts-kit/errors-constructor-not-public
|
|
5
5
|
|
|
6
6
|
Identifiant d'architecture : `errors/constructor-not-public`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
|
|
7
7
|
|
|
8
|
-
S'applique à : les fichiers de production de `domain/errors/` d'un contexte, dans un projet dont la configuration dit `"stack.refusals": "factories"`.
|
|
8
|
+
S'applique à : les fichiers de production de `domain/errors/` d'un contexte, dans un projet dont la configuration dit `"stack.refusals": "named"` ou `"factories"`.
|
|
9
9
|
|
|
10
10
|
## Pourquoi
|
|
11
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`
|
|
12
|
+
Un constructeur public permet à n'importe quel appelant de construire un refus avec un code et un message de son cru. `DomainRefusal` (la base d'un refus sous `named`) et `ConceptError` (la base d'une classe de concept sous `factories`) de `@ddd-ts-kit/kernel` ont un constructeur protégé, et une classe qui étend l'une d'elles n'en déclare aucun : un refus n'existe alors que par une fabrique statique.
|
|
13
13
|
|
|
14
14
|
## Signalé
|
|
15
15
|
|
|
@@ -18,6 +18,8 @@ Un constructeur public permet à n'importe quel appelant de construire un refus
|
|
|
18
18
|
|
|
19
19
|
Une classe abstraite n'est pas jugée.
|
|
20
20
|
|
|
21
|
+
Le message nomme la base de la forme en usage : `DomainRefusal` sous `named`, `ConceptError` sous `factories`.
|
|
22
|
+
|
|
21
23
|
Incorrect :
|
|
22
24
|
|
|
23
25
|
```ts
|
|
@@ -30,7 +32,19 @@ export class SlotTakenError extends DomainError {
|
|
|
30
32
|
}
|
|
31
33
|
```
|
|
32
34
|
|
|
33
|
-
Correct :
|
|
35
|
+
Correct, sous `named` :
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
export class SlotTaken extends DomainRefusal {
|
|
39
|
+
readonly code = SchedulingCodes.SlotTaken;
|
|
40
|
+
|
|
41
|
+
static forCalendar(calendarId: string) {
|
|
42
|
+
return SlotTaken.refusal(`The slot on calendar ${calendarId} is already held.`, { calendarId });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Correct, sous `factories` :
|
|
34
48
|
|
|
35
49
|
```ts
|
|
36
50
|
export class AppointmentError extends ConceptError {
|
|
@@ -49,7 +63,7 @@ Aucune.
|
|
|
49
63
|
## Limites
|
|
50
64
|
|
|
51
65
|
- 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
|
|
66
|
+
- 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 refus nommés (ou, avec `--to factories`, aux classes de concept).
|
|
53
67
|
|
|
54
68
|
## Avec le checker de la CLI
|
|
55
69
|
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
Architecture id: `errors/constructor-not-public`. Default severity: `error` in `recommended`, `error` in `strict`.
|
|
6
6
|
|
|
7
|
-
Applies to: the production files of `domain/errors/` of a context, in a project whose config says `"stack.refusals": "factories"`.
|
|
7
|
+
Applies to: the production files of `domain/errors/` of a context, in a project whose config says `"stack.refusals": "named"` or `"factories"`.
|
|
8
8
|
|
|
9
9
|
## Why
|
|
10
10
|
|
|
11
|
-
A public constructor lets any caller build a refusal with a code and a message of its own. `ConceptError` of `@ddd-ts-kit/kernel`
|
|
11
|
+
A public constructor lets any caller build a refusal with a code and a message of its own. `DomainRefusal` (the base of a refusal under `named`) and `ConceptError` (the base of a concept class under `factories`) of `@ddd-ts-kit/kernel` have a protected constructor, and a class that extends one declares none: a refusal then exists only through a static factory.
|
|
12
12
|
|
|
13
13
|
## Reported
|
|
14
14
|
|
|
@@ -17,6 +17,8 @@ A public constructor lets any caller build a refusal with a code and a message o
|
|
|
17
17
|
|
|
18
18
|
An abstract class is not judged.
|
|
19
19
|
|
|
20
|
+
The message names the base of the form in use: `DomainRefusal` under `named`, `ConceptError` under `factories`.
|
|
21
|
+
|
|
20
22
|
Incorrect:
|
|
21
23
|
|
|
22
24
|
```ts
|
|
@@ -29,7 +31,19 @@ export class SlotTakenError extends DomainError {
|
|
|
29
31
|
}
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
Correct
|
|
34
|
+
Correct, under `named`:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
export class SlotTaken extends DomainRefusal {
|
|
38
|
+
readonly code = SchedulingCodes.SlotTaken;
|
|
39
|
+
|
|
40
|
+
static forCalendar(calendarId: string) {
|
|
41
|
+
return SlotTaken.refusal(`The slot on calendar ${calendarId} is already held.`, { calendarId });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Correct, under `factories`:
|
|
33
47
|
|
|
34
48
|
```ts
|
|
35
49
|
export class AppointmentError extends ConceptError {
|
|
@@ -48,7 +62,7 @@ None.
|
|
|
48
62
|
## Limits
|
|
49
63
|
|
|
50
64
|
- A class that extends a base of the project and declares no constructor is trusted: the visibility it inherits is in another file.
|
|
51
|
-
- Nothing is fixed: making a constructor private breaks every `new` of the class. `ddd-ts-kit error-factories` moves a project to factories as a whole.
|
|
65
|
+
- Nothing is fixed: making a constructor private breaks every `new` of the class. `ddd-ts-kit error-factories` moves a project to named refusals (or, with `--to factories`, to concept classes) as a whole.
|
|
52
66
|
|
|
53
67
|
## With the CLI checker
|
|
54
68
|
|
|
@@ -1,25 +1,59 @@
|
|
|
1
1
|
[English](errors-factory-name.md) · **Français**
|
|
2
|
-
<!-- translation-of: errors-factory-name.md sha256:
|
|
2
|
+
<!-- translation-of: errors-factory-name.md sha256:258dda2c58b2caff -->
|
|
3
3
|
|
|
4
4
|
# ddd-ts-kit/errors-factory-name
|
|
5
5
|
|
|
6
6
|
Identifiant d'architecture : `errors/factory-name`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
|
|
7
7
|
|
|
8
|
-
S'applique à : les fichiers de production de `domain/errors/` d'un contexte, dans un projet dont la configuration dit `"stack.refusals": "factories"`.
|
|
8
|
+
S'applique à : les fichiers de production de `domain/errors/` d'un contexte, dans un projet dont la configuration dit `"stack.refusals": "named"` ou `"factories"`.
|
|
9
9
|
|
|
10
10
|
## Pourquoi
|
|
11
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`.
|
|
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. Sous `named`, la classe dit ce qui est refusé et la fabrique ce sur quoi porte le refus : `SlotTaken.forCalendar`, jamais `SlotTakenError.create`. Sous `factories`, la fabrique dit ce qui est refusé et le code le répète : `slotTaken` et `SLOT_TAKEN`, jamais `create` et `BOOKING_FAILED`.
|
|
13
13
|
|
|
14
14
|
## Signalé
|
|
15
15
|
|
|
16
16
|
Une fabrique (factory) est une méthode statique publique d'une classe d'erreur qui appelle `refusal(...)`.
|
|
17
17
|
|
|
18
|
+
Sous `named` :
|
|
19
|
+
|
|
20
|
+
- une classe dont le nom finit par `Error` : un refus est nommé d'après ce qui est refusé (`SlotTaken`, `InsufficientFunds`), et le message propose le nom sans ce suffixe
|
|
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
|
+
- une fabrique dont le nom contient un chiffre (`forAccount2`)
|
|
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*.
|
|
25
|
+
|
|
26
|
+
Incorrect, sous `named` :
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
export class SlotTakenError extends DomainRefusal {
|
|
30
|
+
readonly code = SchedulingCodes.SlotTakenError;
|
|
31
|
+
|
|
32
|
+
static slotTaken(calendarId: string) {
|
|
33
|
+
return SlotTakenError.refusal('The slot is already held.', { calendarId });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Correct, sous `named` :
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
export class SlotTaken extends DomainRefusal {
|
|
42
|
+
readonly code = SchedulingCodes.SlotTaken;
|
|
43
|
+
|
|
44
|
+
static forCalendar(calendarId: string) {
|
|
45
|
+
return SlotTaken.refusal('The slot is already held.', { calendarId });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Sous `factories` :
|
|
51
|
+
|
|
18
52
|
- 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
53
|
- 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
54
|
- 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
55
|
|
|
22
|
-
Incorrect :
|
|
56
|
+
Incorrect, sous `factories` :
|
|
23
57
|
|
|
24
58
|
```ts
|
|
25
59
|
static slotTaken(calendarId: string) {
|
|
@@ -27,7 +61,7 @@ static slotTaken(calendarId: string) {
|
|
|
27
61
|
}
|
|
28
62
|
```
|
|
29
63
|
|
|
30
|
-
Correct :
|
|
64
|
+
Correct, sous `factories` :
|
|
31
65
|
|
|
32
66
|
```ts
|
|
33
67
|
static slotTaken(calendarId: string) {
|
|
@@ -41,13 +75,13 @@ Aucune.
|
|
|
41
75
|
|
|
42
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`.
|
|
43
77
|
|
|
44
|
-
Un code déjà publié sous d'autres mots ne peut pas changer : renommez la fabrique d'après
|
|
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.
|
|
45
79
|
|
|
46
80
|
## Limites
|
|
47
81
|
|
|
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
|
-
-
|
|
82
|
+
- 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. Sous `factories`, `language/glossary-term` tient le nom de la classe ; sous `named`, elle ne juge pas les classes de `domain/errors/`, car un refus est une phrase et non un terme.
|
|
83
|
+
- Sous `factories`, le premier appel `refusal(...)` de la méthode est celui qui est lu.
|
|
50
84
|
|
|
51
85
|
## Avec le checker de la CLI
|
|
52
86
|
|
|
53
|
-
Tenue par ce *plugin* seul. Qu'un code soit unique dans son contexte relève de `errors/code-unique`,
|
|
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*.
|
|
@@ -4,21 +4,55 @@
|
|
|
4
4
|
|
|
5
5
|
Architecture id: `errors/factory-name`. Default severity: `error` in `recommended`, `error` in `strict`.
|
|
6
6
|
|
|
7
|
-
Applies to: the production files of `domain/errors/` of a context, in a project whose config says `"stack.refusals": "factories"`.
|
|
7
|
+
Applies to: the production files of `domain/errors/` of a context, in a project whose config says `"stack.refusals": "named"` or `"factories"`.
|
|
8
8
|
|
|
9
9
|
## Why
|
|
10
10
|
|
|
11
|
-
The factory is read by the developer who refuses, the code by the client, the mapper, the audit trail and the tests. They must meet the same words, and those words are the business's: `slotTaken` and `SLOT_TAKEN`, never `create` and `BOOKING_FAILED`.
|
|
11
|
+
The factory is read by the developer who refuses, the code by the client, the mapper, the audit trail and the tests. They must meet the same words, and those words are the business's. Under `named`, the class says what is refused and the factory what the refusal is about: `SlotTaken.forCalendar`, never `SlotTakenError.create`. Under `factories`, the factory says what is refused and the code repeats it: `slotTaken` and `SLOT_TAKEN`, never `create` and `BOOKING_FAILED`.
|
|
12
12
|
|
|
13
13
|
## Reported
|
|
14
14
|
|
|
15
15
|
A factory is a public static method of an error class that calls `refusal(...)`.
|
|
16
16
|
|
|
17
|
+
Under `named`:
|
|
18
|
+
|
|
19
|
+
- a class whose name ends with `Error`: a refusal is named after what is refused (`SlotTaken`, `InsufficientFunds`), and the message proposes the name without the suffix
|
|
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
|
+
- a factory whose name holds a digit (`forAccount2`)
|
|
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.
|
|
24
|
+
|
|
25
|
+
Incorrect, under `named`:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
export class SlotTakenError extends DomainRefusal {
|
|
29
|
+
readonly code = SchedulingCodes.SlotTakenError;
|
|
30
|
+
|
|
31
|
+
static slotTaken(calendarId: string) {
|
|
32
|
+
return SlotTakenError.refusal('The slot is already held.', { calendarId });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Correct, under `named`:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
export class SlotTaken extends DomainRefusal {
|
|
41
|
+
readonly code = SchedulingCodes.SlotTaken;
|
|
42
|
+
|
|
43
|
+
static forCalendar(calendarId: string) {
|
|
44
|
+
return SlotTaken.refusal('The slot is already held.', { calendarId });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Under `factories`:
|
|
50
|
+
|
|
17
51
|
- a name that says an error is built and not which rule refused: `create`, `make`, `of`, `from`, `build`, `new`, `error`, `failure`, `fail`, `refusal`, `refuse`, or a name holding a digit (`error1`)
|
|
18
52
|
- a code that is not a string literal, or not in constant case
|
|
19
53
|
- a code that is not the name of the factory in constant case, alone or with the name of the concept before or after it: `AppointmentError.notFound` sets `NOT_FOUND`, `APPOINTMENT_NOT_FOUND` or `NOT_FOUND_APPOINTMENT`
|
|
20
54
|
|
|
21
|
-
Incorrect
|
|
55
|
+
Incorrect, under `factories`:
|
|
22
56
|
|
|
23
57
|
```ts
|
|
24
58
|
static slotTaken(calendarId: string) {
|
|
@@ -26,7 +60,7 @@ static slotTaken(calendarId: string) {
|
|
|
26
60
|
}
|
|
27
61
|
```
|
|
28
62
|
|
|
29
|
-
Correct
|
|
63
|
+
Correct, under `factories`:
|
|
30
64
|
|
|
31
65
|
```ts
|
|
32
66
|
static slotTaken(calendarId: string) {
|
|
@@ -40,13 +74,13 @@ None.
|
|
|
40
74
|
|
|
41
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`.
|
|
42
76
|
|
|
43
|
-
A code already published under other words cannot change: rename the factory after
|
|
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.
|
|
44
78
|
|
|
45
79
|
## Limits
|
|
46
80
|
|
|
47
|
-
- Whether a name is a business phrase cannot be decided by a tool: only the names that are certainly not are refused. `language/glossary-term` holds the name of the class.
|
|
48
|
-
-
|
|
81
|
+
- Whether a name is a business phrase cannot be decided by a tool: only the names that are certainly not are refused. Under `factories`, `language/glossary-term` holds the name of the class; under `named` it does not judge the classes of `domain/errors/`, since a refusal is a sentence and not a term.
|
|
82
|
+
- Under `factories`, the first `refusal(...)` call of the method is the one read.
|
|
49
83
|
|
|
50
84
|
## With the CLI checker
|
|
51
85
|
|
|
52
|
-
Held by this plugin alone. That a code is unique in its context is `errors/code-unique`, 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 `codes.ts` of its context is `errors/code-listed`, both held by the checker.
|
|
@@ -1,21 +1,38 @@
|
|
|
1
1
|
[English](errors-through-factory.md) · **Français**
|
|
2
|
-
<!-- translation-of: errors-through-factory.md sha256:
|
|
2
|
+
<!-- translation-of: errors-through-factory.md sha256:7e28f1f7f23e71fe -->
|
|
3
3
|
|
|
4
4
|
# ddd-ts-kit/errors-through-factory
|
|
5
5
|
|
|
6
6
|
Identifiant d'architecture : `errors/through-factory`. Sévérité par défaut : `error` dans `recommended`, `error` dans `strict`.
|
|
7
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é.
|
|
8
|
+
S'applique à : chaque fichier d'un contexte, tests compris, dans un projet dont la configuration dit `"stack.refusals": "named"` ou `"factories"`. Une configuration sans cette clé a été écrite quand une erreur était une classe construite avec `new` : rien n'y est signalé.
|
|
9
9
|
|
|
10
10
|
## Pourquoi
|
|
11
11
|
|
|
12
|
-
Le code qui refuse se lit comme une phrase,
|
|
12
|
+
Le code qui refuse se lit comme une phrase : `throw SlotTaken.forCalendar(calendar.id, slot.startsAt)` sous `named`, où chaque refus est une classe à lui, et `throw AppointmentError.slotTaken(calendar.id, slot.startsAt)` sous `factories`, où les refus d'un concept vivent dans une classe. La fabrique (factory) écrit une fois le code, le message et les faits. Un `new` est un refus dont le code et le message sont ce que l'appelant a bien voulu écrire.
|
|
13
13
|
|
|
14
14
|
## Signalé
|
|
15
15
|
|
|
16
16
|
- `new X(...)` où `X` est importé d'un fichier de `domain/errors/`
|
|
17
|
+
- sous `named` seulement, `new X(...)` où `X` est une classe du même fichier qui étend `DomainRefusal`, dans ses propres fabriques aussi : une fabrique construit le refus avec `X.refusal(message, facts)`
|
|
17
18
|
|
|
18
|
-
Incorrect :
|
|
19
|
+
Incorrect, sous `named` :
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { SlotTaken } from '@/contexts/scheduling/domain/errors/slot-taken.error';
|
|
23
|
+
|
|
24
|
+
throw new SlotTaken(`The slot at ${slot.startsAt.toISOString()} is held.`);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Correct, sous `named` :
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { SlotTaken } from '@/contexts/scheduling/domain/errors/slot-taken.error';
|
|
31
|
+
|
|
32
|
+
throw SlotTaken.forCalendar(calendar.id, slot.startsAt);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Incorrect, sous `factories` :
|
|
19
36
|
|
|
20
37
|
```ts
|
|
21
38
|
import { SlotTakenError } from '@/contexts/scheduling/domain/errors/slot-taken.error';
|
|
@@ -23,7 +40,7 @@ import { SlotTakenError } from '@/contexts/scheduling/domain/errors/slot-taken.e
|
|
|
23
40
|
throw new SlotTakenError(calendar.id, slot.startsAt);
|
|
24
41
|
```
|
|
25
42
|
|
|
26
|
-
Correct :
|
|
43
|
+
Correct, sous `factories` :
|
|
27
44
|
|
|
28
45
|
```ts
|
|
29
46
|
import { AppointmentError } from '@/contexts/scheduling/domain/errors/appointment.error';
|
|
@@ -45,4 +62,4 @@ Aucune.
|
|
|
45
62
|
|
|
46
63
|
## Avec le checker de la CLI
|
|
47
64
|
|
|
48
|
-
Tenue par ce *plugin* seul : le *checker* liste la règle et ne juge rien. Le compilateur refuse la même chose
|
|
65
|
+
Tenue par ce *plugin* seul : le *checker* liste la règle et ne juge rien. Le compilateur refuse la même chose hors de la classe dès qu'elle étend `DomainRefusal` ou `ConceptError`, dont les constructeurs sont protégés.
|
|
@@ -4,17 +4,34 @@
|
|
|
4
4
|
|
|
5
5
|
Architecture id: `errors/through-factory`. Default severity: `error` in `recommended`, `error` in `strict`.
|
|
6
6
|
|
|
7
|
-
Applies to: every file of a context, tests included, in a project whose config says `"stack.refusals": "factories"`. A config without the key was written when an error was a class built with `new`: nothing is reported there.
|
|
7
|
+
Applies to: every file of a context, tests included, in a project whose config says `"stack.refusals": "named"` or `"factories"`. A config without the key was written when an error was a class built with `new`: nothing is reported there.
|
|
8
8
|
|
|
9
9
|
## Why
|
|
10
10
|
|
|
11
|
-
The code that refuses reads as a sentence,
|
|
11
|
+
The code that refuses reads as a sentence: `throw SlotTaken.forCalendar(calendar.id, slot.startsAt)` under `named`, where each refusal is a class of its own, and `throw AppointmentError.slotTaken(calendar.id, slot.startsAt)` under `factories`, where the refusals of one concept live in one class. The factory writes the code, the message and the facts once. A `new` is a refusal whose code and message are whatever the caller wrote.
|
|
12
12
|
|
|
13
13
|
## Reported
|
|
14
14
|
|
|
15
15
|
- `new X(...)` where `X` is imported from a file of `domain/errors/`
|
|
16
|
+
- under `named` only, `new X(...)` where `X` is a class of the same file that extends `DomainRefusal`, in its own factories too: a factory builds the refusal with `X.refusal(message, facts)`
|
|
16
17
|
|
|
17
|
-
Incorrect
|
|
18
|
+
Incorrect, under `named`:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { SlotTaken } from '@/contexts/scheduling/domain/errors/slot-taken.error';
|
|
22
|
+
|
|
23
|
+
throw new SlotTaken(`The slot at ${slot.startsAt.toISOString()} is held.`);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Correct, under `named`:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { SlotTaken } from '@/contexts/scheduling/domain/errors/slot-taken.error';
|
|
30
|
+
|
|
31
|
+
throw SlotTaken.forCalendar(calendar.id, slot.startsAt);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Incorrect, under `factories`:
|
|
18
35
|
|
|
19
36
|
```ts
|
|
20
37
|
import { SlotTakenError } from '@/contexts/scheduling/domain/errors/slot-taken.error';
|
|
@@ -22,7 +39,7 @@ import { SlotTakenError } from '@/contexts/scheduling/domain/errors/slot-taken.e
|
|
|
22
39
|
throw new SlotTakenError(calendar.id, slot.startsAt);
|
|
23
40
|
```
|
|
24
41
|
|
|
25
|
-
Correct
|
|
42
|
+
Correct, under `factories`:
|
|
26
43
|
|
|
27
44
|
```ts
|
|
28
45
|
import { AppointmentError } from '@/contexts/scheduling/domain/errors/appointment.error';
|
|
@@ -44,4 +61,4 @@ None.
|
|
|
44
61
|
|
|
45
62
|
## With the CLI checker
|
|
46
63
|
|
|
47
|
-
Held by this plugin alone: the checker lists the rule and judges nothing. The compiler refuses the same thing
|
|
64
|
+
Held by this plugin alone: the checker lists the rule and judges nothing. The compiler refuses the same thing outside the class once it extends `DomainRefusal` or `ConceptError`, whose constructors are protected.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.83.1",
|
|
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",
|