@venizia/dev-configs 0.5.0-7 → 0.5.0-9
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 +15 -11
- 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.d.ts +0 -1
- package/dist/cli/check.js +42 -68
- 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.js +13 -12
- 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 +17 -16
- package/dist/cli/codemod/async-style.js.map +1 -1
- package/dist/cli/codemod/binding-keys.js +14 -13
- package/dist/cli/codemod/binding-keys.js.map +1 -1
- package/dist/cli/codemod/class-renames.d.ts +1 -1
- package/dist/cli/codemod/class-renames.js +30 -11
- package/dist/cli/codemod/class-renames.js.map +1 -1
- package/dist/cli/codemod/connector-imports.js +12 -11
- package/dist/cli/codemod/connector-imports.js.map +1 -1
- package/dist/cli/codemod/const-classes.d.ts +1 -1
- package/dist/cli/codemod/const-classes.js +21 -20
- 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 +18 -17
- package/dist/cli/codemod/env-get.js.map +1 -1
- package/dist/cli/codemod/files.js +2 -2
- 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 +19 -4
- package/dist/cli/codemod/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/index.js +13 -12
- package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
- package/dist/cli/codemod/typed-route-context.d.ts +27 -0
- package/dist/cli/codemod/typed-route-context.js +570 -0
- package/dist/cli/codemod/typed-route-context.js.map +1 -0
- package/dist/cli/index.js +5 -5
- 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 +1 -3
- package/dist/linters/house/browser-api-patterns.js +1 -3
- package/dist/linters/house/browser-api-patterns.js.map +1 -1
- package/dist/linters/house/common.d.ts +8 -2
- package/dist/linters/house/common.js +8 -2
- package/dist/linters/house/common.js.map +1 -1
- package/dist/linters/house/configs.js +8 -6
- 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 +1 -1
- package/dist/linters/house/framework-exports.js +13 -13
- package/dist/linters/house/framework-exports.js.map +1 -1
- package/dist/linters/house/index.d.ts +3 -4
- package/dist/linters/house/index.js +4 -6
- 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 +5 -2
- package/dist/linters/house/no-parent-import.rule.js +5 -2
- package/dist/linters/house/no-parent-import.rule.js.map +1 -1
- 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 +2 -2
- package/dist/linters/house/no-shadow-framework-type.rule.js +2 -2
- package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -1
- 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 +6 -5
- package/dist/linters/house/plugin.js.map +1 -1
- package/dist/linters/house/prefer-framework-api.rule.d.ts +39 -7
- package/dist/linters/house/prefer-framework-api.rule.js +285 -12
- package/dist/linters/house/prefer-framework-api.rule.js.map +1 -1
- package/dist/linters/house/prefer-promise-sleep.rule.d.ts +2 -2
- package/dist/linters/house/prefer-promise-sleep.rule.js +3 -2
- package/dist/linters/house/prefer-promise-sleep.rule.js.map +1 -1
- package/dist/linters/house/prefer-tnullable.rule.d.ts +2 -2
- package/dist/linters/house/prefer-tnullable.rule.js +2 -2
- package/dist/linters/house/prefer-tnullable.rule.js.map +1 -1
- package/dist/linters/house/typed-route-context.rule.d.ts +19 -0
- package/dist/linters/house/typed-route-context.rule.js +322 -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/spawn.utility.js +1 -1
- package/dist/testing/spawn.utility.js.map +1 -1
- package/package.json +5 -5
- package/dist/checks/use-when-baseline.d.ts +0 -25
- package/dist/checks/use-when-baseline.js +0 -38
- package/dist/checks/use-when-baseline.js.map +0 -1
- package/dist/linters/house/framework-rule-apis.d.ts +0 -24
- package/dist/linters/house/framework-rule-apis.js +0 -48
- package/dist/linters/house/framework-rule-apis.js.map +0 -1
- package/dist/linters/house/public-surface.d.ts +0 -57
- package/dist/linters/house/public-surface.js +0 -174
- package/dist/linters/house/public-surface.js.map +0 -1
- package/dist/linters/house/published-package-configs.d.ts +0 -23
- package/dist/linters/house/published-package-configs.js +0 -42
- package/dist/linters/house/published-package-configs.js.map +0 -1
- package/dist/linters/house/require-use-when.rule.d.ts +0 -42
- package/dist/linters/house/require-use-when.rule.js +0 -175
- package/dist/linters/house/require-use-when.rule.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import type { TRuleSeverity } from '../rules/common';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* `@venizia/no-silent-catch`. A handled error leaves a trace (V-C-06). Reported: a `.catch(h)` (also `?.catch`,
|
|
5
5
|
* `['catch']`) whose handler is an arrow or function expression that ignores its parameter and whose body is empty
|
|
6
6
|
* or only gives back a constant (`() => null`, `() => undefined`, `() => ({})`, `() => []`, `() => {}`,
|
|
7
7
|
* `function () {}`), and a `catch` block that is empty, holds only a comment, or only assigns or returns a constant
|
|
@@ -13,7 +13,7 @@ import type { TRuleSeverity } from '../rules/common';
|
|
|
13
13
|
* log is a decision. A deliberate silent catch carries an `eslint-disable-next-line` with its reason.
|
|
14
14
|
*/
|
|
15
15
|
export declare class NoSilentCatchRule {
|
|
16
|
-
static readonly NAME = "venizia/no-silent-catch";
|
|
16
|
+
static readonly NAME = "@venizia/no-silent-catch";
|
|
17
17
|
static readonly RULE: Rule.RuleModule;
|
|
18
18
|
static build(opts?: {
|
|
19
19
|
severity?: TRuleSeverity;
|
|
@@ -13,7 +13,7 @@ const isPlainParameter = (opts) => opts.parameter === null ||
|
|
|
13
13
|
opts.parameter === undefined ||
|
|
14
14
|
common_1.AstNode.getType({ node: opts.parameter }) === common_1.AstNodeTypes.IDENTIFIER;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* `@venizia/no-silent-catch`. A handled error leaves a trace (V-C-06). Reported: a `.catch(h)` (also `?.catch`,
|
|
17
17
|
* `['catch']`) whose handler is an arrow or function expression that ignores its parameter and whose body is empty
|
|
18
18
|
* or only gives back a constant (`() => null`, `() => undefined`, `() => ({})`, `() => []`, `() => {}`,
|
|
19
19
|
* `function () {}`), and a `catch` block that is empty, holds only a comment, or only assigns or returns a constant
|
|
@@ -31,8 +31,8 @@ class NoSilentCatchRule {
|
|
|
31
31
|
type: 'suggestion',
|
|
32
32
|
schema: [],
|
|
33
33
|
messages: {
|
|
34
|
-
silentHandler:
|
|
35
|
-
silentBlock:
|
|
34
|
+
silentHandler: "This `.catch` handler swallows the error with no trace: rethrow it, wrap it or log it (V-C-06), as in `LoggerFactory.getLogger(['scope']).error('Failed | Error: %o', error)`: `import { LoggerFactory } from '@venizia/ignis-helpers/core';`",
|
|
35
|
+
silentBlock: "This `catch` block swallows the error with no trace: rethrow it, wrap it or log it (V-C-06), as in `LoggerFactory.getLogger(['scope']).error('Failed | Error: %o', error)`: `import { LoggerFactory } from '@venizia/ignis-helpers/core';`",
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
38
|
create: (context) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-silent-catch.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-silent-catch.rule.ts"],"names":[],"mappings":";;;AAEA,mDAA+C;AAC/C,qCAAyE;AACzE,mEAA8D;AAE9D,iGAAiG;AACjG,MAAM,eAAe,GAAG,CAAC,IAAkD,EAAW,EA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,CAAC,qBAAY,CAAC,YAAY,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE;oBAC/C,IACE,CAAC,gBAAgB,CAAC,EAAE,SAAS,EAAE,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;wBAC3E,eAAe,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAC5C,CAAC;wBACD,OAAO;oBACT,CAAC;oBAED,MAAM,IAAI,GAAG,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;oBAEtD,IACE,2CAAmB,CAAC,aAAa,CAAC;wBAChC,UAAU,EAAE,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;qBAC3D,CAAC,EACF,CAAC;wBACD,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;oBACrD,CAAC;gBACH,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAClC,CAAC;;AAjFH,8CAkFC","sourcesContent":["import type { Rule, SourceCode } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AwaitSupport } from './await-support';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { PromiseChainSupport } from './promise-chain-support';\n\n/** Whether a parameter of `owner` (a function or a catch clause) is read or written anywhere. */\nconst isParameterUsed = (opts: { owner: Rule.Node; sourceCode: SourceCode }): boolean =>\n opts.sourceCode\n .getDeclaredVariables(opts.owner)\n .some(\n (variable) =>\n variable.defs.some((definition) =>\n ['Parameter', AstNodeTypes.CATCH_CLAUSE].includes(definition.type),\n ) && variable.references.length > 0,\n );\n\n/** A parameter that is not a plain name (`({ message }) =>`, `catch ({ message })`) reads the error by itself. */\nconst isPlainParameter = (opts: { parameter: unknown }): boolean =>\n opts.parameter === null ||\n opts.parameter === undefined ||\n AstNode.getType({ node: opts.parameter }) === AstNodeTypes.IDENTIFIER;\n\n/**\n * `@venizia/no-silent-catch`. A handled error leaves a trace (V-C-06). Reported: a `.catch(h)` (also `?.catch`,\n * `['catch']`) whose handler is an arrow or function expression that ignores its parameter and whose body is empty\n * or only gives back a constant (`() => null`, `() => undefined`, `() => ({})`, `() => []`, `() => {}`,\n * `function () {}`), and a `catch` block that is empty, holds only a comment, or only assigns or returns a constant\n * without reading the error. Handled, and not reported: anything that reads the error (logs, wraps or rethrows\n * it), makes any call (a log, a cleanup, a fallback), throws, or reads another variable.\n *\n * It is not ESLint's `no-empty`: `no-empty` reports an empty block only, lets a block that holds a comment pass,\n * and never sees `.catch(() => null)`. Both report `catch {}`, each with its own message. There is no fix: what to\n * log is a decision. A deliberate silent catch carries an `eslint-disable-next-line` with its reason.\n */\nexport class NoSilentCatchRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-silent-catch`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n schema: [],\n messages: {\n silentHandler:\n \"This `.catch` handler swallows the error with no trace: rethrow it, wrap it or log it (V-C-06), as in `LoggerFactory.getLogger(['scope']).error('Failed | Error: %o', error)`: `import { LoggerFactory } from '@venizia/ignis-helpers/core';`\",\n silentBlock:\n \"This `catch` block swallows the error with no trace: rethrow it, wrap it or log it (V-C-06), as in `LoggerFactory.getLogger(['scope']).error('Failed | Error: %o', error)`: `import { LoggerFactory } from '@venizia/ignis-helpers/core';`\",\n },\n },\n create: (context) => {\n const { sourceCode } = context;\n\n return {\n [AstNodeTypes.CALL_EXPRESSION]: (node: Rule.Node) => {\n if (PromiseChainSupport.chainMethodOf({ node }) !== 'catch') {\n return;\n }\n\n const args = AstNode.readField({ node, key: 'arguments' });\n const handler: unknown = Array.isArray(args) ? args[0] : undefined;\n const handlerType = AstNode.getType({ node: handler });\n\n if (\n !AwaitSupport.isNode(handler) ||\n (handlerType !== AstNodeTypes.ARROW_FUNCTION_EXPRESSION &&\n handlerType !== AstNodeTypes.FUNCTION_EXPRESSION)\n ) {\n return;\n }\n\n const params = AstNode.readField({ node: handler, key: 'params' });\n\n if (\n !Array.isArray(params) ||\n !params.every((parameter) => isPlainParameter({ parameter })) ||\n isParameterUsed({ owner: handler, sourceCode })\n ) {\n return;\n }\n\n const body = AstNode.readField({ node: handler, key: 'body' });\n const isSilent =\n AstNode.getType({ node: body }) === AstNodeTypes.BLOCK_STATEMENT\n ? PromiseChainSupport.isSilentBlock({\n statements: AstNode.readField({ node: body, key: 'body' }),\n })\n : PromiseChainSupport.isConstant({ node: body });\n\n if (isSilent) {\n context.report({ node: handler, messageId: 'silentHandler' });\n }\n },\n [AstNodeTypes.CATCH_CLAUSE]: (node: Rule.Node) => {\n if (\n !isPlainParameter({ parameter: AstNode.readField({ node, key: 'param' }) }) ||\n isParameterUsed({ owner: node, sourceCode })\n ) {\n return;\n }\n\n const body = AstNode.readField({ node, key: 'body' });\n\n if (\n PromiseChainSupport.isSilentBlock({\n statements: AstNode.readField({ node: body, key: 'body' }),\n })\n ) {\n context.report({ node, messageId: 'silentBlock' });\n }\n },\n };\n },\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): TRuleSeverity {\n return opts.severity ?? 'error';\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Linter, Rule } from 'eslint';
|
|
2
2
|
import type { TRuleSeverity } from '../rules/common';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* `@venizia/no-unbraced-case`: the statements of a `case` or `default` sit in one block, `case 'a': { ... }`.
|
|
5
5
|
* It is the ESLint twin of oxlint's `unicorn/switch-case-braces` (`SwitchCaseBracesRule`, mode `always`).
|
|
6
6
|
* Stacked labels with no statements stay as written. The fix wraps the statements in `{ }`.
|
|
7
7
|
*/
|
|
8
8
|
export declare class NoUnbracedCaseRule {
|
|
9
|
-
static readonly NAME = "venizia/no-unbraced-case";
|
|
9
|
+
static readonly NAME = "@venizia/no-unbraced-case";
|
|
10
10
|
static readonly RULE: Rule.RuleModule;
|
|
11
11
|
static build(opts?: {
|
|
12
12
|
severity?: TRuleSeverity;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NoUnbracedCaseRule = void 0;
|
|
4
4
|
const common_1 = require("./common");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* `@venizia/no-unbraced-case`: the statements of a `case` or `default` sit in one block, `case 'a': { ... }`.
|
|
7
7
|
* It is the ESLint twin of oxlint's `unicorn/switch-case-braces` (`SwitchCaseBracesRule`, mode `always`).
|
|
8
8
|
* Stacked labels with no statements stay as written. The fix wraps the statements in `{ }`.
|
|
9
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-unbraced-case.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-unbraced-case.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AAEzE;;;;GAIG;AACH,MAAa,kBAAkB;aACb,SAAI,GAAG,GAAG,+BAAsB,mBAAmB,CAAC;aAEpD,SAAI,GAAoB;QACtC,IAAI,EAAE;YACJ,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,MAAM;YACf,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,EAAE,QAAQ,EAAE,iEAAiE,EAAE;SAC1F;QACD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACpB,CAAC,qBAAY,CAAC,WAAW,CAAC,EAAE,CAAC,IAAe,EAAE,EAAE;gBAC9C,MAAM,UAAU,GAAY,gBAAO,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC;gBAE3E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAC1D,OAAO;gBACT,CAAC;gBAED,MAAM,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC;gBAC3B,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;gBAE/C,IACE,UAAU,CAAC,MAAM,KAAK,CAAC;oBACvB,gBAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,KAAK,qBAAY,CAAC,eAAe,EACjE,CAAC;oBACD,OAAO;gBACT,CAAC;gBAED,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,SAAS,EAAE,UAAU;oBACrB,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;iBACzF,CAAC,CAAC;YACL,CAAC;SACF,CAAC;KACH,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,OAAqC,EAAE;QAClD,MAAM,EAAE,QAAQ,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC;QAEpC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;;AAzCH,gDA0CC","sourcesContent":["import type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"no-unbraced-case.rule.js","sourceRoot":"","sources":["../../../src/linters/house/no-unbraced-case.rule.ts"],"names":[],"mappings":";;;AAEA,qCAAyE;AAEzE;;;;GAIG;AACH,MAAa,kBAAkB;aACb,SAAI,GAAG,GAAG,+BAAsB,mBAAmB,CAAC;aAEpD,SAAI,GAAoB;QACtC,IAAI,EA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;;AAzCH,gDA0CC","sourcesContent":["import type { Linter, Rule } from 'eslint';\nimport type { TRuleSeverity } from '../rules/common';\nimport { AstNode, AstNodeTypes, HOUSE_PLUGIN_NAMESPACE } from './common';\n\n/**\n * `@venizia/no-unbraced-case`: the statements of a `case` or `default` sit in one block, `case 'a': { ... }`.\n * It is the ESLint twin of oxlint's `unicorn/switch-case-braces` (`SwitchCaseBracesRule`, mode `always`).\n * Stacked labels with no statements stay as written. The fix wraps the statements in `{ }`.\n */\nexport class NoUnbracedCaseRule {\n static readonly NAME = `${HOUSE_PLUGIN_NAMESPACE}/no-unbraced-case`;\n\n static readonly RULE: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n fixable: 'code',\n schema: [],\n messages: { unbraced: 'Wrap the statements of this case in a block: `case x: { ... }`.' },\n },\n create: (context) => ({\n [AstNodeTypes.SWITCH_CASE]: (node: Rule.Node) => {\n const statements: unknown = AstNode.readField({ node, key: 'consequent' });\n\n if (!Array.isArray(statements) || statements.length === 0) {\n return;\n }\n\n const [first] = statements;\n const last = statements[statements.length - 1];\n\n if (\n statements.length === 1 &&\n AstNode.getType({ node: first }) === AstNodeTypes.BLOCK_STATEMENT\n ) {\n return;\n }\n\n context.report({\n node,\n messageId: 'unbraced',\n fix: (fixer) => [fixer.insertTextBefore(first, '{ '), fixer.insertTextAfter(last, ' }')],\n });\n },\n }),\n };\n\n static build(opts: { severity?: TRuleSeverity } = {}): Linter.RuleEntry {\n const { severity = 'error' } = opts;\n\n return [severity];\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ESLint } from 'eslint';
|
|
2
|
-
/** The ESLint plugin that carries the house rules oxlint cannot express, registered as
|
|
2
|
+
/** The ESLint plugin that carries the house rules oxlint cannot express, registered as `@venizia`. */
|
|
3
3
|
export declare const houseEslintPlugin: ESLint.Plugin;
|
|
4
4
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -19,10 +19,11 @@ const no_unbraced_case_rule_1 = require("./no-unbraced-case.rule");
|
|
|
19
19
|
const prefer_framework_api_rule_1 = require("./prefer-framework-api.rule");
|
|
20
20
|
const prefer_promise_sleep_rule_1 = require("./prefer-promise-sleep.rule");
|
|
21
21
|
const prefer_tnullable_rule_1 = require("./prefer-tnullable.rule");
|
|
22
|
-
const
|
|
23
|
-
|
|
22
|
+
const typed_route_context_rule_1 = require("./typed-route-context.rule");
|
|
23
|
+
const zod_schema_convention_rule_1 = require("./zod-schema-convention.rule");
|
|
24
|
+
/** The ESLint plugin that carries the house rules oxlint cannot express, registered as `@venizia`. */
|
|
24
25
|
exports.houseEslintPlugin = {
|
|
25
|
-
meta: { name:
|
|
26
|
+
meta: { name: `${common_1.HOUSE_PLUGIN_NAMESPACE}/eslint-plugin` },
|
|
26
27
|
rules: {
|
|
27
28
|
'const-class-values': const_class_values_rule_1.ConstClassValuesRule.RULE,
|
|
28
29
|
'effect-cleanup-consistency': effect_cleanup_consistency_rule_1.EffectCleanupConsistencyRule.RULE,
|
|
@@ -38,11 +39,11 @@ exports.houseEslintPlugin = {
|
|
|
38
39
|
'no-shadow-framework-type': no_shadow_framework_type_rule_1.NoShadowFrameworkTypeRule.RULE,
|
|
39
40
|
'no-silent-catch': no_silent_catch_rule_1.NoSilentCatchRule.RULE,
|
|
40
41
|
'no-unbraced-case': no_unbraced_case_rule_1.NoUnbracedCaseRule.RULE,
|
|
41
|
-
'pending-use-when': require_use_when_rule_1.RequireUseWhenRule.PENDING_RULE,
|
|
42
42
|
'prefer-framework-api': prefer_framework_api_rule_1.PreferFrameworkApiRule.RULE,
|
|
43
43
|
'prefer-promise-sleep': prefer_promise_sleep_rule_1.PreferPromiseSleepRule.RULE,
|
|
44
44
|
'prefer-tnullable': prefer_tnullable_rule_1.PreferTNullableRule.RULE,
|
|
45
|
-
'
|
|
45
|
+
'typed-route-context': typed_route_context_rule_1.TypedRouteContextRule.RULE,
|
|
46
|
+
'zod-schema-convention': zod_schema_convention_rule_1.ZodSchemaConventionRule.RULE,
|
|
46
47
|
},
|
|
47
48
|
};
|
|
48
49
|
//# sourceMappingURL=plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/linters/house/plugin.ts"],"names":[],"mappings":";;;AACA,qCAAkD;AAClD,uEAAiE;AACjE,uFAAiF;AACjF,+DAAyD;AACzD,+EAAwE;AACxE,uEAAgE;AAChE,+EAAwE;AACxE,iEAA2D;AAC3D,mEAA6D;AAC7D,2DAAqD;AACrD,mEAA6D;AAC7D,iEAA2D;AAC3D,mFAA4E;AAC5E,iEAA2D;AAC3D,mEAA6D;AAC7D,2EAAqE;AACrE,2EAAqE;AACrE,mEAA8D;AAC9D,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/linters/house/plugin.ts"],"names":[],"mappings":";;;AACA,qCAAkD;AAClD,uEAAiE;AACjE,uFAAiF;AACjF,+DAAyD;AACzD,+EAAwE;AACxE,uEAAgE;AAChE,+EAAwE;AACxE,iEAA2D;AAC3D,mEAA6D;AAC7D,2DAAqD;AACrD,mEAA6D;AAC7D,iEAA2D;AAC3D,mFAA4E;AAC5E,iEAA2D;AAC3D,mEAA6D;AAC7D,2EAAqE;AACrE,2EAAqE;AACrE,mEAA8D;AAC9D,yEAAmE;AACnE,6EAAuE;AAEvE,sGAAsG;AACzF,QAAA,iBAAiB,GAAkB;IAC9C,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,+BAAsB,gBAAgB,EAAE;IACzD,KAAK,EAAE;QACL,oBAAoB,EAAE,8CAAoB,CAAC,IAAI;QAC/C,4BAA4B,EAAE,8DAA4B,CAAC,IAAI;QAC/D,gBAAgB,EAAE,sCAAgB,CAAC,IAAI;QACvC,wBAAwB,EAAE,qDAAuB,CAAC,IAAI;QACtD,oBAAoB,EAAE,6CAAmB,CAAC,IAAI;QAC9C,wBAAwB,EAAE,qDAAuB,CAAC,IAAI;QACtD,iBAAiB,EAAE,wCAAiB,CAAC,IAAI;QACzC,kBAAkB,EAAE,0CAAkB,CAAC,IAAI;QAC3C,cAAc,EAAE,kCAAc,CAAC,IAAI;QACnC,kBAAkB,EAAE,0CAAkB,CAAC,IAAI;QAC3C,iBAAiB,EAAE,wCAAiB,CAAC,IAAI;QACzC,0BAA0B,EAAE,yDAAyB,CAAC,IAAI;QAC1D,iBAAiB,EAAE,wCAAiB,CAAC,IAAI;QACzC,kBAAkB,EAAE,0CAAkB,CAAC,IAAI;QAC3C,sBAAsB,EAAE,kDAAsB,CAAC,IAAI;QACnD,sBAAsB,EAAE,kDAAsB,CAAC,IAAI;QACnD,kBAAkB,EAAE,2CAAmB,CAAC,IAAI;QAC5C,qBAAqB,EAAE,gDAAqB,CAAC,IAAI;QACjD,uBAAuB,EAAE,oDAAuB,CAAC,IAAI;KACtD;CACF,CAAC","sourcesContent":["import type { ESLint } from 'eslint';\nimport { HOUSE_PLUGIN_NAMESPACE } from './common';\nimport { ConstClassValuesRule } from './const-class-values.rule';\nimport { EffectCleanupConsistencyRule } from './effect-cleanup-consistency.rule';\nimport { MaxParamsOwnRule } from './max-params-own.rule';\nimport { NoAsyncHookCallbackRule } from './no-async-hook-callback.rule';\nimport { NoAwaitNewChainRule } from './no-await-new-chain.rule';\nimport { NoAwaitPromiseChainRule } from './no-await-promise-chain.rule';\nimport { NoInlineAwaitRule } from './no-inline-await.rule';\nimport { NoLeakedRenderRule } from './no-leaked-render.rule';\nimport { NoNewErrorRule } from './no-new-error.rule';\nimport { NoParentImportRule } from './no-parent-import.rule';\nimport { NoReturnAwaitRule } from './no-return-await.rule';\nimport { NoShadowFrameworkTypeRule } from './no-shadow-framework-type.rule';\nimport { NoSilentCatchRule } from './no-silent-catch.rule';\nimport { NoUnbracedCaseRule } from './no-unbraced-case.rule';\nimport { PreferFrameworkApiRule } from './prefer-framework-api.rule';\nimport { PreferPromiseSleepRule } from './prefer-promise-sleep.rule';\nimport { PreferTNullableRule } from './prefer-tnullable.rule';\nimport { TypedRouteContextRule } from './typed-route-context.rule';\nimport { ZodSchemaConventionRule } from './zod-schema-convention.rule';\n\n/** The ESLint plugin that carries the house rules oxlint cannot express, registered as `@venizia`. */\nexport const houseEslintPlugin: ESLint.Plugin = {\n meta: { name: `${HOUSE_PLUGIN_NAMESPACE}/eslint-plugin` },\n rules: {\n 'const-class-values': ConstClassValuesRule.RULE,\n 'effect-cleanup-consistency': EffectCleanupConsistencyRule.RULE,\n 'max-params-own': MaxParamsOwnRule.RULE,\n 'no-async-hook-callback': NoAsyncHookCallbackRule.RULE,\n 'no-await-new-chain': NoAwaitNewChainRule.RULE,\n 'no-await-promise-chain': NoAwaitPromiseChainRule.RULE,\n 'no-inline-await': NoInlineAwaitRule.RULE,\n 'no-leaked-render': NoLeakedRenderRule.RULE,\n 'no-new-error': NoNewErrorRule.RULE,\n 'no-parent-import': NoParentImportRule.RULE,\n 'no-return-await': NoReturnAwaitRule.RULE,\n 'no-shadow-framework-type': NoShadowFrameworkTypeRule.RULE,\n 'no-silent-catch': NoSilentCatchRule.RULE,\n 'no-unbraced-case': NoUnbracedCaseRule.RULE,\n 'prefer-framework-api': PreferFrameworkApiRule.RULE,\n 'prefer-promise-sleep': PreferPromiseSleepRule.RULE,\n 'prefer-tnullable': PreferTNullableRule.RULE,\n 'typed-route-context': TypedRouteContextRule.RULE,\n 'zod-schema-convention': ZodSchemaConventionRule.RULE,\n },\n};\n"]}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import type { Linter, Rule } from 'eslint';
|
|
2
2
|
import type { TRuleSeverity } from '../rules/common';
|
|
3
|
+
import type { IFrameworkApiPattern } from './framework-api-patterns';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* `@venizia/prefer-framework-api`. A browser API that `@venizia/ardor-react` wraps in a hook (`window.matchMedia`, a
|
|
5
6
|
* `ResizeObserver`, `navigator.onLine`, a `beforeunload` listener, `navigator.clipboard.writeText`, `window.confirm`...) is
|
|
6
7
|
* used through the hook, which owns the subscribe and cleanup. The rows are `BrowserApiPatterns.TABLE`; the message names
|
|
7
|
-
* the hook. The rule is for apps:
|
|
8
|
+
* the hook. The rule is for apps: the package that ships the hooks (the nearest `package.json` is named
|
|
9
|
+
* `@venizia/ardor-react`) is not reported.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
11
|
+
* The rows of `FrameworkApiPatterns.TABLE` and of the `extra` option are not about React: they report anywhere in a file,
|
|
12
|
+
* with their own message, in a package their `dependsOn` and `owner` allow.
|
|
13
|
+
*
|
|
14
|
+
* 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
|
|
10
15
|
* where a hook can be called: in a component (a PascalCase function that draws JSX) or a hook (`useX`), see `isInReact`. A
|
|
11
16
|
* module function, a class and an event handler making a one-off call are left alone. Hooks the author wants to bypass on
|
|
12
17
|
* purpose take an `eslint-disable-next-line` with the reason, or `ignore` lists pattern ids.
|
|
13
|
-
*
|
|
14
|
-
* @useWhen a React app should reach the browser (media queries, sizes, observers, online status, visibility, unload, clipboard, confirm) through the ardor-react hooks
|
|
15
|
-
* @insteadOf window.matchMedia, new ResizeObserver, navigator.onLine and the other browser APIs written by hand
|
|
16
18
|
*/
|
|
17
19
|
export declare class PreferFrameworkApiRule {
|
|
18
|
-
static readonly NAME = "venizia/prefer-framework-api";
|
|
20
|
+
static readonly NAME = "@venizia/prefer-framework-api";
|
|
19
21
|
/** The dotted text of `a.b.c` (identifiers only), or `undefined` for anything else. */
|
|
20
22
|
private static pathOf;
|
|
21
23
|
/** `window.navigator.onLine` is `navigator.onLine`. */
|
|
@@ -40,10 +42,40 @@ export declare class PreferFrameworkApiRule {
|
|
|
40
42
|
* one-off call a hook cannot make.
|
|
41
43
|
*/
|
|
42
44
|
private static isInReact;
|
|
45
|
+
/** The rows that apply in a file of this package: the table and `extra`, less the ignored ones. */
|
|
46
|
+
private static rowsFor;
|
|
47
|
+
/** The listeners the rows outside React need, by node type or selector. */
|
|
48
|
+
private static rowListeners;
|
|
49
|
+
/** The name of `a.name` or `a['name']`; empty for `a[name]`, whose name the file does not state. */
|
|
50
|
+
private static memberName;
|
|
51
|
+
/** The field each type of an `extra` row cannot do without. */
|
|
52
|
+
private static readonly ROW_FIELDS;
|
|
53
|
+
/** Whether an `extra` entry is a row this rule can run. The option schema refuses the others before it gets here. */
|
|
54
|
+
private static isRow;
|
|
55
|
+
/** The schema of the `match` of an `extra` row: one shape per type, each with its own field required. */
|
|
56
|
+
private static matchSchema;
|
|
57
|
+
/**
|
|
58
|
+
* Whether `node` is assigned to or deleted, rather than read. A member that a destructuring pattern writes
|
|
59
|
+
* (`[process.env.APP_ENV_A] = values`) counts as a read and is reported.
|
|
60
|
+
*/
|
|
61
|
+
private static isWritten;
|
|
62
|
+
private static readonly FALLBACK_KEYS;
|
|
63
|
+
/** Whether `node` is the value used when another is missing. */
|
|
64
|
+
private static isFallback;
|
|
65
|
+
/** Whether an import declaration brings in types only. */
|
|
66
|
+
private static isTypeOnly;
|
|
67
|
+
/** One listener object: two rows that visit the same node both run. */
|
|
68
|
+
private static merge;
|
|
43
69
|
static readonly RULE: Rule.RuleModule;
|
|
70
|
+
/**
|
|
71
|
+
* `hooks: false` leaves out the rows of `BrowserApiPatterns`, for code that is not React: a `use...` function of another
|
|
72
|
+
* library reads as a hook. An entry that sets options replaces the earlier ones, so it states `hooks` again.
|
|
73
|
+
*/
|
|
44
74
|
static build(opts?: {
|
|
45
75
|
severity?: TRuleSeverity;
|
|
76
|
+
hooks?: boolean;
|
|
46
77
|
ignore?: ReadonlyArray<string>;
|
|
78
|
+
extra?: ReadonlyArray<IFrameworkApiPattern>;
|
|
47
79
|
}): Linter.RuleEntry;
|
|
48
80
|
}
|
|
49
81
|
//# sourceMappingURL=prefer-framework-api.rule.d.ts.map
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PreferFrameworkApiRule = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
4
5
|
const browser_api_patterns_1 = require("./browser-api-patterns");
|
|
5
6
|
const common_1 = require("./common");
|
|
7
|
+
const framework_api_patterns_1 = require("./framework-api-patterns");
|
|
8
|
+
const framework_exports_1 = require("./framework-exports");
|
|
6
9
|
/** The objects a global event listener is added to. */
|
|
7
10
|
const GLOBAL_TARGETS = ['window', 'document', 'self', 'globalThis'];
|
|
8
11
|
/** The names that stand for the global object. */
|
|
9
12
|
const GLOBAL_OBJECTS = ['window', 'globalThis', 'self'];
|
|
10
13
|
/**
|
|
11
|
-
*
|
|
14
|
+
* `@venizia/prefer-framework-api`. A browser API that `@venizia/ardor-react` wraps in a hook (`window.matchMedia`, a
|
|
12
15
|
* `ResizeObserver`, `navigator.onLine`, a `beforeunload` listener, `navigator.clipboard.writeText`, `window.confirm`...) is
|
|
13
16
|
* used through the hook, which owns the subscribe and cleanup. The rows are `BrowserApiPatterns.TABLE`; the message names
|
|
14
|
-
* the hook. The rule is for apps:
|
|
17
|
+
* the hook. The rule is for apps: the package that ships the hooks (the nearest `package.json` is named
|
|
18
|
+
* `@venizia/ardor-react`) is not reported.
|
|
15
19
|
*
|
|
16
|
-
*
|
|
20
|
+
* The rows of `FrameworkApiPatterns.TABLE` and of the `extra` option are not about React: they report anywhere in a file,
|
|
21
|
+
* with their own message, in a package their `dependsOn` and `owner` allow.
|
|
22
|
+
*
|
|
23
|
+
* 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
|
|
17
24
|
* where a hook can be called: in a component (a PascalCase function that draws JSX) or a hook (`useX`), see `isInReact`. A
|
|
18
25
|
* module function, a class and an event handler making a one-off call are left alone. Hooks the author wants to bypass on
|
|
19
26
|
* purpose take an `eslint-disable-next-line` with the reason, or `ignore` lists pattern ids.
|
|
20
|
-
*
|
|
21
|
-
* @useWhen a React app should reach the browser (media queries, sizes, observers, online status, visibility, unload, clipboard, confirm) through the ardor-react hooks
|
|
22
|
-
* @insteadOf window.matchMedia, new ResizeObserver, navigator.onLine and the other browser APIs written by hand
|
|
23
27
|
*/
|
|
24
28
|
class PreferFrameworkApiRule {
|
|
25
29
|
static { this.NAME = `${common_1.HOUSE_PLUGIN_NAMESPACE}/prefer-framework-api`; }
|
|
@@ -160,25 +164,271 @@ class PreferFrameworkApiRule {
|
|
|
160
164
|
}
|
|
161
165
|
return false;
|
|
162
166
|
}
|
|
167
|
+
/** The rows that apply in a file of this package: the table and `extra`, less the ignored ones. */
|
|
168
|
+
static rowsFor(opts) {
|
|
169
|
+
const { manifest, extra, ignore } = opts;
|
|
170
|
+
return [...framework_api_patterns_1.FrameworkApiPatterns.TABLE, ...extra].filter((row) => {
|
|
171
|
+
const { id, dependsOn, owner } = row;
|
|
172
|
+
if (ignore.has(id) || (owner !== undefined && manifest?.name === owner)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return (dependsOn === undefined ||
|
|
176
|
+
(manifest?.dependencies.some((entry) => entry.startsWith(dependsOn)) ?? false));
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/** The listeners the rows outside React need, by node type or selector. */
|
|
180
|
+
static rowListeners(opts) {
|
|
181
|
+
const { context, rows } = opts;
|
|
182
|
+
const listeners = [];
|
|
183
|
+
for (const { match, message } of rows) {
|
|
184
|
+
const report = (node) => {
|
|
185
|
+
context.report({ node, message });
|
|
186
|
+
};
|
|
187
|
+
/** Reports a global written as a member path, when `accepts` takes it. */
|
|
188
|
+
const onPath = (given) => {
|
|
189
|
+
listeners.push([
|
|
190
|
+
common_1.AstNodeTypes.MEMBER_EXPRESSION,
|
|
191
|
+
(node) => {
|
|
192
|
+
const path = PreferFrameworkApiRule.pathOf({
|
|
193
|
+
node: given.key === '' ? node : common_1.AstNode.readField({ node, key: given.key }),
|
|
194
|
+
});
|
|
195
|
+
if (path !== undefined &&
|
|
196
|
+
!(given.isReadOnly === true && PreferFrameworkApiRule.isWritten({ node })) &&
|
|
197
|
+
(given.property === undefined ||
|
|
198
|
+
given.property.test(PreferFrameworkApiRule.memberName({ node }))) &&
|
|
199
|
+
given.accepts(PreferFrameworkApiRule.withoutGlobalRoot({ path })) &&
|
|
200
|
+
PreferFrameworkApiRule.isGlobal({ context, node, path })) {
|
|
201
|
+
report(node);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
]);
|
|
205
|
+
};
|
|
206
|
+
switch (match.type) {
|
|
207
|
+
case 'path': {
|
|
208
|
+
onPath({ key: '', accepts: (bare) => match.paths.includes(bare) });
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case 'member': {
|
|
212
|
+
onPath({
|
|
213
|
+
key: 'object',
|
|
214
|
+
accepts: (bare) => match.objects.includes(bare),
|
|
215
|
+
property: match.property === undefined ? undefined : new RegExp(match.property),
|
|
216
|
+
isReadOnly: match.isReadOnly,
|
|
217
|
+
});
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case 'selector': {
|
|
221
|
+
listeners.push([match.selector, report]);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case 'literal': {
|
|
225
|
+
const pattern = new RegExp(match.pattern);
|
|
226
|
+
const check = (node, text) => {
|
|
227
|
+
const isWanted = match.isFallbackOnly !== true || PreferFrameworkApiRule.isFallback({ node });
|
|
228
|
+
if (typeof text === 'string' && isWanted && pattern.test(text)) {
|
|
229
|
+
report(node);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
listeners.push([
|
|
233
|
+
common_1.AstNodeTypes.LITERAL,
|
|
234
|
+
(node) => check(node, common_1.AstNode.readField({ node, key: 'value' })),
|
|
235
|
+
]);
|
|
236
|
+
listeners.push([
|
|
237
|
+
common_1.AstNodeTypes.TEMPLATE_ELEMENT,
|
|
238
|
+
(node) => {
|
|
239
|
+
const value = common_1.AstNode.readField({ node, key: 'value' });
|
|
240
|
+
const template = common_1.AstNode.readField({ node, key: 'parent' });
|
|
241
|
+
const parts = common_1.AstNode.readField({ node: template, key: 'quasis' });
|
|
242
|
+
// The first part is where a URL starts, and the template is what stands in a position.
|
|
243
|
+
if (common_1.AstNode.isNode(template) && Array.isArray(parts) && parts[0] === node) {
|
|
244
|
+
check(template, common_1.AstNode.readField({ node: value, key: 'cooked' }));
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
]);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
case 'import': {
|
|
251
|
+
const check = (node) => {
|
|
252
|
+
const source = common_1.AstNode.readField({ node, key: 'source' });
|
|
253
|
+
const name = common_1.AstNode.readField({ node: source, key: 'value' });
|
|
254
|
+
if (typeof name === 'string' &&
|
|
255
|
+
match.sources.includes(name) &&
|
|
256
|
+
!PreferFrameworkApiRule.isTypeOnly({ node })) {
|
|
257
|
+
report(node);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
listeners.push([common_1.AstNodeTypes.IMPORT_DECLARATION, check]);
|
|
261
|
+
listeners.push([common_1.AstNodeTypes.IMPORT_EXPRESSION, check]);
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
default: {
|
|
265
|
+
// The other types are hook rows of `BrowserApiPatterns`; as an `extra` row they match nothing here.
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return listeners;
|
|
271
|
+
}
|
|
272
|
+
/** The name of `a.name` or `a['name']`; empty for `a[name]`, whose name the file does not state. */
|
|
273
|
+
static memberName(opts) {
|
|
274
|
+
const property = common_1.AstNode.readField({ node: opts.node, key: 'property' });
|
|
275
|
+
const computed = common_1.AstNode.readField({ node: opts.node, key: 'computed' }) === true;
|
|
276
|
+
const name = common_1.AstNode.readField({ node: property, key: computed ? 'value' : 'name' });
|
|
277
|
+
return typeof name === 'string' ? name : '';
|
|
278
|
+
}
|
|
279
|
+
/** The field each type of an `extra` row cannot do without. */
|
|
280
|
+
static { this.ROW_FIELDS = new Map([
|
|
281
|
+
['path', 'paths'],
|
|
282
|
+
['member', 'objects'],
|
|
283
|
+
['selector', 'selector'],
|
|
284
|
+
['literal', 'pattern'],
|
|
285
|
+
['import', 'sources'],
|
|
286
|
+
]); }
|
|
287
|
+
/** Whether an `extra` entry is a row this rule can run. The option schema refuses the others before it gets here. */
|
|
288
|
+
static isRow(value) {
|
|
289
|
+
const match = common_1.AstNode.readField({ node: value, key: 'match' });
|
|
290
|
+
const field = PreferFrameworkApiRule.ROW_FIELDS.get(common_1.AstNode.getType({ node: match }));
|
|
291
|
+
return (typeof common_1.AstNode.readField({ node: value, key: 'id' }) === 'string' &&
|
|
292
|
+
typeof common_1.AstNode.readField({ node: value, key: 'message' }) === 'string' &&
|
|
293
|
+
field !== undefined &&
|
|
294
|
+
common_1.AstNode.readField({ node: match, key: field }) !== undefined);
|
|
295
|
+
}
|
|
296
|
+
/** The schema of the `match` of an `extra` row: one shape per type, each with its own field required. */
|
|
297
|
+
static matchSchema() {
|
|
298
|
+
const text = { type: 'string' };
|
|
299
|
+
const list = { type: 'array', items: text };
|
|
300
|
+
const flag = { type: 'boolean' };
|
|
301
|
+
const shapes = [
|
|
302
|
+
{ type: 'path' },
|
|
303
|
+
{ type: 'member', more: { property: text, isReadOnly: flag } },
|
|
304
|
+
{ type: 'selector' },
|
|
305
|
+
{ type: 'literal', more: { isFallbackOnly: flag } },
|
|
306
|
+
{ type: 'import' },
|
|
307
|
+
];
|
|
308
|
+
return {
|
|
309
|
+
oneOf: shapes.map(({ type, more }) => {
|
|
310
|
+
const field = PreferFrameworkApiRule.ROW_FIELDS.get(type) ?? type;
|
|
311
|
+
const isText = type === 'selector' || type === 'literal';
|
|
312
|
+
return {
|
|
313
|
+
type: 'object',
|
|
314
|
+
properties: { type: { enum: [type] }, [field]: isText ? text : list, ...more },
|
|
315
|
+
required: ['type', field],
|
|
316
|
+
additionalProperties: false,
|
|
317
|
+
};
|
|
318
|
+
}),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Whether `node` is assigned to or deleted, rather than read. A member that a destructuring pattern writes
|
|
323
|
+
* (`[process.env.APP_ENV_A] = values`) counts as a read and is reported.
|
|
324
|
+
*/
|
|
325
|
+
static isWritten(opts) {
|
|
326
|
+
const { node } = opts;
|
|
327
|
+
const parent = common_1.AstNode.readField({ node, key: 'parent' });
|
|
328
|
+
const type = common_1.AstNode.getType({ node: parent });
|
|
329
|
+
if (type === common_1.AstNodeTypes.ASSIGNMENT_EXPRESSION) {
|
|
330
|
+
return common_1.AstNode.readField({ node: parent, key: 'left' }) === node;
|
|
331
|
+
}
|
|
332
|
+
return (type === common_1.AstNodeTypes.UNARY_EXPRESSION &&
|
|
333
|
+
common_1.AstNode.readField({ node: parent, key: 'operator' }) === 'delete');
|
|
334
|
+
}
|
|
335
|
+
static { this.FALLBACK_KEYS = new Set(['default', 'defaultValue', 'fallback']); }
|
|
336
|
+
/** Whether `node` is the value used when another is missing. */
|
|
337
|
+
static isFallback(opts) {
|
|
338
|
+
const { node } = opts;
|
|
339
|
+
const parent = common_1.AstNode.readField({ node, key: 'parent' });
|
|
340
|
+
const type = common_1.AstNode.getType({ node: parent });
|
|
341
|
+
const isRight = common_1.AstNode.readField({ node: parent, key: 'right' }) === node;
|
|
342
|
+
if (type === common_1.AstNodeTypes.LOGICAL_EXPRESSION) {
|
|
343
|
+
return isRight && common_1.AstNode.readField({ node: parent, key: 'operator' }) !== '&&';
|
|
344
|
+
}
|
|
345
|
+
if (type === common_1.AstNodeTypes.ASSIGNMENT_PATTERN) {
|
|
346
|
+
return isRight;
|
|
347
|
+
}
|
|
348
|
+
if (type === common_1.AstNodeTypes.ASSIGNMENT_EXPRESSION) {
|
|
349
|
+
const operator = common_1.AstNode.readField({ node: parent, key: 'operator' });
|
|
350
|
+
return isRight && (operator === '??=' || operator === '||=');
|
|
351
|
+
}
|
|
352
|
+
return (type === common_1.AstNodeTypes.PROPERTY &&
|
|
353
|
+
common_1.AstNode.readField({ node: parent, key: 'value' }) === node &&
|
|
354
|
+
PreferFrameworkApiRule.FALLBACK_KEYS.has(common_1.AstNode.readField({
|
|
355
|
+
node: common_1.AstNode.readField({ node: parent, key: 'key' }),
|
|
356
|
+
key: 'name',
|
|
357
|
+
})));
|
|
358
|
+
}
|
|
359
|
+
/** Whether an import declaration brings in types only. */
|
|
360
|
+
static isTypeOnly(opts) {
|
|
361
|
+
const { node } = opts;
|
|
362
|
+
const specifiers = common_1.AstNode.readField({ node, key: 'specifiers' });
|
|
363
|
+
const isType = (item) => common_1.AstNode.readField({ node: item, key: 'importKind' }) === 'type';
|
|
364
|
+
return (isType(node) ||
|
|
365
|
+
(Array.isArray(specifiers) && specifiers.length > 0 && specifiers.every(isType)));
|
|
366
|
+
}
|
|
367
|
+
/** One listener object: two rows that visit the same node both run. */
|
|
368
|
+
static merge(opts) {
|
|
369
|
+
const byKey = new Map();
|
|
370
|
+
for (const [key, listener] of opts.listeners) {
|
|
371
|
+
byKey.set(key, [...(byKey.get(key) ?? []), listener]);
|
|
372
|
+
}
|
|
373
|
+
return Object.fromEntries([...byKey].map(([key, all]) => [
|
|
374
|
+
key,
|
|
375
|
+
(node) => {
|
|
376
|
+
for (const listener of all) {
|
|
377
|
+
listener(node);
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
]));
|
|
381
|
+
}
|
|
163
382
|
static { this.RULE = {
|
|
164
383
|
meta: {
|
|
165
384
|
type: 'suggestion',
|
|
166
385
|
schema: [
|
|
167
386
|
{
|
|
168
387
|
type: 'object',
|
|
169
|
-
properties: {
|
|
388
|
+
properties: {
|
|
389
|
+
hooks: { type: 'boolean' },
|
|
390
|
+
ignore: { type: 'array', items: { type: 'string' } },
|
|
391
|
+
extra: {
|
|
392
|
+
type: 'array',
|
|
393
|
+
items: {
|
|
394
|
+
type: 'object',
|
|
395
|
+
properties: {
|
|
396
|
+
id: { type: 'string' },
|
|
397
|
+
message: { type: 'string' },
|
|
398
|
+
dependsOn: { type: 'string' },
|
|
399
|
+
owner: { type: 'string' },
|
|
400
|
+
match: PreferFrameworkApiRule.matchSchema(),
|
|
401
|
+
},
|
|
402
|
+
required: ['id', 'match', 'message'],
|
|
403
|
+
additionalProperties: false,
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
},
|
|
170
407
|
additionalProperties: false,
|
|
171
408
|
},
|
|
172
409
|
],
|
|
173
410
|
messages: {
|
|
174
|
-
framework:
|
|
411
|
+
framework: "Use {{hooks}} instead of {{written}}, the hook owns the subscribe and the cleanup: `import { {{name}} } from '{{package}}';`",
|
|
175
412
|
},
|
|
176
413
|
},
|
|
177
414
|
create: (context) => {
|
|
415
|
+
const manifest = framework_exports_1.FrameworkExports.manifestFor({ directory: (0, node_path_1.dirname)(context.filename) });
|
|
178
416
|
const options = context.options[0];
|
|
179
417
|
const ignored = common_1.AstNode.readField({ node: options, key: 'ignore' });
|
|
180
418
|
const ignore = new Set(Array.isArray(ignored) ? ignored : []);
|
|
181
|
-
const
|
|
419
|
+
const added = common_1.AstNode.readField({ node: options, key: 'extra' });
|
|
420
|
+
const rows = PreferFrameworkApiRule.rowsFor({
|
|
421
|
+
manifest,
|
|
422
|
+
extra: Array.isArray(added)
|
|
423
|
+
? added.filter((row) => PreferFrameworkApiRule.isRow(row))
|
|
424
|
+
: [],
|
|
425
|
+
ignore,
|
|
426
|
+
});
|
|
427
|
+
// The package that ships the hooks writes them with the browser APIs they wrap.
|
|
428
|
+
const patterns = common_1.AstNode.readField({ node: options, key: 'hooks' }) === false ||
|
|
429
|
+
manifest?.name === browser_api_patterns_1.BrowserApiPatterns.PACKAGE
|
|
430
|
+
? []
|
|
431
|
+
: browser_api_patterns_1.BrowserApiPatterns.TABLE.filter((pattern) => !ignore.has(pattern.id));
|
|
182
432
|
const report = (opts) => {
|
|
183
433
|
const { node, pattern } = opts;
|
|
184
434
|
const subscribes = pattern.match.type === 'listener' || pattern.match.type === 'new';
|
|
@@ -190,12 +440,14 @@ class PreferFrameworkApiRule {
|
|
|
190
440
|
messageId: 'framework',
|
|
191
441
|
data: {
|
|
192
442
|
hooks: pattern.hooks,
|
|
443
|
+
// One import line, for the first hook the row suggests (the `useX` words are in backticks).
|
|
444
|
+
name: /`(use\w+)`/.exec(pattern.hooks)?.[1],
|
|
193
445
|
package: browser_api_patterns_1.BrowserApiPatterns.PACKAGE,
|
|
194
446
|
written: pattern.written,
|
|
195
447
|
},
|
|
196
448
|
});
|
|
197
449
|
};
|
|
198
|
-
|
|
450
|
+
const hooks = {
|
|
199
451
|
// `window.matchMedia`, `window.innerWidth`, `navigator.onLine`, `navigator.clipboard.writeText`...
|
|
200
452
|
[common_1.AstNodeTypes.MEMBER_EXPRESSION]: (node) => {
|
|
201
453
|
const path = PreferFrameworkApiRule.pathOf({ node });
|
|
@@ -271,11 +523,32 @@ class PreferFrameworkApiRule {
|
|
|
271
523
|
}
|
|
272
524
|
},
|
|
273
525
|
};
|
|
526
|
+
return PreferFrameworkApiRule.merge({
|
|
527
|
+
listeners: [
|
|
528
|
+
...Object.entries(hooks),
|
|
529
|
+
...PreferFrameworkApiRule.rowListeners({ context, rows }),
|
|
530
|
+
],
|
|
531
|
+
});
|
|
274
532
|
},
|
|
275
533
|
}; }
|
|
534
|
+
/**
|
|
535
|
+
* `hooks: false` leaves out the rows of `BrowserApiPatterns`, for code that is not React: a `use...` function of another
|
|
536
|
+
* library reads as a hook. An entry that sets options replaces the earlier ones, so it states `hooks` again.
|
|
537
|
+
*/
|
|
276
538
|
static build(opts = {}) {
|
|
277
|
-
const { severity = 'error', ignore } = opts;
|
|
278
|
-
|
|
539
|
+
const { severity = 'error', hooks, ignore, extra } = opts;
|
|
540
|
+
// Only what was given: the option schema refuses a key whose value is `undefined`.
|
|
541
|
+
const options = {};
|
|
542
|
+
if (hooks !== undefined) {
|
|
543
|
+
options.hooks = hooks;
|
|
544
|
+
}
|
|
545
|
+
if (ignore !== undefined) {
|
|
546
|
+
options.ignore = [...ignore];
|
|
547
|
+
}
|
|
548
|
+
if (extra !== undefined) {
|
|
549
|
+
options.extra = [...extra];
|
|
550
|
+
}
|
|
551
|
+
return Object.keys(options).length === 0 ? [severity] : [severity, options];
|
|
279
552
|
}
|
|
280
553
|
}
|
|
281
554
|
exports.PreferFrameworkApiRule = PreferFrameworkApiRule;
|