@dereekb/util 13.23.0 → 13.25.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.
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@dereekb/util/eslint",
3
- "version": "13.23.0",
3
+ "version": "13.25.0",
4
4
  "peerDependencies": {
5
- "@dereekb/util": "13.23.0",
6
- "@typescript-eslint/utils": "8.59.3"
5
+ "@dereekb/util": "13.25.0",
6
+ "@typescript-eslint/utils": "8.59.3",
7
+ "typescript": "5.9.3"
7
8
  },
8
9
  "devDependencies": {
9
10
  "@typescript-eslint/parser": "8.59.3",
@@ -21,6 +21,7 @@ export { UTIL_REQUIRE_DBX_RULE_COMPANION_TAGS_RULE, type UtilRequireDbxRuleCompa
21
21
  export { UTIL_REQUIRE_CONSTANT_NAMING_RULE, type UtilRequireConstantNamingRuleOptions, type UtilRequireConstantNamingRuleDefinition } from './require-constant-naming.rule';
22
22
  export { UTIL_REQUIRE_DEFAULT_PREFIX_NAMING_RULE, type UtilRequireDefaultPrefixNamingRuleOptions, type UtilRequireDefaultPrefixNamingRuleDefinition } from './require-default-prefix-naming.rule';
23
23
  export { UTIL_REQUIRE_EXPORTED_JSDOC_EXAMPLE_RULE, type UtilRequireExportedJsdocExampleRuleOptions, type UtilRequireExportedJsdocExampleRuleDefinition } from './require-exported-jsdoc-example.rule';
24
+ export { UTIL_NO_ENUM_LITERAL_CAST_RULE, type UtilNoEnumLiteralCastRuleDefinition } from './no-enum-literal-cast.rule';
24
25
  export { UTIL_ESLINT_PLUGIN, utilESLintPlugin, type UtilEslintPlugin } from './plugin';
25
26
  export { getStatementAnchor, leadingJsdocFor } from './comments';
26
27
  export { parseJsdocComment, type ParsedJsdoc, type ParsedJsdocTag, type ParsedJsdocLine } from './jsdoc-parser';
@@ -0,0 +1,51 @@
1
+ interface AstNode {
2
+ readonly type: string;
3
+ [key: string]: any;
4
+ }
5
+ /**
6
+ * ESLint rule definition for no-enum-literal-cast.
7
+ */
8
+ export interface UtilNoEnumLiteralCastRuleDefinition {
9
+ readonly meta: {
10
+ readonly type: 'problem';
11
+ readonly fixable: 'code';
12
+ readonly docs: {
13
+ readonly description: string;
14
+ readonly recommended: boolean;
15
+ };
16
+ readonly messages: {
17
+ readonly useEnumMember: string;
18
+ readonly unsafeEnumCast: string;
19
+ };
20
+ readonly schema: readonly object[];
21
+ };
22
+ create(context: {
23
+ report: (descriptor: {
24
+ node: AstNode;
25
+ messageId: string;
26
+ data?: Record<string, string>;
27
+ fix?: (fixer: AstNode) => AstNode | AstNode[];
28
+ }) => void;
29
+ sourceCode: AstNode;
30
+ }): Record<string, (node: AstNode) => void>;
31
+ }
32
+ /**
33
+ * ESLint rule that flags a numeric/string literal asserted onto an enum type — e.g.
34
+ * `layer: 0 as PromptLayer` — and steers it to the named member (`PromptLayer.REPLY_PROTOCOL`).
35
+ *
36
+ * The cast is doubly harmful: it bypasses type-checking (any in-range *or* out-of-range number
37
+ * satisfies `n as SomeEnum`, so `99 as PromptLayer` compiles silently) and it hides intent behind a
38
+ * magic number. The rule is type-aware: it fires ONLY when the assertion target resolves to a real
39
+ * `enum` / `const enum`, so legitimate branded-primitive aliases (`30 as EntityId`,
40
+ * `7001 as ConceptId`) — which have no named members and for which the cast is the sanctioned form —
41
+ * are never touched.
42
+ *
43
+ * When the literal matches a member, the fix rewrites the assertion to `Enum.MEMBER` and, when the
44
+ * enum is bound via `import type` / `import { type … }`, converts that binding to a value import so
45
+ * the rewritten value reference compiles. When the literal matches NO member, the rule reports the
46
+ * unsafe cast without a fix (there is no correct member to substitute).
47
+ *
48
+ * Requires type information — it no-ops in lint passes without it (no `projectService` / `project`).
49
+ */
50
+ export declare const UTIL_NO_ENUM_LITERAL_CAST_RULE: UtilNoEnumLiteralCastRuleDefinition;
51
+ export {};
@@ -23,6 +23,7 @@ import { type UtilRequireDefaultPrefixNamingRuleDefinition } from './require-def
23
23
  import { type UtilRequireExportedJsdocExampleRuleDefinition } from './require-exported-jsdoc-example.rule';
24
24
  import { type UtilNoInlineStringEmptyObjectIntersectionRuleDefinition } from './no-inline-string-empty-object-intersection.rule';
25
25
  import { type UtilPreferSuggestedStringRuleDefinition } from './prefer-suggested-string.rule';
26
+ import { type UtilNoEnumLiteralCastRuleDefinition } from './no-enum-literal-cast.rule';
26
27
  /**
27
28
  * ESLint plugin interface for @dereekb/util rules.
28
29
  */
@@ -54,6 +55,7 @@ export interface UtilEslintPlugin {
54
55
  readonly 'require-exported-jsdoc-example': UtilRequireExportedJsdocExampleRuleDefinition;
55
56
  readonly 'no-inline-string-empty-object-intersection': UtilNoInlineStringEmptyObjectIntersectionRuleDefinition;
56
57
  readonly 'prefer-suggested-string': UtilPreferSuggestedStringRuleDefinition;
58
+ readonly 'no-enum-literal-cast': UtilNoEnumLiteralCastRuleDefinition;
57
59
  };
58
60
  }
59
61
  /**
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@dereekb/util/fetch",
3
- "version": "13.23.0",
3
+ "version": "13.25.0",
4
4
  "peerDependencies": {
5
- "@dereekb/util": "13.23.0",
5
+ "@dereekb/util": "13.25.0",
6
6
  "make-error": "^1.3.6",
7
7
  "fast-content-type-parse": "^3.0.0"
8
8
  },