@ddd-ts-kit/eslint-plugin 0.25.1 → 0.26.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.
- package/README.fr.md +2 -2
- package/README.md +1 -1
- package/dist/rules/language-declared-vocabulary.d.ts +4 -1
- package/dist/rules/language-declared-vocabulary.d.ts.map +1 -1
- package/dist/rules/language-declared-vocabulary.js +33 -8
- package/dist/rules/language-declared-vocabulary.js.map +1 -1
- package/dist/support/vocabularies/in-outside-record.d.ts +9 -0
- package/dist/support/vocabularies/in-outside-record.d.ts.map +1 -0
- package/dist/support/vocabularies/in-outside-record.js +14 -0
- package/dist/support/vocabularies/in-outside-record.js.map +1 -0
- package/dist/support/vocabularies/is-outside-place.d.ts +4 -0
- package/dist/support/vocabularies/is-outside-place.d.ts.map +1 -0
- package/dist/support/vocabularies/is-outside-place.js +7 -0
- package/dist/support/vocabularies/is-outside-place.js.map +1 -0
- package/dist/support/vocabularies/other-language-of.d.ts +13 -0
- package/dist/support/vocabularies/other-language-of.d.ts.map +1 -0
- package/dist/support/vocabularies/other-language-of.js +67 -0
- package/dist/support/vocabularies/other-language-of.js.map +1 -0
- package/dist/support/vocabularies/type-root-name.d.ts +8 -0
- package/dist/support/vocabularies/type-root-name.d.ts.map +1 -0
- package/dist/support/vocabularies/type-root-name.js +29 -0
- package/dist/support/vocabularies/type-root-name.js.map +1 -0
- package/dist/support/vocabularies/typed-by-other-language.d.ts +9 -0
- package/dist/support/vocabularies/typed-by-other-language.d.ts.map +1 -0
- package/dist/support/vocabularies/typed-by-other-language.js +89 -0
- package/dist/support/vocabularies/typed-by-other-language.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/rules/language-declared-vocabulary.fr.md +19 -2
- package/docs/rules/language-declared-vocabulary.md +18 -1
- 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:bf4e26b225f91ffd -->
|
|
3
3
|
|
|
4
4
|
# @ddd-ts-kit/eslint-plugin
|
|
5
5
|
|
|
@@ -211,7 +211,7 @@ chaque règle à `error`.
|
|
|
211
211
|
| [`context/published-language-only`](docs/rules/context-published-language-only.fr.md) | `ddd-ts-kit/context-published-language-only` | un autre contexte n'est importé qu'à travers son `published-language/` | `error` | maison |
|
|
212
212
|
| [`context/declared-relationship`](docs/rules/context-declared-relationship.fr.md) | `ddd-ts-kit/context-declared-relationship` | un tel import exige que l'amont soit déclaré dans la config | `error` | maison |
|
|
213
213
|
| [`context/published-language-is-a-contract`](docs/rules/context-published-language-is-a-contract.fr.md) | `ddd-ts-kit/context-published-language-is-a-contract` | `published-language/` n'importe que sa liste d'autorisation et d'autres langages publiés | `error` | maison |
|
|
214
|
-
| [`language/declared-vocabulary`](docs/rules/language-declared-vocabulary.fr.md) | `ddd-ts-kit/language-declared-vocabulary` | une valeur d'un vocabulaire fermé que déclare le projet (un objet `as const` avec le type union de son nom, un ensemble de permissions) est lue à travers lui, jamais réécrite sous forme de chaîne, sous `"stack.literals": "named"` ; tests
|
|
214
|
+
| [`language/declared-vocabulary`](docs/rules/language-declared-vocabulary.fr.md) | `ddd-ts-kit/language-declared-vocabulary` | une valeur d'un vocabulaire fermé que déclare le projet (un objet `as const` avec le type union de son nom, un ensemble de permissions) est lue à travers lui, jamais réécrite sous forme de chaîne, sous `"stack.literals": "named"` ; tests, langages publiés et, hors de `domain/`, un mot typé par un autre langage exclus | `error` | maison |
|
|
215
215
|
| [`naming/business-name`](docs/rules/naming-business-name.fr.md) | `ddd-ts-kit/naming-business-name` | une variable, un paramètre, une propriété, un nom déstructuré ou une variable de boucle de `domain/`, `application/` et du noyau partagé porte le nom de son concept, jamais `target`, `data`, `item` ni un autre mot générique (`words`, `allow`, `businessNames` de la configuration) ; corrigible quand l'initialiseur nomme le concept | `error` | maison |
|
|
216
216
|
| [`purity/no-system-clock`](docs/rules/purity-no-system-clock.fr.md) | `ddd-ts-kit/purity-no-system-clock` | pas de `new Date()`, `Date.now()`, `Date()`, `performance.now()` dans `domain/` et `application/` | `error` | maison |
|
|
217
217
|
| [`purity/no-ambient-randomness`](docs/rules/purity-no-ambient-randomness.fr.md) | `ddd-ts-kit/purity-no-ambient-randomness` | pas de `Math.random`, `crypto.randomUUID` ni de bibliothèque d'identifiants dans `domain/` et `application/` | `error` | maison |
|
package/README.md
CHANGED
|
@@ -207,7 +207,7 @@ is an error whatever the configured limit). `strict` sets every rule to `error`.
|
|
|
207
207
|
| [`context/published-language-only`](docs/rules/context-published-language-only.md) | `ddd-ts-kit/context-published-language-only` | another context is imported only through its `published-language/` | `error` | custom |
|
|
208
208
|
| [`context/declared-relationship`](docs/rules/context-declared-relationship.md) | `ddd-ts-kit/context-declared-relationship` | such an import needs the upstream declared in the config | `error` | custom |
|
|
209
209
|
| [`context/published-language-is-a-contract`](docs/rules/context-published-language-is-a-contract.md) | `ddd-ts-kit/context-published-language-is-a-contract` | `published-language/` imports only its allow-list and other published languages | `error` | custom |
|
|
210
|
-
| [`language/declared-vocabulary`](docs/rules/language-declared-vocabulary.md) | `ddd-ts-kit/language-declared-vocabulary` | a value of a closed vocabulary the project declares (an object `as const` with the union type of its name, a permission set) is read through it, never written again as a string, under `"stack.literals": "named"`; tests
|
|
210
|
+
| [`language/declared-vocabulary`](docs/rules/language-declared-vocabulary.md) | `ddd-ts-kit/language-declared-vocabulary` | a value of a closed vocabulary the project declares (an object `as const` with the union type of its name, a permission set) is read through it, never written again as a string, under `"stack.literals": "named"`; tests, published languages and, outside `domain/`, a word typed by another language excluded | `error` | custom |
|
|
211
211
|
| [`naming/business-name`](docs/rules/naming-business-name.md) | `ddd-ts-kit/naming-business-name` | a variable, parameter, property, destructured or loop binding of `domain/`, `application/` and the shared kernel is named after its concept, never `target`, `data`, `item` or another generic word (`words`, `allow`, `businessNames` of the config); fixable where the initializer names the concept | `error` | custom |
|
|
212
212
|
| [`purity/no-system-clock`](docs/rules/purity-no-system-clock.md) | `ddd-ts-kit/purity-no-system-clock` | no `new Date()`, `Date.now()`, `Date()`, `performance.now()` in `domain/` and `application/` | `error` | custom |
|
|
213
213
|
| [`purity/no-ambient-randomness`](docs/rules/purity-no-ambient-randomness.md) | `ddd-ts-kit/purity-no-ambient-randomness` | no `Math.random`, `crypto.randomUUID`, id library in `domain/` and `application/` | `error` | custom |
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
type MessageId = 'raw' | 'rawBesideOtherLanguage';
|
|
3
|
+
export declare const languageDeclaredVocabulary: TSESLint.RuleModule<MessageId, [], import("../index.js").RuleDocs, TSESLint.RuleListener>;
|
|
4
|
+
export {};
|
|
2
5
|
//# sourceMappingURL=language-declared-vocabulary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language-declared-vocabulary.d.ts","sourceRoot":"","sources":["../../src/rules/language-declared-vocabulary.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"language-declared-vocabulary.d.ts","sourceRoot":"","sources":["../../src/rules/language-declared-vocabulary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAiB,MAAM,0BAA0B,CAAC;AASxF,KAAK,SAAS,GAAG,KAAK,GAAG,wBAAwB,CAAC;AAOlD,eAAO,MAAM,0BAA0B,2FAiDrC,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
2
|
import { defineRule } from '../support/rule/define-rule.js';
|
|
3
|
+
import { inOutsideRecord } from '../support/vocabularies/in-outside-record.js';
|
|
4
|
+
import { otherLanguageOf } from '../support/vocabularies/other-language-of.js';
|
|
3
5
|
import { projectVocabularies } from '../support/vocabularies/project-vocabularies.js';
|
|
6
|
+
import { typedByOtherLanguage } from '../support/vocabularies/typed-by-other-language.js';
|
|
4
7
|
/** The relationship schema of the access model declares its relations: like a published language, it names its values itself. */
|
|
5
8
|
const RELATIONSHIP_SCHEMA = /(?<![\w$.])defineSchema\s*\(/;
|
|
6
9
|
/** The properties of an object that name a column, a table or a schema (`{ name: 'note' }`). */
|
|
@@ -9,24 +12,25 @@ export const languageDeclaredVocabulary = defineRule({
|
|
|
9
12
|
id: 'language/declared-vocabulary',
|
|
10
13
|
type: 'suggestion',
|
|
11
14
|
recommended: 'error',
|
|
12
|
-
description: 'Under "stack.literals": "named", a value of a closed vocabulary the project declares is read through it, never written again as a string literal: in its context, in the platform and the route groups for the platform, everywhere for a permission id.',
|
|
15
|
+
description: 'Under "stack.literals": "named", a value of a closed vocabulary the project declares is read through it, never written again as a string literal: in its context, in the platform and the route groups for the platform, everywhere for a permission id; outside domain/, a word whose type says it belongs to another language is not judged.',
|
|
13
16
|
messages: {
|
|
14
17
|
raw: '"{{value}}" is a value of {{vocabularies}}. Write {{written}}, as a computed key `[..]:` for a key: the value is declared once, the editor completes it and a typo stops the build.',
|
|
18
|
+
rawBesideOtherLanguage: '"{{value}}" is a value of {{vocabularies}}. Write {{written}}, as a computed key `[..]:` for a key, if it is the word of this context: the value is declared once, the editor completes it and a typo stops the build. If it is a word of another language this file reads ({{other}}), say so by its type and the compiler holds its spelling: type the table by it, `Record<TheirType, {{vocabulary}}>` for its keys or `Record<{{vocabulary}}, TheirType>` for its values (an annotation or `satisfies`), or write `\'{{value}}\' satisfies TheirType` in a comparison or a `case`.',
|
|
15
19
|
},
|
|
16
20
|
create({ context, file, sourceCode, report }) {
|
|
17
21
|
if (file.config.stack.literals !== 'named' || !isJudged(file) || RELATIONSHIP_SCHEMA.test(sourceCode.text)) {
|
|
18
22
|
return {};
|
|
19
23
|
}
|
|
20
24
|
const declared = projectVocabularies(file, context.languageOptions.parser);
|
|
25
|
+
let read;
|
|
26
|
+
const otherLanguage = () => (read ??= otherLanguageOf(file, sourceCode.ast));
|
|
21
27
|
const judge = (node, value) => {
|
|
22
28
|
const known = (declared.get(value) ?? []).filter((candidate) => isReadBy(file, candidate));
|
|
23
|
-
if (known.length > 0 &&
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
data: { value, vocabularies, written: known.map(({ written }) => written).join(' or ') },
|
|
29
|
-
});
|
|
29
|
+
if (known.length > 0 &&
|
|
30
|
+
!known.some((at) => at.file === file.path) &&
|
|
31
|
+
!isName(file, node) &&
|
|
32
|
+
!isOtherLanguage(file, node, otherLanguage)) {
|
|
33
|
+
report(reportOf({ node, value, known }, otherLanguage()));
|
|
30
34
|
}
|
|
31
35
|
};
|
|
32
36
|
return {
|
|
@@ -44,6 +48,27 @@ export const languageDeclaredVocabulary = defineRule({
|
|
|
44
48
|
};
|
|
45
49
|
},
|
|
46
50
|
});
|
|
51
|
+
/**
|
|
52
|
+
* A word of another language is not the context's when its type says so (a key or a value of a
|
|
53
|
+
* table typed by it, `satisfies`), and neither is a type of an outside record as it arrives.
|
|
54
|
+
*/
|
|
55
|
+
function isOtherLanguage(file, node, otherLanguage) {
|
|
56
|
+
return typedByOtherLanguage(node, otherLanguage()) || inOutsideRecord(file, node);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The report names the vocabulary; when the file reads another language, it also says how a word
|
|
60
|
+
* of that language is written so that the compiler holds it, instead of the vocabulary of the context.
|
|
61
|
+
*/
|
|
62
|
+
function reportOf({ node, value, known }, other) {
|
|
63
|
+
const vocabularies = known.map(({ vocabulary, file: at }) => `${vocabulary} (${at})`).join(' and of ');
|
|
64
|
+
const written = known.map((at) => at.written).join(' or ');
|
|
65
|
+
if (other.size === 0) {
|
|
66
|
+
return { node, messageId: 'raw', data: { value, vocabularies, written } };
|
|
67
|
+
}
|
|
68
|
+
const read = [...other].map(([name, place]) => `${name} of ${place}`).join(', ');
|
|
69
|
+
const vocabulary = known[0]?.vocabulary ?? '';
|
|
70
|
+
return { node, messageId: 'rawBesideOtherLanguage', data: { value, vocabularies, written, other: read, vocabulary } };
|
|
71
|
+
}
|
|
47
72
|
/** Sources only: a test sends the values a client sends; a published language names the values of its contract itself. */
|
|
48
73
|
function isJudged(file) {
|
|
49
74
|
const published = file.location.area === 'context' && file.location.layer === 'published-language';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language-declared-vocabulary.js","sourceRoot":"","sources":["../../src/rules/language-declared-vocabulary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"language-declared-vocabulary.js","sourceRoot":"","sources":["../../src/rules/language-declared-vocabulary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAgC,MAAM,0BAA0B,CAAC;AAExF,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,iDAAiD,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAC;AAI1F,iIAAiI;AACjI,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;AAC3D,gGAAgG;AAChG,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEjE,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAAY;IAC9D,EAAE,EAAE,8BAA8B;IAClC,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,OAAO;IACpB,WAAW,EACT,gVAAgV;IAClV,QAAQ,EAAE;QACR,GAAG,EAAE,qLAAqL;QAC1L,sBAAsB,EACpB,wjBAAwjB;KAC3jB;IACD,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE;QAC1C,IAAI,IAAI,CAA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CAAC,GAAG,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU;QAC7C,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CACrC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,MAA2B;IAC7C,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU,EAAE,CAAC;QAC9C,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,KAAK,cAAc,CAAC,gBAAgB,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU;QAC1G,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI;QACtB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import type { LintedFile } from '../../project/linted-file.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether a literal is a type of an interface or a type alias of `infrastructure/anti-corruption/`
|
|
5
|
+
* or `infrastructure/external/`, which describe an outside record as it arrives (`readonly state:
|
|
6
|
+
* 'draft' | 'issued'`): words of that record, not of the context.
|
|
7
|
+
*/
|
|
8
|
+
export declare function inOutsideRecord(file: LintedFile, node: TSESTree.Node): boolean;
|
|
9
|
+
//# sourceMappingURL=in-outside-record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-outside-record.d.ts","sourceRoot":"","sources":["../../../src/support/vocabularies/in-outside-record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAI/D;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,GAAG,OAAO,CAS9E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
import { ancestors } from '../ancestors.js';
|
|
3
|
+
import { isOutsidePlace } from './is-outside-place.js';
|
|
4
|
+
/**
|
|
5
|
+
* Whether a literal is a type of an interface or a type alias of `infrastructure/anti-corruption/`
|
|
6
|
+
* or `infrastructure/external/`, which describe an outside record as it arrives (`readonly state:
|
|
7
|
+
* 'draft' | 'issued'`): words of that record, not of the context.
|
|
8
|
+
*/
|
|
9
|
+
export function inOutsideRecord(file, node) {
|
|
10
|
+
return (isOutsidePlace(file.location) &&
|
|
11
|
+
[...ancestors(node)].some((ancestor) => ancestor.type === AST_NODE_TYPES.TSInterfaceDeclaration ||
|
|
12
|
+
ancestor.type === AST_NODE_TYPES.TSTypeAliasDeclaration));
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=in-outside-record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-outside-record.js","sourceRoot":"","sources":["../../../src/support/vocabularies/in-outside-record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AAEzE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAgB,EAAE,IAAmB;IACnE,OAAO,CACL,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC7B,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CACvB,CAAC,QAAQ,EAAE,EAAE,CACX,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,sBAAsB;YACvD,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,sBAAsB,CAC1D,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Location } from '../../project/location.js';
|
|
2
|
+
/** `infrastructure/anti-corruption/` and `infrastructure/external/` of a context: where an outside language is declared as it arrives. */
|
|
3
|
+
export declare function isOutsidePlace(location: Location): boolean;
|
|
4
|
+
//# sourceMappingURL=is-outside-place.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-outside-place.d.ts","sourceRoot":"","sources":["../../../src/support/vocabularies/is-outside-place.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAK1D,0IAA0I;AAC1I,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAE1D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The folders of `infrastructure/` where a context meets a language that is not its own. */
|
|
2
|
+
const OUTSIDE = new Set(['anti-corruption', 'external']);
|
|
3
|
+
/** `infrastructure/anti-corruption/` and `infrastructure/external/` of a context: where an outside language is declared as it arrives. */
|
|
4
|
+
export function isOutsidePlace(location) {
|
|
5
|
+
return location.area === 'context' && location.layer === 'infrastructure' && OUTSIDE.has(location.inside[0] ?? '');
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=is-outside-place.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-outside-place.js","sourceRoot":"","sources":["../../../src/support/vocabularies/is-outside-place.ts"],"names":[],"mappings":"AAEA,6FAA6F;AAC7F,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;AAEzD,0IAA0I;AAC1I,MAAM,UAAU,cAAc,CAAC,QAAkB;IAC/C,OAAO,QAAQ,CAAC,IAAI,KAAK,SAAS,IAAI,QAAQ,CAAC,KAAK,KAAK,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AACrH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import type { LintedFile } from '../../project/linted-file.js';
|
|
3
|
+
/**
|
|
4
|
+
* The names a file reads from another language, with where they come from
|
|
5
|
+
* (`catalog/published-language`, `"legacy-erp"`, `this file`), in source order: a name imported
|
|
6
|
+
* from a published language (its own context's included, the contract being a language of its
|
|
7
|
+
* own), a type imported from a package, a name imported from `infrastructure/anti-corruption/` or
|
|
8
|
+
* `infrastructure/external/` of a context, and in those two folders the interfaces and type
|
|
9
|
+
* aliases the file declares at its top, which describe an outside record as it arrives. The model
|
|
10
|
+
* of a context reads none: `domain/` speaks the language of its context only.
|
|
11
|
+
*/
|
|
12
|
+
export declare function otherLanguageOf(file: LintedFile, program: TSESTree.Program): Map<string, string>;
|
|
13
|
+
//# sourceMappingURL=other-language-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"other-language-of.d.ts","sourceRoot":"","sources":["../../../src/support/vocabularies/other-language-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAK/D;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAwBhG"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
import { resolveImport } from '../../project/resolve-import.js';
|
|
3
|
+
import { inLayer } from '../imports/in-layer.js';
|
|
4
|
+
import { isOutsidePlace } from './is-outside-place.js';
|
|
5
|
+
/**
|
|
6
|
+
* The names a file reads from another language, with where they come from
|
|
7
|
+
* (`catalog/published-language`, `"legacy-erp"`, `this file`), in source order: a name imported
|
|
8
|
+
* from a published language (its own context's included, the contract being a language of its
|
|
9
|
+
* own), a type imported from a package, a name imported from `infrastructure/anti-corruption/` or
|
|
10
|
+
* `infrastructure/external/` of a context, and in those two folders the interfaces and type
|
|
11
|
+
* aliases the file declares at its top, which describe an outside record as it arrives. The model
|
|
12
|
+
* of a context reads none: `domain/` speaks the language of its context only.
|
|
13
|
+
*/
|
|
14
|
+
export function otherLanguageOf(file, program) {
|
|
15
|
+
const names = new Map();
|
|
16
|
+
if (inLayer(file, 'domain') !== undefined) {
|
|
17
|
+
return names;
|
|
18
|
+
}
|
|
19
|
+
for (const statement of program.body) {
|
|
20
|
+
const place = statement.type === AST_NODE_TYPES.ImportDeclaration ? importedPlace(file, statement) : undefined;
|
|
21
|
+
if (place !== undefined) {
|
|
22
|
+
for (const name of place.names) {
|
|
23
|
+
names.set(name, place.where);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (isOutsidePlace(file.location)) {
|
|
28
|
+
for (const name of program.body.flatMap(declaredTypeName)) {
|
|
29
|
+
names.set(name, 'this file');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return names;
|
|
33
|
+
}
|
|
34
|
+
/** Where an import comes from when it is another language, and the names it takes from there. */
|
|
35
|
+
function importedPlace(file, statement) {
|
|
36
|
+
const target = resolveImport(file.config, file.path, statement.source.value);
|
|
37
|
+
const where = otherPlace(target);
|
|
38
|
+
const taken = statement.specifiers.filter((specifier) => target.kind !== 'package' ||
|
|
39
|
+
statement.importKind === 'type' ||
|
|
40
|
+
(specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.importKind === 'type'));
|
|
41
|
+
return where === undefined ? undefined : { where, names: taken.map((specifier) => specifier.local.name) };
|
|
42
|
+
}
|
|
43
|
+
function otherPlace(target) {
|
|
44
|
+
if (target.kind === 'package') {
|
|
45
|
+
return `"${target.name}"`;
|
|
46
|
+
}
|
|
47
|
+
const location = target.kind === 'file' ? target.location : undefined;
|
|
48
|
+
if (location?.area !== 'context') {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
if (location.layer === 'published-language') {
|
|
52
|
+
return `${location.context}/published-language`;
|
|
53
|
+
}
|
|
54
|
+
return isOutsidePlace(location) ? `${location.context}/infrastructure/${location.inside[0] ?? ''}` : undefined;
|
|
55
|
+
}
|
|
56
|
+
/** The name of an interface or a type alias declared at the top of the file, exported or not. */
|
|
57
|
+
function declaredTypeName(statement) {
|
|
58
|
+
const declared = statement.type === AST_NODE_TYPES.ExportNamedDeclaration ||
|
|
59
|
+
statement.type === AST_NODE_TYPES.ExportDefaultDeclaration
|
|
60
|
+
? statement.declaration
|
|
61
|
+
: statement;
|
|
62
|
+
return declared?.type === AST_NODE_TYPES.TSInterfaceDeclaration ||
|
|
63
|
+
declared?.type === AST_NODE_TYPES.TSTypeAliasDeclaration
|
|
64
|
+
? [declared.id.name]
|
|
65
|
+
: [];
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=other-language-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"other-language-of.js","sourceRoot":"","sources":["../../../src/support/vocabularies/other-language-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AAEzE,OAAO,EAAqB,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,IAAgB,EAAE,OAAyB;IACzE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IAExC,IAAI,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,OAAO,C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B,CAAC,CAAC,EAAE,CAAC;AACT,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
/**
|
|
3
|
+
* The name a type written as one reference starts from: `Payload` for `Payload['state']`,
|
|
4
|
+
* `typeof x`, `keyof typeof x`, `ns.Name`, `Name<..>` or `(typeof x)[..]`. Nothing for a union,
|
|
5
|
+
* an intersection, an array, a literal or an object type, which are not one reference.
|
|
6
|
+
*/
|
|
7
|
+
export declare function typeRootName(type: TSESTree.TypeNode): string | undefined;
|
|
8
|
+
//# sourceMappingURL=type-root-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-root-name.d.ts","sourceRoot":"","sources":["../../../src/support/vocabularies/type-root-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzE;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,GAAG,MAAM,GAAG,SAAS,CAexE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
/**
|
|
3
|
+
* The name a type written as one reference starts from: `Payload` for `Payload['state']`,
|
|
4
|
+
* `typeof x`, `keyof typeof x`, `ns.Name`, `Name<..>` or `(typeof x)[..]`. Nothing for a union,
|
|
5
|
+
* an intersection, an array, a literal or an object type, which are not one reference.
|
|
6
|
+
*/
|
|
7
|
+
export function typeRootName(type) {
|
|
8
|
+
switch (type.type) {
|
|
9
|
+
case AST_NODE_TYPES.TSTypeReference:
|
|
10
|
+
return leftmost(type.typeName);
|
|
11
|
+
case AST_NODE_TYPES.TSIndexedAccessType:
|
|
12
|
+
return typeRootName(type.objectType);
|
|
13
|
+
case AST_NODE_TYPES.TSTypeQuery:
|
|
14
|
+
return type.exprName.type === AST_NODE_TYPES.TSImportType ? undefined : leftmost(type.exprName);
|
|
15
|
+
case AST_NODE_TYPES.TSTypeOperator:
|
|
16
|
+
return type.operator === 'keyof' && type.typeAnnotation !== undefined
|
|
17
|
+
? typeRootName(type.typeAnnotation)
|
|
18
|
+
: undefined;
|
|
19
|
+
default:
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function leftmost(name) {
|
|
24
|
+
if (name.type === AST_NODE_TYPES.Identifier) {
|
|
25
|
+
return name.name;
|
|
26
|
+
}
|
|
27
|
+
return name.type === AST_NODE_TYPES.TSQualifiedName ? leftmost(name.left) : undefined;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=type-root-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-root-name.js","sourceRoot":"","sources":["../../../src/support/vocabularies/type-root-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AAEzE;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAuB;IAClD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,cAAc,CAAC,eAAe;YACjC,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjC,KAAK,cAAc,CAAC,mBAAmB;YACrC,OAAO,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACvC,KAAK,cAAc,CAAC,WAAW;YAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClG,KAAK,cAAc,CAAC,cAAc;YAChC,OAAO,IAAI,CAAC,QAAQ,KAAK,OAAO,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS;gBACnE,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC;gBACnC,CAAC,CAAC,SAAS,CAAC;QAChB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,IAAyB;IACzC,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Whether the type of a string literal says it is a word of another language, one of `names`
|
|
4
|
+
* (the names a file reads from another language): the literal is written `'x' satisfies T`, or it
|
|
5
|
+
* is a key of an object typed `Record<T, ..>` or the whole value of an entry of one typed
|
|
6
|
+
* `Record<.., T>`, by the annotation of its declaration or by `satisfies`. `T` is one reference.
|
|
7
|
+
*/
|
|
8
|
+
export declare function typedByOtherLanguage(node: TSESTree.Node, names: ReadonlyMap<string, string>): boolean;
|
|
9
|
+
//# sourceMappingURL=typed-by-other-language.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-by-other-language.d.ts","sourceRoot":"","sources":["../../../src/support/vocabularies/typed-by-other-language.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAKzE;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAKrG"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
import { typeRootName } from './type-root-name.js';
|
|
3
|
+
const WRAPPERS = new Set(['Readonly', 'Partial', 'Required']);
|
|
4
|
+
/**
|
|
5
|
+
* Whether the type of a string literal says it is a word of another language, one of `names`
|
|
6
|
+
* (the names a file reads from another language): the literal is written `'x' satisfies T`, or it
|
|
7
|
+
* is a key of an object typed `Record<T, ..>` or the whole value of an entry of one typed
|
|
8
|
+
* `Record<.., T>`, by the annotation of its declaration or by `satisfies`. `T` is one reference.
|
|
9
|
+
*/
|
|
10
|
+
export function typedByOtherLanguage(node, names) {
|
|
11
|
+
const type = satisfiedBy(node) ?? tableSide(node);
|
|
12
|
+
const root = type === undefined ? undefined : typeRootName(type);
|
|
13
|
+
return root !== undefined && names.has(root);
|
|
14
|
+
}
|
|
15
|
+
/** The type an expression is written to satisfy: `T` in `x satisfies T`. */
|
|
16
|
+
function satisfiedBy(expression) {
|
|
17
|
+
const { parent } = expression;
|
|
18
|
+
return parent?.type === AST_NODE_TYPES.TSSatisfiesExpression && parent.expression === expression
|
|
19
|
+
? parent.typeAnnotation
|
|
20
|
+
: undefined;
|
|
21
|
+
}
|
|
22
|
+
/** The key type of the table a literal is a key of, or its value type when the literal is the value of an entry. */
|
|
23
|
+
function tableSide(node) {
|
|
24
|
+
const entry = entryOf(node);
|
|
25
|
+
const isKey = entry?.key === node && !entry.computed;
|
|
26
|
+
const record = isKey || entry?.value === node ? recordArguments(tableType(entry.parent)) : undefined;
|
|
27
|
+
return isKey ? record?.[0] : record?.[1];
|
|
28
|
+
}
|
|
29
|
+
/** The entry of an object literal a node is written in directly, a method or an accessor left out. */
|
|
30
|
+
function entryOf(node) {
|
|
31
|
+
const { parent } = node;
|
|
32
|
+
return parent?.type === AST_NODE_TYPES.Property &&
|
|
33
|
+
parent.parent.type === AST_NODE_TYPES.ObjectExpression &&
|
|
34
|
+
parent.kind === 'init' &&
|
|
35
|
+
!parent.method
|
|
36
|
+
? parent
|
|
37
|
+
: undefined;
|
|
38
|
+
}
|
|
39
|
+
/** The type of an object: the annotation of what it initializes, or what it satisfies, `as const` or not. */
|
|
40
|
+
function tableType(object) {
|
|
41
|
+
const { parent } = object;
|
|
42
|
+
if (parent?.type === AST_NODE_TYPES.TSAsExpression) {
|
|
43
|
+
return isConstAssertion(parent) ? satisfiedBy(parent) : undefined;
|
|
44
|
+
}
|
|
45
|
+
return satisfiedBy(object) ?? annotated(object)?.typeAnnotation?.typeAnnotation;
|
|
46
|
+
}
|
|
47
|
+
/** What holds the annotation of the declaration an object initializes: a variable, a class field or a parameter with a default. */
|
|
48
|
+
function annotated(object) {
|
|
49
|
+
const { parent } = object;
|
|
50
|
+
switch (parent?.type) {
|
|
51
|
+
case AST_NODE_TYPES.VariableDeclarator:
|
|
52
|
+
return parent.init === object ? parent.id : undefined;
|
|
53
|
+
case AST_NODE_TYPES.PropertyDefinition:
|
|
54
|
+
case AST_NODE_TYPES.AccessorProperty:
|
|
55
|
+
return parent.value === object ? parent : undefined;
|
|
56
|
+
case AST_NODE_TYPES.AssignmentPattern:
|
|
57
|
+
return parent.right === object ? parent.left : undefined;
|
|
58
|
+
default:
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function isConstAssertion(assertion) {
|
|
63
|
+
const { typeAnnotation } = assertion;
|
|
64
|
+
return (typeAnnotation.type === AST_NODE_TYPES.TSTypeReference &&
|
|
65
|
+
typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier &&
|
|
66
|
+
typeAnnotation.typeName.name === 'const');
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The key and the value types of `Record<K, V>`, when `type` is one, alone or wrapped whole in
|
|
70
|
+
* `Readonly`, `Partial` or `Required`: `Readonly<Record<K, V>> & Other` is not one.
|
|
71
|
+
*/
|
|
72
|
+
function recordArguments(type) {
|
|
73
|
+
let current = type;
|
|
74
|
+
while (current !== undefined && WRAPPERS.has(referenceName(current) ?? '')) {
|
|
75
|
+
const [only, ...more] = typeArguments(current);
|
|
76
|
+
current = more.length === 0 ? only : undefined;
|
|
77
|
+
}
|
|
78
|
+
const [key, value, ...more] = current !== undefined && referenceName(current) === 'Record' ? typeArguments(current) : [];
|
|
79
|
+
return key !== undefined && value !== undefined && more.length === 0 ? [key, value] : undefined;
|
|
80
|
+
}
|
|
81
|
+
function referenceName(type) {
|
|
82
|
+
return type.type === AST_NODE_TYPES.TSTypeReference && type.typeName.type === AST_NODE_TYPES.Identifier
|
|
83
|
+
? type.typeName.name
|
|
84
|
+
: undefined;
|
|
85
|
+
}
|
|
86
|
+
function typeArguments(type) {
|
|
87
|
+
return type.type === AST_NODE_TYPES.TSTypeReference ? (type.typeArguments?.params ?? []) : [];
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=typed-by-other-language.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-by-other-language.js","sourceRoot":"","sources":["../../../src/support/vocabularies/typed-by-other-language.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAmB,EAAE,KAAkC;IAC1F,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAEjE,OAAO,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC/C,CAAC;AAED,4EAA4E;AAC5E,SAAS,WAAW,CAAC,UAAyB;IAC5C,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;IAE9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,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QAC3E,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QAE/C,OAAO,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,GACzB,OAAO,KAAK,SAAS,IAAI,aAAa,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAE7F,OAAO,GAAG,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClG,CAAC;AAED,SAAS,aAAa,CAAC,IAAuB;IAC5C,OAAO,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,eAAe,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU;QACrG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI;QACpB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,IAAuB;IAC5C,OAAO,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAChG,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.26.0";
|
|
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.26.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
[English](language-declared-vocabulary.md) · **Français**
|
|
2
|
-
<!-- translation-of: language-declared-vocabulary.md sha256:
|
|
2
|
+
<!-- translation-of: language-declared-vocabulary.md sha256:a297ca03357580ce -->
|
|
3
3
|
|
|
4
4
|
# ddd-ts-kit/language-declared-vocabulary
|
|
5
5
|
|
|
6
6
|
Identifiant d'architecture : `language/declared-vocabulary`. Sévérité par défaut : `error`.
|
|
7
7
|
|
|
8
|
-
S'applique à : chaque source sous la racine des sources d'un projet dont la configuration dit `"stack.literals": "named"`, ce qu'écrit `init` (une configuration qui ne dit rien, comme avant la 0.6, garde la règle silencieuse) ; sont exclus les tests, les langages publiés, le schéma des relations du modèle d'accès
|
|
8
|
+
S'applique à : chaque source sous la racine des sources d'un projet dont la configuration dit `"stack.literals": "named"`, ce qu'écrit `init` (une configuration qui ne dit rien, comme avant la 0.6, garde la règle silencieuse) ; sont exclus les tests, les langages publiés, le schéma des relations du modèle d'accès, le fichier qui déclare une valeur et, hors de `domain/`, un mot typé par un autre langage.
|
|
9
9
|
|
|
10
10
|
## Pourquoi
|
|
11
11
|
|
|
@@ -49,6 +49,22 @@ Un mot signifie une chose dans un contexte, et peut signifier autre chose dans l
|
|
|
49
49
|
|
|
50
50
|
Une clé entre guillemets est une valeur réécrite et elle est signalée : écrivez-la comme une clé calculée, `[AppointmentStatus.NoShow]: 'No show'`, ce qui type aussi l'objet par le vocabulaire. Une clé identifiant et le spécificateur d'un import ou d'un export sont des noms et ne sont pas jugés. Dans la persistance d'un contexte (`infrastructure/persistence/`), le nom d'une colonne, d'une table ou d'un schéma est un mot du stockage et n'est pas jugé : le premier argument d'un appel (`text('note')`, `createTable('invoice')`, `.where('note', ..)`) et la valeur de `name`, `tableName` ou `schema` ; une valeur stockée, l'argument de `.default(..)` ou une valeur comparée dans une requête, l'est. Un test écrit volontairement les valeurs qu'envoie un client, et un langage publié nomme lui-même les valeurs de son contrat : ni l'un ni l'autre n'est jugé. Le message nomme le vocabulaire, le fichier qui le déclare et ce qu'il faut écrire à la place.
|
|
51
51
|
|
|
52
|
+
Un mot d'un autre langage qui épelle une valeur du contexte (catalog publie un `state` valant `'draft' | 'issued'`, et billing déclare son propre `InvoiceStatus`) n'est pas celui du contexte, et n'est pas jugé hors de `domain/` quand son type le dit : une clé d'un objet typé `Record<T, ..>`, une valeur chaîne d'un objet typé `Record<.., T>` (par l'annotation de sa déclaration ou par `satisfies`, `as const` et `Readonly`, `Partial` ou `Required` autour permis), ou un littéral écrit `'issued' satisfies T` dans une comparaison ou un `case`. `T` est une seule référence de type (`ProductListedV1Payload['state']`, `typeof x`, `keyof typeof x`, pas une union) dont le nom est importé d'un langage publié (celui de son propre contexte compris), importé comme type d'un paquet (`import type` ou `import { type X }`), ou importé de ou déclaré dans `infrastructure/anti-corruption/` ou `infrastructure/external/` ; dans ces deux dossiers, les types littéraux d'une interface ou d'un alias de type, qui décrivent un enregistrement extérieur tel qu'il arrive, ne sont pas jugés non plus. Le compilateur vérifie alors l'orthographe : une clé qui n'est pas une valeur de `T` arrête la compilation. Quand le fichier lit un autre langage et qu'un littéral reste signalé, le message dit quels types il y lit et comment typer le littéral par l'un d'eux (message `rawBesideOtherLanguage`). Le premier choix reste en amont : un producteur qui déclare ses valeurs fermées comme un vocabulaire de son langage publié laisse le consommateur les lire par leur clé.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import type { ProductListedV1Payload } from '@/contexts/catalog/published-language/product-listed.v1.payload.js';
|
|
56
|
+
|
|
57
|
+
// Signalé : un mot de catalog comparé sans le dire.
|
|
58
|
+
const listedAsIssued = payload.state === 'issued';
|
|
59
|
+
|
|
60
|
+
// Non signalé : la comparaison et les clés sont typées par le contenu de catalog.
|
|
61
|
+
const issued = payload.state === ('issued' satisfies ProductListedV1Payload['state']);
|
|
62
|
+
const statusOf = {
|
|
63
|
+
'draft': InvoiceStatus.Draft,
|
|
64
|
+
'issued': InvoiceStatus.Issued,
|
|
65
|
+
} as const satisfies Record<ProductListedV1Payload['state'], InvoiceStatus>;
|
|
66
|
+
```
|
|
67
|
+
|
|
52
68
|
## Options
|
|
53
69
|
|
|
54
70
|
Aucune.
|
|
@@ -61,6 +77,7 @@ Aucune.
|
|
|
61
77
|
- La déclaration est analysée : une `const` exportée dont la valeur est un objet `as const` (ou `as const satisfies ..`), chaque entrée étant une clé (un nom ou une chaîne entre guillemets) et un littéral de chaîne, avec l'un ou l'autre type de guillemets, commentaires permis, à côté de `export type X = (typeof X)[keyof typeof X]` écrit de cette façon. Un objet avec un nombre, un étalement, une méthode ou une entrée calculée, ou sans ce type union, ne déclare rien. `generate vocabulary` écrit la forme qui est lue.
|
|
62
78
|
- Une valeur de la plateforme est reconnue par sa valeur dans chaque fichier de la plateforme : avec le `Role` d'un projet rbac, `actor.type === 'system'` dans la plateforme est signalé alors qu'il compare une sorte d'acteur, pas un rôle. Déclarez ce mot dans son propre vocabulaire (`ActorType.System`) et lisez-le là, ou faites taire la ligne avec sa raison.
|
|
63
79
|
- Une valeur que partagent deux vocabulaires est signalée avec les deux : le message nomme chacun et ce qu'il faut écrire pour chacun.
|
|
80
|
+
- Un mot d'un autre langage est reconnu par le type avec lequel il est écrit, que la règle lit sans information de type et auquel elle fait confiance : un type étranger qui vaut `string` ne vérifie rien, et un alias local d'un type étranger hors de `infrastructure/anti-corruption/` et `infrastructure/external/` n'est pas reconnu. Une comparaison ou un `case` n'est pas typé par le discriminant auquel il est comparé : `switch (payload.state) { case 'issued': }` est signalé, `case 'issued' satisfies ProductListedV1Payload['state']:` ne l'est pas.
|
|
64
81
|
|
|
65
82
|
## Avec le checker de la CLI
|
|
66
83
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Architecture id: `language/declared-vocabulary`. Default severity: `error`.
|
|
6
6
|
|
|
7
|
-
Applies to: every source under the source root of a project whose config says `"stack.literals": "named"`, which `init` writes (a config that does not say, as before 0.6, keeps the rule silent); tests, published languages, the relationship schema of the access model
|
|
7
|
+
Applies to: every source under the source root of a project whose config says `"stack.literals": "named"`, which `init` writes (a config that does not say, as before 0.6, keeps the rule silent); tests, published languages, the relationship schema of the access model, the file that declares a value and, outside `domain/`, a word typed by another language excluded.
|
|
8
8
|
|
|
9
9
|
## Why
|
|
10
10
|
|
|
@@ -48,6 +48,22 @@ A word means one thing in one context, and may mean something else next door; th
|
|
|
48
48
|
|
|
49
49
|
A quoted key is a value spelled again and is reported: write it as a computed key, `[AppointmentStatus.NoShow]: 'No show'`, which also types the object by the vocabulary. An identifier key and the specifier of an import or an export are names and are not judged. In the persistence of a context (`infrastructure/persistence/`), the name of a column, a table or a schema is a word of the storage and is not judged: the first argument of a call (`text('note')`, `createTable('invoice')`, `.where('note', ..)`) and the value of `name`, `tableName` or `schema`; a stored value, the argument of `.default(..)` or a value compared in a query, is. A test spells the values a client sends on purpose, and a published language names the values of its contract itself: neither is judged. The message names the vocabulary, the file that declares it and what to write instead.
|
|
50
50
|
|
|
51
|
+
A word of another language that spells a value of the context (catalog publishes a `state` of `'draft' | 'issued'`, and billing declares its own `InvoiceStatus`) is not the context's, and is not judged outside `domain/` when its type says so: a key of an object typed `Record<T, ..>`, a string value of one typed `Record<.., T>` (by the annotation of its declaration or by `satisfies`, `as const` and `Readonly`, `Partial` or `Required` around allowed), or a literal written `'issued' satisfies T` in a comparison or a `case`. `T` is one type reference (`ProductListedV1Payload['state']`, `typeof x`, `keyof typeof x`, not a union) whose name is imported from a published language (its own context's included), imported as a type from a package (`import type` or `import { type X }`), or imported from or declared in `infrastructure/anti-corruption/` or `infrastructure/external/`; in those two folders, the literal types of an interface or a type alias, which describe an outside record as it arrives, are not judged either. The compiler then holds the spelling: a key that is not a value of `T` stops the build. When the file reads another language and a literal is still reported, the message says which types it reads from there and how to type the literal by one (message `rawBesideOtherLanguage`). The first choice remains upstream: a producer that declares its closed values as a vocabulary of its published language lets the consumer read them by their key.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import type { ProductListedV1Payload } from '@/contexts/catalog/published-language/product-listed.v1.payload.js';
|
|
55
|
+
|
|
56
|
+
// Reported: a word of catalog compared without saying so.
|
|
57
|
+
const listedAsIssued = payload.state === 'issued';
|
|
58
|
+
|
|
59
|
+
// Not reported: the comparison and the keys are typed by the payload of catalog.
|
|
60
|
+
const issued = payload.state === ('issued' satisfies ProductListedV1Payload['state']);
|
|
61
|
+
const statusOf = {
|
|
62
|
+
'draft': InvoiceStatus.Draft,
|
|
63
|
+
'issued': InvoiceStatus.Issued,
|
|
64
|
+
} as const satisfies Record<ProductListedV1Payload['state'], InvoiceStatus>;
|
|
65
|
+
```
|
|
66
|
+
|
|
51
67
|
## Options
|
|
52
68
|
|
|
53
69
|
None.
|
|
@@ -60,6 +76,7 @@ None.
|
|
|
60
76
|
- The declaration is parsed: an exported `const` whose value is an object `as const` (or `as const satisfies ..`), each entry a key (a name or a quoted string) and a string literal, in either quote, comments allowed, next to `export type X = (typeof X)[keyof typeof X]` written that way. An object with a number, a spread, a method or a computed entry, or without that union type, declares nothing. `generate vocabulary` writes the form that is read.
|
|
61
77
|
- A value of the platform is matched by its value in every file of the platform: with the `Role` of an rbac project, `actor.type === 'system'` in the platform is reported although it compares a kind of actor, not a role. Declare that word in its own vocabulary (`ActorType.System`) and read it there, or silence the line with its reason.
|
|
62
78
|
- A value two vocabularies share is reported with both: the message names each and what to write for each.
|
|
79
|
+
- A word of another language is recognised by the type it is written with, which the rule reads without type information and trusts: a foreign type that is `string` holds nothing, and a local alias of a foreign type outside `infrastructure/anti-corruption/` and `infrastructure/external/` is not recognised. A comparison or a `case` is not typed by the discriminant it is compared with: `switch (payload.state) { case 'issued': }` is reported, `case 'issued' satisfies ProductListedV1Payload['state']:` is not.
|
|
63
80
|
|
|
64
81
|
## With the CLI checker
|
|
65
82
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "AST-accurate ESLint rules for DDD and Clean Architecture in TypeScript: layer and context isolation, domain purity, clean code ordering.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ddd",
|