@venizia/dev-configs 0.5.0-10 → 0.5.0-12

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 (79) hide show
  1. package/README.md +3 -3
  2. package/dist/cli/codemod/async-context.d.ts +22 -0
  3. package/dist/cli/codemod/async-context.js +146 -0
  4. package/dist/cli/codemod/async-context.js.map +1 -0
  5. package/dist/cli/codemod/class-renames.d.ts +63 -0
  6. package/dist/cli/codemod/class-renames.js +208 -17
  7. package/dist/cli/codemod/class-renames.js.map +1 -1
  8. package/dist/cli/codemod/execution-class.d.ts +14 -0
  9. package/dist/cli/codemod/execution-class.js +46 -0
  10. package/dist/cli/codemod/execution-class.js.map +1 -0
  11. package/dist/cli/codemod/execution-scope.d.ts +68 -0
  12. package/dist/cli/codemod/execution-scope.js +727 -0
  13. package/dist/cli/codemod/execution-scope.js.map +1 -0
  14. package/dist/cli/codemod/index.js +25 -0
  15. package/dist/cli/codemod/index.js.map +1 -1
  16. package/dist/cli/codemod/namespace-functions/mapping.d.ts +6 -0
  17. package/dist/cli/codemod/namespace-functions/mapping.js.map +1 -1
  18. package/dist/cli/codemod/namespace-functions/mappings/connectors.d.ts +2 -0
  19. package/dist/cli/codemod/namespace-functions/mappings/connectors.js +19 -1
  20. package/dist/cli/codemod/namespace-functions/mappings/connectors.js.map +1 -1
  21. package/dist/cli/codemod/namespace-functions/mappings/guards.d.ts +4 -0
  22. package/dist/cli/codemod/namespace-functions/mappings/guards.js +15 -0
  23. package/dist/cli/codemod/namespace-functions/mappings/guards.js.map +1 -0
  24. package/dist/cli/codemod/namespace-functions/mappings/helpers.d.ts +3 -2
  25. package/dist/cli/codemod/namespace-functions/mappings/helpers.js +30 -9
  26. package/dist/cli/codemod/namespace-functions/mappings/helpers.js.map +1 -1
  27. package/dist/cli/codemod/namespace-functions/mappings/inversion.d.ts +6 -2
  28. package/dist/cli/codemod/namespace-functions/mappings/inversion.js +42 -3
  29. package/dist/cli/codemod/namespace-functions/mappings/inversion.js.map +1 -1
  30. package/dist/cli/codemod/namespace-functions/mappings/kernel.d.ts +4 -2
  31. package/dist/cli/codemod/namespace-functions/mappings/kernel.js +16 -3
  32. package/dist/cli/codemod/namespace-functions/mappings/kernel.js.map +1 -1
  33. package/dist/cli/codemod/namespace-functions/rewriter.d.ts +7 -0
  34. package/dist/cli/codemod/namespace-functions/rewriter.js +75 -8
  35. package/dist/cli/codemod/namespace-functions/rewriter.js.map +1 -1
  36. package/dist/cli/codemod/public-names.d.ts +25 -0
  37. package/dist/cli/codemod/public-names.js +134 -0
  38. package/dist/cli/codemod/public-names.js.map +1 -0
  39. package/dist/cli/index.js +1 -0
  40. package/dist/cli/index.js.map +1 -1
  41. package/dist/compilers/bun.js +8 -1
  42. package/dist/compilers/bun.js.map +1 -1
  43. package/dist/linters/eslint.js.map +1 -1
  44. package/dist/linters/house/configs.js +8 -4
  45. package/dist/linters/house/configs.js.map +1 -1
  46. package/dist/linters/house/execution-support.d.ts +66 -0
  47. package/dist/linters/house/execution-support.js +161 -0
  48. package/dist/linters/house/execution-support.js.map +1 -0
  49. package/dist/linters/house/framework-api-patterns.js +1 -1
  50. package/dist/linters/house/framework-api-patterns.js.map +1 -1
  51. package/dist/linters/house/index.d.ts +3 -1
  52. package/dist/linters/house/index.js +3 -1
  53. package/dist/linters/house/index.js.map +1 -1
  54. package/dist/linters/house/no-shadow-framework-type.rule.d.ts +1 -1
  55. package/dist/linters/house/no-shadow-framework-type.rule.js +1 -1
  56. package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -1
  57. package/dist/linters/house/plugin.js +6 -2
  58. package/dist/linters/house/plugin.js.map +1 -1
  59. package/dist/linters/house/prefer-execution-sleep.rule.d.ts +31 -0
  60. package/dist/linters/house/{prefer-promise-sleep.rule.js → prefer-execution-sleep.rule.js} +57 -20
  61. package/dist/linters/house/prefer-execution-sleep.rule.js.map +1 -0
  62. package/dist/linters/house/prefer-http-method.rule.d.ts +6 -3
  63. package/dist/linters/house/prefer-http-method.rule.js +116 -9
  64. package/dist/linters/house/prefer-http-method.rule.js.map +1 -1
  65. package/dist/linters/house/restrict-execution-call-sites.rule.d.ts +30 -0
  66. package/dist/linters/house/restrict-execution-call-sites.rule.js +142 -0
  67. package/dist/linters/house/restrict-execution-call-sites.rule.js.map +1 -0
  68. package/dist/linters/house/static-execution-reason.rule.d.ts +27 -0
  69. package/dist/linters/house/static-execution-reason.rule.js +152 -0
  70. package/dist/linters/house/static-execution-reason.rule.js.map +1 -0
  71. package/dist/linters/rules/naming-convention.rule.js +1 -1
  72. package/dist/linters/rules/naming-convention.rule.js.map +1 -1
  73. package/dist/linters/rules/no-restricted-imports.rule.d.ts +4 -2
  74. package/dist/linters/rules/no-restricted-imports.rule.js.map +1 -1
  75. package/dist/linters/rules/no-unused-vars.rule.d.ts +13 -2
  76. package/dist/linters/rules/no-unused-vars.rule.js.map +1 -1
  77. package/package.json +2 -2
  78. package/dist/linters/house/prefer-promise-sleep.rule.d.ts +0 -26
  79. package/dist/linters/house/prefer-promise-sleep.rule.js.map +0 -1
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RestrictExecutionCallSitesRule = void 0;
4
+ const node_path_1 = require("node:path");
5
+ const common_1 = require("./common");
6
+ const execution_support_1 = require("./execution-support");
7
+ /**
8
+ * `@venizia/restrict-execution-call-sites`. A scoped run takes the values its caller names, so an application lists
9
+ * the files that may say who is running: `Execution.run`, `ExecutionFrames.run` and `ExecutionFrames.root` are
10
+ * reported everywhere else. `Execution.sleep` and the other methods are never reported.
11
+ *
12
+ * - `allow`: globs, relative to the working directory, of files that may call `Execution.run` without `isRoot`.
13
+ * - `allowRoot`: globs of files that may also open a root frame: `isRoot`, `ExecutionFrames.run` and `.root`.
14
+ * Options the rule cannot read (a spread, a variable, `run` passed as a value) may set `isRoot`, so they count.
15
+ *
16
+ * A computed name that cannot be read, on either class, counts as one that may open a root.
17
+ * With no list, every call is reported. The presets do not turn the rule on. It follows imports of the framework's
18
+ * packages only: a re-export of the application's own, or `Execution` held in another variable, is not followed.
19
+ */
20
+ class RestrictExecutionCallSitesRule {
21
+ static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/restrict-execution-call-sites`; }
22
+ /** The restricted methods of each class, and whether the method opens a frame of any shape by itself. */
23
+ static { this.METHODS = new Map([
24
+ ['Execution.run', false],
25
+ ['ExecutionFrames.run', true],
26
+ ['ExecutionFrames.root', true],
27
+ ]); }
28
+ static matches(opts) {
29
+ const { context, globs } = opts;
30
+ const absolute = (0, node_path_1.resolve)(context.cwd, context.filename);
31
+ const path = (0, node_path_1.relative)(context.cwd, absolute).split(node_path_1.sep).join('/');
32
+ return (Array.isArray(globs) &&
33
+ globs.some((glob) => typeof glob === 'string' && (0, node_path_1.matchesGlob)(path, glob)));
34
+ }
35
+ /** Whether the `Execution.run` read at `member` opens a root frame, or may. */
36
+ static mayBeRoot(opts) {
37
+ const { context, member } = opts;
38
+ const call = execution_support_1.ExecutionSupport.child({ node: member, key: 'parent' });
39
+ const isCall = call?.type === common_1.AstNodeTypes.CALL_EXPRESSION &&
40
+ execution_support_1.ExecutionSupport.child({ node: call, key: 'callee' }) === member;
41
+ const object = isCall
42
+ ? execution_support_1.ExecutionSupport.unwrap({
43
+ node: execution_support_1.ExecutionSupport.list({ node: call, key: 'arguments' })[0],
44
+ })
45
+ : undefined;
46
+ if (object?.type !== common_1.AstNodeTypes.OBJECT_EXPRESSION) {
47
+ return true;
48
+ }
49
+ // A system run has no `isRoot`.
50
+ const mode = execution_support_1.ExecutionSupport.optionOf({ object, name: 'mode' });
51
+ if (!mode.isUnknown && execution_support_1.ExecutionSupport.isSystemRun({ context, object })) {
52
+ return false;
53
+ }
54
+ const { value, isUnknown } = execution_support_1.ExecutionSupport.optionOf({ object, name: 'isRoot' });
55
+ if (isUnknown || value === undefined) {
56
+ return isUnknown;
57
+ }
58
+ const isFalse = common_1.AstNode.readField({ node: value, key: 'value' }) === false;
59
+ const isUndefined = common_1.AstNode.readField({ node: value, key: 'name' }) === 'undefined';
60
+ return !isFalse && !isUndefined;
61
+ }
62
+ static { this.RULE = {
63
+ meta: {
64
+ type: 'problem',
65
+ schema: [
66
+ {
67
+ type: 'object',
68
+ properties: {
69
+ allow: { type: 'array', items: { type: 'string' } },
70
+ allowRoot: { type: 'array', items: { type: 'string' } },
71
+ },
72
+ additionalProperties: false,
73
+ },
74
+ ],
75
+ messages: {
76
+ restricted: '`{{method}}` says who is running: call it only from a file the lint configuration lists (`allow`).',
77
+ root: '`{{method}}` opens, or may open, a root frame: only a file listed in `allowRoot` may. Write the options as an object, without `isRoot`, or list the file.',
78
+ },
79
+ },
80
+ create: (context) => {
81
+ const options = context.options[0];
82
+ const globsOf = (key) => common_1.AstNode.readField({ node: options, key });
83
+ if (RestrictExecutionCallSitesRule.matches({ context, globs: globsOf('allowRoot') })) {
84
+ return {};
85
+ }
86
+ const isAllowed = RestrictExecutionCallSitesRule.matches({
87
+ context,
88
+ globs: globsOf('allow'),
89
+ });
90
+ const check = (opts) => {
91
+ const { node, owner, name, member } = opts;
92
+ // A name that cannot be read may be any method, the one that opens a root included.
93
+ const isUnread = name === undefined && (owner === 'Execution' || owner === 'ExecutionFrames');
94
+ const method = isUnread ? `${owner}[...]` : `${owner}.${name}`;
95
+ const opensRoot = isUnread || RestrictExecutionCallSitesRule.METHODS.get(method);
96
+ if (opensRoot === undefined) {
97
+ return;
98
+ }
99
+ if (!isAllowed) {
100
+ context.report({ node, messageId: 'restricted', data: { method } });
101
+ return;
102
+ }
103
+ const isRoot = opensRoot ||
104
+ member === undefined ||
105
+ RestrictExecutionCallSitesRule.mayBeRoot({ context, member });
106
+ if (isRoot) {
107
+ context.report({ node, messageId: 'root', data: { method } });
108
+ }
109
+ };
110
+ return {
111
+ [common_1.AstNodeTypes.MEMBER_EXPRESSION]: (node) => {
112
+ const owner = execution_support_1.ExecutionSupport.exportOf({
113
+ context,
114
+ node: execution_support_1.ExecutionSupport.child({ node, key: 'object' }),
115
+ });
116
+ const name = execution_support_1.ExecutionSupport.keyOf({ node, key: 'property' });
117
+ check({ node, owner, name, member: node });
118
+ },
119
+ [common_1.AstNodeTypes.VARIABLE_DECLARATOR]: (node) => {
120
+ const owner = execution_support_1.ExecutionSupport.exportOf({
121
+ context,
122
+ node: execution_support_1.ExecutionSupport.child({ node, key: 'init' }),
123
+ });
124
+ const pattern = execution_support_1.ExecutionSupport.child({ node, key: 'id' });
125
+ for (const property of execution_support_1.ExecutionSupport.list({ node: pattern, key: 'properties' })) {
126
+ const name = execution_support_1.ExecutionSupport.keyOf({ node: property, key: 'key' });
127
+ // A rest element takes the others, and has no key.
128
+ if (property.type === common_1.AstNodeTypes.PROPERTY) {
129
+ check({ node: property, owner, name });
130
+ }
131
+ }
132
+ },
133
+ };
134
+ },
135
+ }; }
136
+ static build(opts = {}) {
137
+ const { severity = 'error', allow = [], allowRoot = [] } = opts;
138
+ return [severity, { allow, allowRoot }];
139
+ }
140
+ }
141
+ exports.RestrictExecutionCallSitesRule = RestrictExecutionCallSitesRule;
142
+ //# sourceMappingURL=restrict-execution-call-sites.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restrict-execution-call-sites.rule.js","sourceRoot":"","sources":["../../../src/linters/house/restrict-execution-call-sites.rule.ts"],"names":[],"mappings":";;;AAAA,yCAAgE;AAGhE,qCAAyE;AACzE,2DAAuD;AAEvD;;;;;;;;;;;;GAYG;AACH,MAAa,8BAA8B;aACzB,SAAI,GAAG,GAAG,+BAAsB,gCAAgC,CAAC;IAEjF,yGAAyG;aACjF,YAAO,GAAiC,IAAI,GAAG,CAAC;QACtE,CAAC,eAAe,EAAE,KAAK,CAAC;QACxB,CAAC,qBAAqB,EAAE,IAAI,CAAC;QAC7B,CAAC,sBAAsB,EAAE,IAAI,CAAC;KAC/B,CAAC,CAAC;IAEK,MAAM,CAAC,OAAO,CAAC,IAAmD;QACxE,MAAM,EAAE,OAAO,EAAE,KA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M,QAAQ,IAAI,oCAAgB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;wBACnF,MAAM,IAAI,GAAG,oCAAgB,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;wBAEpE,mDAAmD;wBACnD,IAAI,QAAQ,CAAC,IAAI,KAAK,qBAAY,CAAC,QAAQ,EAAE,CAAC;4BAC5C,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;wBACzC,CAAC;oBACH,CAAC;gBACH,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CACV,OAA6E,EAAE;QAE/E,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,KAAK,GAAG,EAAE,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC;QAEhE,OAAO,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAC1C,CAAC;;AA9JH,wEA+JC","sourcesContent":["import { matchesGlob, relative, resolve, sep } from 'node:path';\nimport type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { ExecutionSupport } from './execution-support';\n\n/**\n * `@venizia/restrict-execution-call-sites`. A scoped run takes the values its caller names, so an application lists\n * the files that may say who is running: `Execution.run`, `ExecutionFrames.run` and `ExecutionFrames.root` are\n * reported everywhere else. `Execution.sleep` and the other methods are never reported.\n *\n * - `allow`: globs, relative to the working directory, of files that may call `Execution.run` without `isRoot`.\n * - `allowRoot`: globs of files that may also open a root frame: `isRoot`, `ExecutionFrames.run` and `.root`.\n * Options the rule cannot read (a spread, a variable, `run` passed as a value) may set `isRoot`, so they count.\n *\n * A computed name that cannot be read, on either class, counts as one that may open a root.\n * With no list, every call is reported. The presets do not turn the rule on. It follows imports of the framework's\n * packages only: a re-export of the application's own, or `Execution` held in another variable, is not followed.\n */\nexport class RestrictExecutionCallSitesRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/restrict-execution-call-sites`;\n\n /** The restricted methods of each class, and whether the method opens a frame of any shape by itself. */\n private static readonly METHODS: ReadonlyMap<string, boolean> = new Map([\n ['Execution.run', false],\n ['ExecutionFrames.run', true],\n ['ExecutionFrames.root', true],\n ]);\n\n private static matches(opts: { context: Rule.RuleContext; globs: unknown }): boolean {\n const { context, globs } = opts;\n const absolute = resolve(context.cwd, context.filename);\n const path = relative(context.cwd, absolute).split(sep).join('/');\n\n return (\n Array.isArray(globs) &&\n globs.some((glob) => typeof glob === 'string' && matchesGlob(path, glob))\n );\n }\n\n /** Whether the `Execution.run` read at `member` opens a root frame, or may. */\n private static mayBeRoot(opts: { context: Rule.RuleContext; member: Rule.Node }): boolean {\n const { context, member } = opts;\n const call = ExecutionSupport.child({ node: member, key: 'parent' });\n const isCall =\n call?.type === AstNodeTypes.CALL_EXPRESSION &&\n ExecutionSupport.child({ node: call, key: 'callee' }) === member;\n const object = isCall\n ? ExecutionSupport.unwrap({\n node: ExecutionSupport.list({ node: call, key: 'arguments' })[0],\n })\n : undefined;\n\n if (object?.type !== AstNodeTypes.OBJECT_EXPRESSION) {\n return true;\n }\n\n // A system run has no `isRoot`.\n const mode = ExecutionSupport.optionOf({ object, name: 'mode' });\n\n if (!mode.isUnknown && ExecutionSupport.isSystemRun({ context, object })) {\n return false;\n }\n\n const { value, isUnknown } = ExecutionSupport.optionOf({ object, name: 'isRoot' });\n\n if (isUnknown || value === undefined) {\n return isUnknown;\n }\n\n const isFalse = AstNode.readField({ node: value, key: 'value' }) === false;\n const isUndefined = AstNode.readField({ node: value, key: 'name' }) === 'undefined';\n\n return !isFalse && !isUndefined;\n }\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n schema: [\n {\n type: 'object',\n properties: {\n allow: { type: 'array', items: { type: 'string' } },\n allowRoot: { type: 'array', items: { type: 'string' } },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n restricted:\n '`{{method}}` says who is running: call it only from a file the lint configuration lists (`allow`).',\n root: '`{{method}}` opens, or may open, a root frame: only a file listed in `allowRoot` may. Write the options as an object, without `isRoot`, or list the file.',\n },\n },\n create: (context) => {\n const options: unknown = context.options[0];\n const globsOf = (key: string) => AstNode.readField({ node: options, key });\n\n if (RestrictExecutionCallSitesRule.matches({ context, globs: globsOf('allowRoot') })) {\n return {};\n }\n\n const isAllowed = RestrictExecutionCallSitesRule.matches({\n context,\n globs: globsOf('allow'),\n });\n\n const check = (opts: {\n node: Rule.Node;\n owner: string | undefined;\n name: string | undefined;\n member?: Rule.Node;\n }) => {\n const { node, owner, name, member } = opts;\n // A name that cannot be read may be any method, the one that opens a root included.\n const isUnread =\n name === undefined && (owner === 'Execution' || owner === 'ExecutionFrames');\n const method = isUnread ? `${owner}[...]` : `${owner}.${name}`;\n const opensRoot = isUnread || RestrictExecutionCallSitesRule.METHODS.get(method);\n\n if (opensRoot === undefined) {\n return;\n }\n\n if (!isAllowed) {\n context.report({ node, messageId: 'restricted', data: { method } });\n\n return;\n }\n\n const isRoot =\n opensRoot ||\n member === undefined ||\n RestrictExecutionCallSitesRule.mayBeRoot({ context, member });\n\n if (isRoot) {\n context.report({ node, messageId: 'root', data: { method } });\n }\n };\n\n return {\n [AstNodeTypes.MEMBER_EXPRESSION]: (node: Rule.Node) => {\n const owner = ExecutionSupport.exportOf({\n context,\n node: ExecutionSupport.child({ node, key: 'object' }),\n });\n const name = ExecutionSupport.keyOf({ node, key: 'property' });\n\n check({ node, owner, name, member: node });\n },\n [AstNodeTypes.VARIABLE_DECLARATOR]: (node: Rule.Node) => {\n const owner = ExecutionSupport.exportOf({\n context,\n node: ExecutionSupport.child({ node, key: 'init' }),\n });\n const pattern = ExecutionSupport.child({ node, key: 'id' });\n\n for (const property of ExecutionSupport.list({ node: pattern, key: 'properties' })) {\n const name = ExecutionSupport.keyOf({ node: property, key: 'key' });\n\n // A rest element takes the others, and has no key.\n if (property.type === AstNodeTypes.PROPERTY) {\n check({ node: property, owner, name });\n }\n }\n },\n };\n },\n };\n\n static build(\n opts: { severity?: TRuleSeverity; allow?: string[]; allowRoot?: string[] } = {},\n ): Linter.RuleEntry {\n const { severity = 'error', allow = [], allowRoot = [] } = opts;\n\n return [severity, { allow, allowRoot }];\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import type { Linter, Rule } from 'eslint';
2
+ import type { TRuleSeverity } from '../rules/common';
3
+ /**
4
+ * `@venizia/static-execution-reason`. The reason of a system run is logged and names the place, so it is written in
5
+ * the code and is not blank: a string, a template without expressions, a `const` of the file holding one, or a
6
+ * `static readonly` field of a class of the file (`Reasons.REAPER`, `this.REASON` in a static method or field). A constant
7
+ * imported from another file cannot be read here, so it is reported.
8
+ *
9
+ * Only `Execution.run` of the framework's packages is read, with an object literal whose `mode` is
10
+ * `ExecutionModes.SYSTEM` or `'system'`. A missing `reason` is left to the type checker.
11
+ */
12
+ export declare class StaticExecutionReasonRule {
13
+ static readonly NAME = "@venizia/static-execution-reason";
14
+ /** The text of a string literal or of a template without expressions. */
15
+ private static literalOf;
16
+ /** The class `this` stands for at `node`: that of the static method or static field it is written in. */
17
+ private static staticClassOf;
18
+ /** The text of the `static readonly` field `member` reads, from a class of the file. */
19
+ private static fieldOf;
20
+ /** The text of a reason written in the code, or `undefined` when it is built elsewhere. */
21
+ private static reasonOf;
22
+ static readonly RULE: Rule.RuleModule;
23
+ static build(opts?: {
24
+ severity?: TRuleSeverity;
25
+ }): Linter.RuleEntry;
26
+ }
27
+ //# sourceMappingURL=static-execution-reason.rule.d.ts.map
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StaticExecutionReasonRule = void 0;
4
+ const common_1 = require("./common");
5
+ const execution_support_1 = require("./execution-support");
6
+ /**
7
+ * `@venizia/static-execution-reason`. The reason of a system run is logged and names the place, so it is written in
8
+ * the code and is not blank: a string, a template without expressions, a `const` of the file holding one, or a
9
+ * `static readonly` field of a class of the file (`Reasons.REAPER`, `this.REASON` in a static method or field). A constant
10
+ * imported from another file cannot be read here, so it is reported.
11
+ *
12
+ * Only `Execution.run` of the framework's packages is read, with an object literal whose `mode` is
13
+ * `ExecutionModes.SYSTEM` or `'system'`. A missing `reason` is left to the type checker.
14
+ */
15
+ class StaticExecutionReasonRule {
16
+ static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/static-execution-reason`; }
17
+ /** The text of a string literal or of a template without expressions. */
18
+ static literalOf(opts) {
19
+ const node = execution_support_1.ExecutionSupport.unwrap(opts);
20
+ if (node?.type === common_1.AstNodeTypes.LITERAL) {
21
+ const value = common_1.AstNode.readField({ node, key: 'value' });
22
+ return typeof value === 'string' ? value : undefined;
23
+ }
24
+ return execution_support_1.ExecutionSupport.templateTextOf({ node });
25
+ }
26
+ /** The class `this` stands for at `node`: that of the static method or static field it is written in. */
27
+ static staticClassOf(opts) {
28
+ const parent = execution_support_1.ExecutionSupport.child({ node: opts.node, key: 'parent' });
29
+ if (!parent || parent.type === common_1.AstNodeTypes.FUNCTION_DECLARATION) {
30
+ return undefined;
31
+ }
32
+ // An arrow in a static field reads `this` as the class.
33
+ if (parent.type === common_1.AstNodeTypes.PROPERTY_DEFINITION) {
34
+ const body = execution_support_1.ExecutionSupport.child({ node: parent, key: 'parent' });
35
+ return common_1.AstNode.readField({ node: parent, key: 'static' }) === true
36
+ ? execution_support_1.ExecutionSupport.child({ node: body, key: 'parent' })
37
+ : undefined;
38
+ }
39
+ if (parent.type !== common_1.AstNodeTypes.FUNCTION_EXPRESSION) {
40
+ return StaticExecutionReasonRule.staticClassOf({ node: parent });
41
+ }
42
+ const method = execution_support_1.ExecutionSupport.child({ node: parent, key: 'parent' });
43
+ if (method?.type !== common_1.AstNodeTypes.METHOD_DEFINITION ||
44
+ common_1.AstNode.readField({ node: method, key: 'static' }) !== true) {
45
+ return undefined;
46
+ }
47
+ const body = execution_support_1.ExecutionSupport.child({ node: method, key: 'parent' });
48
+ return execution_support_1.ExecutionSupport.child({ node: body, key: 'parent' });
49
+ }
50
+ /** The text of the `static readonly` field `member` reads, from a class of the file. */
51
+ static fieldOf(opts) {
52
+ const { context, member } = opts;
53
+ const object = execution_support_1.ExecutionSupport.child({ node: member, key: 'object' });
54
+ const name = execution_support_1.ExecutionSupport.keyOf({ node: member, key: 'property' });
55
+ let owner;
56
+ if (object?.type === common_1.AstNodeTypes.THIS_EXPRESSION) {
57
+ owner = StaticExecutionReasonRule.staticClassOf({ node: member });
58
+ }
59
+ else if (object?.type === common_1.AstNodeTypes.IDENTIFIER) {
60
+ const definition = execution_support_1.ExecutionSupport.variableOf({ context, node: object })?.defs[0];
61
+ owner = definition?.type === 'ClassName' ? definition.node : undefined;
62
+ }
63
+ const field = execution_support_1.ExecutionSupport.list({
64
+ node: common_1.AstNode.readField({ node: owner, key: 'body' }),
65
+ key: 'body',
66
+ }).find((item) => name !== undefined &&
67
+ common_1.AstNode.getType({ node: item }) === common_1.AstNodeTypes.PROPERTY_DEFINITION &&
68
+ common_1.AstNode.readField({ node: item, key: 'static' }) === true &&
69
+ common_1.AstNode.readField({ node: item, key: 'readonly' }) === true &&
70
+ execution_support_1.ExecutionSupport.keyOf({ node: item, key: 'key' }) === name);
71
+ return StaticExecutionReasonRule.literalOf({
72
+ node: execution_support_1.ExecutionSupport.child({ node: field, key: 'value' }),
73
+ });
74
+ }
75
+ /** The text of a reason written in the code, or `undefined` when it is built elsewhere. */
76
+ static reasonOf(opts) {
77
+ const { context } = opts;
78
+ const node = execution_support_1.ExecutionSupport.unwrap({ node: opts.node });
79
+ if (node?.type === common_1.AstNodeTypes.MEMBER_EXPRESSION) {
80
+ return StaticExecutionReasonRule.fieldOf({ context, member: node });
81
+ }
82
+ if (node?.type !== common_1.AstNodeTypes.IDENTIFIER) {
83
+ return StaticExecutionReasonRule.literalOf({ node });
84
+ }
85
+ const definition = execution_support_1.ExecutionSupport.variableOf({ context, node })?.defs[0];
86
+ const declaration = common_1.AstNode.readField({ node: definition, key: 'parent' });
87
+ if (common_1.AstNode.readField({ node: declaration, key: 'kind' }) !== 'const') {
88
+ return undefined;
89
+ }
90
+ const declarator = common_1.AstNode.readField({ node: definition, key: 'node' });
91
+ const id = execution_support_1.ExecutionSupport.child({ node: declarator, key: 'id' });
92
+ return id?.type === common_1.AstNodeTypes.IDENTIFIER
93
+ ? StaticExecutionReasonRule.literalOf({
94
+ node: execution_support_1.ExecutionSupport.child({ node: declarator, key: 'init' }),
95
+ })
96
+ : undefined;
97
+ }
98
+ static { this.RULE = {
99
+ meta: {
100
+ type: 'problem',
101
+ schema: [],
102
+ messages: {
103
+ notStatic: "Write the reason of a system run in the code, so the log names the place: `reason: 'draft order reaper'`, a `const` of the file, or a `static readonly` field of a class of the file.",
104
+ blank: 'The reason of a system run is blank: name the work it does.',
105
+ },
106
+ },
107
+ create: (context) => ({
108
+ [common_1.AstNodeTypes.CALL_EXPRESSION]: (node) => {
109
+ const callee = execution_support_1.ExecutionSupport.unwrap({
110
+ node: execution_support_1.ExecutionSupport.child({ node, key: 'callee' }),
111
+ });
112
+ if (callee?.type !== common_1.AstNodeTypes.MEMBER_EXPRESSION ||
113
+ execution_support_1.ExecutionSupport.keyOf({ node: callee, key: 'property' }) !== 'run' ||
114
+ execution_support_1.ExecutionSupport.exportOf({
115
+ context,
116
+ node: execution_support_1.ExecutionSupport.child({ node: callee, key: 'object' }),
117
+ }) !== 'Execution') {
118
+ return;
119
+ }
120
+ const object = execution_support_1.ExecutionSupport.unwrap({
121
+ node: execution_support_1.ExecutionSupport.list({ node, key: 'arguments' })[0],
122
+ });
123
+ if (object?.type !== common_1.AstNodeTypes.OBJECT_EXPRESSION ||
124
+ !execution_support_1.ExecutionSupport.isSystemRun({ context, object })) {
125
+ return;
126
+ }
127
+ const { value, isUnknown } = execution_support_1.ExecutionSupport.optionOf({ object, name: 'reason' });
128
+ // What a spread supplies or replaces is not written here.
129
+ if (isUnknown) {
130
+ context.report({ node, messageId: 'notStatic' });
131
+ return;
132
+ }
133
+ if (value === undefined) {
134
+ return;
135
+ }
136
+ const reason = StaticExecutionReasonRule.reasonOf({ context, node: value });
137
+ if (reason === undefined) {
138
+ context.report({ node: value, messageId: 'notStatic' });
139
+ }
140
+ else if (reason.trim() === '') {
141
+ context.report({ node: value, messageId: 'blank' });
142
+ }
143
+ },
144
+ }),
145
+ }; }
146
+ static build(opts = {}) {
147
+ const { severity = 'error' } = opts;
148
+ return [severity];
149
+ }
150
+ }
151
+ exports.StaticExecutionReasonRule = StaticExecutionReasonRule;
152
+ //# sourceMappingURL=static-execution-reason.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-execution-reason.rule.js","sourceRoot":"","sources":["../../../src/linters/house/static-execution-reason.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AACzE,2DAAuD;AAEvD;;;;;;;;GAQG;AACH,MAAa,yBAAyB;aACpB,SAAI,GAAG,GAAG,+BAAsB,0BAA0B,CAAC;IAE3E,yEAAyE;IACjE,MAAM,CAAC,SAAS,CAAC,IAAqC;QAC5D,MAAM,IAAI,GAAG,oCAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAE3C,IAAI,IAAI,EAAE,IAAI,KAAK,qBAAY,CAAC,OAAO,EAAE,CAAC;YACxC,MAAM,KAAK,GAAG,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;YAExD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QACvD,CAAC;QAED,OAAO,oCAAgB,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,yGAAyG;IACjG,MAA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AM,GAAG,yBAAyB,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;gBAE5E,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBACzB,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;gBAC1D,CAAC;qBAAM,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;oBAChC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;gBACtD,CAAC;YACH,CAAC;SACF,CAAC;KACH,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC;QAEpC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;;AAzLH,8DA0LC","sourcesContent":["import type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { ExecutionSupport } from './execution-support';\n\n/**\n * `@venizia/static-execution-reason`. The reason of a system run is logged and names the place, so it is written in\n * the code and is not blank: a string, a template without expressions, a `const` of the file holding one, or a\n * `static readonly` field of a class of the file (`Reasons.REAPER`, `this.REASON` in a static method or field). A constant\n * imported from another file cannot be read here, so it is reported.\n *\n * Only `Execution.run` of the framework's packages is read, with an object literal whose `mode` is\n * `ExecutionModes.SYSTEM` or `'system'`. A missing `reason` is left to the type checker.\n */\nexport class StaticExecutionReasonRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/static-execution-reason`;\n\n /** The text of a string literal or of a template without expressions. */\n private static literalOf(opts: { node: Rule.Node | undefined }): string | undefined {\n const node = ExecutionSupport.unwrap(opts);\n\n if (node?.type === AstNodeTypes.LITERAL) {\n const value = AstNode.readField({ node, key: 'value' });\n\n return typeof value === 'string' ? value : undefined;\n }\n\n return ExecutionSupport.templateTextOf({ node });\n }\n\n /** The class `this` stands for at `node`: that of the static method or static field it is written in. */\n private static staticClassOf(opts: { node: Rule.Node }): Rule.Node | undefined {\n const parent = ExecutionSupport.child({ node: opts.node, key: 'parent' });\n\n if (!parent || parent.type === AstNodeTypes.FUNCTION_DECLARATION) {\n return undefined;\n }\n\n // An arrow in a static field reads `this` as the class.\n if (parent.type === AstNodeTypes.PROPERTY_DEFINITION) {\n const body = ExecutionSupport.child({ node: parent, key: 'parent' });\n\n return AstNode.readField({ node: parent, key: 'static' }) === true\n ? ExecutionSupport.child({ node: body, key: 'parent' })\n : undefined;\n }\n\n if (parent.type !== AstNodeTypes.FUNCTION_EXPRESSION) {\n return StaticExecutionReasonRule.staticClassOf({ node: parent });\n }\n\n const method = ExecutionSupport.child({ node: parent, key: 'parent' });\n\n if (\n method?.type !== AstNodeTypes.METHOD_DEFINITION ||\n AstNode.readField({ node: method, key: 'static' }) !== true\n ) {\n return undefined;\n }\n\n const body = ExecutionSupport.child({ node: method, key: 'parent' });\n\n return ExecutionSupport.child({ node: body, key: 'parent' });\n }\n\n /** The text of the `static readonly` field `member` reads, from a class of the file. */\n private static fieldOf(opts: {\n context: Rule.RuleContext;\n member: Rule.Node;\n }): string | undefined {\n const { context, member } = opts;\n const object = ExecutionSupport.child({ node: member, key: 'object' });\n const name = ExecutionSupport.keyOf({ node: member, key: 'property' });\n let owner: unknown;\n\n if (object?.type === AstNodeTypes.THIS_EXPRESSION) {\n owner = StaticExecutionReasonRule.staticClassOf({ node: member });\n } else if (object?.type === AstNodeTypes.IDENTIFIER) {\n const definition = ExecutionSupport.variableOf({ context, node: object })?.defs[0];\n\n owner = definition?.type === 'ClassName' ? definition.node : undefined;\n }\n\n const field = ExecutionSupport.list({\n node: AstNode.readField({ node: owner, key: 'body' }),\n key: 'body',\n }).find(\n (item) =>\n name !== undefined &&\n AstNode.getType({ node: item }) === AstNodeTypes.PROPERTY_DEFINITION &&\n AstNode.readField({ node: item, key: 'static' }) === true &&\n AstNode.readField({ node: item, key: 'readonly' }) === true &&\n ExecutionSupport.keyOf({ node: item, key: 'key' }) === name,\n );\n\n return StaticExecutionReasonRule.literalOf({\n node: ExecutionSupport.child({ node: field, key: 'value' }),\n });\n }\n\n /** The text of a reason written in the code, or `undefined` when it is built elsewhere. */\n private static reasonOf(opts: {\n context: Rule.RuleContext;\n node: Rule.Node;\n }): string | undefined {\n const { context } = opts;\n const node = ExecutionSupport.unwrap({ node: opts.node });\n\n if (node?.type === AstNodeTypes.MEMBER_EXPRESSION) {\n return StaticExecutionReasonRule.fieldOf({ context, member: node });\n }\n\n if (node?.type !== AstNodeTypes.IDENTIFIER) {\n return StaticExecutionReasonRule.literalOf({ node });\n }\n\n const definition: unknown = ExecutionSupport.variableOf({ context, node })?.defs[0];\n const declaration = AstNode.readField({ node: definition, key: 'parent' });\n\n if (AstNode.readField({ node: declaration, key: 'kind' }) !== 'const') {\n return undefined;\n }\n\n const declarator = AstNode.readField({ node: definition, key: 'node' });\n const id = ExecutionSupport.child({ node: declarator, key: 'id' });\n\n return id?.type === AstNodeTypes.IDENTIFIER\n ? StaticExecutionReasonRule.literalOf({\n node: ExecutionSupport.child({ node: declarator, key: 'init' }),\n })\n : undefined;\n }\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'problem',\n schema: [],\n messages: {\n notStatic:\n \"Write the reason of a system run in the code, so the log names the place: `reason: 'draft order reaper'`, a `const` of the file, or a `static readonly` field of a class of the file.\",\n blank: 'The reason of a system run is blank: name the work it does.',\n },\n },\n create: (context) => ({\n [AstNodeTypes.CALL_EXPRESSION]: (node: Rule.Node) => {\n const callee = ExecutionSupport.unwrap({\n node: ExecutionSupport.child({ node, key: 'callee' }),\n });\n\n if (\n callee?.type !== AstNodeTypes.MEMBER_EXPRESSION ||\n ExecutionSupport.keyOf({ node: callee, key: 'property' }) !== 'run' ||\n ExecutionSupport.exportOf({\n context,\n node: ExecutionSupport.child({ node: callee, key: 'object' }),\n }) !== 'Execution'\n ) {\n return;\n }\n\n const object = ExecutionSupport.unwrap({\n node: ExecutionSupport.list({ node, key: 'arguments' })[0],\n });\n\n if (\n object?.type !== AstNodeTypes.OBJECT_EXPRESSION ||\n !ExecutionSupport.isSystemRun({ context, object })\n ) {\n return;\n }\n\n const { value, isUnknown } = ExecutionSupport.optionOf({ object, name: 'reason' });\n\n // What a spread supplies or replaces is not written here.\n if (isUnknown) {\n context.report({ node, messageId: 'notStatic' });\n\n return;\n }\n\n if (value === undefined) {\n return;\n }\n\n const reason = StaticExecutionReasonRule.reasonOf({ context, node: value });\n\n if (reason === undefined) {\n context.report({ node: value, messageId: 'notStatic' });\n } else if (reason.trim() === '') {\n context.report({ node: value, messageId: 'blank' });\n }\n },\n }),\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): Linter.RuleEntry {\n const { severity = 'error' } = opts;\n\n return [severity];\n }\n}\n"]}
@@ -56,7 +56,7 @@ class NamingConventionRule {
56
56
  {
57
57
  selector: 'typeAlias',
58
58
  filter: {
59
- regex: '^(ValueOf|ValueOptional|ValueOptionalExcept|ValueOrPromise|PGliteCRUDRepository)$',
59
+ regex: '^(ValueOptional|ValueOptionalExcept|PGliteCRUDRepository)$',
60
60
  match: true,
61
61
  },
62
62
  format: null,
@@ -1 +1 @@
1
- {"version":3,"file":"naming-convention.rule.js","sourceRoot":"","sources":["../../../src/linters/rules/naming-convention.rule.ts"],"names":[],"mappings":";;;AAMA;;;GAGG;AACH,MAAa,oBAAoB;aACf,SAAI,GAAG,sCAAsC,CAAC;aAE9C,cAAS,GAA+B;QACtD,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,WAAW,CAAC,EAAE;QAC9C,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC,EAAE;QAC3E,EAAE,QAAQ,EA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,CAAC;IAC1E,CAAC;;AA/FH,oDAgGC","sourcesContent":["import type { Linter } from 'eslint';\nimport type { TRuleSeverity } from './common';\n\n/** One selector of `@typescript-eslint/naming-convention`, as its documentation types it. */\nexport type TNamingSelector = Record<string, unknown> & { selector: string | string[] };\n\n/**\n * `@typescript-eslint/naming-convention`, owned here. oxlint has no port of it, so it runs in ESLint.\n * The selectors are the LoopBack 4 set the base preset carried, kept one for one.\n */\nexport class NamingConventionRule {\n static readonly NAME = '@typescript-eslint/naming-convention';\n\n static readonly SELECTORS: readonly TNamingSelector[] = [\n { selector: 'default', format: ['camelCase'] },\n { selector: 'variable', format: ['camelCase', 'UPPER_CASE', 'PascalCase'] },\n { selector: 'variable', format: null, filter: '^_$' },\n // A `_name` variable names an omitted value (`{ page: _page, ...rest }`); its case is still checked.\n {\n selector: 'variable',\n filter: { regex: '^_.', match: true },\n format: ['camelCase', 'UPPER_CASE', 'PascalCase'],\n leadingUnderscore: 'allow',\n },\n { selector: 'function', format: ['PascalCase'], filter: 'Mixin$' },\n { selector: 'parameter', format: ['camelCase'], leadingUnderscore: 'allow' },\n {\n selector: 'enumMember',\n format: ['camelCase', 'UPPER_CASE', 'PascalCase'],\n leadingUnderscore: 'allow',\n },\n {\n selector: 'property',\n format: ['camelCase', 'UPPER_CASE', 'PascalCase'],\n leadingUnderscore: 'allow',\n },\n { selector: 'method', format: ['camelCase'], leadingUnderscore: 'allow' },\n { selector: 'memberLike', modifiers: ['static'], format: ['camelCase', 'UPPER_CASE'] },\n {\n selector: 'memberLike',\n modifiers: ['private'],\n format: ['camelCase'],\n leadingUnderscore: 'allow',\n },\n {\n selector: 'memberLike',\n modifiers: ['protected'],\n format: ['camelCase'],\n leadingUnderscore: 'allow',\n },\n { selector: 'typeLike', format: ['PascalCase'] },\n // A type alias starts with `T` or ends with `Type`; an interface starts with `I`.\n {\n selector: 'typeAlias',\n format: ['PascalCase'],\n custom: { regex: '^T[A-Z0-9]|Type$', match: true },\n },\n { selector: 'interface', format: ['PascalCase'], prefix: ['I'] },\n // Names that stay as they are: the framework's value helpers, and a type that shares its name with a class value.\n {\n selector: 'typeAlias',\n filter: {\n regex: '^(ValueOf|ValueOptional|ValueOptionalExcept|ValueOrPromise|PGliteCRUDRepository)$',\n match: true,\n },\n format: null,\n },\n // Interfaces that `declare module` or `declare global` adds to: the name belongs to the library, and the rule\n // cannot see where an interface is declared.\n {\n selector: 'interface',\n filter: {\n regex:\n '^(ContextRenderer|ContextVariableMap|ImportMeta|ImportMetaEnv|Matchers|ProcessEnv|Register|Window)$',\n match: true,\n },\n format: null,\n },\n {\n selector: [\n 'objectLiteralProperty',\n 'objectLiteralMethod',\n 'typeProperty',\n 'typeMethod',\n 'classProperty',\n 'classMethod',\n 'enumMember',\n ],\n format: null,\n modifiers: ['requiresQuotes'],\n },\n { selector: 'import', format: ['camelCase', 'PascalCase'] },\n { selector: 'import', format: null, filter: '^_$' },\n ];\n\n /**\n * `extraSelectors` are appended, but position decides nothing: typescript-eslint orders selectors by how specific\n * they are. To let a name through the base type selectors, give a selector a `filter` and `format: null`.\n */\n static build(\n opts: { severity?: TRuleSeverity; extraSelectors?: TNamingSelector[] } = {},\n ): Linter.RuleEntry {\n const { severity = 'error', extraSelectors = [] } = opts;\n\n return [severity, ...NamingConventionRule.SELECTORS, ...extraSelectors];\n }\n}\n"]}
1
+ {"version":3,"file":"naming-convention.rule.js","sourceRoot":"","sources":["../../../src/linters/rules/naming-convention.rule.ts"],"names":[],"mappings":";;;AAMA;;;GAGG;AACH,MAAa,oBAAoB;aACf,SAAI,GAAG,sCAAsC,CAAC;aAE9C,cAAS,GAA+B;QACtD,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,WAAW,CAAC,EAAE;QAC9C,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC,EAAE;QAC3E,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,IAA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gGC","sourcesContent":["import type { Linter } from 'eslint';\nimport type { TRuleSeverity } from './common';\n\n/** One selector of `@typescript-eslint/naming-convention`, as its documentation types it. */\nexport type TNamingSelector = Record<string, unknown> & { selector: string | string[] };\n\n/**\n * `@typescript-eslint/naming-convention`, owned here. oxlint has no port of it, so it runs in ESLint.\n * The selectors are the LoopBack 4 set the base preset carried, kept one for one.\n */\nexport class NamingConventionRule {\n static readonly NAME = '@typescript-eslint/naming-convention';\n\n static readonly SELECTORS: readonly TNamingSelector[] = [\n { selector: 'default', format: ['camelCase'] },\n { selector: 'variable', format: ['camelCase', 'UPPER_CASE', 'PascalCase'] },\n { selector: 'variable', format: null, filter: '^_$' },\n // A `_name` variable names an omitted value (`{ page: _page, ...rest }`); its case is still checked.\n {\n selector: 'variable',\n filter: { regex: '^_.', match: true },\n format: ['camelCase', 'UPPER_CASE', 'PascalCase'],\n leadingUnderscore: 'allow',\n },\n { selector: 'function', format: ['PascalCase'], filter: 'Mixin$' },\n { selector: 'parameter', format: ['camelCase'], leadingUnderscore: 'allow' },\n {\n selector: 'enumMember',\n format: ['camelCase', 'UPPER_CASE', 'PascalCase'],\n leadingUnderscore: 'allow',\n },\n {\n selector: 'property',\n format: ['camelCase', 'UPPER_CASE', 'PascalCase'],\n leadingUnderscore: 'allow',\n },\n { selector: 'method', format: ['camelCase'], leadingUnderscore: 'allow' },\n { selector: 'memberLike', modifiers: ['static'], format: ['camelCase', 'UPPER_CASE'] },\n {\n selector: 'memberLike',\n modifiers: ['private'],\n format: ['camelCase'],\n leadingUnderscore: 'allow',\n },\n {\n selector: 'memberLike',\n modifiers: ['protected'],\n format: ['camelCase'],\n leadingUnderscore: 'allow',\n },\n { selector: 'typeLike', format: ['PascalCase'] },\n // A type alias starts with `T` or ends with `Type`; an interface starts with `I`.\n {\n selector: 'typeAlias',\n format: ['PascalCase'],\n custom: { regex: '^T[A-Z0-9]|Type$', match: true },\n },\n { selector: 'interface', format: ['PascalCase'], prefix: ['I'] },\n // Names that stay as they are: the framework's value helpers, and a type that shares its name with a class value.\n {\n selector: 'typeAlias',\n filter: {\n regex: '^(ValueOptional|ValueOptionalExcept|PGliteCRUDRepository)$',\n match: true,\n },\n format: null,\n },\n // Interfaces that `declare module` or `declare global` adds to: the name belongs to the library, and the rule\n // cannot see where an interface is declared.\n {\n selector: 'interface',\n filter: {\n regex:\n '^(ContextRenderer|ContextVariableMap|ImportMeta|ImportMetaEnv|Matchers|ProcessEnv|Register|Window)$',\n match: true,\n },\n format: null,\n },\n {\n selector: [\n 'objectLiteralProperty',\n 'objectLiteralMethod',\n 'typeProperty',\n 'typeMethod',\n 'classProperty',\n 'classMethod',\n 'enumMember',\n ],\n format: null,\n modifiers: ['requiresQuotes'],\n },\n { selector: 'import', format: ['camelCase', 'PascalCase'] },\n { selector: 'import', format: null, filter: '^_$' },\n ];\n\n /**\n * `extraSelectors` are appended, but position decides nothing: typescript-eslint orders selectors by how specific\n * they are. To let a name through the base type selectors, give a selector a `filter` and `format: null`.\n */\n static build(\n opts: { severity?: TRuleSeverity; extraSelectors?: TNamingSelector[] } = {},\n ): Linter.RuleEntry {\n const { severity = 'error', extraSelectors = [] } = opts;\n\n return [severity, ...NamingConventionRule.SELECTORS, ...extraSelectors];\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { TOxlintRuleEntry, TRuleSeverity } from './common';
1
+ import type { TRuleSeverity } from './common';
2
2
  /** One forbidden import path, with the message the author sees. */
3
3
  export interface IRestrictedImportPath {
4
4
  name: string;
@@ -12,6 +12,8 @@ export declare class NoRestrictedImportsRule {
12
12
  static build(opts?: {
13
13
  severity?: TRuleSeverity;
14
14
  extraPaths?: IRestrictedImportPath[];
15
- }): TOxlintRuleEntry<'no-restricted-imports'>;
15
+ }): [TRuleSeverity, {
16
+ paths: IRestrictedImportPath[];
17
+ }];
16
18
  }
17
19
  //# sourceMappingURL=no-restricted-imports.rule.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"no-restricted-imports.rule.js","sourceRoot":"","sources":["../../../src/linters/rules/no-restricted-imports.rule.ts"],"names":[],"mappings":";;;AASA,iGAAiG;AACjG,MAAa,uBAAuB;aAClB,SAAI,GAAG,uBAAuB,CAAC;aAE/B,UAAK,GAAqC;QACxD;YACE,IAAI,EAAE,QAAQ;YACd,OAAO,EACL,iGAAiG;SACpG;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CACV,OAA2E,EAAE;QAE7E,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,UAAU,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC;QAErD,OAAO,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,uBAAuB,CAAC,KAAK,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;IAClF,CAAC;;AAjBH,0DAkBC","sourcesContent":["import type { TOxlintRuleEntry, TRuleSeverity } from './common';\n\n/** One forbidden import path, with the message the author sees. */\nexport interface IRestrictedImportPath {\n name: string;\n message: string;\n importNames?: string[];\n}\n\n/** `no-restricted-imports`. The base forbids the whole of lodash, which defeats tree-shaking. */\nexport class NoRestrictedImportsRule {\n static readonly NAME = 'no-restricted-imports';\n\n static readonly PATHS: readonly IRestrictedImportPath[] = [\n {\n name: 'lodash',\n message:\n \"Please import 'fn' from 'lodash/fn' instead of * from lodash | Ex: import get from 'lodash/get'\",\n },\n ];\n\n static build(\n opts: { severity?: TRuleSeverity; extraPaths?: IRestrictedImportPath[] } = {},\n ): TOxlintRuleEntry<'no-restricted-imports'> {\n const { severity = 'error', extraPaths = [] } = opts;\n\n return [severity, { paths: [...NoRestrictedImportsRule.PATHS, ...extraPaths] }];\n }\n}\n"]}
1
+ {"version":3,"file":"no-restricted-imports.rule.js","sourceRoot":"","sources":["../../../src/linters/rules/no-restricted-imports.rule.ts"],"names":[],"mappings":";;;AASA,iGAAiG;AACjG,MAAa,uBAAuB;aAClB,SAAI,GAAG,uBAAuB,CAAC;aAE/B,UAAK,GAAqC;QACxD;YACE,IAAI,EAAE,QAAQ;YACd,OAAO,EACL,iGAAiG;SACpG;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CACV,OAA2E,EAAE;QAE7E,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,UAAU,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC;QAErD,OAAO,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,uBAAuB,CAAC,KAAK,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;IAClF,CAAC;;AAjBH,0DAkBC","sourcesContent":["import type { TRuleSeverity } from './common';\n\n/** One forbidden import path, with the message the author sees. */\nexport interface IRestrictedImportPath {\n name: string;\n message: string;\n importNames?: string[];\n}\n\n/** `no-restricted-imports`. The base forbids the whole of lodash, which defeats tree-shaking. */\nexport class NoRestrictedImportsRule {\n static readonly NAME = 'no-restricted-imports';\n\n static readonly PATHS: readonly IRestrictedImportPath[] = [\n {\n name: 'lodash',\n message:\n \"Please import 'fn' from 'lodash/fn' instead of * from lodash | Ex: import get from 'lodash/get'\",\n },\n ];\n\n static build(\n opts: { severity?: TRuleSeverity; extraPaths?: IRestrictedImportPath[] } = {},\n ): [TRuleSeverity, { paths: IRestrictedImportPath[] }] {\n const { severity = 'error', extraPaths = [] } = opts;\n\n return [severity, { paths: [...NoRestrictedImportsRule.PATHS, ...extraPaths] }];\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { type TOxlintRuleEntry, type TRuleSeverity, type TUnusedArgsMode, type TUnusedVarsScope } from './common';
1
+ import { type TRuleSeverity, type TUnusedArgsMode, type TUnusedVarsScope } from './common';
2
2
  /** `no-unused-vars`. Unused arguments pass: an override keeps its signature. A `_name` variable is an omitted value (`{ page: _page, ...rest }`) and passes too. */
3
3
  export declare class NoUnusedVarsRule {
4
4
  static readonly NAME = "no-unused-vars";
@@ -17,6 +17,17 @@ export declare class NoUnusedVarsRule {
17
17
  varsIgnorePattern?: string;
18
18
  caughtErrorsIgnorePattern?: string;
19
19
  destructuredArrayIgnorePattern?: string;
20
- }): TOxlintRuleEntry<'no-unused-vars'>;
20
+ }): [
21
+ TRuleSeverity,
22
+ {
23
+ vars: TUnusedVarsScope;
24
+ args: TUnusedArgsMode;
25
+ ignoreRestSiblings: boolean;
26
+ varsIgnorePattern: string;
27
+ argsIgnorePattern?: string;
28
+ caughtErrorsIgnorePattern?: string;
29
+ destructuredArrayIgnorePattern?: string;
30
+ }
31
+ ];
21
32
  }
22
33
  //# sourceMappingURL=no-unused-vars.rule.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"no-unused-vars.rule.js","sourceRoot":"","sources":["../../../src/linters/rules/no-unused-vars.rule.ts"],"names":[],"mappings":";;;AAAA,qCAOkB;AAElB,oKAAoK;AACpK,MAAa,gBAAgB;aACX,SAAI,GAAG,gBAAgB,CAAC;IAExC,MAAM,CAAC,KAAK,CACV,OAeI,EAAE;QAEN,MAAM,EACJ,QAAQ,GAAG,OAAO,EAClB,IAAI,GAAG,yBAAgB,CAAC,GAAG,EAC3B,IAAI,GAAG,wBAAe,CAAC,IAAI,EAC3B,kBAAkB,GAAG,KAAK,EAC1B,iBAAiB,GAAG,IAAI,EACxB,GAAG,QAAQ,EACZ,GAAG,IAAI,CAAC;QAET,OAAO,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC;IACxF,CAAC;;AA/BH,4CAgCC","sourcesContent":["import {\n UnusedArgsModes,\n UnusedVarsScopes,\n type TOxlintRuleEntry,\n type TRuleSeverity,\n type TUnusedArgsMode,\n type TUnusedVarsScope,\n} from './common';\n\n/** `no-unused-vars`. Unused arguments pass: an override keeps its signature. A `_name` variable is an omitted value (`{ page: _page, ...rest }`) and passes too. */\nexport class NoUnusedVarsRule {\n static readonly NAME = 'no-unused-vars';\n\n static build(\n opts: {\n /** @default 'error' */\n severity?: TRuleSeverity;\n /** @default 'all' */\n vars?: TUnusedVarsScope;\n /** @default 'none' */\n args?: TUnusedArgsMode;\n /** @default false */\n ignoreRestSiblings?: boolean;\n /** Names that may stay unused, e.g. `^_` - a placeholder a signature needs. */\n argsIgnorePattern?: string;\n /** @default '^_' */\n varsIgnorePattern?: string;\n caughtErrorsIgnorePattern?: string;\n destructuredArrayIgnorePattern?: string;\n } = {},\n ): TOxlintRuleEntry<'no-unused-vars'> {\n const {\n severity = 'error',\n vars = UnusedVarsScopes.ALL,\n args = UnusedArgsModes.NONE,\n ignoreRestSiblings = false,\n varsIgnorePattern = '^_',\n ...patterns\n } = opts;\n\n return [severity, { vars, args, ignoreRestSiblings, varsIgnorePattern, ...patterns }];\n }\n}\n"]}
1
+ {"version":3,"file":"no-unused-vars.rule.js","sourceRoot":"","sources":["../../../src/linters/rules/no-unused-vars.rule.ts"],"names":[],"mappings":";;;AAAA,qCAMkB;AAElB,oKAAoK;AACpK,MAAa,gBAAgB;aACX,SAAI,GAAG,gBAAgB,CAAC;IAExC,MAAM,CAAC,KAAK,CACV,OAeI,EAAE;QAaN,MAAM,EACJ,QAAQ,GAAG,OAAO,EAClB,IAAI,GAAG,yBAAgB,CAAC,GAAG,EAC3B,IAAI,GAAG,wBAAe,CAAC,IAAI,EAC3B,kBAAkB,GAAG,KAAK,EAC1B,iBAAiB,GAAG,IAAI,EACxB,GAAG,QAAQ,EACZ,GAAG,IAAI,CAAC;QAET,OAAO,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC;IACxF,CAAC;;AA1CH,4CA2CC","sourcesContent":["import {\n UnusedArgsModes,\n UnusedVarsScopes,\n type TRuleSeverity,\n type TUnusedArgsMode,\n type TUnusedVarsScope,\n} from './common';\n\n/** `no-unused-vars`. Unused arguments pass: an override keeps its signature. A `_name` variable is an omitted value (`{ page: _page, ...rest }`) and passes too. */\nexport class NoUnusedVarsRule {\n static readonly NAME = 'no-unused-vars';\n\n static build(\n opts: {\n /** @default 'error' */\n severity?: TRuleSeverity;\n /** @default 'all' */\n vars?: TUnusedVarsScope;\n /** @default 'none' */\n args?: TUnusedArgsMode;\n /** @default false */\n ignoreRestSiblings?: boolean;\n /** Names that may stay unused, e.g. `^_` - a placeholder a signature needs. */\n argsIgnorePattern?: string;\n /** @default '^_' */\n varsIgnorePattern?: string;\n caughtErrorsIgnorePattern?: string;\n destructuredArrayIgnorePattern?: string;\n } = {},\n ): [\n TRuleSeverity,\n {\n vars: TUnusedVarsScope;\n args: TUnusedArgsMode;\n ignoreRestSiblings: boolean;\n varsIgnorePattern: string;\n argsIgnorePattern?: string;\n caughtErrorsIgnorePattern?: string;\n destructuredArrayIgnorePattern?: string;\n },\n ] {\n const {\n severity = 'error',\n vars = UnusedVarsScopes.ALL,\n args = UnusedArgsModes.NONE,\n ignoreRestSiblings = false,\n varsIgnorePattern = '^_',\n ...patterns\n } = opts;\n\n return [severity, { vars, args, ignoreRestSiblings, varsIgnorePattern, ...patterns }];\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/dev-configs",
3
- "version": "0.5.0-10",
3
+ "version": "0.5.0-12",
4
4
  "description": "Shareable development configurations for TypeScript projects: oxlint presets with per-rule builders, the ESLint naming-convention rule, the legacy ESLint flat config, and TypeScript compiler options with critical decorator support (experimentalDecorators, emitDecoratorMetadata, useDefineForClassFields). Single source of truth for consistent code style, type checking, and build settings across monorepo packages.",
5
5
  "keywords": [
6
6
  "build-tools",
@@ -108,7 +108,7 @@
108
108
  },
109
109
  "dependencies": {
110
110
  "@eslint/js": "^10.0.1",
111
- "@stylistic/eslint-plugin": "^5.10.0",
111
+ "@stylistic/eslint-plugin": "^6.0.1",
112
112
  "typescript-eslint": "^8.74.0"
113
113
  },
114
114
  "devDependencies": {
@@ -1,26 +0,0 @@
1
- import type { Linter, Rule } from 'eslint';
2
- import type { TRuleSeverity } from '../rules/common';
3
- /**
4
- * `@venizia/prefer-promise-sleep`. A sleep written by hand, `new Promise((resolve) => setTimeout(resolve, ms))`, is
5
- * `PromiseUtility.sleep({ ms })` (`@venizia/ignis-helpers/core`). Only that exact shape is reported: a callback that
6
- * does anything else is not a sleep.
7
- *
8
- * The fix replaces the expression and adds the import; `source` is where `PromiseUtility` comes from, `null` turns
9
- * the fix off.
10
- */
11
- export declare class PreferPromiseSleepRule {
12
- static readonly NAME = "@venizia/prefer-promise-sleep";
13
- static readonly DEFAULT_SOURCE = "@venizia/ignis-helpers/core";
14
- /** The `setTimeout(<resolve>, <delay>)` call a sleep callback consists of, or `undefined`. */
15
- private static delayOf;
16
- /** `PromiseUtility.sleep({ ms })`, with the shorthand when the delay is a variable named `ms`. */
17
- private static call;
18
- /** Whether `setTimeout` at `node` resolves to a binding of the file (not the global timer). */
19
- private static isRebound;
20
- static readonly RULE: Rule.RuleModule;
21
- static build(opts?: {
22
- severity?: TRuleSeverity;
23
- source?: string | null;
24
- }): Linter.RuleEntry;
25
- }
26
- //# sourceMappingURL=prefer-promise-sleep.rule.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prefer-promise-sleep.rule.js","sourceRoot":"","sources":["../../../src/linters/house/prefer-promise-sleep.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AACzE,qDAAiD;AAEjD;;;;;;;GAOG;AACH,MAAa,sBAAsB;aACjB,SAAI,GAAG,GAAG,+BAAsB,uBAAuB,CAAC;aAExD,mBAAc,GAAG,6BAA6B,CAAC;IAE/D,8FAA8F;IACtF,MAAM,CAAC,OAAO,CAAC,IAA2B;QAChD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC1B,MAAM,IAAI,GAAG,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEjD,IACE,IAAI,KAAK,qBAAY,CAAC,yBAAyB;YAC/C,IAAI,KAAK,qBAAY,CAAC,mBAAmB,EACzC,CAAC;YAC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C,CAAC;IACpE,CAAC;;AAzLH,wDA0LC","sourcesContent":["import type { Linter, Rule, Scope } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { ImportSupport } from './import-support';\n\n/**\n * `@venizia/prefer-promise-sleep`. A sleep written by hand, `new Promise((resolve) => setTimeout(resolve, ms))`, is\n * `PromiseUtility.sleep({ ms })` (`@venizia/ignis-helpers/core`). Only that exact shape is reported: a callback that\n * does anything else is not a sleep.\n *\n * The fix replaces the expression and adds the import; `source` is where `PromiseUtility` comes from, `null` turns\n * the fix off.\n */\nexport class PreferPromiseSleepRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/prefer-promise-sleep`;\n\n static readonly DEFAULT_SOURCE = '@venizia/ignis-helpers/core';\n\n /** The `setTimeout(<resolve>, <delay>)` call a sleep callback consists of, or `undefined`. */\n private static delayOf(opts: { callback: unknown }): Rule.Node | undefined {\n const { callback } = opts;\n const type = AstNode.getType({ node: callback });\n\n if (\n type !== AstNodeTypes.ARROW_FUNCTION_EXPRESSION &&\n type !== AstNodeTypes.FUNCTION_EXPRESSION\n ) {\n return undefined;\n }\n\n const params: unknown = AstNode.readField({ node: callback, key: 'params' });\n const [param] = Array.isArray(params) ? params : [];\n\n if (\n !Array.isArray(params) ||\n params.length !== 1 ||\n AstNode.getType({ node: param }) !== AstNodeTypes.IDENTIFIER\n ) {\n return undefined;\n }\n\n let body: unknown = AstNode.readField({ node: callback, key: 'body' });\n\n if (AstNode.getType({ node: body }) === AstNodeTypes.BLOCK_STATEMENT) {\n const statements: unknown = AstNode.readField({ node: body, key: 'body' });\n const [only] = Array.isArray(statements) ? statements : [];\n\n if (!Array.isArray(statements) || statements.length !== 1) {\n return undefined;\n }\n\n body =\n AstNode.getType({ node: only }) === AstNodeTypes.EXPRESSION_STATEMENT\n ? AstNode.readField({ node: only, key: 'expression' })\n : undefined;\n }\n\n const callee = AstNode.readField({ node: body, key: 'callee' });\n const args: unknown = AstNode.readField({ node: body, key: 'arguments' });\n\n if (\n AstNode.getType({ node: body }) !== AstNodeTypes.CALL_EXPRESSION ||\n AstNode.readField({ node: callee, key: 'name' }) !== 'setTimeout' ||\n !Array.isArray(args) ||\n args.length !== 2\n ) {\n return undefined;\n }\n\n const [resolver, delay] = args;\n const isResolver =\n AstNode.getType({ node: resolver }) === AstNodeTypes.IDENTIFIER &&\n AstNode.readField({ node: resolver, key: 'name' }) ===\n AstNode.readField({ node: param, key: 'name' });\n\n return isResolver && AstNode.isNode(delay) ? delay : undefined;\n }\n\n /** `PromiseUtility.sleep({ ms })`, with the shorthand when the delay is a variable named `ms`. */\n private static call(opts: { context: Rule.RuleContext; delay: Rule.Node }): string {\n const { context, delay } = opts;\n const utility =\n ImportSupport.importedAs({ context, name: 'PromiseUtility', asValue: true }) ??\n 'PromiseUtility';\n const text = context.sourceCode.getText(delay);\n\n return `${utility}.sleep({ ${text === 'ms' ? 'ms' : `ms: ${text}`} })`;\n }\n\n /** Whether `setTimeout` at `node` resolves to a binding of the file (not the global timer). */\n private static isRebound(opts: { context: Rule.RuleContext; node: Rule.Node }): boolean {\n const { context, node } = opts;\n let scope: Scope.Scope | null = context.sourceCode.getScope(node);\n\n while (scope) {\n const variable = scope.set.get('setTimeout');\n\n if (variable && variable.defs.length > 0) {\n return true;\n }\n\n scope = scope.upper;\n }\n\n return false;\n }\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n fixable: 'code',\n schema: [\n {\n type: 'object',\n properties: { source: { type: ['string', 'null'] } },\n additionalProperties: false,\n },\n ],\n messages: {\n sleep:\n \"Use `await PromiseUtility.sleep({ ms })`, not a hand-written `new Promise(resolve => setTimeout(resolve, ms))`: `import { PromiseUtility } from '{{source}}';`\",\n },\n },\n create: (context) => {\n const options: unknown = context.options[0];\n const configured = AstNode.readField({ node: options, key: 'source' });\n const source =\n configured === null\n ? undefined\n : typeof configured === 'string'\n ? configured\n : PreferPromiseSleepRule.DEFAULT_SOURCE;\n\n return {\n [AstNodeTypes.NEW_EXPRESSION]: (node: Rule.Node) => {\n const callee = AstNode.readField({ node, key: 'callee' });\n const args: unknown = AstNode.readField({ node, key: 'arguments' });\n\n if (\n AstNode.readField({ node: callee, key: 'name' }) !== 'Promise' ||\n !Array.isArray(args) ||\n args.length !== 1\n ) {\n return;\n }\n\n const delay = PreferPromiseSleepRule.delayOf({ callback: args[0] });\n\n if (delay === undefined) {\n return;\n }\n\n // A `setTimeout` the file binds itself (a parameter, a local, an import) is not the timer, and a comma expression is\n // not one delay: neither is a sleep.\n if (\n PreferPromiseSleepRule.isRebound({ context, node }) ||\n AstNode.getType({ node: delay }) === AstNodeTypes.SEQUENCE_EXPRESSION\n ) {\n return;\n }\n\n context.report({\n node,\n messageId: 'sleep',\n data: { source: source ?? PreferPromiseSleepRule.DEFAULT_SOURCE },\n fix: (fixer) => {\n if (\n source === undefined &&\n !ImportSupport.isInScope({ context, name: 'PromiseUtility' })\n ) {\n return null;\n }\n\n const imports = ImportSupport.ensure({\n context,\n fixer,\n name: 'PromiseUtility',\n source: source ?? PreferPromiseSleepRule.DEFAULT_SOURCE,\n isType: false,\n });\n\n return imports\n ? [\n fixer.replaceText(node, PreferPromiseSleepRule.call({ context, delay })),\n ...imports,\n ]\n : null;\n },\n });\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity; source?: string | null } = {}): Linter.RuleEntry {\n const { severity = 'error', source } = opts;\n\n return source === undefined ? [severity] : [severity, { source }];\n }\n}\n"]}