@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
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PreferPromiseSleepRule = void 0;
3
+ exports.PreferExecutionSleepRule = void 0;
4
4
  const common_1 = require("./common");
5
5
  const import_support_1 = require("./import-support");
6
6
  /**
7
- * `@venizia/prefer-promise-sleep`. A sleep written by hand, `new Promise((resolve) => setTimeout(resolve, ms))`, is
8
- * `PromiseUtility.sleep({ ms })` (`@venizia/ignis-helpers/core`). Only that exact shape is reported: a callback that
7
+ * `@venizia/prefer-execution-sleep`. A sleep written by hand, `new Promise((resolve) => setTimeout(resolve, ms))`, is
8
+ * `Execution.sleep({ ms })` (`@venizia/ignis-helpers/core`). Only that exact shape is reported: a callback that
9
9
  * does anything else is not a sleep.
10
10
  *
11
- * The fix replaces the expression and adds the import; `source` is where `PromiseUtility` comes from, `null` turns
11
+ * The fix replaces the expression and adds the import; `source` is where `Execution` comes from, `null` turns
12
12
  * the fix off.
13
13
  */
14
- class PreferPromiseSleepRule {
15
- static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/prefer-promise-sleep`; }
14
+ class PreferExecutionSleepRule {
15
+ static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/prefer-execution-sleep`; }
16
16
  static { this.DEFAULT_SOURCE = '@venizia/ignis-helpers/core'; }
17
17
  /** The `setTimeout(<resolve>, <delay>)` call a sleep callback consists of, or `undefined`. */
18
18
  static delayOf(opts) {
@@ -55,14 +55,45 @@ class PreferPromiseSleepRule {
55
55
  common_1.AstNode.readField({ node: param, key: 'name' });
56
56
  return isResolver && common_1.AstNode.isNode(delay) ? delay : undefined;
57
57
  }
58
- /** `PromiseUtility.sleep({ ms })`, with the shorthand when the delay is a variable named `ms`. */
58
+ /** `Execution.sleep({ ms })`, with the shorthand when the delay is a variable named `ms`. */
59
59
  static call(opts) {
60
60
  const { context, delay } = opts;
61
- const utility = import_support_1.ImportSupport.importedAs({ context, name: 'PromiseUtility', asValue: true }) ??
62
- 'PromiseUtility';
61
+ const utility = import_support_1.ImportSupport.importedAs({ context, name: 'Execution', asValue: true }) ?? 'Execution';
63
62
  const text = context.sourceCode.getText(delay);
64
63
  return `${utility}.sleep({ ${text === 'ms' ? 'ms' : `ms: ${text}`} })`;
65
64
  }
65
+ /**
66
+ * Whether the file binds `Execution` to something else: an import from a module other than the helpers or the
67
+ * configured `source`. The fix would call that one.
68
+ */
69
+ static isForeign(opts) {
70
+ const { context, source } = opts;
71
+ return context.sourceCode.ast.body.some((statement) => {
72
+ const specifiers = common_1.AstNode.readField({ node: statement, key: 'specifiers' });
73
+ const from = common_1.AstNode.readField({
74
+ node: common_1.AstNode.readField({ node: statement, key: 'source' }),
75
+ key: 'value',
76
+ });
77
+ if (!Array.isArray(specifiers) ||
78
+ typeof from !== 'string' ||
79
+ from === source ||
80
+ from === '@venizia/ignis-helpers' ||
81
+ from.startsWith('@venizia/ignis-helpers/')) {
82
+ return false;
83
+ }
84
+ return specifiers.some((specifier) => {
85
+ const imported = common_1.AstNode.readField({
86
+ node: common_1.AstNode.readField({ node: specifier, key: 'imported' }),
87
+ key: 'name',
88
+ });
89
+ const local = common_1.AstNode.readField({
90
+ node: common_1.AstNode.readField({ node: specifier, key: 'local' }),
91
+ key: 'name',
92
+ });
93
+ return local === 'Execution' || imported === 'Execution';
94
+ });
95
+ });
96
+ }
66
97
  /** Whether `setTimeout` at `node` resolves to a binding of the file (not the global timer). */
67
98
  static isRebound(opts) {
68
99
  const { context, node } = opts;
@@ -88,7 +119,7 @@ class PreferPromiseSleepRule {
88
119
  },
89
120
  ],
90
121
  messages: {
91
- sleep: "Use `await PromiseUtility.sleep({ ms })`, not a hand-written `new Promise(resolve => setTimeout(resolve, ms))`: `import { PromiseUtility } from '{{source}}';`",
122
+ sleep: "Use `await Execution.sleep({ ms })`, not a hand-written `new Promise(resolve => setTimeout(resolve, ms))`: `import { Execution } from '{{source}}';`",
92
123
  },
93
124
  },
94
125
  create: (context) => {
@@ -98,7 +129,7 @@ class PreferPromiseSleepRule {
98
129
  ? undefined
99
130
  : typeof configured === 'string'
100
131
  ? configured
101
- : PreferPromiseSleepRule.DEFAULT_SOURCE;
132
+ : PreferExecutionSleepRule.DEFAULT_SOURCE;
102
133
  return {
103
134
  [common_1.AstNodeTypes.NEW_EXPRESSION]: (node) => {
104
135
  const callee = common_1.AstNode.readField({ node, key: 'callee' });
@@ -108,35 +139,41 @@ class PreferPromiseSleepRule {
108
139
  args.length !== 1) {
109
140
  return;
110
141
  }
111
- const delay = PreferPromiseSleepRule.delayOf({ callback: args[0] });
142
+ const delay = PreferExecutionSleepRule.delayOf({ callback: args[0] });
112
143
  if (delay === undefined) {
113
144
  return;
114
145
  }
115
146
  // A `setTimeout` the file binds itself (a parameter, a local, an import) is not the timer, and a comma expression is
116
147
  // not one delay: neither is a sleep.
117
- if (PreferPromiseSleepRule.isRebound({ context, node }) ||
148
+ if (PreferExecutionSleepRule.isRebound({ context, node }) ||
118
149
  common_1.AstNode.getType({ node: delay }) === common_1.AstNodeTypes.SEQUENCE_EXPRESSION) {
119
150
  return;
120
151
  }
121
152
  context.report({
122
153
  node,
123
154
  messageId: 'sleep',
124
- data: { source: source ?? PreferPromiseSleepRule.DEFAULT_SOURCE },
155
+ data: { source: source ?? PreferExecutionSleepRule.DEFAULT_SOURCE },
125
156
  fix: (fixer) => {
157
+ if (PreferExecutionSleepRule.isForeign({
158
+ context,
159
+ source: source ?? PreferExecutionSleepRule.DEFAULT_SOURCE,
160
+ })) {
161
+ return null;
162
+ }
126
163
  if (source === undefined &&
127
- !import_support_1.ImportSupport.isInScope({ context, name: 'PromiseUtility' })) {
164
+ !import_support_1.ImportSupport.isInScope({ context, name: 'Execution' })) {
128
165
  return null;
129
166
  }
130
167
  const imports = import_support_1.ImportSupport.ensure({
131
168
  context,
132
169
  fixer,
133
- name: 'PromiseUtility',
134
- source: source ?? PreferPromiseSleepRule.DEFAULT_SOURCE,
170
+ name: 'Execution',
171
+ source: source ?? PreferExecutionSleepRule.DEFAULT_SOURCE,
135
172
  isType: false,
136
173
  });
137
174
  return imports
138
175
  ? [
139
- fixer.replaceText(node, PreferPromiseSleepRule.call({ context, delay })),
176
+ fixer.replaceText(node, PreferExecutionSleepRule.call({ context, delay })),
140
177
  ...imports,
141
178
  ]
142
179
  : null;
@@ -151,5 +188,5 @@ class PreferPromiseSleepRule {
151
188
  return source === undefined ? [severity] : [severity, { source }];
152
189
  }
153
190
  }
154
- exports.PreferPromiseSleepRule = PreferPromiseSleepRule;
155
- //# sourceMappingURL=prefer-promise-sleep.rule.js.map
191
+ exports.PreferExecutionSleepRule = PreferExecutionSleepRule;
192
+ //# sourceMappingURL=prefer-execution-sleep.rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer-execution-sleep.rule.js","sourceRoot":"","sources":["../../../src/linters/house/prefer-execution-sleep.rule.ts"],"names":[],"mappings":";;;AAEA,qC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G,8BAAa,CAAC,MAAM,CAAC;gCACnC,OAAO;gCACP,KAAK;gCACL,IAAI,EAAE,WAAW;gCACjB,MAAM,EAAE,MAAM,IAAI,wBAAwB,CAAC,cAAc;gCACzD,MAAM,EAAE,KAAK;6BACd,CAAC,CAAC;4BAEH,OAAO,OAAO;gCACZ,CAAC,CAAC;oCACE,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,wBAAwB,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;oCAC1E,GAAG,OAAO;iCACX;gCACH,CAAC,CAAC,IAAI,CAAC;wBACX,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAA6D,EAAE;QAC1E,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAE5C,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACpE,CAAC;;AAxOH,4DAyOC","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-execution-sleep`. A sleep written by hand, `new Promise((resolve) => setTimeout(resolve, ms))`, is\n * `Execution.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 `Execution` comes from, `null` turns\n * the fix off.\n */\nexport class PreferExecutionSleepRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/prefer-execution-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 /** `Execution.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: 'Execution', asValue: true }) ?? 'Execution';\n const text = context.sourceCode.getText(delay);\n\n return `${utility}.sleep({ ${text === 'ms' ? 'ms' : `ms: ${text}`} })`;\n }\n\n /**\n * Whether the file binds `Execution` to something else: an import from a module other than the helpers or the\n * configured `source`. The fix would call that one.\n */\n private static isForeign(opts: { context: Rule.RuleContext; source: string }): boolean {\n const { context, source } = opts;\n\n return context.sourceCode.ast.body.some((statement) => {\n const specifiers: unknown = AstNode.readField({ node: statement, key: 'specifiers' });\n const from = AstNode.readField({\n node: AstNode.readField({ node: statement, key: 'source' }),\n key: 'value',\n });\n\n if (\n !Array.isArray(specifiers) ||\n typeof from !== 'string' ||\n from === source ||\n from === '@venizia/ignis-helpers' ||\n from.startsWith('@venizia/ignis-helpers/')\n ) {\n return false;\n }\n\n return specifiers.some((specifier) => {\n const imported = AstNode.readField({\n node: AstNode.readField({ node: specifier, key: 'imported' }),\n key: 'name',\n });\n const local = AstNode.readField({\n node: AstNode.readField({ node: specifier, key: 'local' }),\n key: 'name',\n });\n\n return local === 'Execution' || imported === 'Execution';\n });\n });\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 Execution.sleep({ ms })`, not a hand-written `new Promise(resolve => setTimeout(resolve, ms))`: `import { Execution } 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 : PreferExecutionSleepRule.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 = PreferExecutionSleepRule.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 PreferExecutionSleepRule.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 ?? PreferExecutionSleepRule.DEFAULT_SOURCE },\n fix: (fixer) => {\n if (\n PreferExecutionSleepRule.isForeign({\n context,\n source: source ?? PreferExecutionSleepRule.DEFAULT_SOURCE,\n })\n ) {\n return null;\n }\n\n if (\n source === undefined &&\n !ImportSupport.isInScope({ context, name: 'Execution' })\n ) {\n return null;\n }\n\n const imports = ImportSupport.ensure({\n context,\n fixer,\n name: 'Execution',\n source: source ?? PreferExecutionSleepRule.DEFAULT_SOURCE,\n isType: false,\n });\n\n return imports\n ? [\n fixer.replaceText(node, PreferExecutionSleepRule.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"]}
@@ -5,9 +5,12 @@ import type { TRuleSeverity } from '../rules/common';
5
5
  * (`@venizia/ignis-helpers/common`). Read where the syntax says it is one: `method`, `verb` or `httpMethod` in a route
6
6
  * config or a request, and a variable or parameter of those names.
7
7
  *
8
- * The fix is offered only for a string that is exactly the constant's value (lowercase), so what is sent does not
9
- * change. Another spelling is reported only: the constants are lowercase, the framework's fetchers send a method
10
- * uppercased, and the platform `fetch` does not uppercase `patch`. It applies in a project that depends on an IGNIS
8
+ * The fix is offered for a string that is exactly the constant's value (lowercase), so what is sent does not change,
9
+ * and for an uppercase one where the framework reads it (see `isFrameworkRead`). Anything else is reported only:
10
+ * the constants are lowercase, and the platform `fetch` does not uppercase `patch`.
11
+ *
12
+ * It reads syntax only. Another client reached through `require`, a dynamic `import()` or a sub-path of its package
13
+ * is not seen, and neither is a `send` on a client socket that carries a `path`: check the diff `--fix` makes. It applies in a project that depends on an IGNIS
11
14
  * package. `source` is where `HTTP` is imported from; `null` turns the import, and so the fix, off.
12
15
  */
13
16
  export declare class PreferHttpMethodRule {
@@ -28,6 +28,23 @@ class HttpMethodSites {
28
28
  ]); }
29
29
  /** A call that takes a request init: `fetch`, `fetchFn`, a name ending in `Fetch`, `new Request`. */
30
30
  static { this.REQUEST_CALLEE = /^(?:fetch|fetchFn|Request)$|Fetch$/; }
31
+ /** The call names under which an object with a target is a request the framework sends, uppercasing its method. */
32
+ static { this.SENDERS = new Set(['execute', 'request', 'send']); }
33
+ /** The properties that say where a request goes. */
34
+ static { this.TARGET_KEYS = new Set(['baseUrl', 'path', 'paths', 'url']); }
35
+ /** HTTP clients that send a method as written: in a file that imports one, a request call is not the framework's. */
36
+ static { this.FOREIGN_CLIENTS = new Set([
37
+ 'got',
38
+ 'http',
39
+ 'https',
40
+ 'ky',
41
+ 'node-fetch',
42
+ 'node:http',
43
+ 'node:http2',
44
+ 'node:https',
45
+ 'ofetch',
46
+ 'undici',
47
+ ]); }
31
48
  static field(node, key) {
32
49
  return common_1.AstNode.readField({ node, key });
33
50
  }
@@ -57,6 +74,87 @@ class HttpMethodSites {
57
74
  const asserted = HttpMethodSites.nameOf(HttpMethodSites.field(annotation, 'typeName'));
58
75
  return asserted === 'const' && common_1.AstNode.isNode(parent) ? parent : node;
59
76
  }
77
+ static keysOf(object) {
78
+ const properties = HttpMethodSites.field(object, 'properties');
79
+ if (!Array.isArray(properties)) {
80
+ return [];
81
+ }
82
+ return properties.flatMap((property) => {
83
+ return HttpMethodSites.nameOf(HttpMethodSites.field(property, 'key')) ?? [];
84
+ });
85
+ }
86
+ static importsForeignClient(context) {
87
+ return context.sourceCode.ast.body.some((statement) => {
88
+ const source = HttpMethodSites.field(HttpMethodSites.field(statement, 'source'), 'value');
89
+ return typeof source === 'string' && HttpMethodSites.FOREIGN_CLIENTS.has(source);
90
+ });
91
+ }
92
+ /** The call an object literal is written in as an argument, through the literals and type wrappers around it. */
93
+ static enclosingCall(object) {
94
+ const wrappers = new Set([
95
+ 'ConditionalExpression',
96
+ 'LogicalExpression',
97
+ 'ObjectExpression',
98
+ 'Property',
99
+ 'SpreadElement',
100
+ 'TSAsExpression',
101
+ 'TSSatisfiesExpression',
102
+ ]);
103
+ let current = HttpMethodSites.field(object, 'parent');
104
+ while (common_1.AstNode.isNode(current) && wrappers.has(current.type)) {
105
+ current = HttpMethodSites.field(current, 'parent');
106
+ }
107
+ return current;
108
+ }
109
+ static calleeName(call) {
110
+ const callee = HttpMethodSites.field(call, 'callee');
111
+ return HttpMethodSites.nameOf(HttpMethodSites.field(callee, 'property') ?? callee);
112
+ }
113
+ /** The `params` of a `send` that names a `resource`: how a data provider is told the method. */
114
+ static isSendParams(object) {
115
+ const property = HttpMethodSites.field(object, 'parent');
116
+ if (HttpMethodSites.nameOf(HttpMethodSites.field(property, 'key')) !== 'params') {
117
+ return false;
118
+ }
119
+ const argument = HttpMethodSites.field(property, 'parent');
120
+ const call = HttpMethodSites.field(argument, 'parent');
121
+ const callee = HttpMethodSites.field(call, 'callee');
122
+ return (HttpMethodSites.nameOf(HttpMethodSites.field(callee, 'property')) === 'send' &&
123
+ HttpMethodSites.keysOf(argument).includes('resource'));
124
+ }
125
+ /**
126
+ * Whether the framework reads the method of this object, so its lowercase constant is what goes out. Never an
127
+ * object written into a `fetch` or `new Request` call. Otherwise: a route config (`responses`, a `configs`
128
+ * property, `satisfies IAuthRouteConfig`); a request with a target passed to an `execute`, `send` or `request`
129
+ * method; or the `params` of a `send` that names a `resource`. The last two need a file that imports no other
130
+ * HTTP client.
131
+ */
132
+ static isFrameworkRead(opts) {
133
+ const { object, context } = opts;
134
+ const enclosing = HttpMethodSites.calleeName(HttpMethodSites.enclosingCall(object));
135
+ if (enclosing !== undefined && HttpMethodSites.REQUEST_CALLEE.test(enclosing)) {
136
+ return false;
137
+ }
138
+ const keys = HttpMethodSites.keysOf(object);
139
+ const parent = HttpMethodSites.field(object, 'parent');
140
+ const annotation = HttpMethodSites.field(parent, 'typeAnnotation');
141
+ const typeName = HttpMethodSites.nameOf(HttpMethodSites.field(annotation, 'typeName'));
142
+ const heldAs = HttpMethodSites.nameOf(HttpMethodSites.field(parent, 'key'));
143
+ if (keys.includes('responses') || typeName === 'IAuthRouteConfig' || heldAs === 'configs') {
144
+ return true;
145
+ }
146
+ if (HttpMethodSites.importsForeignClient(context)) {
147
+ return false;
148
+ }
149
+ if (HttpMethodSites.isSendParams(object)) {
150
+ return true;
151
+ }
152
+ const callee = HttpMethodSites.field(parent, 'callee');
153
+ const called = HttpMethodSites.nameOf(HttpMethodSites.field(callee, 'property'));
154
+ return (called !== undefined &&
155
+ HttpMethodSites.SENDERS.has(called) &&
156
+ keys.some((key) => HttpMethodSites.TARGET_KEYS.has(key)));
157
+ }
60
158
  /** Whether an object literal is a route config or a request: by a sibling property, or by the call it is passed to. */
61
159
  static isRequest(object) {
62
160
  const properties = HttpMethodSites.field(object, 'properties');
@@ -79,9 +177,12 @@ class HttpMethodSites {
79
177
  * (`@venizia/ignis-helpers/common`). Read where the syntax says it is one: `method`, `verb` or `httpMethod` in a route
80
178
  * config or a request, and a variable or parameter of those names.
81
179
  *
82
- * The fix is offered only for a string that is exactly the constant's value (lowercase), so what is sent does not
83
- * change. Another spelling is reported only: the constants are lowercase, the framework's fetchers send a method
84
- * uppercased, and the platform `fetch` does not uppercase `patch`. It applies in a project that depends on an IGNIS
180
+ * The fix is offered for a string that is exactly the constant's value (lowercase), so what is sent does not change,
181
+ * and for an uppercase one where the framework reads it (see `isFrameworkRead`). Anything else is reported only:
182
+ * the constants are lowercase, and the platform `fetch` does not uppercase `patch`.
183
+ *
184
+ * It reads syntax only. Another client reached through `require`, a dynamic `import()` or a sub-path of its package
185
+ * is not seen, and neither is a `send` on a client socket that carries a `path`: check the diff `--fix` makes. It applies in a project that depends on an IGNIS
85
186
  * package. `source` is where `HTTP` is imported from; `null` turns the import, and so the fix, off.
86
187
  */
87
188
  class PreferHttpMethodRule {
@@ -113,7 +214,7 @@ class PreferHttpMethodRule {
113
214
  const source = typeof configured === 'string' ? configured : PreferHttpMethodRule.DEFAULT_SOURCE;
114
215
  // A package does not import itself by name.
115
216
  const isOwner = source.startsWith(`${manifest?.name}/`);
116
- const check = (value) => {
217
+ const check = (value, opts) => {
117
218
  for (const node of HttpMethodSites.literalsOf(value)) {
118
219
  const written = HttpMethodSites.field(node, 'value');
119
220
  if (typeof written !== 'string' ||
@@ -128,7 +229,9 @@ class PreferHttpMethodRule {
128
229
  messageId: isExact ? 'constant' : 'spelling',
129
230
  data: { member, written, source },
130
231
  fix: (fixer) => {
131
- if (!isExact || isOwner || configured === null) {
232
+ // An uppercase spelling is rewritten only where the framework sends it: a plain `fetch` sends the value.
233
+ const isSafe = isExact || (written === member && opts.isFrameworkRead);
234
+ if (!isSafe || isOwner || configured === null) {
132
235
  return null;
133
236
  }
134
237
  const imports = import_support_1.ImportSupport.ensure({
@@ -149,16 +252,20 @@ class PreferHttpMethodRule {
149
252
  });
150
253
  }
151
254
  };
152
- const checkNamed = (name, value) => {
255
+ const checkNamed = (name, value, opts = { isFrameworkRead: false }) => {
153
256
  const held = HttpMethodSites.nameOf(name);
154
257
  if (held !== undefined && HttpMethodSites.NAMES.has(held)) {
155
- check(value);
258
+ check(value, opts);
156
259
  }
157
260
  };
158
261
  return {
159
262
  [common_1.AstNodeTypes.PROPERTY]: (node) => {
160
- if (HttpMethodSites.isRequest(HttpMethodSites.field(node, 'parent'))) {
161
- checkNamed(HttpMethodSites.field(node, 'key'), HttpMethodSites.field(node, 'value'));
263
+ const object = HttpMethodSites.field(node, 'parent');
264
+ const isFrameworkRead = HttpMethodSites.isFrameworkRead({ object, context });
265
+ if (isFrameworkRead || HttpMethodSites.isRequest(object)) {
266
+ checkNamed(HttpMethodSites.field(node, 'key'), HttpMethodSites.field(node, 'value'), {
267
+ isFrameworkRead,
268
+ });
162
269
  }
163
270
  },
164
271
  [common_1.AstNodeTypes.VARIABLE_DECLARATOR]: (node) => {
@@ -1 +1 @@
1
- {"version":3,"file":"prefer-http-method.rule.js","sourceRoot":"","sources":["../../../src/linters/house/prefer-http-method.rule.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAGpC,qCAAyE;AACzE,2DAAuD;AACvD,qDAAiD;AAEjD,mGAAmG;AACnG,MAAM,eAAe;IACnB,iDAAiD;aACjC,SAAI,GAAG,qDAAqD,CAAC;IAE7E,wCAAwC;aACxB,UAAK,GAAwB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAEvF,iHAAiH;aACjG,iBAAY,GAAwB,IAAI,GAAG,CAAC;QAC1D,SAAS;QACT,MAAM;QACN,SAAS;QACT,MAAM;QACN,SAAS;QACT,MAAM;QACN,OAAO;QACP,OAAO;QACP,SAAS;QACT,WAAW;QACX,QAAQ;QACR,KAAK;KACN,CAAC,CAAC;IAEH,qGAAqG;aACrF,mBAAc,GAAG,oCAAoC,CAAC;IAEtE,MAAM,CAAC,KAAK,CAAC,IAAa,EAAE,GAAW;QACrC,OAAO,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,IAAa;QACzB,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,eAA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MAAM,CAAC,EAAE,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;gBACxF,CAAC;gBACD,CAAC,qBAAY,CAAC,kBAAkB,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE;oBACrD,UAAU,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;gBACxF,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAA6D,EAAE;QAC1E,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAE5C,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACpE,CAAC;;AAjHH,oDAkHC","sourcesContent":["import { dirname } from 'node:path';\nimport type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { FrameworkExports } from './framework-exports';\nimport { ImportSupport } from './import-support';\n\n/** What makes a string a place where an HTTP method is written, read from the syntax around it. */\nclass HttpMethodSites {\n /** The values of `HTTP.Methods`, in any case. */\n static readonly VERB = /^(?:get|post|put|patch|delete|head|options|query)$/i;\n\n /** The names a method is held under. */\n static readonly NAMES: ReadonlySet<string> = new Set(['method', 'verb', 'httpMethod']);\n\n /** A property beside `method` that makes its object a route config or a request, not a table of method names. */\n static readonly REQUEST_KEYS: ReadonlySet<string> = new Set([\n 'baseUrl',\n 'body',\n 'configs',\n 'data',\n 'headers',\n 'path',\n 'paths',\n 'query',\n 'request',\n 'responses',\n 'signal',\n 'url',\n ]);\n\n /** A call that takes a request init: `fetch`, `fetchFn`, a name ending in `Fetch`, `new Request`. */\n static readonly REQUEST_CALLEE = /^(?:fetch|fetchFn|Request)$|Fetch$/;\n\n static field(node: unknown, key: string): unknown {\n return AstNode.readField({ node, key });\n }\n\n static nameOf(node: unknown): string | undefined {\n const name = HttpMethodSites.field(node, 'name') ?? HttpMethodSites.field(node, 'value');\n\n return typeof name === 'string' ? name : undefined;\n }\n\n /** The strings an expression writes out: itself, either branch of a conditional, either side of `??` and `||`. */\n static literalsOf(node: unknown): unknown[] {\n const type = AstNode.getType({ node });\n\n if (type === AstNodeTypes.LITERAL) {\n return [node];\n }\n\n if (type === AstNodeTypes.CONDITIONAL_EXPRESSION) {\n return ['consequent', 'alternate'].flatMap((key) =>\n HttpMethodSites.literalsOf(HttpMethodSites.field(node, key)),\n );\n }\n\n if (type === AstNodeTypes.LOGICAL_EXPRESSION) {\n return ['left', 'right'].flatMap((key) =>\n HttpMethodSites.literalsOf(HttpMethodSites.field(node, key)),\n );\n }\n\n const isWrapped =\n type === AstNodeTypes.AS_EXPRESSION || type === AstNodeTypes.SATISFIES_EXPRESSION;\n\n return isWrapped ? HttpMethodSites.literalsOf(HttpMethodSites.field(node, 'expression')) : [];\n }\n\n /** What a fix replaces: the literal, or its `as const`, which TypeScript refuses on a member reference (TS1355). */\n static replaced(node: Rule.Node): Rule.Node {\n const parent = HttpMethodSites.field(node, 'parent');\n const annotation = HttpMethodSites.field(parent, 'typeAnnotation');\n const asserted = HttpMethodSites.nameOf(HttpMethodSites.field(annotation, 'typeName'));\n\n return asserted === 'const' && AstNode.isNode(parent) ? parent : node;\n }\n\n /** Whether an object literal is a route config or a request: by a sibling property, or by the call it is passed to. */\n static isRequest(object: unknown): boolean {\n const properties = HttpMethodSites.field(object, 'properties');\n const hasSibling =\n Array.isArray(properties) &&\n properties.some((property) => {\n const key = HttpMethodSites.nameOf(HttpMethodSites.field(property, 'key'));\n\n return key !== undefined && HttpMethodSites.REQUEST_KEYS.has(key);\n });\n\n if (hasSibling) {\n return true;\n }\n\n const parent = HttpMethodSites.field(object, 'parent');\n const callee = HttpMethodSites.field(parent, 'callee');\n const name = HttpMethodSites.nameOf(HttpMethodSites.field(callee, 'property') ?? callee);\n\n return name !== undefined && HttpMethodSites.REQUEST_CALLEE.test(name);\n }\n}\n\n/**\n * `@venizia/prefer-http-method`. An HTTP method written by hand (`method: 'get'`) is `HTTP.Methods.GET`\n * (`@venizia/ignis-helpers/common`). Read where the syntax says it is one: `method`, `verb` or `httpMethod` in a route\n * config or a request, and a variable or parameter of those names.\n *\n * The fix is offered only for a string that is exactly the constant's value (lowercase), so what is sent does not\n * change. Another spelling is reported only: the constants are lowercase, the framework's fetchers send a method\n * uppercased, and the platform `fetch` does not uppercase `patch`. It applies in a project that depends on an IGNIS\n * package. `source` is where `HTTP` is imported from; `null` turns the import, and so the fix, off.\n */\nexport class PreferHttpMethodRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/prefer-http-method`;\n\n static readonly DEFAULT_SOURCE = '@venizia/ignis-helpers/common';\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 constant:\n \"Write `HTTP.Methods.{{member}}`, not `'{{written}}'`: `import { HTTP } from '{{source}}';`\",\n spelling:\n \"Write `HTTP.Methods.{{member}}`, not `'{{written}}'`: `import { HTTP } from '{{source}}';` The constant is lowercase: the framework's fetchers send it uppercased, a plain `fetch` sends `patch` as written, so uppercase it there.\",\n },\n },\n create: (context) => {\n const manifest = FrameworkExports.manifestFor({ directory: dirname(context.filename) });\n const isIgnis = manifest?.dependencies.some((name) => name.startsWith('@venizia/ignis'));\n\n if (isIgnis !== true) {\n return {};\n }\n\n const configured = AstNode.readField({ node: context.options[0], key: 'source' });\n const source =\n typeof configured === 'string' ? configured : PreferHttpMethodRule.DEFAULT_SOURCE;\n // A package does not import itself by name.\n const isOwner = source.startsWith(`${manifest?.name}/`);\n\n const check = (value: unknown) => {\n for (const node of HttpMethodSites.literalsOf(value)) {\n const written = HttpMethodSites.field(node, 'value');\n\n if (\n typeof written !== 'string' ||\n !HttpMethodSites.VERB.test(written) ||\n !AstNode.isNode(node)\n ) {\n continue;\n }\n\n const member = written.toUpperCase();\n const isExact = written === written.toLowerCase();\n\n context.report({\n node,\n messageId: isExact ? 'constant' : 'spelling',\n data: { member, written, source },\n fix: (fixer) => {\n if (!isExact || isOwner || configured === null) {\n return null;\n }\n\n const imports = ImportSupport.ensure({\n context,\n fixer,\n name: 'HTTP',\n source,\n isType: false,\n });\n const local =\n ImportSupport.importedAs({ context, name: 'HTTP', asValue: true }) ?? 'HTTP';\n\n return imports\n ? [\n fixer.replaceText(HttpMethodSites.replaced(node), `${local}.Methods.${member}`),\n ...imports,\n ]\n : null;\n },\n });\n }\n };\n\n const checkNamed = (name: unknown, value: unknown) => {\n const held = HttpMethodSites.nameOf(name);\n\n if (held !== undefined && HttpMethodSites.NAMES.has(held)) {\n check(value);\n }\n };\n\n return {\n [AstNodeTypes.PROPERTY]: (node: Rule.Node) => {\n if (HttpMethodSites.isRequest(HttpMethodSites.field(node, 'parent'))) {\n checkNamed(HttpMethodSites.field(node, 'key'), HttpMethodSites.field(node, 'value'));\n }\n },\n [AstNodeTypes.VARIABLE_DECLARATOR]: (node: Rule.Node) => {\n checkNamed(HttpMethodSites.field(node, 'id'), HttpMethodSites.field(node, 'init'));\n },\n [AstNodeTypes.ASSIGNMENT_EXPRESSION]: (node: Rule.Node) => {\n checkNamed(HttpMethodSites.field(node, 'left'), HttpMethodSites.field(node, 'right'));\n },\n [AstNodeTypes.ASSIGNMENT_PATTERN]: (node: Rule.Node) => {\n checkNamed(HttpMethodSites.field(node, 'left'), HttpMethodSites.field(node, 'right'));\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"]}
1
+ {"version":3,"file":"prefer-http-method.rule.js","sourceRoot":"","sources":["../../../src/linters/house/prefer-http-method.rule.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAGpC,qCAAyE;AACzE,2DAAuD;AACvD,qDAAiD;AAEjD,mGAAmG;AACnG,MAAM,eAAe;IACnB,iDAAiD;aACjC,SAAI,GAAG,qDAAqD,CAAC;IAE7E,wCAAwC;aACxB,UAAK,GAAwB,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAEvF,iHAAiH;aACjG,iBAAY,GAAwB,IAAI,GAAG,CAAC;QAC1D,SAAS;QACT,MAAM;QACN,SAAS;QACT,MAAM;QACN,SAAS;QACT,MAAM;QACN,OAAO;QACP,OAAO;QACP,SAAS;QACT,WAAW;QACX,QAAQ;QACR,KAAK;KACN,CAAC,CAAC;IAEH,qGAAqG;aACrF,mBAAc,GAAG,oCAAoC,CAAC;IAEtE,mHAAmH;aACnG,YAAO,GAAwB,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;IAEvF,oDAAoD;aACpC,gBAAW,GAAwB,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAEhG,qHAAqH;aACrG,oBAAe,GAAwB,IAAI,GAAG,CAAC;QAC7D,KAAK;QACL,MAAM;QACN,OAAO;QACP,IAAI;QACJ,YAAY;QACZ,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,QAAQ;QACR,QAAQ;KACT,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,IAAa,EAAE,GAAW;QACrC,OAAO,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,IAAa;QACzB,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,CA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TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { FrameworkExports } from './framework-exports';\nimport { ImportSupport } from './import-support';\n\n/** What makes a string a place where an HTTP method is written, read from the syntax around it. */\nclass HttpMethodSites {\n /** The values of `HTTP.Methods`, in any case. */\n static readonly VERB = /^(?:get|post|put|patch|delete|head|options|query)$/i;\n\n /** The names a method is held under. */\n static readonly NAMES: ReadonlySet<string> = new Set(['method', 'verb', 'httpMethod']);\n\n /** A property beside `method` that makes its object a route config or a request, not a table of method names. */\n static readonly REQUEST_KEYS: ReadonlySet<string> = new Set([\n 'baseUrl',\n 'body',\n 'configs',\n 'data',\n 'headers',\n 'path',\n 'paths',\n 'query',\n 'request',\n 'responses',\n 'signal',\n 'url',\n ]);\n\n /** A call that takes a request init: `fetch`, `fetchFn`, a name ending in `Fetch`, `new Request`. */\n static readonly REQUEST_CALLEE = /^(?:fetch|fetchFn|Request)$|Fetch$/;\n\n /** The call names under which an object with a target is a request the framework sends, uppercasing its method. */\n static readonly SENDERS: ReadonlySet<string> = new Set(['execute', 'request', 'send']);\n\n /** The properties that say where a request goes. */\n static readonly TARGET_KEYS: ReadonlySet<string> = new Set(['baseUrl', 'path', 'paths', 'url']);\n\n /** HTTP clients that send a method as written: in a file that imports one, a request call is not the framework's. */\n static readonly FOREIGN_CLIENTS: ReadonlySet<string> = new Set([\n 'got',\n 'http',\n 'https',\n 'ky',\n 'node-fetch',\n 'node:http',\n 'node:http2',\n 'node:https',\n 'ofetch',\n 'undici',\n ]);\n\n static field(node: unknown, key: string): unknown {\n return AstNode.readField({ node, key });\n }\n\n static nameOf(node: unknown): string | undefined {\n const name = HttpMethodSites.field(node, 'name') ?? HttpMethodSites.field(node, 'value');\n\n return typeof name === 'string' ? name : undefined;\n }\n\n /** The strings an expression writes out: itself, either branch of a conditional, either side of `??` and `||`. */\n static literalsOf(node: unknown): unknown[] {\n const type = AstNode.getType({ node });\n\n if (type === AstNodeTypes.LITERAL) {\n return [node];\n }\n\n if (type === AstNodeTypes.CONDITIONAL_EXPRESSION) {\n return ['consequent', 'alternate'].flatMap((key) =>\n HttpMethodSites.literalsOf(HttpMethodSites.field(node, key)),\n );\n }\n\n if (type === AstNodeTypes.LOGICAL_EXPRESSION) {\n return ['left', 'right'].flatMap((key) =>\n HttpMethodSites.literalsOf(HttpMethodSites.field(node, key)),\n );\n }\n\n const isWrapped =\n type === AstNodeTypes.AS_EXPRESSION || type === AstNodeTypes.SATISFIES_EXPRESSION;\n\n return isWrapped ? HttpMethodSites.literalsOf(HttpMethodSites.field(node, 'expression')) : [];\n }\n\n /** What a fix replaces: the literal, or its `as const`, which TypeScript refuses on a member reference (TS1355). */\n static replaced(node: Rule.Node): Rule.Node {\n const parent = HttpMethodSites.field(node, 'parent');\n const annotation = HttpMethodSites.field(parent, 'typeAnnotation');\n const asserted = HttpMethodSites.nameOf(HttpMethodSites.field(annotation, 'typeName'));\n\n return asserted === 'const' && AstNode.isNode(parent) ? parent : node;\n }\n\n static keysOf(object: unknown): string[] {\n const properties = HttpMethodSites.field(object, 'properties');\n\n if (!Array.isArray(properties)) {\n return [];\n }\n\n return properties.flatMap((property) => {\n return HttpMethodSites.nameOf(HttpMethodSites.field(property, 'key')) ?? [];\n });\n }\n\n static importsForeignClient(context: Rule.RuleContext): boolean {\n return context.sourceCode.ast.body.some((statement) => {\n const source = HttpMethodSites.field(HttpMethodSites.field(statement, 'source'), 'value');\n\n return typeof source === 'string' && HttpMethodSites.FOREIGN_CLIENTS.has(source);\n });\n }\n\n /** The call an object literal is written in as an argument, through the literals and type wrappers around it. */\n static enclosingCall(object: unknown): unknown {\n const wrappers: ReadonlySet<string> = new Set([\n 'ConditionalExpression',\n 'LogicalExpression',\n 'ObjectExpression',\n 'Property',\n 'SpreadElement',\n 'TSAsExpression',\n 'TSSatisfiesExpression',\n ]);\n let current = HttpMethodSites.field(object, 'parent');\n\n while (AstNode.isNode(current) && wrappers.has(current.type)) {\n current = HttpMethodSites.field(current, 'parent');\n }\n\n return current;\n }\n\n static calleeName(call: unknown): string | undefined {\n const callee = HttpMethodSites.field(call, 'callee');\n\n return HttpMethodSites.nameOf(HttpMethodSites.field(callee, 'property') ?? callee);\n }\n\n /** The `params` of a `send` that names a `resource`: how a data provider is told the method. */\n static isSendParams(object: unknown): boolean {\n const property = HttpMethodSites.field(object, 'parent');\n\n if (HttpMethodSites.nameOf(HttpMethodSites.field(property, 'key')) !== 'params') {\n return false;\n }\n\n const argument = HttpMethodSites.field(property, 'parent');\n const call = HttpMethodSites.field(argument, 'parent');\n const callee = HttpMethodSites.field(call, 'callee');\n\n return (\n HttpMethodSites.nameOf(HttpMethodSites.field(callee, 'property')) === 'send' &&\n HttpMethodSites.keysOf(argument).includes('resource')\n );\n }\n\n /**\n * Whether the framework reads the method of this object, so its lowercase constant is what goes out. Never an\n * object written into a `fetch` or `new Request` call. Otherwise: a route config (`responses`, a `configs`\n * property, `satisfies IAuthRouteConfig`); a request with a target passed to an `execute`, `send` or `request`\n * method; or the `params` of a `send` that names a `resource`. The last two need a file that imports no other\n * HTTP client.\n */\n static isFrameworkRead(opts: { object: unknown; context: Rule.RuleContext }): boolean {\n const { object, context } = opts;\n const enclosing = HttpMethodSites.calleeName(HttpMethodSites.enclosingCall(object));\n\n if (enclosing !== undefined && HttpMethodSites.REQUEST_CALLEE.test(enclosing)) {\n return false;\n }\n\n const keys = HttpMethodSites.keysOf(object);\n const parent = HttpMethodSites.field(object, 'parent');\n const annotation = HttpMethodSites.field(parent, 'typeAnnotation');\n const typeName = HttpMethodSites.nameOf(HttpMethodSites.field(annotation, 'typeName'));\n const heldAs = HttpMethodSites.nameOf(HttpMethodSites.field(parent, 'key'));\n\n if (keys.includes('responses') || typeName === 'IAuthRouteConfig' || heldAs === 'configs') {\n return true;\n }\n\n if (HttpMethodSites.importsForeignClient(context)) {\n return false;\n }\n\n if (HttpMethodSites.isSendParams(object)) {\n return true;\n }\n\n const callee = HttpMethodSites.field(parent, 'callee');\n const called = HttpMethodSites.nameOf(HttpMethodSites.field(callee, 'property'));\n\n return (\n called !== undefined &&\n HttpMethodSites.SENDERS.has(called) &&\n keys.some((key) => HttpMethodSites.TARGET_KEYS.has(key))\n );\n }\n\n /** Whether an object literal is a route config or a request: by a sibling property, or by the call it is passed to. */\n static isRequest(object: unknown): boolean {\n const properties = HttpMethodSites.field(object, 'properties');\n const hasSibling =\n Array.isArray(properties) &&\n properties.some((property) => {\n const key = HttpMethodSites.nameOf(HttpMethodSites.field(property, 'key'));\n\n return key !== undefined && HttpMethodSites.REQUEST_KEYS.has(key);\n });\n\n if (hasSibling) {\n return true;\n }\n\n const parent = HttpMethodSites.field(object, 'parent');\n const callee = HttpMethodSites.field(parent, 'callee');\n const name = HttpMethodSites.nameOf(HttpMethodSites.field(callee, 'property') ?? callee);\n\n return name !== undefined && HttpMethodSites.REQUEST_CALLEE.test(name);\n }\n}\n\n/**\n * `@venizia/prefer-http-method`. An HTTP method written by hand (`method: 'get'`) is `HTTP.Methods.GET`\n * (`@venizia/ignis-helpers/common`). Read where the syntax says it is one: `method`, `verb` or `httpMethod` in a route\n * config or a request, and a variable or parameter of those names.\n *\n * The fix is offered for a string that is exactly the constant's value (lowercase), so what is sent does not change,\n * and for an uppercase one where the framework reads it (see `isFrameworkRead`). Anything else is reported only:\n * the constants are lowercase, and the platform `fetch` does not uppercase `patch`.\n *\n * It reads syntax only. Another client reached through `require`, a dynamic `import()` or a sub-path of its package\n * is not seen, and neither is a `send` on a client socket that carries a `path`: check the diff `--fix` makes. It applies in a project that depends on an IGNIS\n * package. `source` is where `HTTP` is imported from; `null` turns the import, and so the fix, off.\n */\nexport class PreferHttpMethodRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/prefer-http-method`;\n\n static readonly DEFAULT_SOURCE = '@venizia/ignis-helpers/common';\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 constant:\n \"Write `HTTP.Methods.{{member}}`, not `'{{written}}'`: `import { HTTP } from '{{source}}';`\",\n spelling:\n \"Write `HTTP.Methods.{{member}}`, not `'{{written}}'`: `import { HTTP } from '{{source}}';` The constant is lowercase: the framework's fetchers send it uppercased, a plain `fetch` sends `patch` as written, so uppercase it there.\",\n },\n },\n create: (context) => {\n const manifest = FrameworkExports.manifestFor({ directory: dirname(context.filename) });\n const isIgnis = manifest?.dependencies.some((name) => name.startsWith('@venizia/ignis'));\n\n if (isIgnis !== true) {\n return {};\n }\n\n const configured = AstNode.readField({ node: context.options[0], key: 'source' });\n const source =\n typeof configured === 'string' ? configured : PreferHttpMethodRule.DEFAULT_SOURCE;\n // A package does not import itself by name.\n const isOwner = source.startsWith(`${manifest?.name}/`);\n\n const check = (value: unknown, opts: { isFrameworkRead: boolean }) => {\n for (const node of HttpMethodSites.literalsOf(value)) {\n const written = HttpMethodSites.field(node, 'value');\n\n if (\n typeof written !== 'string' ||\n !HttpMethodSites.VERB.test(written) ||\n !AstNode.isNode(node)\n ) {\n continue;\n }\n\n const member = written.toUpperCase();\n const isExact = written === written.toLowerCase();\n\n context.report({\n node,\n messageId: isExact ? 'constant' : 'spelling',\n data: { member, written, source },\n fix: (fixer) => {\n // An uppercase spelling is rewritten only where the framework sends it: a plain `fetch` sends the value.\n const isSafe = isExact || (written === member && opts.isFrameworkRead);\n\n if (!isSafe || isOwner || configured === null) {\n return null;\n }\n\n const imports = ImportSupport.ensure({\n context,\n fixer,\n name: 'HTTP',\n source,\n isType: false,\n });\n const local =\n ImportSupport.importedAs({ context, name: 'HTTP', asValue: true }) ?? 'HTTP';\n\n return imports\n ? [\n fixer.replaceText(HttpMethodSites.replaced(node), `${local}.Methods.${member}`),\n ...imports,\n ]\n : null;\n },\n });\n }\n };\n\n const checkNamed = (name: unknown, value: unknown, opts = { isFrameworkRead: false }) => {\n const held = HttpMethodSites.nameOf(name);\n\n if (held !== undefined && HttpMethodSites.NAMES.has(held)) {\n check(value, opts);\n }\n };\n\n return {\n [AstNodeTypes.PROPERTY]: (node: Rule.Node) => {\n const object = HttpMethodSites.field(node, 'parent');\n const isFrameworkRead = HttpMethodSites.isFrameworkRead({ object, context });\n\n if (isFrameworkRead || HttpMethodSites.isRequest(object)) {\n checkNamed(HttpMethodSites.field(node, 'key'), HttpMethodSites.field(node, 'value'), {\n isFrameworkRead,\n });\n }\n },\n [AstNodeTypes.VARIABLE_DECLARATOR]: (node: Rule.Node) => {\n checkNamed(HttpMethodSites.field(node, 'id'), HttpMethodSites.field(node, 'init'));\n },\n [AstNodeTypes.ASSIGNMENT_EXPRESSION]: (node: Rule.Node) => {\n checkNamed(HttpMethodSites.field(node, 'left'), HttpMethodSites.field(node, 'right'));\n },\n [AstNodeTypes.ASSIGNMENT_PATTERN]: (node: Rule.Node) => {\n checkNamed(HttpMethodSites.field(node, 'left'), HttpMethodSites.field(node, 'right'));\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"]}
@@ -0,0 +1,30 @@
1
+ import type { Linter, Rule } from 'eslint';
2
+ import type { TRuleSeverity } from '../rules/common';
3
+ /**
4
+ * `@venizia/restrict-execution-call-sites`. A scoped run takes the values its caller names, so an application lists
5
+ * the files that may say who is running: `Execution.run`, `ExecutionFrames.run` and `ExecutionFrames.root` are
6
+ * reported everywhere else. `Execution.sleep` and the other methods are never reported.
7
+ *
8
+ * - `allow`: globs, relative to the working directory, of files that may call `Execution.run` without `isRoot`.
9
+ * - `allowRoot`: globs of files that may also open a root frame: `isRoot`, `ExecutionFrames.run` and `.root`.
10
+ * Options the rule cannot read (a spread, a variable, `run` passed as a value) may set `isRoot`, so they count.
11
+ *
12
+ * A computed name that cannot be read, on either class, counts as one that may open a root.
13
+ * With no list, every call is reported. The presets do not turn the rule on. It follows imports of the framework's
14
+ * packages only: a re-export of the application's own, or `Execution` held in another variable, is not followed.
15
+ */
16
+ export declare class RestrictExecutionCallSitesRule {
17
+ static readonly NAME = "@venizia/restrict-execution-call-sites";
18
+ /** The restricted methods of each class, and whether the method opens a frame of any shape by itself. */
19
+ private static readonly METHODS;
20
+ private static matches;
21
+ /** Whether the `Execution.run` read at `member` opens a root frame, or may. */
22
+ private static mayBeRoot;
23
+ static readonly RULE: Rule.RuleModule;
24
+ static build(opts?: {
25
+ severity?: TRuleSeverity;
26
+ allow?: string[];
27
+ allowRoot?: string[];
28
+ }): Linter.RuleEntry;
29
+ }
30
+ //# sourceMappingURL=restrict-execution-call-sites.rule.d.ts.map