@dsivd/prestations-ng 19.2.0-beta.3 → 19.2.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/AI_GUIDELINES.md +152 -0
  2. package/ANGULAR_SIGNALS.md +6 -2
  3. package/CHANGELOG.md +476 -0
  4. package/CONTRIBUTING.md +128 -8
  5. package/ESLINT_PLUGIN.md +262 -30
  6. package/GOOD_PRACTICES.md +983 -388
  7. package/INTRODUCTION_ANGULAR_SIGNALS.md +227 -155
  8. package/README.md +22 -12
  9. package/UPGRADING_V18.md +5 -5
  10. package/UPGRADING_V19.md +636 -19
  11. package/eslint/configs/spec-ts-recommended.mjs +34 -0
  12. package/eslint/configs/template-recommended.mjs +2 -0
  13. package/eslint/configs/template-rules.mjs +14 -2
  14. package/eslint/configs/ts-recommended.mjs +11 -0
  15. package/eslint/configs/ts-rules.mjs +6 -2
  16. package/eslint/form-reads.mjs +63 -0
  17. package/eslint/index.mjs +17 -0
  18. package/eslint/rules/index.mjs +6 -0
  19. package/eslint/rules/no-direct-signal-mutation.mjs +162 -41
  20. package/eslint/rules/no-item-track-in-form-list.mjs +173 -0
  21. package/eslint/rules/no-uninvoked-signal-in-template.mjs +8 -3
  22. package/eslint/rules/require-model-change.mjs +89 -0
  23. package/eslint/rules/require-track-index.mjs +162 -0
  24. package/eslint/signal-names.mjs +127 -21
  25. package/eslint/template-ast.mjs +12 -2
  26. package/fesm2022/dsivd-prestations-ng.mjs +2889 -2061
  27. package/fesm2022/dsivd-prestations-ng.mjs.map +1 -1
  28. package/package.json +1 -2
  29. package/schematics/migration-collection.json +5 -0
  30. package/schematics/ng-add/index.js +2 -4
  31. package/schematics/ng-update/migrations/update-13_2_0/index.js +7 -2
  32. package/schematics/ng-update/migrations/update-19_2_0/index.js +52 -0
  33. package/schematics/utility/add-allowed-common-js-dependencies.js +39 -29
  34. package/schematics/utility/form-signal/class-migration.js +795 -0
  35. package/schematics/utility/form-signal/edits.js +34 -0
  36. package/schematics/utility/form-signal/form-members.js +318 -0
  37. package/schematics/utility/form-signal/form-signal-migration.js +134 -0
  38. package/schematics/utility/form-signal/page-classes.js +139 -0
  39. package/schematics/utility/form-signal/template-migration.js +775 -0
  40. package/schematics/utility/never-connected-migration.js +87 -0
  41. package/schematics/utility/remove-emit-decorator-metadata.js +8 -9
  42. package/schematics/utility/typescript-files.js +95 -0
  43. package/src/eslint/configs/__tests__/configs.test.mjs +61 -2
  44. package/src/eslint/configs/spec-ts-recommended.mjs +34 -0
  45. package/src/eslint/configs/template-recommended.mjs +2 -0
  46. package/src/eslint/configs/template-rules.mjs +14 -2
  47. package/src/eslint/configs/ts-recommended.mjs +11 -0
  48. package/src/eslint/configs/ts-rules.mjs +6 -2
  49. package/src/eslint/form-reads.mjs +63 -0
  50. package/src/eslint/index.mjs +17 -0
  51. package/src/eslint/rules/__tests__/no-direct-signal-mutation.test.mjs +200 -0
  52. package/src/eslint/rules/__tests__/no-item-track-in-form-list.test.mjs +234 -0
  53. package/src/eslint/rules/__tests__/no-uninvoked-signal-in-template.test.mjs +6 -0
  54. package/src/eslint/rules/__tests__/require-model-change.test.mjs +93 -0
  55. package/src/eslint/rules/__tests__/require-track-index.test.mjs +106 -0
  56. package/src/eslint/rules/index.mjs +6 -0
  57. package/src/eslint/rules/no-direct-signal-mutation.mjs +162 -41
  58. package/src/eslint/rules/no-item-track-in-form-list.mjs +173 -0
  59. package/src/eslint/rules/no-uninvoked-signal-in-template.mjs +8 -3
  60. package/src/eslint/rules/require-model-change.mjs +89 -0
  61. package/src/eslint/rules/require-track-index.mjs +162 -0
  62. package/src/eslint/signal-names.mjs +127 -21
  63. package/src/eslint/template-ast.mjs +12 -2
  64. package/types/dsivd-prestations-ng.d.ts +719 -243
  65. package/dsivd-prestations-ng-19.2.0-beta.3.tgz +0 -0
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migrateNeverConnected = migrateNeverConnected;
4
+ const ts = require("typescript");
5
+ const edits_1 = require("./form-signal/edits");
6
+ const typescript_files_1 = require("./typescript-files");
7
+ const STRING_TOKEN = 'neverConnected';
8
+ const TOKEN = 'NEVER_CONNECTED';
9
+ // The calls taking a token as their first argument: inject(), @Inject(), TestBed.inject(), injector.get()
10
+ const INJECTING_CALLS = new Set(['inject', 'Inject', 'get']);
11
+ /**
12
+ * Replaces the string token `'neverConnected'` with `NEVER_CONNECTED` (prestations-ng 19.2.0): `SessionInfo` reads the
13
+ * `InjectionToken` only, a provider of the string is ignored without any error. Rewrites the providers
14
+ * (`{ provide: 'neverConnected', ... }`) and the injections (`inject('neverConnected')`, `@Inject('neverConnected')`),
15
+ * and reports the other uses of the string.
16
+ *
17
+ * @param tree the workspace
18
+ * @returns what was replaced, and what must be checked by hand
19
+ */
20
+ function migrateNeverConnected(tree) {
21
+ const report = { replaced: 0, warnings: [] };
22
+ for (const file of (0, typescript_files_1.typeScriptFiles)(tree.root)) {
23
+ const source = file.source;
24
+ const edits = [];
25
+ const notReplaced = [];
26
+ const visit = (node) => {
27
+ if ((ts.isStringLiteral(node) ||
28
+ ts.isNoSubstitutionTemplateLiteral(node)) &&
29
+ node.text === STRING_TOKEN) {
30
+ // inject<boolean>('neverConnected' as any): the cast goes with the string
31
+ const token = ts.isAsExpression(node.parent)
32
+ ? node.parent
33
+ : node;
34
+ if (isToken(token)) {
35
+ edits.push({
36
+ start: token.getStart(source),
37
+ end: token.getEnd(),
38
+ text: TOKEN,
39
+ });
40
+ }
41
+ else {
42
+ notReplaced.push({
43
+ offset: node.getStart(source),
44
+ text: node.parent.getText(source),
45
+ });
46
+ }
47
+ }
48
+ ts.forEachChild(node, visit);
49
+ };
50
+ visit(source);
51
+ if (edits.length) {
52
+ report.replaced += edits.length;
53
+ edits.push((0, typescript_files_1.prestationsNgImport)(source, TOKEN));
54
+ }
55
+ const migrated = (0, edits_1.applyEdits)(source.text, edits);
56
+ if (migrated !== source.text) {
57
+ tree.overwrite(file.path, migrated);
58
+ }
59
+ // The lines in the migrated file
60
+ for (const { offset, text } of notReplaced) {
61
+ const shift = edits
62
+ .filter((edit) => edit.end <= offset)
63
+ .reduce((total, edit) => total + edit.text.length - (edit.end - edit.start), 0);
64
+ report.warnings.push(`${file.path}:${(0, edits_1.lineOf)(migrated, offset + shift)}: '${STRING_TOKEN}' not replaced: ${text}`);
65
+ }
66
+ }
67
+ return report;
68
+ }
69
+ function isToken(expression) {
70
+ const parent = expression.parent;
71
+ if (ts.isPropertyAssignment(parent)) {
72
+ return (parent.initializer === expression &&
73
+ ts.isIdentifier(parent.name) &&
74
+ parent.name.text === 'provide');
75
+ }
76
+ if (ts.isCallExpression(parent) && parent.arguments[0] === expression) {
77
+ const callee = parent.expression;
78
+ const name = ts.isPropertyAccessExpression(callee)
79
+ ? callee.name.text
80
+ : ts.isIdentifier(callee)
81
+ ? callee.text
82
+ : undefined;
83
+ return !!name && INJECTING_CALLS.has(name);
84
+ }
85
+ return false;
86
+ }
87
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmV2ZXItY29ubmVjdGVkLW1pZ3JhdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL3ByZXN0YXRpb25zLW5nL3NjaGVtYXRpY3MvdXRpbGl0eS9uZXZlci1jb25uZWN0ZWQtbWlncmF0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBMkJBLHNEQXlEQztBQW5GRCxpQ0FBaUM7QUFFakMsK0NBQStEO0FBQy9ELHlEQUEwRTtBQUUxRSxNQUFNLFlBQVksR0FBRyxnQkFBZ0IsQ0FBQztBQUN0QyxNQUFNLEtBQUssR0FBRyxpQkFBaUIsQ0FBQztBQUNoQywwR0FBMEc7QUFDMUcsTUFBTSxlQUFlLEdBQUcsSUFBSSxHQUFHLENBQUMsQ0FBQyxR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UFLLFVBQVUsRUFBRSxDQUFDO1FBQ3BFLE1BQU0sTUFBTSxHQUFHLE1BQU0sQ0FBQyxVQUFVLENBQUM7UUFDakMsTUFBTSxJQUFJLEdBQUcsRUFBRSxDQUFDLDBCQUEwQixDQUFDLE1BQU0sQ0FBQztZQUM5QyxDQUFDLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJO1lBQ2xCLENBQUMsQ0FBQyxFQUFFLENBQUMsWUFBWSxDQUFDLE1BQU0sQ0FBQztnQkFDdkIsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxJQUFJO2dCQUNiLENBQUMsQ0FBQyxTQUFTLENBQUM7UUFDbEIsT0FBTyxDQUFDLENBQUMsSUFBSSxJQUFJLGVBQWUsQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDL0MsQ0FBQztJQUNELE9BQU8sS0FBSyxDQUFDO0FBQ2pCLENBQUMifQ==
@@ -1,18 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeEmitDecoratorMetadata = void 0;
4
+ const json_file_1 = require("@schematics/angular/utility/json-file");
4
5
  const removeEmitDecoratorMetadata = (tree) => {
5
6
  const tsConfig = 'tsconfig.json';
6
- const file = tree.read(tsConfig);
7
- if (!file) {
7
+ if (!tree.exists(tsConfig)) {
8
8
  return;
9
9
  }
10
- const json = JSON.parse(file.toString());
11
- const compilerOptions = json.compilerOptions;
12
- if (Object.hasOwn(compilerOptions, 'emitDecoratorMetadata')) {
13
- delete json.compilerOptions.emitDecoratorMetadata;
14
- tree.overwrite(tsConfig, JSON.stringify(json, null, 2));
15
- }
10
+ // JSONFile keeps the formatting and the comments of the file
11
+ new json_file_1.JSONFile(tree, tsConfig).remove([
12
+ 'compilerOptions',
13
+ 'emitDecoratorMetadata',
14
+ ]);
16
15
  };
17
16
  exports.removeEmitDecoratorMetadata = removeEmitDecoratorMetadata;
18
- //# sourceMappingURL=data:application/json;base64,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VtaXQtZGVjb3JhdG9yLW1ldGFkYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvcHJlc3RhdGlvbnMtbmcvc2NoZW1hdGljcy91dGlsaXR5L3JlbW92ZS1lbWl0LWRlY29yYXRvci1tZXRhZGF0YS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFDQSxxRUFBaUU7QUFFMUQsTUFBTSwyQkFBMkIsR0FBRyxDQUFDLElBQVUsRUFBUSxFQUFFO0lBQzVELE1BQU0sUUFBUSxHQUFHLGVBQWUsQ0FBQztJQUNqQyxJQUFJLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsRUFBRSxDQUFDO1FBQ3pCLE9BQU87SUFDWCxDQUFDO0lBRUQsNkRBQTZEO0lBQzdELElBQUksb0JBQVEsQ0FBQyxJQUFJLEVBQUUsUUFBUSxDQUFDLENBQUMsTUFBTSxDQUFDO1FBQ2hDLGlCQUFpQjtRQUNqQix1QkFBdUI7S0FDMUIsQ0FBQyxDQUFDO0FBQ1AsQ0FBQyxDQUFDO0FBWFcsUUFBQSwyQkFBMkIsK0JBV3RDIn0=
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.typeScriptFiles = typeScriptFiles;
4
+ exports.prestationsNgImport = prestationsNgImport;
5
+ const ts = require("typescript");
6
+ const SKIPPED_DIRECTORIES = new Set([
7
+ 'node_modules',
8
+ 'dist',
9
+ '.angular',
10
+ '.git',
11
+ 'coverage',
12
+ ]);
13
+ /**
14
+ * @param directory a directory of the workspace
15
+ * @returns its TypeScript files and the ones of its subdirectories, parsed, except the declaration files and the
16
+ * generated or installed directories (`node_modules`, `dist`...)
17
+ */
18
+ function typeScriptFiles(directory) {
19
+ const files = [];
20
+ for (const name of directory.subfiles) {
21
+ if (name.endsWith('.ts') && !name.endsWith('.d.ts')) {
22
+ const entry = directory.file(name);
23
+ if (entry) {
24
+ files.push({
25
+ path: entry.path,
26
+ source: ts.createSourceFile(entry.path, entry.content.toString('utf-8'), ts.ScriptTarget.Latest, true),
27
+ });
28
+ }
29
+ }
30
+ }
31
+ for (const name of directory.subdirs) {
32
+ if (!SKIPPED_DIRECTORIES.has(name)) {
33
+ files.push(...typeScriptFiles(directory.dir(name)));
34
+ }
35
+ }
36
+ return files;
37
+ }
38
+ /**
39
+ * Imports a name of `@dsivd/prestations-ng`: adds it to the import of `@dsivd/prestations-ng`, or adds a new import.
40
+ * Nothing when the file already imports it, from `@dsivd/prestations-ng` or one of its paths.
41
+ *
42
+ * @param source the file
43
+ * @param name the name to import
44
+ * @returns the edit of the file
45
+ */
46
+ function prestationsNgImport(source, name) {
47
+ var _a, _b;
48
+ const imports = source.statements.filter(ts.isImportDeclaration);
49
+ const imported = imports.some((declaration) => {
50
+ var _a;
51
+ const namedBindings = (_a = declaration.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings;
52
+ return (ts.isStringLiteral(declaration.moduleSpecifier) &&
53
+ declaration.moduleSpecifier.text.startsWith('@dsivd/prestations-ng') &&
54
+ !!namedBindings &&
55
+ ts.isNamedImports(namedBindings) &&
56
+ namedBindings.elements.some((element) => element.name.text === name));
57
+ });
58
+ if (imported) {
59
+ return { start: 0, end: 0, text: '' };
60
+ }
61
+ for (const declaration of imports) {
62
+ const namedBindings = (_a = declaration.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings;
63
+ if (ts.isStringLiteral(declaration.moduleSpecifier) &&
64
+ declaration.moduleSpecifier.text === '@dsivd/prestations-ng' &&
65
+ namedBindings &&
66
+ ts.isNamedImports(namedBindings) &&
67
+ !((_b = declaration.importClause) === null || _b === void 0 ? void 0 : _b.isTypeOnly)) {
68
+ // At its alphabetical place (simple-import-sort), with the separator of the other names
69
+ const elements = namedBindings.elements;
70
+ const next = elements.find((element) => element.name.text.localeCompare(name, 'en', {
71
+ sensitivity: 'base',
72
+ }) > 0);
73
+ const separator = elements.length > 1
74
+ ? source.text.slice(elements[0].getEnd(), elements[1].getStart(source))
75
+ : ', ';
76
+ if (next) {
77
+ const start = next.getStart(source);
78
+ return { start, end: start, text: `${name}${separator}` };
79
+ }
80
+ const last = elements[elements.length - 1];
81
+ return {
82
+ start: last.getEnd(),
83
+ end: last.getEnd(),
84
+ text: `${separator}${name}`,
85
+ };
86
+ }
87
+ }
88
+ const end = imports.length ? imports[imports.length - 1].getEnd() : 0;
89
+ return {
90
+ start: end,
91
+ end,
92
+ text: `${end ? '\n' : ''}import { ${name} } from '@dsivd/prestations-ng';${end ? '' : '\n'}`,
93
+ };
94
+ }
95
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXNjcmlwdC1maWxlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL3ByZXN0YXRpb25zLW5nL3NjaGVtYXRpY3MvdXRpbGl0eS90eXBlc2NyaXB0LWZpbGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBbUJBLDBDQXdCQztBQVVELGtEQTJEQztBQS9HRCxpQ0FBaUM7QUFLakMsTUFBTSxtQkFBbUIsR0FBRyxJQUFJLEdBQUcsQ0FBQztJQUNoQyxjQUFjO0lBQ2QsTUFBTTtJQUNOLFVBQVU7SUFDVixNQUFNO0lBQ04sVUFBVTtDQUNiLENBQUMsQ0FBQztBQUVIOzs7O0dBSUc7QUFDSCxTQUFnQixlQUFlLENBQUMsU0FBbUI7SUFDL0MsTUFBTSxLQUFLLEdBQWtCLEVBQUUsQ0FBQztJQUNoQyxLQUFLLE1BQU0sSUFBSSxJQUFJLFNBQVMsQ0FBQyxRQUFRLEVBQUUsQ0FBQztRQUNwQyxJQUFJLElBQUksQ0FBQyxRQUFRLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsUUFBUSx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QUFNLEVBQUU7Z0JBQ2xCLElBQUksRUFBRSxHQUFHLFNBQVMsR0FBRyxJQUFJLEVBQUU7YUFDOUIsQ0FBQztRQUNOLENBQUM7SUFDTCxDQUFDO0lBQ0QsTUFBTSxHQUFHLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxNQUFNLEdBQUcsQ0FBQyxDQUFDLENBQUMsTUFBTSxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN0RSxPQUFPO1FBQ0gsS0FBSyxFQUFFLEdBQUc7UUFDVixHQUFHO1FBQ0gsSUFBSSxFQUFFLEdBQUcsR0FBRyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLEVBQUUsWUFBWSxJQUFJLG1DQUFtQyxHQUFHLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsSUFBSSxFQUFFO0tBQy9GLENBQUM7QUFDTixDQUFDIn0=
@@ -1,3 +1,4 @@
1
+ import vitest from '@vitest/eslint-plugin';
1
2
  import { builtinRules } from 'eslint/use-at-your-own-risk';
2
3
  import { describe, expect, it } from 'vitest';
3
4
 
@@ -6,6 +7,10 @@ import prestationsNg, { configs, plugin, rules } from '../../index.mjs';
6
7
  const PLUGIN_KEY = '@dsivd/prestations-ng';
7
8
 
8
9
  const configNames = Object.keys(configs);
10
+ // The configs of this library's plugin (the preset of the Vitest specs only configures @vitest/eslint-plugin)
11
+ const pluginConfigNames = configNames.filter(
12
+ (name) => name !== 'specTsRecommended',
13
+ );
9
14
 
10
15
  // Configs that only register this library's rules, and the presets built on top of them.
11
16
  const RULE_LAYERS = ['tsRules', 'templateRules'];
@@ -52,6 +57,7 @@ describe('eslint configs', () => {
52
57
  'templateRecommended',
53
58
  'tsRules',
54
59
  'templateRules',
60
+ 'specTsRecommended',
55
61
  ]);
56
62
  });
57
63
 
@@ -88,7 +94,7 @@ describe('eslint configs', () => {
88
94
 
89
95
  // Two entries declaring the same plugin key from different copies is a hard ESLint
90
96
  // failure, so the preset must register ours exactly once.
91
- it.each(configNames)('%s should register the plugin once', (name) => {
97
+ it.each(pluginConfigNames)('%s should register the plugin once', (name) => {
92
98
  const declarations = configs[name]
93
99
  .map((entry) => entry.plugins?.[PLUGIN_KEY])
94
100
  .filter(Boolean);
@@ -101,7 +107,9 @@ describe('eslint configs', () => {
101
107
  });
102
108
 
103
109
  it('should enable every rule in at least one config', () => {
104
- const enabled = new Set(configNames.flatMap((n) => ownIdsOf(configs[n])));
110
+ const enabled = new Set(
111
+ pluginConfigNames.flatMap((n) => ownIdsOf(configs[n])),
112
+ );
105
113
 
106
114
  for (const ruleName of Object.keys(rules)) {
107
115
  expect(enabled).toContain(`${PLUGIN_KEY}/${ruleName}`);
@@ -118,6 +126,57 @@ describe('eslint configs', () => {
118
126
  );
119
127
  });
120
128
 
129
+ describe('tsRecommended', () => {
130
+ // The last entry setting a rule wins, as in ESLint
131
+ const rules = Object.assign(
132
+ {},
133
+ ...configs.tsRecommended.map((entry) => entry.rules ?? {}),
134
+ );
135
+
136
+ it('should report a constructor only calling super() with the rule of typescript-eslint', () => {
137
+ expect(rules['@typescript-eslint/no-useless-constructor']).toBe(
138
+ 'error',
139
+ );
140
+ expect(rules['no-useless-constructor']).toBe('off');
141
+ });
142
+ });
143
+
144
+ describe('specTsRecommended', () => {
145
+ const rulesOf = (config) =>
146
+ Object.assign({}, ...config.map((entry) => entry.rules ?? {}));
147
+
148
+ it('should build on the recommended config of @vitest/eslint-plugin', () => {
149
+ expect(configs.specTsRecommended[0]).toBe(vitest.configs.recommended);
150
+ expect(pluginsOf(configs.specTsRecommended)).toEqual({ vitest });
151
+ });
152
+
153
+ it('should count the assertions of the helpers and of the HttpTestingController', () => {
154
+ const [, options] = rulesOf(configs.specTsRecommended)[
155
+ 'vitest/expect-expect'
156
+ ];
157
+
158
+ expect(options.assertFunctionNames).toEqual(
159
+ expect.arrayContaining([
160
+ 'expect',
161
+ 'expect*',
162
+ '*.expectOne',
163
+ '*.verify',
164
+ ]),
165
+ );
166
+ });
167
+
168
+ // An expect which may not run lets a test pass without asserting anything
169
+ it('should keep vitest/no-conditional-expect enabled', () => {
170
+ expect(
171
+ isOff(
172
+ rulesOf(configs.specTsRecommended)[
173
+ 'vitest/no-conditional-expect'
174
+ ],
175
+ ),
176
+ ).toBe(false);
177
+ });
178
+ });
179
+
121
180
  describe('eslint plugin', () => {
122
181
  it('should be named after the npm package', () => {
123
182
  expect(plugin.meta.name).toBe(PLUGIN_KEY);
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The house preset of the Vitest specs: the recommended rules of `@vitest/eslint-plugin`, with the
3
+ * assertions also made by the helpers of the specs and by the `HttpTestingController`.
4
+ *
5
+ * Meant for the `extends` of a `**\/*.spec.ts` block (the Cypress `*.spec.cy.ts` files are not
6
+ * Vitest specs).
7
+ *
8
+ * @param {import('@vitest/eslint-plugin').default} vitest the `@vitest/eslint-plugin` module
9
+ * @returns {import('typescript-eslint').ConfigArray}
10
+ */
11
+ const specTsRecommended = (vitest) => [
12
+ vitest.configs.recommended,
13
+ {
14
+ name: 'prestations-ng/spec-ts-recommended',
15
+ rules: {
16
+ 'vitest/expect-expect': [
17
+ 'error',
18
+ {
19
+ assertFunctionNames: [
20
+ 'expect',
21
+ 'expect*',
22
+ 'assert*',
23
+ 'test*',
24
+ '*.expectOne',
25
+ '*.expectNone',
26
+ '*.verify',
27
+ ],
28
+ },
29
+ ],
30
+ },
31
+ },
32
+ ];
33
+
34
+ export default specTsRecommended;
@@ -8,6 +8,8 @@ import templateRules from './template-rules.mjs';
8
8
  *
9
9
  * Meant for the `extends` of a `**\/*.html` block. It brings its own parser and plugins,
10
10
  * so do not spread `angular.configs.templateRecommended` alongside it.
11
+ *
12
+ * @returns {import('typescript-eslint').ConfigArray}
11
13
  */
12
14
  const templateRecommended = (plugin) => [
13
15
  ...angular.configs.templateRecommended,
@@ -1,7 +1,11 @@
1
1
  import templateBase from './template-base.mjs';
2
2
 
3
- // Only the rules written by this library. `templateRecommended` includes it, alongside
4
- // the house style; use this layer directly to opt out of the latter.
3
+ /**
4
+ * Only the rules written by this library. `templateRecommended` includes it, alongside
5
+ * the house style; use this layer directly to opt out of the latter.
6
+ *
7
+ * @returns {import('typescript-eslint').ConfigArray}
8
+ */
5
9
  const templateRules = (plugin) => [
6
10
  templateBase(plugin),
7
11
  {
@@ -11,6 +15,14 @@ const templateRules = (plugin) => [
11
15
  // template visitor, and each fires on its own kind of file.
12
16
  '@dsivd/prestations-ng/no-direct-signal-mutation': 'error',
13
17
  '@dsivd/prestations-ng/no-uninvoked-signal-in-template': 'error',
18
+ // The form of the pages is a signal: a one-way [model] without
19
+ // (modelChange) loses the input, and a row tracked by its item
20
+ // loses the focus at every input
21
+ '@dsivd/prestations-ng/require-model-change': 'error',
22
+ '@dsivd/prestations-ng/no-item-track-in-form-list': 'error',
23
+ // The rows naming their fields with their index keep these names
24
+ // only when tracked by $index
25
+ '@dsivd/prestations-ng/require-track-index': 'error',
14
26
  },
15
27
  },
16
28
  ];
@@ -14,6 +14,8 @@ import tsRules from './ts-rules.mjs';
14
14
  * Meant for the `extends` of a `**\/*.ts` block. It brings its own parser and plugins,
15
15
  * so do not spread `angular.configs.tsRecommended` alongside it — declaring the same
16
16
  * plugin twice from two different copies makes ESLint fail outright.
17
+ *
18
+ * @returns {import('typescript-eslint').ConfigArray}
17
19
  */
18
20
  const tsRecommended = (plugin) => [
19
21
  eslint.configs.recommended,
@@ -71,6 +73,10 @@ const tsRecommended = (plugin) => [
71
73
  ],
72
74
  '@typescript-eslint/member-ordering': 'error',
73
75
  '@typescript-eslint/no-base-to-string': 'warn',
76
+ // a template literal only takes strings, numbers, booleans, null,
77
+ // undefined, any and RegExp: also reports a signal not called
78
+ // (`${this.reference}`), which no-uncalled-signals skips there
79
+ '@typescript-eslint/restrict-template-expressions': 'error',
74
80
  // stylistic enables no-inferrable-types with default options (ignoreParameters: false);
75
81
  // override here to allow typed parameters explicitly
76
82
  '@typescript-eslint/no-inferrable-types': [
@@ -86,6 +92,11 @@ const tsRecommended = (plugin) => [
86
92
  // off here — @typescript-eslint/no-shadow handles it correctly for TS
87
93
  'no-shadow': 'off',
88
94
  '@typescript-eslint/no-shadow': ['error', { hoist: 'all' }],
95
+ // a constructor only passing its parameters to super(), e.g. the
96
+ // `constructor() { super(); }` left once the services are injected with
97
+ // inject(); off here — the core rule ignores the parameter properties
98
+ 'no-useless-constructor': 'off',
99
+ '@typescript-eslint/no-useless-constructor': 'error',
89
100
  '@typescript-eslint/no-unused-vars': [
90
101
  'error',
91
102
  {
@@ -1,7 +1,11 @@
1
1
  import tsBase from './ts-base.mjs';
2
2
 
3
- // Only the rules written by this library. `tsRecommended` includes it, alongside the
4
- // house style; use this layer directly to opt out of the latter.
3
+ /**
4
+ * Only the rules written by this library. `tsRecommended` includes it, alongside the
5
+ * house style; use this layer directly to opt out of the latter.
6
+ *
7
+ * @returns {import('typescript-eslint').ConfigArray}
8
+ */
5
9
  const tsRules = (plugin) => [
6
10
  tsBase(plugin),
7
11
  {
@@ -0,0 +1,63 @@
1
+ import { isComponentReceiver } from "./template-ast.mjs";
2
+
3
+ /**
4
+ * Where a template expression reads its value from: the form of the page (a signal since
5
+ * 19.2.0), through the names bound by `@if (form(); as form)`, `@let form = this.form()` and
6
+ * `@for (child of form.children)`.
7
+ */
8
+
9
+ const MEMBER_READS = new Set([
10
+ "PropertyRead",
11
+ "SafePropertyRead",
12
+ "KeyedRead",
13
+ "SafeKeyedRead",
14
+ ]);
15
+
16
+ export const astOf = (expression) =>
17
+ expression?.type === "ASTWithSource" ? expression.ast : expression;
18
+
19
+ /**
20
+ * The root of an expression: a member of the component (`{ member }`), or the item of an
21
+ * enclosing `@for` (`{ forBlock }`). A name bound by `@if … as` is followed to its expression,
22
+ * evaluated outside its block (in `@if (form(); as form)`, `form()` is the member).
23
+ * `undefined` for anything else (a literal, a call with arguments...).
24
+ */
25
+ export function resolveRoot(expression, node) {
26
+ let base = expression;
27
+ while (MEMBER_READS.has(base?.type) && MEMBER_READS.has(base.receiver?.type)) {
28
+ base = base.receiver;
29
+ }
30
+ if (base?.type === "Call" || base?.type === "SafeCall") {
31
+ base = base.receiver;
32
+ }
33
+ const receiver = base?.receiver;
34
+ if (receiver?.type === "Call" || receiver?.type === "SafeCall") {
35
+ return resolveRoot(receiver, node);
36
+ }
37
+ if (!MEMBER_READS.has(base?.type) || !isComponentReceiver(receiver)) {
38
+ return undefined;
39
+ }
40
+ for (let current = node; current; current = current.parent) {
41
+ if (current.type === "ForLoopBlock" && current.item?.name === base.name) {
42
+ return { forBlock: current };
43
+ }
44
+ if (
45
+ current.type === "IfBlockBranch" &&
46
+ current.expressionAlias?.name === base.name
47
+ ) {
48
+ return resolveRoot(astOf(current.expression), current.parent);
49
+ }
50
+ }
51
+ return { member: base.name };
52
+ }
53
+
54
+ /**
55
+ * Whether an expression reads the form of the page, directly or through a template name.
56
+ */
57
+ export function readsForm(expression, node) {
58
+ const root = resolveRoot(expression, node);
59
+ if (root?.forBlock) {
60
+ return readsForm(astOf(root.forBlock.expression), root.forBlock.parent);
61
+ }
62
+ return root?.member === "form";
63
+ }
@@ -1,9 +1,17 @@
1
+ import specTsRecommended from './configs/spec-ts-recommended.mjs';
1
2
  import templateRecommended from './configs/template-recommended.mjs';
2
3
  import templateRules from './configs/template-rules.mjs';
3
4
  import tsRecommended from './configs/ts-recommended.mjs';
4
5
  import tsRules from './configs/ts-rules.mjs';
5
6
  import rules from './rules/index.mjs';
6
7
 
8
+ // Only needed by the projects linting Vitest specs: the other configs can be used without it.
9
+ const vitest = await import('@vitest/eslint-plugin').then(
10
+ (module) => module.default,
11
+ () => null,
12
+ );
13
+ const specTsRecommendedConfig = vitest ? specTsRecommended(vitest) : null;
14
+
7
15
  const plugin = {
8
16
  meta: { name: '@dsivd/prestations-ng' },
9
17
  rules,
@@ -16,6 +24,15 @@ const configs = {
16
24
  // Only this library's own rules, for a project that supplies its own style.
17
25
  tsRules: tsRules(plugin),
18
26
  templateRules: templateRules(plugin),
27
+ // The preset of the Vitest specs (needs @vitest/eslint-plugin)
28
+ get specTsRecommended() {
29
+ if (!specTsRecommendedConfig) {
30
+ throw new Error(
31
+ 'prestationsNg.configs.specTsRecommended needs @vitest/eslint-plugin: npm install --save-dev @vitest/eslint-plugin@1',
32
+ );
33
+ }
34
+ return specTsRecommendedConfig;
35
+ },
19
36
  };
20
37
 
21
38
  export { configs, plugin, rules };