eslint-plugin-functype 2.110.0 → 2.111.0
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 +21 -14
- package/dist/configs/recommended.d.ts +2 -1
- package/dist/configs/recommended.js.map +1 -1
- package/dist/rules/prefer-either.js +1 -1
- package/dist/rules/prefer-either.js.map +1 -1
- package/dist/utils/boundary-tags.d.ts +7 -6
- package/dist/utils/boundary-tags.js +1 -1
- package/dist/utils/boundary-tags.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -49,11 +49,24 @@ A rule is **`error` in `recommended` once it is right on ~95–99% of real code*
|
|
|
49
49
|
|
|
50
50
|
`prefer-fold` reports only; its rewrite is a suggestion you apply, never an autofix, so `eslint --fix` can't change code on your behalf.
|
|
51
51
|
|
|
52
|
-
##
|
|
52
|
+
## Throwing on purpose: `invariant()` and `@interop`
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
`prefer-either` reports every `throw`. Two kinds of throw are correct, and each has its own tool:
|
|
55
|
+
|
|
56
|
+
| The throw is… | Use |
|
|
57
|
+
| --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
|
|
58
|
+
| A bug check: the condition can only fail because of a programmer error | `invariant(cond, msg)` from `functype` |
|
|
59
|
+
| A host contract: the caller (React `use()`, React Query, a step runner, an MCP tool) needs a throw or rejection | `@interop <reason>` on the declaration, or `orThrow(builder)` |
|
|
60
|
+
| Anything that can fail in normal operation | return an `Either` |
|
|
55
61
|
|
|
56
62
|
```ts
|
|
63
|
+
import { invariant } from "functype"
|
|
64
|
+
|
|
65
|
+
function deriveRunId(workflowId: string, step: number): string {
|
|
66
|
+
invariant(step >= 0, "step must be non-negative") // a call, not a throw: nothing to report
|
|
67
|
+
return `${workflowId}:${step}`
|
|
68
|
+
}
|
|
69
|
+
|
|
57
70
|
/**
|
|
58
71
|
* Runs the effect, or throws a boxed error.
|
|
59
72
|
*
|
|
@@ -61,24 +74,18 @@ Some code is correct _because_ it isn't FP-shaped: a bridge to a host whose cont
|
|
|
61
74
|
*/
|
|
62
75
|
const runBoxed = async <E, A>(effect: () => IO<never, E, A>): Promise<A> => { … }
|
|
63
76
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (step < 0) throw new Error("step must be non-negative")
|
|
67
|
-
…
|
|
68
|
-
}
|
|
77
|
+
// A host throw built from the failure, with no tag at all:
|
|
78
|
+
const value = either.orThrow((left) => new StepError(left.message))
|
|
69
79
|
```
|
|
70
80
|
|
|
71
|
-
|
|
72
|
-
| --------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
73
|
-
| `@interop <reason>` | `prefer-either`, `prefer-option`, `prefer-fold`, `prefer-try` | This declaration bridges functype to a host (React, React Query, an SDK) whose contract requires the non-FP shape. |
|
|
74
|
-
| `@invariant <reason>` | `prefer-either` | This declaration throws only for programmer errors, never for expected failures. |
|
|
81
|
+
`invariant()` covers one statement and narrows the condition for the code after it, so a function can mix bug checks with `Either`-returning failures. `@interop` rules:
|
|
75
82
|
|
|
76
|
-
- **Scope:** the tagged declaration and everything nested in it. That can be a function, `const`, method, class field, object property, type alias or interface. A sibling declaration is not covered.
|
|
83
|
+
- **Scope:** the tagged declaration and everything nested in it. That can be a function, `const`, method, class field, object property, type alias or interface. A sibling declaration is not covered. Honored by `prefer-either`, `prefer-option`, `prefer-fold` and `prefer-try`.
|
|
77
84
|
- **The reason is required**, on the same line as the tag. A bare `@interop` exempts nothing.
|
|
78
85
|
- **Only JSDoc (`/** … */`) counts.** A `//` comment mentioning the tag does not.
|
|
79
|
-
- **Opt out** per rule with `allowInteropMarker: false
|
|
86
|
+
- **Opt out** per rule with `allowInteropMarker: false`.
|
|
80
87
|
|
|
81
|
-
Prefer
|
|
88
|
+
Prefer either tool to `eslint-disable`. A disable covers a whole file or line and says only "be quiet". `rg 'invariant\('` lists every bug check, and `rg '@interop'` lists every place the code touches a throw-based host.
|
|
82
89
|
|
|
83
90
|
## Rule options
|
|
84
91
|
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Still `warn`, and why:
|
|
9
9
|
* - prefer-option / prefer-either / prefer-try: fire on correct code at serialization boundaries
|
|
10
|
-
* (JSON rows, DTOs) and on
|
|
10
|
+
* (JSON rows, DTOs) and on throws that are correct (bug checks, host contracts). Wire<T> (#325 B),
|
|
11
|
+
* invariant() and @interop (#342) close those; graduating them is a measured decision.
|
|
11
12
|
* - prefer-flatmap / prefer-do-notation: heuristics without type information; precision unmeasured.
|
|
12
13
|
*
|
|
13
14
|
* Graduated with a precision condition: prefer-fold checks functype predicate calls (`isSome()`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recommended.js","names":["recommendedRules"],"sources":["../../src/configs/recommended.ts"],"sourcesContent":["/**\n * Severity policy (#325): a rule is `error` once it is right on ~95–99% of real code and its known\n * false-positive classes are closed; it stays `warn` only while those classes are still open. FP here\n * is governance — a rule that is reliably right should fail the build, not print advice nobody reads\n * (CivalaOS shipped 85 new violations under \"lint OK\" because every rule but `no-let` warned).\n *\n * Still `warn`, and why:\n * - prefer-option / prefer-either / prefer-try: fire on correct code at serialization boundaries\n * (JSON rows, DTOs) and on
|
|
1
|
+
{"version":3,"file":"recommended.js","names":["recommendedRules"],"sources":["../../src/configs/recommended.ts"],"sourcesContent":["/**\n * Severity policy (#325): a rule is `error` once it is right on ~95–99% of real code and its known\n * false-positive classes are closed; it stays `warn` only while those classes are still open. FP here\n * is governance — a rule that is reliably right should fail the build, not print advice nobody reads\n * (CivalaOS shipped 85 new violations under \"lint OK\" because every rule but `no-let` warned).\n *\n * Still `warn`, and why:\n * - prefer-option / prefer-either / prefer-try: fire on correct code at serialization boundaries\n * (JSON rows, DTOs) and on throws that are correct (bug checks, host contracts). Wire<T> (#325 B),\n * invariant() and @interop (#342) close those; graduating them is a measured decision.\n * - prefer-flatmap / prefer-do-notation: heuristics without type information; precision unmeasured.\n *\n * Graduated with a precision condition: prefer-fold checks functype predicate calls (`isSome()`,\n * `isLeft()`) only; its null-check heuristic is opt-in (`checkNullable`) because it fired on plain\n * nullables — 31 of 31 hits in CivalaOS. prefer-map leaves loops to no-imperative-loops (`checkForLoops`\n * off), so one loop is one error.\n */\nconst recommendedRules = {\n \"functype/no-let\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/prefer-map\": \"error\",\n \"functype/prefer-fold\": \"error\",\n \"functype/prefer-option\": \"warn\",\n \"functype/prefer-either\": \"warn\",\n \"functype/prefer-try\": \"warn\",\n \"functype/prefer-flatmap\": \"warn\",\n \"functype/prefer-do-notation\": \"warn\",\n \"functype/no-get-unsafe\": \"off\",\n \"functype/prefer-list\": \"off\",\n}\n\nexport default recommendedRules\n"],"mappings":"AAiBA,MAAMA,EAAmB,CACvB,kBAAmB,QACnB,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,QAChC,sBAAuB,QACvB,uBAAwB,QACxB,yBAA0B,OAC1B,yBAA0B,OAC1B,sBAAuB,OACvB,0BAA2B,OAC3B,8BAA+B,OAC/B,yBAA0B,MAC1B,uBAAwB,KAC1B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{isInsideTaggedDeclaration as e}from"../utils/boundary-tags.js";import{createImportFixer as t,hasFunctypeSymbol as n}from"../utils/import-fixer.js";function r(e){let t=e?.parent;return t?t.type===`CatchClause`||r(t):!1}const i={meta:{type:`suggestion`,hasSuggestions:!0,docs:{description:`Use Either/Left/Right for typed domain errors instead of throwing`,recommended:!0},schema:[{type:`object`,properties:{allowInteropMarker:{type:`boolean`,default:!0},
|
|
1
|
+
import{isInsideTaggedDeclaration as e}from"../utils/boundary-tags.js";import{createImportFixer as t,hasFunctypeSymbol as n}from"../utils/import-fixer.js";function r(e){let t=e?.parent;return t?t.type===`CatchClause`||r(t):!1}const i={meta:{type:`suggestion`,hasSuggestions:!0,docs:{description:`Use Either/Left/Right for typed domain errors instead of throwing`,recommended:!0},schema:[{type:`object`,properties:{allowInteropMarker:{type:`boolean`,default:!0},allowThrowInTests:{type:`boolean`,default:!0}},additionalProperties:!1}],messages:{preferEitherOverThrow:`Prefer Either.left(error) over throw statement. For a bug check use invariant(); for a host that needs the throw, tag the function @interop`,preferEitherReturn:`Consider returning Either<Error, {{type}}> instead of throwing. For a bug check use invariant(); for a host that needs the throw, tag the function @interop`,suggestEitherLeft:`Replace with Either.left(...)`,suggestAddImport:`Add {{symbol}} import from functype`}},create(i){let a=i.options[0]||{},o=a.allowInteropMarker!==!1,s=t=>o&&e(t,`interop`,i.sourceCode),c=a.allowThrowInTests!==!1;function l(){let e=i.filename;return/\.(test|spec)\.(ts|js|tsx|jsx)$/.test(e)||e.includes(`__tests__`)||e.includes(`/test/`)||e.includes(`/tests/`)}function u(e){let t=e.parent;return t?f(t)?t:u(t):null}function d(e){let t=e?.returnType?.typeAnnotation;if(!t)return null;let n=i.sourceCode.getText(t);return n.includes(`Either`)?null:n}function f(e){return e?[`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`].includes(e.type):!1}function p(e){let t=e.parent;if(!t)return!1;if(t.type===`BlockStatement`&&f(t.parent))return!0;if(t.type===`BlockStatement`&&t.parent?.type===`IfStatement`){let e=t.parent.parent;return e?.type===`BlockStatement`&&f(e.parent)}return!1}return{ThrowStatement(e){if(s(e)||c&&l()||r(e))return;let a=i.sourceCode,o=[];if(p(e)){let r=e.argument,i=a.getText(r),s=r?.type===`NewExpression`&&r.callee?.type===`Identifier`&&r.callee.name===`Error`?i:`new Error(String(${i}))`;o.push({messageId:`suggestEitherLeft`,fix(t){return t.replaceText(e,`return Either.left(${s})`)}}),n(a,`Either`)||o.push({messageId:`suggestAddImport`,data:{symbol:`Either`},fix:t(a,`Either`)})}let f=d(u(e));i.report({node:e,...f===null?{messageId:`preferEitherOverThrow`}:{messageId:`preferEitherReturn`,data:{type:f}},suggest:o})}}}};export{i as default};
|
|
2
2
|
//# sourceMappingURL=prefer-either.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-either.js","names":["insideCatchClause","parent","node","rule","options","context","allowInteropMarker","
|
|
1
|
+
{"version":3,"file":"prefer-either.js","names":["insideCatchClause","parent","node","rule","options","context","allowInteropMarker","isExemptByMarker","isInsideTaggedDeclaration","allowThrowInTests","isInTestFile","filename","enclosingFunction","isFunctionLike","nonEitherReturnType","returnType","fn","text","isDirectInFunctionBody","ifParent","sourceCode","suggest","throwArg","argText","eitherArg","fixer","hasFunctypeSymbol","createImportFixer"],"sources":["../../src/rules/prefer-either.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { createImportFixer, hasFunctypeSymbol } from \"../utils/import-fixer\"\n\n/** True iff any ancestor of `node` is a `CatchClause`. Pure tail recursion. */\nfunction insideCatchClause(node: ASTNode | null | undefined): boolean {\n const parent = node?.parent as ASTNode | undefined\n if (!parent) return false\n return parent.type === \"CatchClause\" || insideCatchClause(parent)\n}\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"suggestion\",\n hasSuggestions: true,\n docs: {\n description: \"Use Either/Left/Right for typed domain errors instead of throwing\",\n recommended: true,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n allowThrowInTests: {\n type: \"boolean\",\n default: true,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n preferEitherOverThrow:\n \"Prefer Either.left(error) over throw statement. For a bug check use invariant(); for a host that needs the throw, tag the function @interop\",\n preferEitherReturn:\n \"Consider returning Either<Error, {{type}}> instead of throwing. For a bug check use invariant(); for a host that needs the throw, tag the function @interop\",\n suggestEitherLeft: \"Replace with Either.left(...)\",\n suggestAddImport: \"Add {{symbol}} import from functype\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n // `@interop <reason>` on an enclosing declaration marks a host-contract boundary (#241).\n const allowInteropMarker = options.allowInteropMarker !== false\n // Bug checks are `invariant()` calls from functype (#342): a call, not a throw, so nothing to exempt.\n const isExemptByMarker = (node: ASTNode): boolean =>\n allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, context.sourceCode)\n const allowThrowInTests = options.allowThrowInTests !== false\n\n function isInTestFile() {\n const filename = context.filename\n return (\n /\\.(test|spec)\\.(ts|js|tsx|jsx)$/.test(filename) ||\n filename.includes(\"__tests__\") ||\n filename.includes(\"/test/\") ||\n filename.includes(\"/tests/\")\n )\n }\n\n /** The nearest function the throw belongs to — a nested function owns its own throws. */\n function enclosingFunction(node: ASTNode): ASTNode | null {\n const parent = node.parent\n if (!parent) return null\n return isFunctionLike(parent) ? parent : enclosingFunction(parent)\n }\n\n /** The declared return type when the function declares one that is not already an Either. */\n function nonEitherReturnType(fn: ASTNode | null): string | null {\n const returnType = fn?.returnType?.typeAnnotation\n if (!returnType) return null\n const text = context.sourceCode.getText(returnType)\n return text.includes(\"Either\") ? null : text\n }\n\n function isFunctionLike(node: ASTNode): boolean {\n if (!node) return false\n return [\"FunctionDeclaration\", \"FunctionExpression\", \"ArrowFunctionExpression\"].includes(node.type)\n }\n\n function isDirectInFunctionBody(node: ASTNode): boolean {\n const parent = node.parent\n if (!parent) return false\n if (parent.type === \"BlockStatement\" && isFunctionLike(parent.parent)) return true\n if (parent.type === \"BlockStatement\" && parent.parent?.type === \"IfStatement\") {\n const ifParent = parent.parent.parent\n return ifParent?.type === \"BlockStatement\" && isFunctionLike(ifParent.parent)\n }\n return false\n }\n\n return {\n ThrowStatement(node: ASTNode) {\n if (isExemptByMarker(node)) return\n // Allow throws in test files if configured\n if (allowThrowInTests && isInTestFile()) return\n\n // Allow re-throwing in catch blocks (common pattern)\n if (insideCatchClause(node)) return\n\n const sourceCode = context.sourceCode\n const suggest: Rule.SuggestionReportDescriptor[] = []\n\n if (isDirectInFunctionBody(node)) {\n const throwArg = node.argument\n const argText = sourceCode.getText(throwArg)\n const isErrorExpr =\n throwArg?.type === \"NewExpression\" &&\n throwArg.callee?.type === \"Identifier\" &&\n throwArg.callee.name === \"Error\"\n const eitherArg = isErrorExpr ? argText : `new Error(String(${argText}))`\n\n suggest.push({\n messageId: \"suggestEitherLeft\",\n fix(fixer) {\n return fixer.replaceText(node, `return Either.left(${eitherArg})`)\n },\n })\n\n if (!hasFunctypeSymbol(sourceCode, \"Either\")) {\n suggest.push({\n messageId: \"suggestAddImport\",\n data: { symbol: \"Either\" },\n fix: createImportFixer(sourceCode, \"Either\"),\n })\n }\n }\n\n // One report per throw (#324). When the enclosing function declares a non-Either return type,\n // the message names the Either it should return instead of reporting the function separately.\n const returnType = nonEitherReturnType(enclosingFunction(node))\n context.report({\n node,\n ...(returnType === null\n ? { messageId: \"preferEitherOverThrow\" }\n : { messageId: \"preferEitherReturn\", data: { type: returnType } }),\n suggest,\n })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"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"}
|
|
@@ -4,18 +4,19 @@ import { SourceCode } from "eslint";
|
|
|
4
4
|
/**
|
|
5
5
|
* Structural exemptions recorded in JSDoc, instead of `eslint-disable` (#241).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* `@interop <reason>` — the enclosing declaration bridges functype to a host whose contract is the
|
|
8
|
+
* non-FP shape: React's `use()` needs a throw, React Query needs a rejected promise, a hook that converts
|
|
9
|
+
* nullables into `Option` must accept nullables.
|
|
10
|
+
*
|
|
11
|
+
* Bug checks are not tagged: they are `invariant(cond, msg)` calls from functype, which narrow types and
|
|
12
|
+
* cover one statement. (An `@invariant` tag shipped in 1.10.0 and was removed in #342 — it exempted a
|
|
13
|
+
* whole function, including any expected-failure throw added to it later.)
|
|
12
14
|
*
|
|
13
15
|
* Why a tag rather than a disable comment: it covers one declaration (and what is nested inside it), not
|
|
14
16
|
* a whole file; it must carry a reason on the same line, so a bare tag exempts nothing; and it is
|
|
15
17
|
* greppable — `rg '@interop'` is the inventory of every place the code touches a throw-based host.
|
|
16
18
|
*/
|
|
17
19
|
export declare const INTEROP_TAG = "interop";
|
|
18
|
-
export declare const INVARIANT_TAG = "invariant";
|
|
19
20
|
/**
|
|
20
21
|
* Is `node` inside a declaration whose JSDoc carries `@<tag> <reason>`? Every enclosing documentable
|
|
21
22
|
* declaration is checked, so a tag on a function covers the callbacks nested inside it.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=`interop`,t
|
|
1
|
+
const e=`interop`,t=/* @__PURE__ */ new Set([`FunctionDeclaration`,`VariableDeclaration`,`MethodDefinition`,`PropertyDefinition`,`Property`,`TSTypeAliasDeclaration`,`TSInterfaceDeclaration`,`TSPropertySignature`,`TSMethodSignature`]),n=/* @__PURE__ */ new Set([`ExportNamedDeclaration`,`ExportDefaultDeclaration`]),r=(e,t)=>{let r=e.parent&&n.has(e.parent.type)?e.parent:e,i=t.getCommentsBefore(r),a=i[i.length-1];return a?.type===`Block`&&a.value.startsWith(`*`)?a.value:null},i=(e,t)=>RegExp(`(^|[\\s*])@${t}[ \\t]+\\S`,`m`).test(e),a=(e,n,a)=>{let o=e=>{if(!e)return!1;if(t.has(e.type)){let t=r(e,a);if(t!==null&&i(t,n))return!0}return o(e.parent)};return o(e)};export{e as INTEROP_TAG,a as isInsideTaggedDeclaration};
|
|
2
2
|
//# sourceMappingURL=boundary-tags.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary-tags.js","names":["INTEROP_TAG","
|
|
1
|
+
{"version":3,"file":"boundary-tags.js","names":["INTEROP_TAG","DOCUMENTABLE","EXPORT_WRAPPERS","leadingJSDoc","anchor","node","comments","sourceCode","last","hasTagWithReason","tag","jsdoc","isInsideTaggedDeclaration","check","current"],"sources":["../../src/utils/boundary-tags.ts"],"sourcesContent":["import type { SourceCode } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\n\n/**\n * Structural exemptions recorded in JSDoc, instead of `eslint-disable` (#241).\n *\n * `@interop <reason>` — the enclosing declaration bridges functype to a host whose contract is the\n * non-FP shape: React's `use()` needs a throw, React Query needs a rejected promise, a hook that converts\n * nullables into `Option` must accept nullables.\n *\n * Bug checks are not tagged: they are `invariant(cond, msg)` calls from functype, which narrow types and\n * cover one statement. (An `@invariant` tag shipped in 1.10.0 and was removed in #342 — it exempted a\n * whole function, including any expected-failure throw added to it later.)\n *\n * Why a tag rather than a disable comment: it covers one declaration (and what is nested inside it), not\n * a whole file; it must carry a reason on the same line, so a bare tag exempts nothing; and it is\n * greppable — `rg '@interop'` is the inventory of every place the code touches a throw-based host.\n */\n\nexport const INTEROP_TAG = \"interop\"\n\n/** Declarations whose leading JSDoc can carry a tag. */\nconst DOCUMENTABLE: ReadonlySet<string> = new Set([\n \"FunctionDeclaration\",\n \"VariableDeclaration\",\n \"MethodDefinition\",\n \"PropertyDefinition\",\n \"Property\",\n \"TSTypeAliasDeclaration\",\n \"TSInterfaceDeclaration\",\n \"TSPropertySignature\",\n \"TSMethodSignature\",\n])\n\nconst EXPORT_WRAPPERS: ReadonlySet<string> = new Set([\"ExportNamedDeclaration\", \"ExportDefaultDeclaration\"])\n\n/** The JSDoc block (`/** … *\\/`) directly before `node`, or before its `export` wrapper. */\nconst leadingJSDoc = (node: ASTNode, sourceCode: SourceCode): string | null => {\n const anchor = node.parent && EXPORT_WRAPPERS.has(node.parent.type) ? node.parent : node\n const comments = sourceCode.getCommentsBefore(anchor)\n const last = comments[comments.length - 1]\n return last?.type === \"Block\" && last.value.startsWith(\"*\") ? last.value : null\n}\n\n/** `@tag` followed by a reason on the same line. A bare tag carries no reason and exempts nothing. */\nconst hasTagWithReason = (jsdoc: string, tag: string): boolean =>\n new RegExp(`(^|[\\\\s*])@${tag}[ \\\\t]+\\\\S`, \"m\").test(jsdoc)\n\n/**\n * Is `node` inside a declaration whose JSDoc carries `@<tag> <reason>`? Every enclosing documentable\n * declaration is checked, so a tag on a function covers the callbacks nested inside it.\n */\nexport const isInsideTaggedDeclaration = (node: ASTNode, tag: string, sourceCode: SourceCode): boolean => {\n const check = (current: ASTNode | null | undefined): boolean => {\n if (!current) return false\n if (DOCUMENTABLE.has(current.type)) {\n const jsdoc = leadingJSDoc(current, sourceCode)\n if (jsdoc !== null && hasTagWithReason(jsdoc, tag)) return true\n }\n return check(current.parent)\n }\n return check(node)\n}\n"],"mappings":"AAoBA,MAAaA,EAAc,UAGrBC,kBAAoC,IAAI,IAAI,CAChD,sBACA,sBACA,mBACA,qBACA,WACA,yBACA,yBACA,sBACA,mBACF,CAAC,EAEKC,kBAAuC,IAAI,IAAI,CAAC,yBAA0B,0BAA0B,CAAC,EAGrGC,GAAgB,EAAe,IAA0C,CAC7E,IAAMC,EAASC,EAAK,QAAUH,EAAgB,IAAIG,EAAK,OAAO,IAAI,EAAIA,EAAK,OAASA,EAC9EC,EAAWC,EAAW,kBAAkBH,CAAM,EAC9CI,EAAOF,EAASA,EAAS,OAAS,GACxC,OAAOE,GAAM,OAAS,SAAWA,EAAK,MAAM,WAAW,GAAG,EAAIA,EAAK,MAAQ,IAC7E,EAGMC,GAAoB,EAAe,IACnC,OAAO,cAAcC,EAAI,YAAa,GAAG,CAAC,CAAC,KAAKC,CAAK,EAM9CC,GAA6B,EAAe,EAAa,IAAoC,CACxG,IAAMC,EAAS,GAAiD,CAC9D,GAAI,CAACC,EAAS,MAAO,GACrB,GAAIb,EAAa,IAAIa,EAAQ,IAAI,EAAG,CAClC,IAAMH,EAAQR,EAAaW,EAASP,CAAU,EAC9C,GAAII,IAAU,MAAQF,EAAiBE,EAAOD,CAAG,EAAG,MAAO,EAC7D,CACA,OAAOG,EAAMC,EAAQ,MAAM,CAC7B,EACA,OAAOD,EAAMR,CAAI,CACnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-functype",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.111.0",
|
|
4
4
|
"description": "Custom ESLint rules for functional TypeScript programming with functype library patterns including Do notation (ESLint 10+)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/node": "^24.19.0",
|
|
43
43
|
"@typescript-eslint/rule-tester": "^8.71.0",
|
|
44
44
|
"eslint-config-prettier": "^10.1.8",
|
|
45
|
-
"functype": "^1.
|
|
45
|
+
"functype": "^1.11.0",
|
|
46
46
|
"ts-builds": "^3.4.3",
|
|
47
47
|
"tsdown": "^0.23.0"
|
|
48
48
|
},
|