@venizia/dev-configs 0.5.0-1 → 0.5.0-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -13
- package/dist/checks/purity/manifest.js +11 -3
- package/dist/checks/purity/manifest.js.map +1 -1
- package/dist/checks/purity/probe.js +19 -2
- package/dist/checks/purity/probe.js.map +1 -1
- package/dist/checks/split-report.js +2 -1
- package/dist/checks/split-report.js.map +1 -1
- package/dist/checks/test-controls.d.ts +9 -1
- package/dist/checks/test-controls.js +9 -3
- package/dist/checks/test-controls.js.map +1 -1
- package/dist/checks/test-dead-code.d.ts +9 -1
- package/dist/checks/test-dead-code.js +13 -2
- package/dist/checks/test-dead-code.js.map +1 -1
- package/dist/checks/test-mutate.d.ts +9 -1
- package/dist/checks/test-mutate.js +12 -6
- package/dist/checks/test-mutate.js.map +1 -1
- package/dist/cli/check.js +42 -38
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/clean.js +3 -2
- package/dist/cli/clean.js.map +1 -1
- package/dist/cli/codemod/any-aliases.d.ts +1 -1
- package/dist/cli/codemod/any-aliases.js +14 -13
- package/dist/cli/codemod/any-aliases.js.map +1 -1
- package/dist/cli/codemod/async-style.d.ts +1 -1
- package/dist/cli/codemod/async-style.js +18 -17
- package/dist/cli/codemod/async-style.js.map +1 -1
- package/dist/cli/codemod/binding-keys.d.ts +32 -1
- package/dist/cli/codemod/binding-keys.js +238 -58
- package/dist/cli/codemod/binding-keys.js.map +1 -1
- package/dist/cli/codemod/class-renames.d.ts +39 -0
- package/dist/cli/codemod/class-renames.js +297 -0
- package/dist/cli/codemod/class-renames.js.map +1 -0
- package/dist/cli/codemod/connector-imports.d.ts +1 -1
- package/dist/cli/codemod/connector-imports.js +13 -12
- package/dist/cli/codemod/connector-imports.js.map +1 -1
- package/dist/cli/codemod/const-class-sets.d.ts +55 -0
- package/dist/cli/codemod/const-class-sets.js +219 -0
- package/dist/cli/codemod/const-class-sets.js.map +1 -0
- package/dist/cli/codemod/const-classes.d.ts +21 -3
- package/dist/cli/codemod/const-classes.js +151 -36
- package/dist/cli/codemod/const-classes.js.map +1 -1
- package/dist/cli/codemod/drop-redundant-casts.d.ts +6 -1
- package/dist/cli/codemod/drop-redundant-casts.js +27 -19
- package/dist/cli/codemod/drop-redundant-casts.js.map +1 -1
- package/dist/cli/codemod/env-get.d.ts +3 -3
- package/dist/cli/codemod/env-get.js +19 -18
- package/dist/cli/codemod/env-get.js.map +1 -1
- package/dist/cli/codemod/files.d.ts +4 -2
- package/dist/cli/codemod/files.js +7 -8
- package/dist/cli/codemod/files.js.map +1 -1
- package/dist/cli/codemod/function-to-arrow.d.ts +76 -0
- package/dist/cli/codemod/function-to-arrow.js +357 -0
- package/dist/cli/codemod/function-to-arrow.js.map +1 -0
- package/dist/cli/codemod/index.js +25 -4
- package/dist/cli/codemod/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/index.d.ts +1 -1
- package/dist/cli/codemod/namespace-functions/index.js +14 -13
- package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js +3 -3
- package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/helpers.js +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/helpers.js.map +1 -1
- package/dist/cli/codemod/typed-route-context.d.ts +58 -0
- package/dist/cli/codemod/typed-route-context.js +918 -0
- package/dist/cli/codemod/typed-route-context.js.map +1 -0
- package/dist/cli/index.js +5 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/common/cli-output.d.ts +16 -0
- package/dist/common/cli-output.js +49 -0
- package/dist/common/cli-output.js.map +1 -0
- package/dist/compilers/bun.js +1 -1
- package/dist/compilers/bun.js.map +1 -1
- package/dist/linters/eslint.js +1 -1
- package/dist/linters/eslint.js.map +1 -1
- package/dist/linters/house/browser-api-patterns.d.ts +43 -0
- package/dist/linters/house/browser-api-patterns.js +87 -0
- package/dist/linters/house/browser-api-patterns.js.map +1 -0
- package/dist/linters/house/common.d.ts +17 -2
- package/dist/linters/house/common.js +18 -2
- package/dist/linters/house/common.js.map +1 -1
- package/dist/linters/house/configs.js +25 -0
- package/dist/linters/house/configs.js.map +1 -1
- package/dist/linters/house/const-class-values.rule.d.ts +2 -2
- package/dist/linters/house/const-class-values.rule.js +14 -5
- package/dist/linters/house/const-class-values.rule.js.map +1 -1
- package/dist/linters/house/effect-cleanup-consistency.rule.d.ts +2 -2
- package/dist/linters/house/effect-cleanup-consistency.rule.js +1 -1
- package/dist/linters/house/effect-cleanup-consistency.rule.js.map +1 -1
- package/dist/linters/house/framework-api-patterns.d.ts +54 -0
- package/dist/linters/house/framework-api-patterns.js +62 -0
- package/dist/linters/house/framework-api-patterns.js.map +1 -0
- package/dist/linters/house/framework-exports.d.ts +62 -0
- package/dist/linters/house/framework-exports.js +325 -0
- package/dist/linters/house/framework-exports.js.map +1 -0
- package/dist/linters/house/import-support.d.ts +56 -0
- package/dist/linters/house/import-support.js +179 -0
- package/dist/linters/house/import-support.js.map +1 -0
- package/dist/linters/house/index.d.ts +12 -0
- package/dist/linters/house/index.js +15 -1
- package/dist/linters/house/index.js.map +1 -1
- package/dist/linters/house/max-params-own.rule.d.ts +2 -2
- package/dist/linters/house/max-params-own.rule.js +1 -1
- package/dist/linters/house/max-params-own.rule.js.map +1 -1
- package/dist/linters/house/no-async-hook-callback.rule.d.ts +2 -2
- package/dist/linters/house/no-async-hook-callback.rule.js +1 -1
- package/dist/linters/house/no-async-hook-callback.rule.js.map +1 -1
- package/dist/linters/house/no-await-new-chain.rule.d.ts +2 -2
- package/dist/linters/house/no-await-new-chain.rule.js +1 -1
- package/dist/linters/house/no-await-new-chain.rule.js.map +1 -1
- package/dist/linters/house/no-await-promise-chain.rule.d.ts +2 -2
- package/dist/linters/house/no-await-promise-chain.rule.js +5 -5
- package/dist/linters/house/no-await-promise-chain.rule.js.map +1 -1
- package/dist/linters/house/no-inline-await.rule.d.ts +2 -2
- package/dist/linters/house/no-inline-await.rule.js +1 -1
- package/dist/linters/house/no-inline-await.rule.js.map +1 -1
- package/dist/linters/house/no-leaked-render.rule.d.ts +2 -2
- package/dist/linters/house/no-leaked-render.rule.js +1 -1
- package/dist/linters/house/no-leaked-render.rule.js.map +1 -1
- package/dist/linters/house/no-new-error.rule.d.ts +2 -2
- package/dist/linters/house/no-new-error.rule.js +2 -2
- package/dist/linters/house/no-new-error.rule.js.map +1 -1
- package/dist/linters/house/no-parent-import.rule.d.ts +45 -0
- package/dist/linters/house/no-parent-import.rule.js +176 -0
- package/dist/linters/house/no-parent-import.rule.js.map +1 -0
- package/dist/linters/house/no-return-await.rule.d.ts +2 -2
- package/dist/linters/house/no-return-await.rule.js +1 -1
- package/dist/linters/house/no-return-await.rule.js.map +1 -1
- package/dist/linters/house/no-shadow-framework-type.rule.d.ts +24 -0
- package/dist/linters/house/no-shadow-framework-type.rule.js +100 -0
- package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -0
- package/dist/linters/house/no-silent-catch.rule.d.ts +2 -2
- package/dist/linters/house/no-silent-catch.rule.js +3 -3
- package/dist/linters/house/no-silent-catch.rule.js.map +1 -1
- package/dist/linters/house/no-unbraced-case.rule.d.ts +2 -2
- package/dist/linters/house/no-unbraced-case.rule.js +1 -1
- package/dist/linters/house/no-unbraced-case.rule.js.map +1 -1
- package/dist/linters/house/plugin.d.ts +1 -1
- package/dist/linters/house/plugin.js +18 -2
- package/dist/linters/house/plugin.js.map +1 -1
- package/dist/linters/house/prefer-framework-api.rule.d.ts +83 -0
- package/dist/linters/house/prefer-framework-api.rule.js +562 -0
- package/dist/linters/house/prefer-framework-api.rule.js.map +1 -0
- package/dist/linters/house/prefer-http-method.rule.d.ts +22 -0
- package/dist/linters/house/prefer-http-method.rule.js +182 -0
- package/dist/linters/house/prefer-http-method.rule.js.map +1 -0
- package/dist/linters/house/prefer-promise-sleep.rule.d.ts +26 -0
- package/dist/linters/house/prefer-promise-sleep.rule.js +155 -0
- package/dist/linters/house/prefer-promise-sleep.rule.js.map +1 -0
- package/dist/linters/house/prefer-tnullable.rule.d.ts +25 -0
- package/dist/linters/house/prefer-tnullable.rule.js +124 -0
- package/dist/linters/house/prefer-tnullable.rule.js.map +1 -0
- package/dist/linters/house/typed-route-context.rule.d.ts +19 -0
- package/dist/linters/house/typed-route-context.rule.js +334 -0
- package/dist/linters/house/typed-route-context.rule.js.map +1 -0
- package/dist/linters/house/zod-schema-convention.rule.d.ts +82 -0
- package/dist/linters/house/zod-schema-convention.rule.js +477 -0
- package/dist/linters/house/zod-schema-convention.rule.js.map +1 -0
- package/dist/linters/oxlint.js +11 -1
- package/dist/linters/oxlint.js.map +1 -1
- package/dist/linters/react-eslint.js.map +1 -1
- package/dist/linters/rules/naming-convention.rule.d.ts +4 -1
- package/dist/linters/rules/naming-convention.rule.js +30 -1
- package/dist/linters/rules/naming-convention.rule.js.map +1 -1
- package/dist/linters/rules/no-restricted-properties.rule.js +1 -1
- package/dist/linters/rules/no-restricted-properties.rule.js.map +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/{rejection.helper.d.ts → rejection.utility.d.ts} +4 -4
- package/dist/testing/{rejection.helper.js → rejection.utility.js} +7 -7
- package/dist/testing/rejection.utility.js.map +1 -0
- package/dist/testing/{spawn.helper.d.ts → spawn.utility.d.ts} +2 -2
- package/dist/testing/{spawn.helper.js → spawn.utility.js} +6 -6
- package/dist/testing/spawn.utility.js.map +1 -0
- package/package.json +7 -7
- package/dist/testing/rejection.helper.js.map +0 -1
- package/dist/testing/spawn.helper.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-framework-api.rule.js","sourceRoot":"","sources":["../../../src/linters/house/prefer-framework-api.rule.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAIpC,iEAA4D;AAC5D,qCAAyE;AAEzE,qEA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,CAAC;iBAC1D;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;IAEF;;;OAGG;IACH,MAAM,CAAC,KAAK,CACV,OAKI,EAAE;QAEN,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAC1D,mFAAmF;QACnF,MAAM,OAAO,GAA4B,EAAE,CAAC;QAE5C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QACxB,CAAC;QAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;QAC/B,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;QAC7B,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC9E,CAAC;;AAzsBH,wDA0sBC","sourcesContent":["import { dirname } from 'node:path';\nimport type { Linter, Rule, Scope } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport type { IBrowserApiPattern } from './browser-api-patterns';\nimport { BrowserApiPatterns } from './browser-api-patterns';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport type { IFrameworkApiPattern } from './framework-api-patterns';\nimport { FrameworkApiPatterns } from './framework-api-patterns';\nimport type { IPackageManifest } from './framework-exports';\nimport { FrameworkExports } from './framework-exports';\n\n/** The objects a global event listener is added to. */\nconst GLOBAL_TARGETS: ReadonlyArray<string> = ['window', 'document', 'self', 'globalThis'];\n\n/** The names that stand for the global object. */\nconst GLOBAL_OBJECTS: ReadonlyArray<string> = ['window', 'globalThis', 'self'];\n\n/**\n * `@venizia/prefer-framework-api`. A browser API that `@venizia/ardor-react` wraps in a hook (`window.matchMedia`, a\n * `ResizeObserver`, `navigator.onLine`, a `beforeunload` listener, `navigator.clipboard.writeText`, `window.confirm`...) is\n * used through the hook, which owns the subscribe and cleanup. The rows are `BrowserApiPatterns.TABLE`; the message names\n * the hook. The rule is for apps: the package that ships the hooks (the nearest `package.json` is named\n * `@venizia/ardor-react`) is not reported.\n *\n * The rows of `FrameworkApiPatterns.TABLE` and of the `extra` option are not about React: they report anywhere in a file,\n * with their own message, in a package their `dependsOn` and `owner` allow.\n *\n * For the hook rows, only a reference to the global is reported: a `window`, `navigator` or `document` the file binds itself is not. And only\n * where a hook can be called: in a component (a PascalCase function that draws JSX) or a hook (`useX`), see `isInReact`. A\n * module function, a class and an event handler making a one-off call are left alone. Hooks the author wants to bypass on\n * purpose take an `eslint-disable-next-line` with the reason, or `ignore` lists pattern ids.\n */\nexport class PreferFrameworkApiRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/prefer-framework-api`;\n\n /** The dotted text of `a.b.c` (identifiers only), or `undefined` for anything else. */\n private static pathOf(opts: { node: unknown }): string | undefined {\n const { node } = opts;\n\n if (AstNode.getType({ node }) === AstNodeTypes.IDENTIFIER) {\n const name = AstNode.readField({ node, key: 'name' });\n\n return typeof name === 'string' ? name : undefined;\n }\n\n if (AstNode.getType({ node }) !== AstNodeTypes.MEMBER_EXPRESSION) {\n return undefined;\n }\n\n const property = AstNode.readField({ node, key: 'property' });\n const name = AstNode.readField({ node: property, key: 'name' });\n const head = PreferFrameworkApiRule.pathOf({\n node: AstNode.readField({ node, key: 'object' }),\n });\n\n return head !== undefined &&\n typeof name === 'string' &&\n AstNode.readField({ node, key: 'computed' }) !== true\n ? `${head}.${name}`\n : undefined;\n }\n\n /** `window.navigator.onLine` is `navigator.onLine`. */\n private static withoutGlobalRoot(opts: { path: string }): string {\n const [first, ...rest] = opts.path.split('.');\n\n return GLOBAL_OBJECTS.includes(first ?? '') && rest.length > 0 ? rest.join('.') : opts.path;\n }\n\n /** Whether the root identifier of `path` is the global one: no scope of the file binds it. */\n private static isGlobal(opts: {\n context: Rule.RuleContext;\n node: Rule.Node;\n path: string;\n }): boolean {\n const { context, node, path } = opts;\n const root = path.split('.')[0] ?? '';\n let scope: Scope.Scope | null = context.sourceCode.getScope(node);\n\n while (scope) {\n if ((scope.set.get(root)?.defs.length ?? 0) > 0) {\n return false;\n }\n\n scope = scope.upper;\n }\n\n return true;\n }\n\n private static readonly FUNCTIONS = new Set<string>([\n AstNodeTypes.FUNCTION_DECLARATION,\n AstNodeTypes.FUNCTION_EXPRESSION,\n AstNodeTypes.ARROW_FUNCTION_EXPRESSION,\n ]);\n\n /** Whether a function has JSX anywhere in it: with a PascalCase name, that is a component. */\n private static readonly jsxCache = new WeakMap<object, boolean>();\n\n private static containsJsx(opts: { context: Rule.RuleContext; node: unknown }): boolean {\n const { context, node } = opts;\n\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n const cached = PreferFrameworkApiRule.jsxCache.get(node);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const type = AstNode.getType({ node });\n let found = type === AstNodeTypes.JSX_ELEMENT || type === AstNodeTypes.JSX_FRAGMENT;\n\n for (const key of type === undefined ? [] : (context.sourceCode.visitorKeys[type] ?? [])) {\n const child = AstNode.readField({ node, key });\n\n for (const entry of Array.isArray(child) ? child : [child]) {\n found = found || PreferFrameworkApiRule.containsJsx({ context, node: entry });\n }\n }\n\n PreferFrameworkApiRule.jsxCache.set(node, found);\n\n return found;\n }\n\n /** The name a function is known by: its own, or the variable it is assigned to (through one `memo(...)` / `forwardRef(...)`). */\n private static nameOf(opts: { fn: Rule.Node }): string | undefined {\n const { fn } = opts;\n const own = AstNode.readField({\n node: AstNode.readField({ node: fn, key: 'id' }),\n key: 'name',\n });\n\n if (typeof own === 'string') {\n return own;\n }\n\n let parent: unknown = AstNode.readField({ node: fn, key: 'parent' });\n\n if (AstNode.getType({ node: parent }) === AstNodeTypes.CALL_EXPRESSION) {\n parent = AstNode.readField({ node: parent, key: 'parent' });\n }\n\n const name = AstNode.readField({\n node: AstNode.readField({ node: parent, key: 'id' }),\n key: 'name',\n });\n\n return AstNode.getType({ node: parent }) === AstNodeTypes.VARIABLE_DECLARATOR &&\n typeof name === 'string'\n ? name\n : undefined;\n }\n\n /** A hook (`useX`), or a component: a PascalCase function that draws JSX. */\n private static isReactFunction(opts: { context: Rule.RuleContext; fn: Rule.Node }): boolean {\n const name = PreferFrameworkApiRule.nameOf({ fn: opts.fn });\n\n if (name === undefined) {\n return false;\n }\n\n return (\n /^use[A-Z0-9]/.test(name) ||\n (/^[A-Z]/.test(name) &&\n PreferFrameworkApiRule.containsJsx({ context: opts.context, node: opts.fn }))\n );\n }\n\n /** Whether `fn` is an argument of a hook call (`useEffect(() => ...)`): the callback runs for the component or the hook. */\n private static isHookCallback(opts: { fn: Rule.Node }): boolean {\n const parent: unknown = AstNode.readField({ node: opts.fn, key: 'parent' });\n const callee = AstNode.readField({ node: parent, key: 'callee' });\n const name =\n AstNode.readField({ node: callee, key: 'name' }) ??\n AstNode.readField({\n node: AstNode.readField({ node: callee, key: 'property' }),\n key: 'name',\n });\n\n return (\n AstNode.getType({ node: parent }) === AstNodeTypes.CALL_EXPRESSION &&\n typeof name === 'string' &&\n /^use[A-Z0-9]/.test(name)\n );\n }\n\n /**\n * Whether `node` is in a component or a hook, which is where a hook can be called. A subscription (a listener, an\n * observer) counts through any handler or helper on the way up: it belongs in a hook. A plain read (`window.innerWidth`,\n * `window.confirm`) counts only in the body of the component or the hook, or in a callback it hands to a hook\n * (`useEffect`, `useMemo`): inside an event handler, or outside every component (a module function, a class), it is a\n * one-off call a hook cannot make.\n */\n private static isInReact(opts: {\n context: Rule.RuleContext;\n node: Rule.Node;\n subscribes: boolean;\n }): boolean {\n const { context, node, subscribes } = opts;\n\n for (const ancestor of [...context.sourceCode.getAncestors(node)].reverse()) {\n const type = AstNode.getType({ node: ancestor });\n\n if (\n type === undefined ||\n !PreferFrameworkApiRule.FUNCTIONS.has(type) ||\n !AstNode.isNode(ancestor)\n ) {\n continue;\n }\n\n if (PreferFrameworkApiRule.isReactFunction({ context, fn: ancestor })) {\n return true;\n }\n\n if (!subscribes && !PreferFrameworkApiRule.isHookCallback({ fn: ancestor })) {\n return false;\n }\n }\n\n return false;\n }\n\n /** A dev tool's own configuration: what it names never reaches a browser or a deployment (a dev server's proxy target). */\n private static readonly DEV_TOOL_CONFIG =\n /(?:^|\\/)(?:vite\\.config\\.[cm]?[jt]s|\\.configs\\/builders\\/.+)$/;\n\n /** The rows that apply in a file of this package: the table and `extra`, less the ignored ones. */\n private static rowsFor(opts: {\n filename: string;\n manifest: IPackageManifest | undefined;\n extra: ReadonlyArray<IFrameworkApiPattern>;\n ignore: ReadonlySet<unknown>;\n }): ReadonlyArray<IFrameworkApiPattern> {\n const { manifest, extra, ignore } = opts;\n const isDevToolConfig = PreferFrameworkApiRule.DEV_TOOL_CONFIG.test(\n opts.filename.replaceAll('\\\\', '/'),\n );\n\n return [...FrameworkApiPatterns.TABLE, ...extra].filter((row) => {\n const { id, dependsOn, owner } = row;\n\n if (isDevToolConfig && id === 'localhost-url') {\n return false;\n }\n\n if (ignore.has(id) || (owner !== undefined && manifest?.name === owner)) {\n return false;\n }\n\n return (\n dependsOn === undefined ||\n (manifest?.dependencies.some((entry) => entry.startsWith(dependsOn)) ?? false)\n );\n });\n }\n\n /** The listeners the rows outside React need, by node type or selector. */\n private static rowListeners(opts: {\n context: Rule.RuleContext;\n rows: ReadonlyArray<IFrameworkApiPattern>;\n }): Array<[string, (node: Rule.Node) => void]> {\n const { context, rows } = opts;\n const listeners: Array<[string, (node: Rule.Node) => void]> = [];\n\n for (const { match, message } of rows) {\n const report = (node: Rule.Node) => {\n context.report({ node, message });\n };\n\n /** Reports a global written as a member path, when `accepts` takes it. */\n const onPath = (given: {\n key: string;\n accepts: (bare: string) => boolean;\n property?: RegExp;\n isReadOnly?: boolean;\n }) => {\n listeners.push([\n AstNodeTypes.MEMBER_EXPRESSION,\n (node) => {\n const path = PreferFrameworkApiRule.pathOf({\n node: given.key === '' ? node : AstNode.readField({ node, key: given.key }),\n });\n\n if (\n path !== undefined &&\n !(given.isReadOnly === true && PreferFrameworkApiRule.isWritten({ node })) &&\n (given.property === undefined ||\n given.property.test(PreferFrameworkApiRule.memberName({ node }))) &&\n given.accepts(PreferFrameworkApiRule.withoutGlobalRoot({ path })) &&\n PreferFrameworkApiRule.isGlobal({ context, node, path })\n ) {\n report(node);\n }\n },\n ]);\n };\n\n switch (match.type) {\n case 'path': {\n onPath({ key: '', accepts: (bare) => match.paths.includes(bare) });\n break;\n }\n\n case 'member': {\n onPath({\n key: 'object',\n accepts: (bare) => match.objects.includes(bare),\n property: match.property === undefined ? undefined : new RegExp(match.property),\n isReadOnly: match.isReadOnly,\n });\n break;\n }\n\n case 'selector': {\n listeners.push([match.selector, report]);\n break;\n }\n\n case 'literal': {\n const pattern = new RegExp(match.pattern);\n\n const check = (node: Rule.Node, text: unknown) => {\n const isWanted =\n match.isFallbackOnly !== true || PreferFrameworkApiRule.isFallback({ node });\n\n if (typeof text === 'string' && isWanted && pattern.test(text)) {\n report(node);\n }\n };\n\n listeners.push([\n AstNodeTypes.LITERAL,\n (node) => check(node, AstNode.readField({ node, key: 'value' })),\n ]);\n listeners.push([\n AstNodeTypes.TEMPLATE_ELEMENT,\n (node) => {\n const value = AstNode.readField({ node, key: 'value' });\n const template: unknown = AstNode.readField({ node, key: 'parent' });\n const parts: unknown = AstNode.readField({ node: template, key: 'quasis' });\n\n // The first part is where a URL starts, and the template is what stands in a position.\n if (AstNode.isNode(template) && Array.isArray(parts) && parts[0] === node) {\n check(template, AstNode.readField({ node: value, key: 'cooked' }));\n }\n },\n ]);\n break;\n }\n\n case 'import': {\n const check = (node: Rule.Node) => {\n const source = AstNode.readField({ node, key: 'source' });\n const name = AstNode.readField({ node: source, key: 'value' });\n\n if (\n typeof name === 'string' &&\n match.sources.includes(name) &&\n !PreferFrameworkApiRule.isTypeOnly({ node })\n ) {\n report(node);\n }\n };\n\n listeners.push([AstNodeTypes.IMPORT_DECLARATION, check]);\n listeners.push([AstNodeTypes.IMPORT_EXPRESSION, check]);\n break;\n }\n\n default: {\n // The other types are hook rows of `BrowserApiPatterns`; as an `extra` row they match nothing here.\n break;\n }\n }\n }\n\n return listeners;\n }\n\n /** The name of `a.name` or `a['name']`; empty for `a[name]`, whose name the file does not state. */\n private static memberName(opts: { node: Rule.Node }): string {\n const property = AstNode.readField({ node: opts.node, key: 'property' });\n const computed = AstNode.readField({ node: opts.node, key: 'computed' }) === true;\n const name = AstNode.readField({ node: property, key: computed ? 'value' : 'name' });\n\n return typeof name === 'string' ? name : '';\n }\n\n /** The field each type of an `extra` row cannot do without. */\n private static readonly ROW_FIELDS = new Map<unknown, string>([\n ['path', 'paths'],\n ['member', 'objects'],\n ['selector', 'selector'],\n ['literal', 'pattern'],\n ['import', 'sources'],\n ]);\n\n /** Whether an `extra` entry is a row this rule can run. The option schema refuses the others before it gets here. */\n private static isRow(value: unknown): value is IFrameworkApiPattern {\n const match = AstNode.readField({ node: value, key: 'match' });\n const field = PreferFrameworkApiRule.ROW_FIELDS.get(AstNode.getType({ node: match }));\n\n return (\n typeof AstNode.readField({ node: value, key: 'id' }) === 'string' &&\n typeof AstNode.readField({ node: value, key: 'message' }) === 'string' &&\n field !== undefined &&\n AstNode.readField({ node: match, key: field }) !== undefined\n );\n }\n\n /** The schema of the `match` of an `extra` row: one shape per type, each with its own field required. */\n private static matchSchema() {\n const text = { type: 'string' } as const;\n const list = { type: 'array', items: text } as const;\n const flag = { type: 'boolean' } as const;\n const shapes: Array<{ type: string; more?: Record<string, typeof text | typeof flag> }> = [\n { type: 'path' },\n { type: 'member', more: { property: text, isReadOnly: flag } },\n { type: 'selector' },\n { type: 'literal', more: { isFallbackOnly: flag } },\n { type: 'import' },\n ];\n\n return {\n oneOf: shapes.map(({ type, more }) => {\n const field = PreferFrameworkApiRule.ROW_FIELDS.get(type) ?? type;\n const isText = type === 'selector' || type === 'literal';\n\n return {\n type: 'object' as const,\n properties: { type: { enum: [type] }, [field]: isText ? text : list, ...more },\n required: ['type', field],\n additionalProperties: false,\n };\n }),\n };\n }\n\n /**\n * Whether `node` is assigned to or deleted, rather than read. A member that a destructuring pattern writes\n * (`[process.env.APP_ENV_A] = values`) counts as a read and is reported.\n */\n private static isWritten(opts: { node: Rule.Node }): boolean {\n const { node } = opts;\n const parent: unknown = AstNode.readField({ node, key: 'parent' });\n const type = AstNode.getType({ node: parent });\n\n if (type === AstNodeTypes.ASSIGNMENT_EXPRESSION) {\n return AstNode.readField({ node: parent, key: 'left' }) === node;\n }\n\n return (\n type === AstNodeTypes.UNARY_EXPRESSION &&\n AstNode.readField({ node: parent, key: 'operator' }) === 'delete'\n );\n }\n\n private static readonly FALLBACK_KEYS = new Set<unknown>(['default', 'defaultValue', 'fallback']);\n\n /** Whether `node` is the value used when another is missing. */\n private static isFallback(opts: { node: Rule.Node }): boolean {\n const { node } = opts;\n const parent: unknown = AstNode.readField({ node, key: 'parent' });\n const type = AstNode.getType({ node: parent });\n const isRight = AstNode.readField({ node: parent, key: 'right' }) === node;\n\n if (type === AstNodeTypes.LOGICAL_EXPRESSION) {\n return isRight && AstNode.readField({ node: parent, key: 'operator' }) !== '&&';\n }\n\n if (type === AstNodeTypes.ASSIGNMENT_PATTERN) {\n return isRight;\n }\n\n if (type === AstNodeTypes.ASSIGNMENT_EXPRESSION) {\n const operator = AstNode.readField({ node: parent, key: 'operator' });\n\n return isRight && (operator === '??=' || operator === '||=');\n }\n\n return (\n type === AstNodeTypes.PROPERTY &&\n AstNode.readField({ node: parent, key: 'value' }) === node &&\n PreferFrameworkApiRule.FALLBACK_KEYS.has(\n AstNode.readField({\n node: AstNode.readField({ node: parent, key: 'key' }),\n key: 'name',\n }),\n )\n );\n }\n\n /** Whether an import declaration brings in types only. */\n private static isTypeOnly(opts: { node: unknown }): boolean {\n const { node } = opts;\n const specifiers: unknown = AstNode.readField({ node, key: 'specifiers' });\n const isType = (item: unknown) =>\n AstNode.readField({ node: item, key: 'importKind' }) === 'type';\n\n return (\n isType(node) ||\n (Array.isArray(specifiers) && specifiers.length > 0 && specifiers.every(isType))\n );\n }\n\n /** One listener object: two rows that visit the same node both run. */\n private static merge(opts: {\n listeners: Array<[string, (node: Rule.Node) => void]>;\n }): Rule.RuleListener {\n const byKey = new Map<string, Array<(node: Rule.Node) => void>>();\n\n for (const [key, listener] of opts.listeners) {\n byKey.set(key, [...(byKey.get(key) ?? []), listener]);\n }\n\n return Object.fromEntries(\n [...byKey].map(([key, all]) => [\n key,\n (node: Rule.Node) => {\n for (const listener of all) {\n listener(node);\n }\n },\n ]),\n );\n }\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n schema: [\n {\n type: 'object',\n properties: {\n hooks: { type: 'boolean' },\n ignore: { type: 'array', items: { type: 'string' } },\n extra: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n id: { type: 'string' },\n message: { type: 'string' },\n dependsOn: { type: 'string' },\n owner: { type: 'string' },\n match: PreferFrameworkApiRule.matchSchema(),\n },\n required: ['id', 'match', 'message'],\n additionalProperties: false,\n },\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n framework:\n \"Use {{hooks}} instead of {{written}}, the hook owns the subscribe and the cleanup: `import { {{name}} } from '{{package}}';`\",\n },\n },\n create: (context) => {\n const manifest = FrameworkExports.manifestFor({ directory: dirname(context.filename) });\n const options: unknown = context.options[0];\n const ignored = AstNode.readField({ node: options, key: 'ignore' });\n const ignore = new Set(Array.isArray(ignored) ? ignored : []);\n const added: unknown = AstNode.readField({ node: options, key: 'extra' });\n const rows = PreferFrameworkApiRule.rowsFor({\n filename: context.filename,\n manifest,\n extra: Array.isArray(added)\n ? added.filter((row: unknown) => PreferFrameworkApiRule.isRow(row))\n : [],\n ignore,\n });\n // The package that ships the hooks writes them with the browser APIs they wrap.\n const patterns =\n AstNode.readField({ node: options, key: 'hooks' }) === false ||\n manifest?.name === BrowserApiPatterns.PACKAGE\n ? []\n : BrowserApiPatterns.TABLE.filter((pattern) => !ignore.has(pattern.id));\n\n const report = (opts: { node: Rule.Node; pattern: IBrowserApiPattern }) => {\n const { node, pattern } = opts;\n const subscribes = pattern.match.type === 'listener' || pattern.match.type === 'new';\n\n if (!PreferFrameworkApiRule.isInReact({ context, node, subscribes })) {\n return;\n }\n\n context.report({\n node,\n messageId: 'framework',\n data: {\n hooks: pattern.hooks,\n // One import line, for the first hook the row suggests (the `useX` words are in backticks).\n name: /`(use\\w+)`/.exec(pattern.hooks)?.[1],\n package: BrowserApiPatterns.PACKAGE,\n written: pattern.written,\n },\n });\n };\n\n const hooks: Record<string, (node: Rule.Node) => void> = {\n // `window.matchMedia`, `window.innerWidth`, `navigator.onLine`, `navigator.clipboard.writeText`...\n [AstNodeTypes.MEMBER_EXPRESSION]: (node: Rule.Node) => {\n const path = PreferFrameworkApiRule.pathOf({ node });\n\n if (path === undefined || !PreferFrameworkApiRule.isGlobal({ context, node, path })) {\n return;\n }\n\n const bare = PreferFrameworkApiRule.withoutGlobalRoot({ path });\n\n for (const pattern of patterns) {\n const { match } = pattern;\n\n if (\n (match.type === 'global' &&\n GLOBAL_OBJECTS.includes(path.split('.')[0] ?? '') &&\n path.split('.').length === 2 &&\n match.names.includes(bare)) ||\n (match.type === 'path' && match.paths.includes(bare))\n ) {\n report({ node, pattern });\n }\n }\n },\n [AstNodeTypes.CALL_EXPRESSION]: (node: Rule.Node) => {\n const callee = AstNode.readField({ node, key: 'callee' });\n const args: unknown = AstNode.readField({ node, key: 'arguments' });\n const first = Array.isArray(args) ? args[0] : undefined;\n const event = AstNode.readField({ node: first, key: 'value' });\n\n // `matchMedia(...)`, `confirm(...)` with no `window.`.\n if (AstNode.getType({ node: callee }) === AstNodeTypes.IDENTIFIER) {\n const name = AstNode.readField({ node: callee, key: 'name' });\n\n for (const pattern of patterns) {\n if (\n pattern.match.type === 'global' &&\n typeof name === 'string' &&\n pattern.match.names.includes(name) &&\n PreferFrameworkApiRule.isGlobal({ context, node, path: name })\n ) {\n report({ node, pattern });\n }\n }\n }\n\n // `<object>.addEventListener('<event>', ...)`.\n const path = PreferFrameworkApiRule.pathOf({ node: callee });\n\n if (path === undefined || typeof event !== 'string') {\n return;\n }\n\n const parts = path.split('.');\n const method = parts.pop();\n const owner = parts.join('.');\n\n if (method !== 'addEventListener') {\n return;\n }\n\n // A listener on a socket, an element or an `EventTarget` of the author's own is not the browser's.\n const isOwnerGlobal =\n owner === '' ||\n (PreferFrameworkApiRule.isGlobal({ context, node, path: owner }) &&\n GLOBAL_TARGETS.includes(owner));\n\n for (const pattern of patterns) {\n const { match } = pattern;\n\n if (\n match.type === 'listener' &&\n match.events.includes(event) &&\n isOwnerGlobal &&\n (match.objects === undefined || owner === '' || match.objects.includes(owner))\n ) {\n report({ node, pattern });\n }\n }\n },\n [AstNodeTypes.NEW_EXPRESSION]: (node: Rule.Node) => {\n const path = PreferFrameworkApiRule.pathOf({\n node: AstNode.readField({ node, key: 'callee' }),\n });\n\n if (path === undefined || !PreferFrameworkApiRule.isGlobal({ context, node, path })) {\n return;\n }\n\n const bare = PreferFrameworkApiRule.withoutGlobalRoot({ path });\n\n for (const pattern of patterns) {\n if (pattern.match.type === 'new' && pattern.match.callees.includes(bare)) {\n report({ node, pattern });\n }\n }\n },\n };\n\n return PreferFrameworkApiRule.merge({\n listeners: [\n ...Object.entries(hooks),\n ...PreferFrameworkApiRule.rowListeners({ context, rows }),\n ],\n });\n },\n };\n\n /**\n * `hooks: false` leaves out the rows of `BrowserApiPatterns`, for code that is not React: a `use...` function of another\n * library reads as a hook. An entry that sets options replaces the earlier ones, so it states `hooks` again.\n */\n static build(\n opts: {\n severity?: TRuleSeverity;\n hooks?: boolean;\n ignore?: ReadonlyArray<string>;\n extra?: ReadonlyArray<IFrameworkApiPattern>;\n } = {},\n ): Linter.RuleEntry {\n const { severity = 'error', hooks, ignore, extra } = opts;\n // Only what was given: the option schema refuses a key whose value is `undefined`.\n const options: Record<string, unknown> = {};\n\n if (hooks !== undefined) {\n options.hooks = hooks;\n }\n\n if (ignore !== undefined) {\n options.ignore = [...ignore];\n }\n\n if (extra !== undefined) {\n options.extra = [...extra];\n }\n\n return Object.keys(options).length === 0 ? [severity] : [severity, options];\n }\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Linter, Rule } from 'eslint';
|
|
2
|
+
import type { TRuleSeverity } from '../rules/common';
|
|
3
|
+
/**
|
|
4
|
+
* `@venizia/prefer-http-method`. An HTTP method written by hand (`method: 'get'`) is `HTTP.Methods.GET`
|
|
5
|
+
* (`@venizia/ignis-helpers/common`). Read where the syntax says it is one: `method`, `verb` or `httpMethod` in a route
|
|
6
|
+
* config or a request, and a variable or parameter of those names.
|
|
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
|
|
11
|
+
* package. `source` is where `HTTP` is imported from; `null` turns the import, and so the fix, off.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PreferHttpMethodRule {
|
|
14
|
+
static readonly NAME = "@venizia/prefer-http-method";
|
|
15
|
+
static readonly DEFAULT_SOURCE = "@venizia/ignis-helpers/common";
|
|
16
|
+
static readonly RULE: Rule.RuleModule;
|
|
17
|
+
static build(opts?: {
|
|
18
|
+
severity?: TRuleSeverity;
|
|
19
|
+
source?: string | null;
|
|
20
|
+
}): Linter.RuleEntry;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=prefer-http-method.rule.d.ts.map
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PreferHttpMethodRule = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const common_1 = require("./common");
|
|
6
|
+
const framework_exports_1 = require("./framework-exports");
|
|
7
|
+
const import_support_1 = require("./import-support");
|
|
8
|
+
/** What makes a string a place where an HTTP method is written, read from the syntax around it. */
|
|
9
|
+
class HttpMethodSites {
|
|
10
|
+
/** The values of `HTTP.Methods`, in any case. */
|
|
11
|
+
static { this.VERB = /^(?:get|post|put|patch|delete|head|options|query)$/i; }
|
|
12
|
+
/** The names a method is held under. */
|
|
13
|
+
static { this.NAMES = new Set(['method', 'verb', 'httpMethod']); }
|
|
14
|
+
/** A property beside `method` that makes its object a route config or a request, not a table of method names. */
|
|
15
|
+
static { this.REQUEST_KEYS = new Set([
|
|
16
|
+
'baseUrl',
|
|
17
|
+
'body',
|
|
18
|
+
'configs',
|
|
19
|
+
'data',
|
|
20
|
+
'headers',
|
|
21
|
+
'path',
|
|
22
|
+
'paths',
|
|
23
|
+
'query',
|
|
24
|
+
'request',
|
|
25
|
+
'responses',
|
|
26
|
+
'signal',
|
|
27
|
+
'url',
|
|
28
|
+
]); }
|
|
29
|
+
/** A call that takes a request init: `fetch`, `fetchFn`, a name ending in `Fetch`, `new Request`. */
|
|
30
|
+
static { this.REQUEST_CALLEE = /^(?:fetch|fetchFn|Request)$|Fetch$/; }
|
|
31
|
+
static field(node, key) {
|
|
32
|
+
return common_1.AstNode.readField({ node, key });
|
|
33
|
+
}
|
|
34
|
+
static nameOf(node) {
|
|
35
|
+
const name = HttpMethodSites.field(node, 'name') ?? HttpMethodSites.field(node, 'value');
|
|
36
|
+
return typeof name === 'string' ? name : undefined;
|
|
37
|
+
}
|
|
38
|
+
/** The strings an expression writes out: itself, either branch of a conditional, either side of `??` and `||`. */
|
|
39
|
+
static literalsOf(node) {
|
|
40
|
+
const type = common_1.AstNode.getType({ node });
|
|
41
|
+
if (type === common_1.AstNodeTypes.LITERAL) {
|
|
42
|
+
return [node];
|
|
43
|
+
}
|
|
44
|
+
if (type === common_1.AstNodeTypes.CONDITIONAL_EXPRESSION) {
|
|
45
|
+
return ['consequent', 'alternate'].flatMap((key) => HttpMethodSites.literalsOf(HttpMethodSites.field(node, key)));
|
|
46
|
+
}
|
|
47
|
+
if (type === common_1.AstNodeTypes.LOGICAL_EXPRESSION) {
|
|
48
|
+
return ['left', 'right'].flatMap((key) => HttpMethodSites.literalsOf(HttpMethodSites.field(node, key)));
|
|
49
|
+
}
|
|
50
|
+
const isWrapped = type === common_1.AstNodeTypes.AS_EXPRESSION || type === common_1.AstNodeTypes.SATISFIES_EXPRESSION;
|
|
51
|
+
return isWrapped ? HttpMethodSites.literalsOf(HttpMethodSites.field(node, 'expression')) : [];
|
|
52
|
+
}
|
|
53
|
+
/** What a fix replaces: the literal, or its `as const`, which TypeScript refuses on a member reference (TS1355). */
|
|
54
|
+
static replaced(node) {
|
|
55
|
+
const parent = HttpMethodSites.field(node, 'parent');
|
|
56
|
+
const annotation = HttpMethodSites.field(parent, 'typeAnnotation');
|
|
57
|
+
const asserted = HttpMethodSites.nameOf(HttpMethodSites.field(annotation, 'typeName'));
|
|
58
|
+
return asserted === 'const' && common_1.AstNode.isNode(parent) ? parent : node;
|
|
59
|
+
}
|
|
60
|
+
/** Whether an object literal is a route config or a request: by a sibling property, or by the call it is passed to. */
|
|
61
|
+
static isRequest(object) {
|
|
62
|
+
const properties = HttpMethodSites.field(object, 'properties');
|
|
63
|
+
const hasSibling = Array.isArray(properties) &&
|
|
64
|
+
properties.some((property) => {
|
|
65
|
+
const key = HttpMethodSites.nameOf(HttpMethodSites.field(property, 'key'));
|
|
66
|
+
return key !== undefined && HttpMethodSites.REQUEST_KEYS.has(key);
|
|
67
|
+
});
|
|
68
|
+
if (hasSibling) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
const parent = HttpMethodSites.field(object, 'parent');
|
|
72
|
+
const callee = HttpMethodSites.field(parent, 'callee');
|
|
73
|
+
const name = HttpMethodSites.nameOf(HttpMethodSites.field(callee, 'property') ?? callee);
|
|
74
|
+
return name !== undefined && HttpMethodSites.REQUEST_CALLEE.test(name);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* `@venizia/prefer-http-method`. An HTTP method written by hand (`method: 'get'`) is `HTTP.Methods.GET`
|
|
79
|
+
* (`@venizia/ignis-helpers/common`). Read where the syntax says it is one: `method`, `verb` or `httpMethod` in a route
|
|
80
|
+
* config or a request, and a variable or parameter of those names.
|
|
81
|
+
*
|
|
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
|
|
85
|
+
* package. `source` is where `HTTP` is imported from; `null` turns the import, and so the fix, off.
|
|
86
|
+
*/
|
|
87
|
+
class PreferHttpMethodRule {
|
|
88
|
+
static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/prefer-http-method`; }
|
|
89
|
+
static { this.DEFAULT_SOURCE = '@venizia/ignis-helpers/common'; }
|
|
90
|
+
static { this.RULE = {
|
|
91
|
+
meta: {
|
|
92
|
+
type: 'suggestion',
|
|
93
|
+
fixable: 'code',
|
|
94
|
+
schema: [
|
|
95
|
+
{
|
|
96
|
+
type: 'object',
|
|
97
|
+
properties: { source: { type: ['string', 'null'] } },
|
|
98
|
+
additionalProperties: false,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
messages: {
|
|
102
|
+
constant: "Write `HTTP.Methods.{{member}}`, not `'{{written}}'`: `import { HTTP } from '{{source}}';`",
|
|
103
|
+
spelling: "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.",
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
create: (context) => {
|
|
107
|
+
const manifest = framework_exports_1.FrameworkExports.manifestFor({ directory: (0, node_path_1.dirname)(context.filename) });
|
|
108
|
+
const isIgnis = manifest?.dependencies.some((name) => name.startsWith('@venizia/ignis'));
|
|
109
|
+
if (isIgnis !== true) {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
const configured = common_1.AstNode.readField({ node: context.options[0], key: 'source' });
|
|
113
|
+
const source = typeof configured === 'string' ? configured : PreferHttpMethodRule.DEFAULT_SOURCE;
|
|
114
|
+
// A package does not import itself by name.
|
|
115
|
+
const isOwner = source.startsWith(`${manifest?.name}/`);
|
|
116
|
+
const check = (value) => {
|
|
117
|
+
for (const node of HttpMethodSites.literalsOf(value)) {
|
|
118
|
+
const written = HttpMethodSites.field(node, 'value');
|
|
119
|
+
if (typeof written !== 'string' ||
|
|
120
|
+
!HttpMethodSites.VERB.test(written) ||
|
|
121
|
+
!common_1.AstNode.isNode(node)) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const member = written.toUpperCase();
|
|
125
|
+
const isExact = written === written.toLowerCase();
|
|
126
|
+
context.report({
|
|
127
|
+
node,
|
|
128
|
+
messageId: isExact ? 'constant' : 'spelling',
|
|
129
|
+
data: { member, written, source },
|
|
130
|
+
fix: (fixer) => {
|
|
131
|
+
if (!isExact || isOwner || configured === null) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const imports = import_support_1.ImportSupport.ensure({
|
|
135
|
+
context,
|
|
136
|
+
fixer,
|
|
137
|
+
name: 'HTTP',
|
|
138
|
+
source,
|
|
139
|
+
isType: false,
|
|
140
|
+
});
|
|
141
|
+
const local = import_support_1.ImportSupport.importedAs({ context, name: 'HTTP', asValue: true }) ?? 'HTTP';
|
|
142
|
+
return imports
|
|
143
|
+
? [
|
|
144
|
+
fixer.replaceText(HttpMethodSites.replaced(node), `${local}.Methods.${member}`),
|
|
145
|
+
...imports,
|
|
146
|
+
]
|
|
147
|
+
: null;
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const checkNamed = (name, value) => {
|
|
153
|
+
const held = HttpMethodSites.nameOf(name);
|
|
154
|
+
if (held !== undefined && HttpMethodSites.NAMES.has(held)) {
|
|
155
|
+
check(value);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
return {
|
|
159
|
+
[common_1.AstNodeTypes.PROPERTY]: (node) => {
|
|
160
|
+
if (HttpMethodSites.isRequest(HttpMethodSites.field(node, 'parent'))) {
|
|
161
|
+
checkNamed(HttpMethodSites.field(node, 'key'), HttpMethodSites.field(node, 'value'));
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
[common_1.AstNodeTypes.VARIABLE_DECLARATOR]: (node) => {
|
|
165
|
+
checkNamed(HttpMethodSites.field(node, 'id'), HttpMethodSites.field(node, 'init'));
|
|
166
|
+
},
|
|
167
|
+
[common_1.AstNodeTypes.ASSIGNMENT_EXPRESSION]: (node) => {
|
|
168
|
+
checkNamed(HttpMethodSites.field(node, 'left'), HttpMethodSites.field(node, 'right'));
|
|
169
|
+
},
|
|
170
|
+
[common_1.AstNodeTypes.ASSIGNMENT_PATTERN]: (node) => {
|
|
171
|
+
checkNamed(HttpMethodSites.field(node, 'left'), HttpMethodSites.field(node, 'right'));
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
}; }
|
|
176
|
+
static build(opts = {}) {
|
|
177
|
+
const { severity = 'error', source } = opts;
|
|
178
|
+
return source === undefined ? [severity] : [severity, { source }];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.PreferHttpMethodRule = PreferHttpMethodRule;
|
|
182
|
+
//# sourceMappingURL=prefer-http-method.rule.js.map
|
|
@@ -0,0 +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,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C,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"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PreferPromiseSleepRule = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const import_support_1 = require("./import-support");
|
|
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
|
|
9
|
+
* does anything else is not a sleep.
|
|
10
|
+
*
|
|
11
|
+
* The fix replaces the expression and adds the import; `source` is where `PromiseUtility` comes from, `null` turns
|
|
12
|
+
* the fix off.
|
|
13
|
+
*/
|
|
14
|
+
class PreferPromiseSleepRule {
|
|
15
|
+
static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/prefer-promise-sleep`; }
|
|
16
|
+
static { this.DEFAULT_SOURCE = '@venizia/ignis-helpers/core'; }
|
|
17
|
+
/** The `setTimeout(<resolve>, <delay>)` call a sleep callback consists of, or `undefined`. */
|
|
18
|
+
static delayOf(opts) {
|
|
19
|
+
const { callback } = opts;
|
|
20
|
+
const type = common_1.AstNode.getType({ node: callback });
|
|
21
|
+
if (type !== common_1.AstNodeTypes.ARROW_FUNCTION_EXPRESSION &&
|
|
22
|
+
type !== common_1.AstNodeTypes.FUNCTION_EXPRESSION) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const params = common_1.AstNode.readField({ node: callback, key: 'params' });
|
|
26
|
+
const [param] = Array.isArray(params) ? params : [];
|
|
27
|
+
if (!Array.isArray(params) ||
|
|
28
|
+
params.length !== 1 ||
|
|
29
|
+
common_1.AstNode.getType({ node: param }) !== common_1.AstNodeTypes.IDENTIFIER) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
let body = common_1.AstNode.readField({ node: callback, key: 'body' });
|
|
33
|
+
if (common_1.AstNode.getType({ node: body }) === common_1.AstNodeTypes.BLOCK_STATEMENT) {
|
|
34
|
+
const statements = common_1.AstNode.readField({ node: body, key: 'body' });
|
|
35
|
+
const [only] = Array.isArray(statements) ? statements : [];
|
|
36
|
+
if (!Array.isArray(statements) || statements.length !== 1) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
body =
|
|
40
|
+
common_1.AstNode.getType({ node: only }) === common_1.AstNodeTypes.EXPRESSION_STATEMENT
|
|
41
|
+
? common_1.AstNode.readField({ node: only, key: 'expression' })
|
|
42
|
+
: undefined;
|
|
43
|
+
}
|
|
44
|
+
const callee = common_1.AstNode.readField({ node: body, key: 'callee' });
|
|
45
|
+
const args = common_1.AstNode.readField({ node: body, key: 'arguments' });
|
|
46
|
+
if (common_1.AstNode.getType({ node: body }) !== common_1.AstNodeTypes.CALL_EXPRESSION ||
|
|
47
|
+
common_1.AstNode.readField({ node: callee, key: 'name' }) !== 'setTimeout' ||
|
|
48
|
+
!Array.isArray(args) ||
|
|
49
|
+
args.length !== 2) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const [resolver, delay] = args;
|
|
53
|
+
const isResolver = common_1.AstNode.getType({ node: resolver }) === common_1.AstNodeTypes.IDENTIFIER &&
|
|
54
|
+
common_1.AstNode.readField({ node: resolver, key: 'name' }) ===
|
|
55
|
+
common_1.AstNode.readField({ node: param, key: 'name' });
|
|
56
|
+
return isResolver && common_1.AstNode.isNode(delay) ? delay : undefined;
|
|
57
|
+
}
|
|
58
|
+
/** `PromiseUtility.sleep({ ms })`, with the shorthand when the delay is a variable named `ms`. */
|
|
59
|
+
static call(opts) {
|
|
60
|
+
const { context, delay } = opts;
|
|
61
|
+
const utility = import_support_1.ImportSupport.importedAs({ context, name: 'PromiseUtility', asValue: true }) ??
|
|
62
|
+
'PromiseUtility';
|
|
63
|
+
const text = context.sourceCode.getText(delay);
|
|
64
|
+
return `${utility}.sleep({ ${text === 'ms' ? 'ms' : `ms: ${text}`} })`;
|
|
65
|
+
}
|
|
66
|
+
/** Whether `setTimeout` at `node` resolves to a binding of the file (not the global timer). */
|
|
67
|
+
static isRebound(opts) {
|
|
68
|
+
const { context, node } = opts;
|
|
69
|
+
let scope = context.sourceCode.getScope(node);
|
|
70
|
+
while (scope) {
|
|
71
|
+
const variable = scope.set.get('setTimeout');
|
|
72
|
+
if (variable && variable.defs.length > 0) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
scope = scope.upper;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
static { this.RULE = {
|
|
80
|
+
meta: {
|
|
81
|
+
type: 'suggestion',
|
|
82
|
+
fixable: 'code',
|
|
83
|
+
schema: [
|
|
84
|
+
{
|
|
85
|
+
type: 'object',
|
|
86
|
+
properties: { source: { type: ['string', 'null'] } },
|
|
87
|
+
additionalProperties: false,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
messages: {
|
|
91
|
+
sleep: "Use `await PromiseUtility.sleep({ ms })`, not a hand-written `new Promise(resolve => setTimeout(resolve, ms))`: `import { PromiseUtility } from '{{source}}';`",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
create: (context) => {
|
|
95
|
+
const options = context.options[0];
|
|
96
|
+
const configured = common_1.AstNode.readField({ node: options, key: 'source' });
|
|
97
|
+
const source = configured === null
|
|
98
|
+
? undefined
|
|
99
|
+
: typeof configured === 'string'
|
|
100
|
+
? configured
|
|
101
|
+
: PreferPromiseSleepRule.DEFAULT_SOURCE;
|
|
102
|
+
return {
|
|
103
|
+
[common_1.AstNodeTypes.NEW_EXPRESSION]: (node) => {
|
|
104
|
+
const callee = common_1.AstNode.readField({ node, key: 'callee' });
|
|
105
|
+
const args = common_1.AstNode.readField({ node, key: 'arguments' });
|
|
106
|
+
if (common_1.AstNode.readField({ node: callee, key: 'name' }) !== 'Promise' ||
|
|
107
|
+
!Array.isArray(args) ||
|
|
108
|
+
args.length !== 1) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const delay = PreferPromiseSleepRule.delayOf({ callback: args[0] });
|
|
112
|
+
if (delay === undefined) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// A `setTimeout` the file binds itself (a parameter, a local, an import) is not the timer, and a comma expression is
|
|
116
|
+
// not one delay: neither is a sleep.
|
|
117
|
+
if (PreferPromiseSleepRule.isRebound({ context, node }) ||
|
|
118
|
+
common_1.AstNode.getType({ node: delay }) === common_1.AstNodeTypes.SEQUENCE_EXPRESSION) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
context.report({
|
|
122
|
+
node,
|
|
123
|
+
messageId: 'sleep',
|
|
124
|
+
data: { source: source ?? PreferPromiseSleepRule.DEFAULT_SOURCE },
|
|
125
|
+
fix: (fixer) => {
|
|
126
|
+
if (source === undefined &&
|
|
127
|
+
!import_support_1.ImportSupport.isInScope({ context, name: 'PromiseUtility' })) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const imports = import_support_1.ImportSupport.ensure({
|
|
131
|
+
context,
|
|
132
|
+
fixer,
|
|
133
|
+
name: 'PromiseUtility',
|
|
134
|
+
source: source ?? PreferPromiseSleepRule.DEFAULT_SOURCE,
|
|
135
|
+
isType: false,
|
|
136
|
+
});
|
|
137
|
+
return imports
|
|
138
|
+
? [
|
|
139
|
+
fixer.replaceText(node, PreferPromiseSleepRule.call({ context, delay })),
|
|
140
|
+
...imports,
|
|
141
|
+
]
|
|
142
|
+
: null;
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
}; }
|
|
149
|
+
static build(opts = {}) {
|
|
150
|
+
const { severity = 'error', source } = opts;
|
|
151
|
+
return source === undefined ? [severity] : [severity, { source }];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.PreferPromiseSleepRule = PreferPromiseSleepRule;
|
|
155
|
+
//# sourceMappingURL=prefer-promise-sleep.rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,MAAM,GAAY,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,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B,EACrE,CAAC;wBACD,OAAO;oBACT,CAAC;oBAED,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI;wBACJ,SAAS,EAAE,OAAO;wBAClB,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,IAAI,sBAAsB,CAAC,cAAc,EAAE;wBACjE,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE;4BACb,IACE,MAAM,KAAK,SAAS;gCACpB,CAAC,8BAAa,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,EAC7D,CAAC;gCACD,OAAO,IAAI,CAAC;4BACd,CAAC;4BAED,MAAM,OAAO,GAAG,8BAAa,CAAC,MAAM,CAAC;gCACnC,OAAO;gCACP,KAAK;gCACL,IAAI,EAAE,gBAAgB;gCACtB,MAAM,EAAE,MAAM,IAAI,sBAAsB,CAAC,cAAc;gCACvD,MAAM,EAAE,KAAK;6BACd,CAAC,CAAC;4BAEH,OAAO,OAAO;gCACZ,CAAC,CAAC;oCACE,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,sBAAsB,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;oCACxE,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;;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"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Linter, Rule } from 'eslint';
|
|
2
|
+
import type { TRuleSeverity } from '../rules/common';
|
|
3
|
+
/**
|
|
4
|
+
* `@venizia/prefer-tnullable`. `X | null | undefined` is `TNullable<X>`, the framework's own name for it
|
|
5
|
+
* (`@venizia/ignis-helpers/common`). A union with only `null` or only `undefined` is not reported: those say
|
|
6
|
+
* something different.
|
|
7
|
+
*
|
|
8
|
+
* The fix rewrites the union and adds the import. `source` is where `TNullable` comes from (default the helpers
|
|
9
|
+
* `common` entry); `null` turns the import, and so the fix, off for a project that has no such package.
|
|
10
|
+
*/
|
|
11
|
+
export declare class PreferTNullableRule {
|
|
12
|
+
static readonly NAME = "@venizia/prefer-tnullable";
|
|
13
|
+
static readonly DEFAULT_SOURCE = "@venizia/ignis-helpers/common";
|
|
14
|
+
/**
|
|
15
|
+
* The source of a union member with the parentheses that belong to it: a function, constructor or conditional type is
|
|
16
|
+
* written `(...)` inside a union, and the member text alone (`() => void`) would change the type or not parse.
|
|
17
|
+
*/
|
|
18
|
+
private static textOf;
|
|
19
|
+
static readonly RULE: Rule.RuleModule;
|
|
20
|
+
static build(opts?: {
|
|
21
|
+
severity?: TRuleSeverity;
|
|
22
|
+
source?: string | null;
|
|
23
|
+
}): Linter.RuleEntry;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=prefer-tnullable.rule.d.ts.map
|