@typescript-eslint/eslint-plugin
Advanced tools
export type Options = [ | ||
{ | ||
checkLiteralConstAssertions?: boolean; | ||
typesToIgnore?: string[]; | ||
@@ -4,0 +5,0 @@ } |
@@ -59,2 +59,6 @@ "use strict"; | ||
properties: { | ||
checkLiteralConstAssertions: { | ||
type: 'boolean', | ||
description: 'Whether to check literal const assertions.', | ||
}, | ||
typesToIgnore: { | ||
@@ -184,2 +188,5 @@ type: 'array', | ||
} | ||
function isTypeLiteral(type) { | ||
return type.isLiteral() || tsutils.isBooleanLiteralType(type); | ||
} | ||
return { | ||
@@ -191,7 +198,14 @@ 'TSAsExpression, TSTypeAssertion'(node) { | ||
const castType = services.getTypeAtLocation(node); | ||
const castTypeIsLiteral = isTypeLiteral(castType); | ||
const typeAnnotationIsConstAssertion = isConstAssertion(node.typeAnnotation); | ||
if (!options.checkLiteralConstAssertions && | ||
castTypeIsLiteral && | ||
typeAnnotationIsConstAssertion) { | ||
return; | ||
} | ||
const uncastType = services.getTypeAtLocation(node.expression); | ||
const typeIsUnchanged = isTypeUnchanged(uncastType, castType); | ||
const wouldSameTypeBeInferred = castType.isLiteral() | ||
const wouldSameTypeBeInferred = castTypeIsLiteral | ||
? isImplicitlyNarrowedLiteralDeclaration(node) | ||
: !isConstAssertion(node.typeAnnotation); | ||
: !typeAnnotationIsConstAssertion; | ||
if (typeIsUnchanged && wouldSameTypeBeInferred) { | ||
@@ -198,0 +212,0 @@ context.report({ |
{ | ||
"name": "@typescript-eslint/eslint-plugin", | ||
"version": "8.30.2-alpha.5", | ||
"version": "8.30.2-alpha.6", | ||
"description": "TypeScript plugin for ESLint", | ||
@@ -65,6 +65,6 @@ "files": [ | ||
"@eslint-community/regexpp": "^4.10.0", | ||
"@typescript-eslint/scope-manager": "8.30.2-alpha.5", | ||
"@typescript-eslint/type-utils": "8.30.2-alpha.5", | ||
"@typescript-eslint/utils": "8.30.2-alpha.5", | ||
"@typescript-eslint/visitor-keys": "8.30.2-alpha.5", | ||
"@typescript-eslint/scope-manager": "8.30.2-alpha.6", | ||
"@typescript-eslint/type-utils": "8.30.2-alpha.6", | ||
"@typescript-eslint/utils": "8.30.2-alpha.6", | ||
"@typescript-eslint/visitor-keys": "8.30.2-alpha.6", | ||
"graphemer": "^1.4.0", | ||
@@ -79,4 +79,4 @@ "ignore": "^5.3.1", | ||
"@types/natural-compare": "*", | ||
"@typescript-eslint/rule-schema-to-typescript-types": "8.30.2-alpha.5", | ||
"@typescript-eslint/rule-tester": "8.30.2-alpha.5", | ||
"@typescript-eslint/rule-schema-to-typescript-types": "8.30.2-alpha.6", | ||
"@typescript-eslint/rule-tester": "8.30.2-alpha.6", | ||
"@vitest/coverage-v8": "^3.1.1", | ||
@@ -83,0 +83,0 @@ "ajv": "^6.12.6", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
2495776
0.05%39151
0.04%