@sarj/eslint-plugin 2.4.1 → 2.6.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/dist/index.cjs +94 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +95 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -7,7 +7,7 @@ declare const rules: {
|
|
|
7
7
|
"no-client-side-data-fetching": _typescript_eslint_utils_ts_eslint.RuleModule<"noClientFetch", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
8
8
|
name: string;
|
|
9
9
|
};
|
|
10
|
-
"no-comment-cruft": _typescript_eslint_utils_ts_eslint.RuleModule<"commentedOutCode" | "sectionBanner" | "fileHeaderPreamble", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
10
|
+
"no-comment-cruft": _typescript_eslint_utils_ts_eslint.RuleModule<"commentedOutCode" | "sectionBanner" | "fileHeaderPreamble" | "redundantNarration", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
11
11
|
name: string;
|
|
12
12
|
};
|
|
13
13
|
"no-enum": _typescript_eslint_utils_ts_eslint.RuleModule<"noEnum", readonly [{
|
|
@@ -72,6 +72,9 @@ declare const rules: {
|
|
|
72
72
|
"no-secret-in-log": _typescript_eslint_utils_ts_eslint.RuleModule<"noSecretInLog", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
73
73
|
name: string;
|
|
74
74
|
};
|
|
75
|
+
"no-unsafe-cast": _typescript_eslint_utils_ts_eslint.RuleModule<"asAny" | "doubleCast", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
76
|
+
name: string;
|
|
77
|
+
};
|
|
75
78
|
"prefer-string-literal-union": _typescript_eslint_utils_ts_eslint.RuleModule<"bareChoiceField" | "comparisonCluster", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
76
79
|
name: string;
|
|
77
80
|
};
|
|
@@ -91,7 +94,7 @@ declare const plugin: {
|
|
|
91
94
|
"no-client-side-data-fetching": _typescript_eslint_utils_ts_eslint.RuleModule<"noClientFetch", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
92
95
|
name: string;
|
|
93
96
|
};
|
|
94
|
-
"no-comment-cruft": _typescript_eslint_utils_ts_eslint.RuleModule<"commentedOutCode" | "sectionBanner" | "fileHeaderPreamble", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
97
|
+
"no-comment-cruft": _typescript_eslint_utils_ts_eslint.RuleModule<"commentedOutCode" | "sectionBanner" | "fileHeaderPreamble" | "redundantNarration", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
95
98
|
name: string;
|
|
96
99
|
};
|
|
97
100
|
"no-enum": _typescript_eslint_utils_ts_eslint.RuleModule<"noEnum", readonly [{
|
|
@@ -156,6 +159,9 @@ declare const plugin: {
|
|
|
156
159
|
"no-secret-in-log": _typescript_eslint_utils_ts_eslint.RuleModule<"noSecretInLog", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
157
160
|
name: string;
|
|
158
161
|
};
|
|
162
|
+
"no-unsafe-cast": _typescript_eslint_utils_ts_eslint.RuleModule<"asAny" | "doubleCast", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
163
|
+
name: string;
|
|
164
|
+
};
|
|
159
165
|
"prefer-string-literal-union": _typescript_eslint_utils_ts_eslint.RuleModule<"bareChoiceField" | "comparisonCluster", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
160
166
|
name: string;
|
|
161
167
|
};
|
|
@@ -187,6 +193,7 @@ declare const plugin: {
|
|
|
187
193
|
"@sarj/no-fat-try-blocks": string;
|
|
188
194
|
"@sarj/no-cors-wildcard-with-credentials": string;
|
|
189
195
|
"@sarj/no-secret-in-log": string;
|
|
196
|
+
"@sarj/no-unsafe-cast": string;
|
|
190
197
|
"@sarj/single-public-export": string;
|
|
191
198
|
"@sarj/prefer-string-literal-union": string;
|
|
192
199
|
};
|
|
@@ -217,6 +224,7 @@ declare const plugin: {
|
|
|
217
224
|
"@sarj/no-fat-try-blocks": string;
|
|
218
225
|
"@sarj/no-cors-wildcard-with-credentials": string;
|
|
219
226
|
"@sarj/no-secret-in-log": string;
|
|
227
|
+
"@sarj/no-unsafe-cast": string;
|
|
220
228
|
"@sarj/single-public-export": string;
|
|
221
229
|
"@sarj/prefer-string-literal-union": string;
|
|
222
230
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ declare const rules: {
|
|
|
7
7
|
"no-client-side-data-fetching": _typescript_eslint_utils_ts_eslint.RuleModule<"noClientFetch", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
8
8
|
name: string;
|
|
9
9
|
};
|
|
10
|
-
"no-comment-cruft": _typescript_eslint_utils_ts_eslint.RuleModule<"commentedOutCode" | "sectionBanner" | "fileHeaderPreamble", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
10
|
+
"no-comment-cruft": _typescript_eslint_utils_ts_eslint.RuleModule<"commentedOutCode" | "sectionBanner" | "fileHeaderPreamble" | "redundantNarration", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
11
11
|
name: string;
|
|
12
12
|
};
|
|
13
13
|
"no-enum": _typescript_eslint_utils_ts_eslint.RuleModule<"noEnum", readonly [{
|
|
@@ -72,6 +72,9 @@ declare const rules: {
|
|
|
72
72
|
"no-secret-in-log": _typescript_eslint_utils_ts_eslint.RuleModule<"noSecretInLog", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
73
73
|
name: string;
|
|
74
74
|
};
|
|
75
|
+
"no-unsafe-cast": _typescript_eslint_utils_ts_eslint.RuleModule<"asAny" | "doubleCast", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
76
|
+
name: string;
|
|
77
|
+
};
|
|
75
78
|
"prefer-string-literal-union": _typescript_eslint_utils_ts_eslint.RuleModule<"bareChoiceField" | "comparisonCluster", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
76
79
|
name: string;
|
|
77
80
|
};
|
|
@@ -91,7 +94,7 @@ declare const plugin: {
|
|
|
91
94
|
"no-client-side-data-fetching": _typescript_eslint_utils_ts_eslint.RuleModule<"noClientFetch", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
92
95
|
name: string;
|
|
93
96
|
};
|
|
94
|
-
"no-comment-cruft": _typescript_eslint_utils_ts_eslint.RuleModule<"commentedOutCode" | "sectionBanner" | "fileHeaderPreamble", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
97
|
+
"no-comment-cruft": _typescript_eslint_utils_ts_eslint.RuleModule<"commentedOutCode" | "sectionBanner" | "fileHeaderPreamble" | "redundantNarration", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
95
98
|
name: string;
|
|
96
99
|
};
|
|
97
100
|
"no-enum": _typescript_eslint_utils_ts_eslint.RuleModule<"noEnum", readonly [{
|
|
@@ -156,6 +159,9 @@ declare const plugin: {
|
|
|
156
159
|
"no-secret-in-log": _typescript_eslint_utils_ts_eslint.RuleModule<"noSecretInLog", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
157
160
|
name: string;
|
|
158
161
|
};
|
|
162
|
+
"no-unsafe-cast": _typescript_eslint_utils_ts_eslint.RuleModule<"asAny" | "doubleCast", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
163
|
+
name: string;
|
|
164
|
+
};
|
|
159
165
|
"prefer-string-literal-union": _typescript_eslint_utils_ts_eslint.RuleModule<"bareChoiceField" | "comparisonCluster", readonly [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
160
166
|
name: string;
|
|
161
167
|
};
|
|
@@ -187,6 +193,7 @@ declare const plugin: {
|
|
|
187
193
|
"@sarj/no-fat-try-blocks": string;
|
|
188
194
|
"@sarj/no-cors-wildcard-with-credentials": string;
|
|
189
195
|
"@sarj/no-secret-in-log": string;
|
|
196
|
+
"@sarj/no-unsafe-cast": string;
|
|
190
197
|
"@sarj/single-public-export": string;
|
|
191
198
|
"@sarj/prefer-string-literal-union": string;
|
|
192
199
|
};
|
|
@@ -217,6 +224,7 @@ declare const plugin: {
|
|
|
217
224
|
"@sarj/no-fat-try-blocks": string;
|
|
218
225
|
"@sarj/no-cors-wildcard-with-credentials": string;
|
|
219
226
|
"@sarj/no-secret-in-log": string;
|
|
227
|
+
"@sarj/no-unsafe-cast": string;
|
|
220
228
|
"@sarj/single-public-export": string;
|
|
221
229
|
"@sarj/prefer-string-literal-union": string;
|
|
222
230
|
};
|
package/dist/index.js
CHANGED
|
@@ -213,6 +213,8 @@ var no_client_side_data_fetching_default = ESLintUtils2.RuleCreator(
|
|
|
213
213
|
// src/rules/no-comment-cruft.ts
|
|
214
214
|
import { ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
|
|
215
215
|
var LEADING_PREAMBLE_MIN = 4;
|
|
216
|
+
var STEP_NARRATION_RE = /^(?:first(?:ly)?|second(?:ly)?|third(?:ly)?|then|next|after(?:wards| that)?|finally|lastly|now)\s*[,:]\s*\S|^step\s+\d+\b/i;
|
|
217
|
+
var META_COMMENTARY_RE = /\b(?:for now|keeping (?:it|this) simple|could be (?:refactored|improved|cleaned up|simplified)|refactor(?:ed|ing)? (?:later|this)|not sure (?:if|whether|why|how)|quick[- ](?:and[- ]dirty|fix)|(?:a |bit of a )?hacky|is a hack|temporary (?:solution|workaround|fix|hack)|revisit (?:this|later|below)|clean (?:this|it) up|not ideal|placeholder for now)\b/i;
|
|
216
218
|
var DIRECTIVE_RE = /^(eslint\b|eslint-|@ts-|prettier-ignore|prettier\b|biome-|c8\b|v8\b|istanbul\b|@type\b|@vite|webpack|<reference|<amd|global\b|noinspection|todo\b|fixme\b|hack\b|xxx\b)/i;
|
|
217
219
|
var LICENSE_RE = /copyright|licen[cs]ed?|spdx|permission is hereby granted|all rights reserved/i;
|
|
218
220
|
var BANNER_FULL_RE = /^[\s\-=*#~_+.]{4,}$/;
|
|
@@ -251,6 +253,13 @@ function isProse(text) {
|
|
|
251
253
|
}
|
|
252
254
|
return false;
|
|
253
255
|
}
|
|
256
|
+
function isRedundantNarration(body) {
|
|
257
|
+
const t = body.trim();
|
|
258
|
+
if (!t || looksLikeCode(t) || hasPseudocode(t)) return false;
|
|
259
|
+
if (STEP_NARRATION_RE.test(t)) return true;
|
|
260
|
+
if (META_COMMENTARY_RE.test(t)) return true;
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
254
263
|
function hasCommentedOutCode(texts, precedingProse) {
|
|
255
264
|
for (let i = 0; i < texts.length; i++) {
|
|
256
265
|
const line = texts[i];
|
|
@@ -276,7 +285,8 @@ var no_comment_cruft_default = ESLintUtils3.RuleCreator(
|
|
|
276
285
|
messages: {
|
|
277
286
|
commentedOutCode: "Commented-out code \u2014 delete it; git history remembers.",
|
|
278
287
|
sectionBanner: "Section-banner / region comment \u2014 structure code with functions, not ASCII rules.",
|
|
279
|
-
fileHeaderPreamble: "File-header comment preamble \u2014 use a brief doc comment for the why, not a block of `//` lines."
|
|
288
|
+
fileHeaderPreamble: "File-header comment preamble \u2014 use a brief doc comment for the why, not a block of `//` lines.",
|
|
289
|
+
redundantNarration: "Comment narrates the code \u2014 delete it or say *why*, not *what*. Code is self-documenting."
|
|
280
290
|
}
|
|
281
291
|
},
|
|
282
292
|
defaultOptions: [],
|
|
@@ -331,6 +341,13 @@ var no_comment_cruft_default = ESLintUtils3.RuleCreator(
|
|
|
331
341
|
const precedingProse = prev !== void 0 && prev.type === "Line" && prev.loc.end.line === comment.loc.start.line - 1 && isProse(stripCommentMarker(prev.value));
|
|
332
342
|
if (hasCommentedOutCode(texts, precedingProse)) {
|
|
333
343
|
context.report({ node: comment, messageId: "commentedOutCode" });
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (comment.type === "Line" && texts.length === 1) {
|
|
347
|
+
const body = texts[0];
|
|
348
|
+
if (body !== void 0 && isRedundantNarration(body)) {
|
|
349
|
+
context.report({ node: comment, messageId: "redundantNarration" });
|
|
350
|
+
}
|
|
334
351
|
}
|
|
335
352
|
}
|
|
336
353
|
reportLeadingPreamble(comments, firstCodeLine);
|
|
@@ -3230,10 +3247,56 @@ var no_secret_in_log_default = ESLintUtils23.RuleCreator(
|
|
|
3230
3247
|
}
|
|
3231
3248
|
});
|
|
3232
3249
|
|
|
3250
|
+
// src/rules/no-unsafe-cast.ts
|
|
3251
|
+
import { ESLintUtils as ESLintUtils24 } from "@typescript-eslint/utils";
|
|
3252
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES13 } from "@typescript-eslint/utils";
|
|
3253
|
+
function isAnyAnnotation(node) {
|
|
3254
|
+
return node.type === AST_NODE_TYPES13.TSAnyKeyword;
|
|
3255
|
+
}
|
|
3256
|
+
function isConstAssertion(typeAnnotation) {
|
|
3257
|
+
return typeAnnotation.type === AST_NODE_TYPES13.TSTypeReference && typeAnnotation.typeName.type === AST_NODE_TYPES13.Identifier && typeAnnotation.typeName.name === "const";
|
|
3258
|
+
}
|
|
3259
|
+
var no_unsafe_cast_default = ESLintUtils24.RuleCreator(
|
|
3260
|
+
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3261
|
+
)({
|
|
3262
|
+
name: "no-unsafe-cast",
|
|
3263
|
+
meta: {
|
|
3264
|
+
type: "problem",
|
|
3265
|
+
docs: {
|
|
3266
|
+
description: "Disallow `as any`/`<any>` casts and `as unknown as T` double-casts, which fully disable type checking."
|
|
3267
|
+
},
|
|
3268
|
+
schema: [],
|
|
3269
|
+
messages: {
|
|
3270
|
+
asAny: "`as any` disables type checking on this value. Narrow with a type guard, model the shape, or cast to a specific type instead.",
|
|
3271
|
+
doubleCast: "`as unknown as T` double-cast bypasses the compiler's structural check. Prefer a runtime validator (e.g. a zod schema) or an accurate type at the boundary."
|
|
3272
|
+
}
|
|
3273
|
+
},
|
|
3274
|
+
defaultOptions: [],
|
|
3275
|
+
create(context) {
|
|
3276
|
+
function checkAssertion(node) {
|
|
3277
|
+
if (isConstAssertion(node.typeAnnotation)) {
|
|
3278
|
+
return;
|
|
3279
|
+
}
|
|
3280
|
+
if (isAnyAnnotation(node.typeAnnotation)) {
|
|
3281
|
+
context.report({ node, messageId: "asAny" });
|
|
3282
|
+
return;
|
|
3283
|
+
}
|
|
3284
|
+
const inner = node.expression;
|
|
3285
|
+
if (inner.type === AST_NODE_TYPES13.TSAsExpression || inner.type === AST_NODE_TYPES13.TSTypeAssertion) {
|
|
3286
|
+
context.report({ node, messageId: "doubleCast" });
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
return {
|
|
3290
|
+
TSAsExpression: checkAssertion,
|
|
3291
|
+
TSTypeAssertion: checkAssertion
|
|
3292
|
+
};
|
|
3293
|
+
}
|
|
3294
|
+
});
|
|
3295
|
+
|
|
3233
3296
|
// src/rules/prefer-string-literal-union.ts
|
|
3234
3297
|
import {
|
|
3235
|
-
ESLintUtils as
|
|
3236
|
-
AST_NODE_TYPES as
|
|
3298
|
+
ESLintUtils as ESLintUtils25,
|
|
3299
|
+
AST_NODE_TYPES as AST_NODE_TYPES14
|
|
3237
3300
|
} from "@typescript-eslint/utils";
|
|
3238
3301
|
import * as ts from "typescript";
|
|
3239
3302
|
var CHOICE_TOKENS = /* @__PURE__ */ new Set([
|
|
@@ -3277,19 +3340,19 @@ function isChoiceLikeName(name) {
|
|
|
3277
3340
|
return CHOICE_TOKENS.has(lastWord(name));
|
|
3278
3341
|
}
|
|
3279
3342
|
function keyName(key) {
|
|
3280
|
-
if (key.type ===
|
|
3343
|
+
if (key.type === AST_NODE_TYPES14.Identifier) {
|
|
3281
3344
|
return key.name;
|
|
3282
3345
|
}
|
|
3283
|
-
if (key.type ===
|
|
3346
|
+
if (key.type === AST_NODE_TYPES14.Literal && typeof key.value === "string") {
|
|
3284
3347
|
return key.value;
|
|
3285
3348
|
}
|
|
3286
3349
|
return null;
|
|
3287
3350
|
}
|
|
3288
3351
|
function isStringLiteralMember(t) {
|
|
3289
|
-
return t.type ===
|
|
3352
|
+
return t.type === AST_NODE_TYPES14.TSLiteralType && t.literal.type === AST_NODE_TYPES14.Literal && typeof t.literal.value === "string";
|
|
3290
3353
|
}
|
|
3291
3354
|
function isStringLiteralUnion(node) {
|
|
3292
|
-
if (node?.type !==
|
|
3355
|
+
if (node?.type !== AST_NODE_TYPES14.TSUnionType) {
|
|
3293
3356
|
return false;
|
|
3294
3357
|
}
|
|
3295
3358
|
return node.types.filter(isStringLiteralMember).length >= MIN_CLUSTER_SIZE;
|
|
@@ -3318,12 +3381,12 @@ function bindingSourceExpression(decl) {
|
|
|
3318
3381
|
return ts.isForOfStatement(node) ? node.expression : node.initializer;
|
|
3319
3382
|
}
|
|
3320
3383
|
function refKey(node) {
|
|
3321
|
-
if (node.type ===
|
|
3384
|
+
if (node.type === AST_NODE_TYPES14.Identifier) {
|
|
3322
3385
|
return node.name;
|
|
3323
3386
|
}
|
|
3324
|
-
if (node.type ===
|
|
3387
|
+
if (node.type === AST_NODE_TYPES14.MemberExpression && !node.computed) {
|
|
3325
3388
|
const inner = refKey(node.object);
|
|
3326
|
-
if (inner === null || node.property.type !==
|
|
3389
|
+
if (inner === null || node.property.type !== AST_NODE_TYPES14.Identifier) {
|
|
3327
3390
|
return null;
|
|
3328
3391
|
}
|
|
3329
3392
|
return `${inner}.${node.property.name}`;
|
|
@@ -3331,12 +3394,12 @@ function refKey(node) {
|
|
|
3331
3394
|
return null;
|
|
3332
3395
|
}
|
|
3333
3396
|
function strLiteral(node) {
|
|
3334
|
-
if (node.type ===
|
|
3397
|
+
if (node.type === AST_NODE_TYPES14.Literal && typeof node.value === "string") {
|
|
3335
3398
|
return node.value;
|
|
3336
3399
|
}
|
|
3337
3400
|
return null;
|
|
3338
3401
|
}
|
|
3339
|
-
var prefer_string_literal_union_default =
|
|
3402
|
+
var prefer_string_literal_union_default = ESLintUtils25.RuleCreator(
|
|
3340
3403
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3341
3404
|
)({
|
|
3342
3405
|
name: "prefer-string-literal-union",
|
|
@@ -3360,7 +3423,7 @@ var prefer_string_literal_union_default = ESLintUtils24.RuleCreator(
|
|
|
3360
3423
|
}
|
|
3361
3424
|
let services;
|
|
3362
3425
|
try {
|
|
3363
|
-
services =
|
|
3426
|
+
services = ESLintUtils25.getParserServices(context);
|
|
3364
3427
|
} catch {
|
|
3365
3428
|
services = null;
|
|
3366
3429
|
}
|
|
@@ -3444,7 +3507,7 @@ var prefer_string_literal_union_default = ESLintUtils24.RuleCreator(
|
|
|
3444
3507
|
containersWithUnion.add(container);
|
|
3445
3508
|
return;
|
|
3446
3509
|
}
|
|
3447
|
-
if (typeNode?.type !==
|
|
3510
|
+
if (typeNode?.type !== AST_NODE_TYPES14.TSStringKeyword) {
|
|
3448
3511
|
return;
|
|
3449
3512
|
}
|
|
3450
3513
|
const name = keyName(key);
|
|
@@ -3532,10 +3595,10 @@ var prefer_string_literal_union_default = ESLintUtils24.RuleCreator(
|
|
|
3532
3595
|
}
|
|
3533
3596
|
};
|
|
3534
3597
|
function refKeyText(node) {
|
|
3535
|
-
if (node.type ===
|
|
3598
|
+
if (node.type === AST_NODE_TYPES14.BinaryExpression) {
|
|
3536
3599
|
return refKey(node.left) ?? refKey(node.right) ?? "value";
|
|
3537
3600
|
}
|
|
3538
|
-
if (node.type ===
|
|
3601
|
+
if (node.type === AST_NODE_TYPES14.SwitchStatement) {
|
|
3539
3602
|
return refKey(node.discriminant) ?? "value";
|
|
3540
3603
|
}
|
|
3541
3604
|
return "value";
|
|
@@ -3544,7 +3607,7 @@ var prefer_string_literal_union_default = ESLintUtils24.RuleCreator(
|
|
|
3544
3607
|
});
|
|
3545
3608
|
|
|
3546
3609
|
// src/rules/single-public-export.ts
|
|
3547
|
-
import { ESLintUtils as
|
|
3610
|
+
import { ESLintUtils as ESLintUtils26, AST_NODE_TYPES as AST_NODE_TYPES15 } from "@typescript-eslint/utils";
|
|
3548
3611
|
var JUNK_DRAWER_STEMS = /* @__PURE__ */ new Set([
|
|
3549
3612
|
"util",
|
|
3550
3613
|
"utils",
|
|
@@ -3578,12 +3641,12 @@ var kebabCase2 = (name) => {
|
|
|
3578
3641
|
}
|
|
3579
3642
|
return normalized.replace(CAMEL_BOUNDARY_RE, "-").toLowerCase();
|
|
3580
3643
|
};
|
|
3581
|
-
var isFunctionExpression = (node) => node !== null && (node.type ===
|
|
3644
|
+
var isFunctionExpression = (node) => node !== null && (node.type === AST_NODE_TYPES15.ArrowFunctionExpression || node.type === AST_NODE_TYPES15.FunctionExpression);
|
|
3582
3645
|
var functionConstName = (decl) => {
|
|
3583
3646
|
if (decl.declarations.length !== 1) return null;
|
|
3584
3647
|
const [declarator] = decl.declarations;
|
|
3585
3648
|
if (declarator === void 0) return null;
|
|
3586
|
-
if (declarator.id.type !==
|
|
3649
|
+
if (declarator.id.type !== AST_NODE_TYPES15.Identifier) return null;
|
|
3587
3650
|
if (!isFunctionExpression(declarator.init)) return null;
|
|
3588
3651
|
return declarator.id.name;
|
|
3589
3652
|
};
|
|
@@ -3597,20 +3660,20 @@ var summarizeExports = (body) => {
|
|
|
3597
3660
|
};
|
|
3598
3661
|
for (const statement of body) {
|
|
3599
3662
|
switch (statement.type) {
|
|
3600
|
-
case
|
|
3663
|
+
case AST_NODE_TYPES15.ExportAllDeclaration:
|
|
3601
3664
|
hasReExport = true;
|
|
3602
3665
|
break;
|
|
3603
|
-
case
|
|
3666
|
+
case AST_NODE_TYPES15.ExportDefaultDeclaration: {
|
|
3604
3667
|
names += 1;
|
|
3605
3668
|
const decl = statement.declaration;
|
|
3606
|
-
if (decl.type ===
|
|
3669
|
+
if (decl.type === AST_NODE_TYPES15.FunctionDeclaration && decl.id !== null) {
|
|
3607
3670
|
candidate = { name: decl.id.name, node: statement };
|
|
3608
|
-
} else if (decl.type ===
|
|
3671
|
+
} else if (decl.type === AST_NODE_TYPES15.ClassDeclaration && decl.id !== null) {
|
|
3609
3672
|
candidate = { name: decl.id.name, node: statement };
|
|
3610
3673
|
}
|
|
3611
3674
|
break;
|
|
3612
3675
|
}
|
|
3613
|
-
case
|
|
3676
|
+
case AST_NODE_TYPES15.ExportNamedDeclaration: {
|
|
3614
3677
|
if (statement.source !== null) {
|
|
3615
3678
|
hasReExport = true;
|
|
3616
3679
|
break;
|
|
@@ -3621,15 +3684,15 @@ var summarizeExports = (body) => {
|
|
|
3621
3684
|
break;
|
|
3622
3685
|
}
|
|
3623
3686
|
switch (decl.type) {
|
|
3624
|
-
case
|
|
3687
|
+
case AST_NODE_TYPES15.FunctionDeclaration:
|
|
3625
3688
|
if (decl.id !== null) addCandidate(decl.id.name, statement);
|
|
3626
3689
|
else names += 1;
|
|
3627
3690
|
break;
|
|
3628
|
-
case
|
|
3691
|
+
case AST_NODE_TYPES15.ClassDeclaration:
|
|
3629
3692
|
if (decl.id !== null) addCandidate(decl.id.name, statement);
|
|
3630
3693
|
else names += 1;
|
|
3631
3694
|
break;
|
|
3632
|
-
case
|
|
3695
|
+
case AST_NODE_TYPES15.VariableDeclaration: {
|
|
3633
3696
|
const fnName = functionConstName(decl);
|
|
3634
3697
|
if (fnName !== null && decl.declarations.length === 1) {
|
|
3635
3698
|
addCandidate(fnName, statement);
|
|
@@ -3649,7 +3712,7 @@ var summarizeExports = (body) => {
|
|
|
3649
3712
|
}
|
|
3650
3713
|
return { names, hasReExport, candidate };
|
|
3651
3714
|
};
|
|
3652
|
-
var single_public_export_default =
|
|
3715
|
+
var single_public_export_default = ESLintUtils26.RuleCreator(
|
|
3653
3716
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
3654
3717
|
)({
|
|
3655
3718
|
name: "single-public-export",
|
|
@@ -3713,13 +3776,14 @@ var rules = {
|
|
|
3713
3776
|
"no-cors-wildcard-with-credentials": no_cors_wildcard_with_credentials_default,
|
|
3714
3777
|
"no-fat-try-blocks": no_fat_try_blocks_default,
|
|
3715
3778
|
"no-secret-in-log": no_secret_in_log_default,
|
|
3779
|
+
"no-unsafe-cast": no_unsafe_cast_default,
|
|
3716
3780
|
"prefer-string-literal-union": prefer_string_literal_union_default,
|
|
3717
3781
|
"single-public-export": single_public_export_default
|
|
3718
3782
|
};
|
|
3719
3783
|
var plugin = {
|
|
3720
3784
|
meta: {
|
|
3721
3785
|
name: "@sarj/eslint-plugin",
|
|
3722
|
-
version: "2.
|
|
3786
|
+
version: "2.6.0"
|
|
3723
3787
|
},
|
|
3724
3788
|
rules,
|
|
3725
3789
|
configs: {
|
|
@@ -3749,6 +3813,7 @@ var plugin = {
|
|
|
3749
3813
|
"@sarj/no-fat-try-blocks": "warn",
|
|
3750
3814
|
"@sarj/no-cors-wildcard-with-credentials": "warn",
|
|
3751
3815
|
"@sarj/no-secret-in-log": "warn",
|
|
3816
|
+
"@sarj/no-unsafe-cast": "warn",
|
|
3752
3817
|
"@sarj/single-public-export": "warn",
|
|
3753
3818
|
"@sarj/prefer-string-literal-union": "warn"
|
|
3754
3819
|
}
|
|
@@ -3783,6 +3848,7 @@ var plugin = {
|
|
|
3783
3848
|
"@sarj/no-fat-try-blocks": "error",
|
|
3784
3849
|
"@sarj/no-cors-wildcard-with-credentials": "error",
|
|
3785
3850
|
"@sarj/no-secret-in-log": "error",
|
|
3851
|
+
"@sarj/no-unsafe-cast": "warn",
|
|
3786
3852
|
"@sarj/single-public-export": "error",
|
|
3787
3853
|
// High-volume/stylistic — warn until rollout proves FP rate.
|
|
3788
3854
|
"@sarj/prefer-string-literal-union": "warn"
|