@dereekb/util 13.11.2 → 13.11.4
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/eslint/index.cjs.default.js +1 -0
- package/eslint/index.cjs.js +687 -0
- package/eslint/index.cjs.mjs +2 -0
- package/eslint/index.d.ts +1 -0
- package/eslint/index.esm.js +683 -0
- package/eslint/package.json +23 -0
- package/eslint/src/index.d.ts +1 -0
- package/eslint/src/lib/comments.d.ts +101 -0
- package/eslint/src/lib/index.d.ts +3 -0
- package/eslint/src/lib/plugin.d.ts +18 -0
- package/eslint/src/lib/prefer-no-side-effects-in-jsdoc.rule.d.ts +50 -0
- package/eslint/src/lib/require-no-side-effects.rule.d.ts +67 -0
- package/fetch/package.json +2 -2
- package/index.cjs.js +1421 -23
- package/index.esm.js +1421 -24
- package/package.json +7 -1
- package/src/lib/array/array.factory.d.ts +2 -0
- package/src/lib/array/array.filter.d.ts +50 -17
- package/src/lib/array/array.find.d.ts +1 -0
- package/src/lib/array/array.index.d.ts +7 -0
- package/src/lib/array/array.indexed.d.ts +21 -0
- package/src/lib/array/array.make.d.ts +7 -0
- package/src/lib/array/array.random.d.ts +1 -0
- package/src/lib/array/array.unique.d.ts +3 -0
- package/src/lib/array/array.value.d.ts +7 -0
- package/src/lib/auth/auth.role.claims.d.ts +7 -0
- package/src/lib/boolean.d.ts +1 -0
- package/src/lib/contact/random.d.ts +14 -0
- package/src/lib/date/date.d.ts +229 -0
- package/src/lib/date/time.d.ts +7 -0
- package/src/lib/date/week.d.ts +7 -0
- package/src/lib/error/error.d.ts +7 -0
- package/src/lib/filter/filter.d.ts +7 -0
- package/src/lib/function/function.boolean.d.ts +7 -0
- package/src/lib/function/function.forward.d.ts +14 -0
- package/src/lib/getter/getter.cache.d.ts +7 -0
- package/src/lib/getter/getter.d.ts +34 -0
- package/src/lib/getter/getter.map.d.ts +7 -0
- package/src/lib/getter/getter.util.d.ts +7 -0
- package/src/lib/grouping.d.ts +8 -0
- package/src/lib/hash.d.ts +1 -0
- package/src/lib/key.d.ts +16 -0
- package/src/lib/map/map.key.d.ts +14 -0
- package/src/lib/model/id.batch.d.ts +7 -0
- package/src/lib/model/id.factory.d.ts +7 -0
- package/src/lib/model/model.conversion.d.ts +35 -0
- package/src/lib/model/model.copy.d.ts +7 -0
- package/src/lib/model/model.d.ts +19 -0
- package/src/lib/model/model.modify.d.ts +14 -0
- package/src/lib/nodejs/stream.d.ts +7 -0
- package/src/lib/number/bound.d.ts +3 -0
- package/src/lib/number/dollar.d.ts +7 -0
- package/src/lib/number/factory.d.ts +7 -0
- package/src/lib/number/random.d.ts +1 -0
- package/src/lib/number/round.d.ts +22 -0
- package/src/lib/number/sort.d.ts +7 -0
- package/src/lib/number/transform.d.ts +7 -0
- package/src/lib/object/object.array.delta.d.ts +7 -0
- package/src/lib/object/object.equal.d.ts +7 -0
- package/src/lib/object/object.filter.pojo.d.ts +87 -0
- package/src/lib/object/object.filter.tuple.d.ts +16 -0
- package/src/lib/object/object.key.d.ts +14 -0
- package/src/lib/object/object.map.d.ts +14 -0
- package/src/lib/path/path.d.ts +9 -0
- package/src/lib/promise/promise.d.ts +21 -0
- package/src/lib/promise/promise.factory.d.ts +7 -0
- package/src/lib/promise/promise.task.d.ts +7 -0
- package/src/lib/service/handler.config.d.ts +28 -0
- package/src/lib/service/handler.d.ts +14 -0
- package/src/lib/set/set.d.ts +21 -0
- package/src/lib/set/set.decision.d.ts +7 -0
- package/src/lib/set/set.delta.d.ts +7 -0
- package/src/lib/set/set.selection.d.ts +7 -0
- package/src/lib/sort.d.ts +8 -0
- package/src/lib/string/char.d.ts +7 -0
- package/src/lib/string/dencoder.d.ts +35 -0
- package/src/lib/string/factory.d.ts +22 -1
- package/src/lib/string/replace.d.ts +78 -0
- package/src/lib/string/search.d.ts +7 -0
- package/src/lib/string/sort.d.ts +7 -0
- package/src/lib/string/string.d.ts +1 -0
- package/src/lib/string/transform.d.ts +53 -0
- package/src/lib/string/tree.d.ts +7 -0
- package/src/lib/string/url.d.ts +7 -0
- package/src/lib/tree/tree.array.d.ts +1 -0
- package/src/lib/tree/tree.explore.d.ts +3 -0
- package/src/lib/type.d.ts +3 -2
- package/src/lib/value/bound.d.ts +28 -0
- package/src/lib/value/comparator.d.ts +16 -0
- package/src/lib/value/decision.d.ts +5 -0
- package/src/lib/value/equal.d.ts +2 -0
- package/src/lib/value/indexed.d.ts +127 -0
- package/src/lib/value/map.d.ts +22 -0
- package/src/lib/value/maybe.type.d.ts +2 -2
- package/src/lib/value/modifier.d.ts +13 -0
- package/src/lib/value/point.d.ts +56 -0
- package/src/lib/value/use.d.ts +37 -0
- package/src/lib/value/vector.d.ts +7 -0
- package/test/index.cjs.js +17 -4
- package/test/index.esm.js +17 -4
- package/test/package.json +2 -2
- package/test/src/lib/shared/shared.fail.d.ts +24 -5
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dereekb/util/eslint",
|
|
3
|
+
"version": "13.11.4",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@typescript-eslint/utils": "8.59.0"
|
|
6
|
+
},
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@typescript-eslint/parser": "8.59.0",
|
|
9
|
+
"eslint": "9.39.4"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
".": {
|
|
14
|
+
"module": "./index.esm.js",
|
|
15
|
+
"types": "./index.d.ts",
|
|
16
|
+
"import": "./index.cjs.mjs",
|
|
17
|
+
"default": "./index.cjs.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"module": "./index.esm.js",
|
|
21
|
+
"main": "./index.cjs.js",
|
|
22
|
+
"types": "./index.d.ts"
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bundler hint string that marks a function call as side-effect-free.
|
|
3
|
+
*/
|
|
4
|
+
export declare const NO_SIDE_EFFECTS_TAG = "@__NO_SIDE_EFFECTS__";
|
|
5
|
+
type AstNode = any;
|
|
6
|
+
export interface JsdocCommentInfo {
|
|
7
|
+
readonly node: AstNode;
|
|
8
|
+
readonly text: string;
|
|
9
|
+
readonly hasNoSideEffects: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface FunctionLeadingContext {
|
|
12
|
+
readonly jsdoc: JsdocCommentInfo | null;
|
|
13
|
+
/**
|
|
14
|
+
* Adjacent `@__NO_SIDE_EFFECTS__` line/block comments that should be migrated into the JSDoc
|
|
15
|
+
* and removed. Excludes the implementation-leading annotation on overloaded functions, which
|
|
16
|
+
* is tracked separately by {@link implLineComment} because it must be preserved.
|
|
17
|
+
*/
|
|
18
|
+
readonly orphanLineComments: readonly AstNode[];
|
|
19
|
+
/**
|
|
20
|
+
* True when this implementation is preceded by sibling overload signatures (`TSDeclareFunction`
|
|
21
|
+
* statements with the same name).
|
|
22
|
+
*/
|
|
23
|
+
readonly hasOverloads: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The `@__NO_SIDE_EFFECTS__` line/block comment immediately above the implementation
|
|
26
|
+
* declaration when the function has overloads. TypeScript erases overload signatures during
|
|
27
|
+
* emit, so JSDoc placed only on the first overload is dropped from the bundled JS — the
|
|
28
|
+
* line comment directly above the implementation is what survives and reaches the bundler.
|
|
29
|
+
*
|
|
30
|
+
* `null` when the function is single-signature (the line comment is then a removable orphan)
|
|
31
|
+
* or when no such comment is present.
|
|
32
|
+
*/
|
|
33
|
+
readonly implLineComment: AstNode | null;
|
|
34
|
+
/**
|
|
35
|
+
* True when the implementation will carry the `@__NO_SIDE_EFFECTS__` annotation in the emitted
|
|
36
|
+
* JavaScript:
|
|
37
|
+
*
|
|
38
|
+
* - Single-signature: true when the (only) JSDoc carries the tag.
|
|
39
|
+
* - Overloaded: true when a line/block comment with the tag sits immediately above the
|
|
40
|
+
* implementation, OR the implementation has its own JSDoc carrying the tag.
|
|
41
|
+
*
|
|
42
|
+
* This is the signal upstream packages need so esbuild/rollup can tree-shake unused calls.
|
|
43
|
+
*/
|
|
44
|
+
readonly implHasSurvivingAnnotation: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The first statement in the overload chain (i.e. the first overload's export wrapper, or the
|
|
47
|
+
* implementation itself when there are no overloads). Use this as the insertion anchor when
|
|
48
|
+
* creating a brand-new JSDoc for the function, since docs conventionally live on the first
|
|
49
|
+
* overload rather than the implementation.
|
|
50
|
+
*/
|
|
51
|
+
readonly chainStartStatement: AstNode;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns true if the given comment text contains the @__NO_SIDE_EFFECTS__ marker.
|
|
55
|
+
*
|
|
56
|
+
* @param text - The comment body text (without the `/*` and `*\/` delimiters).
|
|
57
|
+
* @returns True when the marker substring is present.
|
|
58
|
+
*/
|
|
59
|
+
export declare function commentContainsNoSideEffects(text: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the leading whitespace (column indent) of the line containing the given offset.
|
|
62
|
+
*
|
|
63
|
+
* @param sourceText - The full source text being inspected.
|
|
64
|
+
* @param offset - A character offset into `sourceText` indicating the line of interest.
|
|
65
|
+
* @returns The whitespace prefix (spaces/tabs) of that line.
|
|
66
|
+
*/
|
|
67
|
+
export declare function getLineIndent(sourceText: string, offset: number): string;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the outermost statement node for a FunctionDeclaration — its `ExportNamedDeclaration`
|
|
70
|
+
* or `ExportDefaultDeclaration` parent if exported, otherwise the declaration itself. This is the
|
|
71
|
+
* node ESLint attaches leading comments to.
|
|
72
|
+
*
|
|
73
|
+
* @param node - The FunctionDeclaration AST node.
|
|
74
|
+
* @returns The statement node ESLint attaches leading comments to.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getStatementAnchor(node: AstNode): AstNode;
|
|
77
|
+
/**
|
|
78
|
+
* Walks backward from the implementation FunctionDeclaration through any overload signatures
|
|
79
|
+
* with the same name, collecting:
|
|
80
|
+
*
|
|
81
|
+
* - The leading JSDoc block (preferring the one attached to the **first** overload, since that's
|
|
82
|
+
* where the function's documentation conventionally lives).
|
|
83
|
+
* - All orphan `@__NO_SIDE_EFFECTS__` line/block comments encountered between overloads or
|
|
84
|
+
* between the last overload and the implementation.
|
|
85
|
+
*
|
|
86
|
+
* This handles the common pattern:
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* \/\*\* doc \*\/
|
|
90
|
+
* export function foo(a: number): number;
|
|
91
|
+
* export function foo(a: string): string;
|
|
92
|
+
* \/\/ \@__NO_SIDE_EFFECTS__
|
|
93
|
+
* export function foo(a: any) { ... }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @param sourceCode - The ESLint `SourceCode` object used to read leading comments.
|
|
97
|
+
* @param implNode - The implementation FunctionDeclaration node.
|
|
98
|
+
* @returns The leading JSDoc (if any) and any orphan side-effect annotation comments.
|
|
99
|
+
*/
|
|
100
|
+
export declare function findFunctionLeadingContext(sourceCode: AstNode, implNode: AstNode): FunctionLeadingContext;
|
|
101
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { utilRequireNoSideEffectsRule, type UtilRequireNoSideEffectsRuleOptions, type UtilRequireNoSideEffectsRuleDefinition } from './require-no-side-effects.rule';
|
|
2
|
+
export { utilPreferNoSideEffectsInJsdocRule, type UtilPreferNoSideEffectsInJsdocRuleDefinition } from './prefer-no-side-effects-in-jsdoc.rule';
|
|
3
|
+
export { utilEslintPlugin, type UtilEslintPlugin } from './plugin';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type UtilRequireNoSideEffectsRuleDefinition } from './require-no-side-effects.rule';
|
|
2
|
+
import { type UtilPreferNoSideEffectsInJsdocRuleDefinition } from './prefer-no-side-effects-in-jsdoc.rule';
|
|
3
|
+
/**
|
|
4
|
+
* ESLint plugin interface for @dereekb/util rules.
|
|
5
|
+
*/
|
|
6
|
+
export interface UtilEslintPlugin {
|
|
7
|
+
readonly rules: {
|
|
8
|
+
readonly 'require-no-side-effects': UtilRequireNoSideEffectsRuleDefinition;
|
|
9
|
+
readonly 'prefer-no-side-effects-in-jsdoc': UtilPreferNoSideEffectsInJsdocRuleDefinition;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* ESLint plugin for @dereekb/util rules.
|
|
14
|
+
*
|
|
15
|
+
* Register as a plugin in your flat ESLint config, then enable individual rules
|
|
16
|
+
* under the chosen plugin prefix (e.g. 'dereekb-util/require-no-side-effects').
|
|
17
|
+
*/
|
|
18
|
+
export declare const utilEslintPlugin: UtilEslintPlugin;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
type AstNode = any;
|
|
2
|
+
/**
|
|
3
|
+
* ESLint rule definition for prefer-no-side-effects-in-jsdoc.
|
|
4
|
+
*/
|
|
5
|
+
export interface UtilPreferNoSideEffectsInJsdocRuleDefinition {
|
|
6
|
+
readonly meta: {
|
|
7
|
+
readonly type: 'suggestion';
|
|
8
|
+
readonly fixable: 'code';
|
|
9
|
+
readonly docs: {
|
|
10
|
+
readonly description: string;
|
|
11
|
+
readonly recommended: boolean;
|
|
12
|
+
};
|
|
13
|
+
readonly messages: {
|
|
14
|
+
readonly preferJsdocPlacement: string;
|
|
15
|
+
readonly missingImplAnnotationOverloaded: string;
|
|
16
|
+
};
|
|
17
|
+
readonly schema: readonly object[];
|
|
18
|
+
};
|
|
19
|
+
create(context: {
|
|
20
|
+
options: unknown[];
|
|
21
|
+
report: (descriptor: {
|
|
22
|
+
node: AstNode;
|
|
23
|
+
messageId: string;
|
|
24
|
+
data?: Record<string, string>;
|
|
25
|
+
fix?: (fixer: AstNode) => AstNode | AstNode[];
|
|
26
|
+
}) => void;
|
|
27
|
+
sourceCode: AstNode;
|
|
28
|
+
}): Record<string, (node: AstNode) => void>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* ESLint rule that flags functions with both a JSDoc block and a separate
|
|
32
|
+
* `// @__NO_SIDE_EFFECTS__` (or block-comment equivalent) line comment between
|
|
33
|
+
* the JSDoc and the declaration. Auto-fix migrates the annotation into the JSDoc
|
|
34
|
+
* (last tag before the closing) and removes the standalone comment, since the
|
|
35
|
+
* JSDoc form is the workspace's preferred placement.
|
|
36
|
+
*
|
|
37
|
+
* Unlike `require-no-side-effects`, this rule does not require the function to
|
|
38
|
+
* be tagged as a factory — it triggers purely on the presence of an existing
|
|
39
|
+
* line-comment annotation alongside a JSDoc, so it can sweep all 688 historical
|
|
40
|
+
* annotations through `eslint --fix`.
|
|
41
|
+
*
|
|
42
|
+
* Overloaded functions are a special case: TypeScript erases overload signatures
|
|
43
|
+
* during emit, so a JSDoc tag on the first overload doesn't reach the bundled JS.
|
|
44
|
+
* The `// @__NO_SIDE_EFFECTS__` line comment immediately above the implementation
|
|
45
|
+
* is the only annotation that survives compilation, so this rule preserves it
|
|
46
|
+
* (and treats line comments between overloads — but not directly above the impl —
|
|
47
|
+
* as ordinary orphans to migrate).
|
|
48
|
+
*/
|
|
49
|
+
export declare const utilPreferNoSideEffectsInJsdocRule: UtilPreferNoSideEffectsInJsdocRuleDefinition;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the require-no-side-effects rule.
|
|
3
|
+
*/
|
|
4
|
+
export interface UtilRequireNoSideEffectsRuleOptions {
|
|
5
|
+
/**
|
|
6
|
+
* When true, also flag functions whose names match the factory naming patterns
|
|
7
|
+
* in addition to JSDoc-tag detection.
|
|
8
|
+
*/
|
|
9
|
+
readonly checkNamePatterns?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Additional name pattern source strings (compiled to RegExp) when `checkNamePatterns` is true.
|
|
12
|
+
*/
|
|
13
|
+
readonly additionalNamePatterns?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
type AstNode = any;
|
|
16
|
+
/**
|
|
17
|
+
* ESLint rule definition for require-no-side-effects.
|
|
18
|
+
*/
|
|
19
|
+
export interface UtilRequireNoSideEffectsRuleDefinition {
|
|
20
|
+
readonly meta: {
|
|
21
|
+
readonly type: 'suggestion';
|
|
22
|
+
readonly fixable: 'code';
|
|
23
|
+
readonly docs: {
|
|
24
|
+
readonly description: string;
|
|
25
|
+
readonly recommended: boolean;
|
|
26
|
+
};
|
|
27
|
+
readonly messages: {
|
|
28
|
+
readonly missingNoSideEffectsJsdoc: string;
|
|
29
|
+
readonly missingJsdocForFactory: string;
|
|
30
|
+
readonly missingImplAnnotationOverloaded: string;
|
|
31
|
+
};
|
|
32
|
+
readonly schema: readonly object[];
|
|
33
|
+
};
|
|
34
|
+
create(context: {
|
|
35
|
+
options: UtilRequireNoSideEffectsRuleOptions[];
|
|
36
|
+
report: (descriptor: {
|
|
37
|
+
node: AstNode;
|
|
38
|
+
messageId: string;
|
|
39
|
+
data?: Record<string, string>;
|
|
40
|
+
fix?: (fixer: AstNode) => AstNode | AstNode[];
|
|
41
|
+
}) => void;
|
|
42
|
+
sourceCode: AstNode;
|
|
43
|
+
}): Record<string, (node: AstNode) => void>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* ESLint rule requiring the side-effect-free annotation on every factory function — that is,
|
|
47
|
+
* declarations carrying the `@dbxUtilKind factory` JSDoc tag (and optionally functions matching
|
|
48
|
+
* factory name patterns). The rule guarantees the marker reaches the bundled JavaScript so
|
|
49
|
+
* esbuild/rollup can drop unused calls during tree-shaking.
|
|
50
|
+
*
|
|
51
|
+
* Behavior:
|
|
52
|
+
*
|
|
53
|
+
* - **Single-signature functions:** the JSDoc above the declaration is preserved during emit, so
|
|
54
|
+
* the rule simply requires `@__NO_SIDE_EFFECTS__` inside that JSDoc.
|
|
55
|
+
*
|
|
56
|
+
* - **Overloaded functions:** TypeScript erases overload signatures during emit, so a JSDoc tag
|
|
57
|
+
* placed only on the first overload is dropped from the bundled JS. The rule additionally requires
|
|
58
|
+
* either (a) a `// @__NO_SIDE_EFFECTS__` line comment immediately above the implementation, or
|
|
59
|
+
* (b) a JSDoc with the tag attached directly to the implementation. Auto-fix inserts the line
|
|
60
|
+
* comment alongside the JSDoc tag so consumer-facing docs and the bundler annotation stay in sync.
|
|
61
|
+
*
|
|
62
|
+
* Auto-fix also removes any redundant standalone-comment annotations between the JSDoc and the
|
|
63
|
+
* declaration (other than the required impl-leading line comment on overloaded functions), and
|
|
64
|
+
* when no JSDoc is present, creates a minimal one carrying both tags.
|
|
65
|
+
*/
|
|
66
|
+
export declare const utilRequireNoSideEffectsRule: UtilRequireNoSideEffectsRuleDefinition;
|
|
67
|
+
export {};
|
package/fetch/package.json
CHANGED