@fimbul/mimir
Advanced tools
Comparing version 0.23.0-dev.20210112 to 0.23.0-dev.20210114
{ | ||
"name": "@fimbul/mimir", | ||
"version": "0.23.0-dev.20210112", | ||
"version": "0.23.0-dev.20210114", | ||
"description": "Core rules of the Fimbullinter project", | ||
@@ -5,0 +5,0 @@ "main": "recommended.yaml", |
@@ -63,2 +63,3 @@ # Mímir | ||
[`no-useless-try-catch`](docs/no-useless-try-catch.md) | :wrench: Detects `try` statements or parts thereof that can be removed. | There's no similar TSLint rule. | ||
[`no-writeonly-property-read`](docs/no-writeonly-property-read.md) | :mag: Disallows read access to properties that only have a `set` accessor. | There's no similar TSLint rule. | ||
[`parameter-properties`](docs/parameter-properties.md) | :wrench: :nut_and_bolt: :x: Enforces or disallows the use of parameter properties. | TSlint only has `no-parameter-properties` to disallow all parameter properties and has no autofixer. | ||
@@ -65,0 +66,0 @@ [`prefer-const`](docs/prefer-const.md) | :wrench: :nut_and_bolt: Enforces the use of `const` for variables that are never reassigned. | TSLint's `prefer-const` rule gives some false positives for merged declarations and variables used before being declared which results in a compiler or runtime error after fixing. |
@@ -70,6 +70,4 @@ "use strict"; | ||
const checker = this.program.getTypeChecker(); | ||
let type = checker.getTypeAtLocation(node); | ||
type = checker.getBaseConstraintOfType(type) || type; | ||
const result = new Set(); | ||
for (const t of tsutils_1.unionTypeParts(type)) { | ||
for (const t of tsutils_1.unionTypeParts(utils_1.tryGetBaseConstraintType(checker.getTypeAtLocation(node), checker))) { | ||
// TODO handle intersection types | ||
@@ -76,0 +74,0 @@ if (tsutils_1.isLiteralType(t)) { |
@@ -8,2 +8,3 @@ "use strict"; | ||
const ts = require("typescript"); | ||
const utils_1 = require("../utils"); | ||
let Rule = class Rule extends ymir_1.TypedRule { | ||
@@ -22,4 +23,3 @@ apply() { | ||
return; | ||
let assertedType = this.checker.getTypeFromTypeNode(node.type); | ||
assertedType = this.checker.getBaseConstraintOfType(assertedType) || assertedType; | ||
const assertedType = utils_1.tryGetBaseConstraintType(this.checker.getTypeFromTypeNode(node.type), this.checker); | ||
const assertedLiterals = getLiteralsByType(assertedType); | ||
@@ -26,0 +26,0 @@ if (isEmpty(assertedLiterals)) |
@@ -45,3 +45,3 @@ "use strict"; | ||
checkObjectDestructuring(node) { | ||
const type = this.checker.getTypeOfAssignmentPattern(node.parent); | ||
const type = utils_1.tryGetBaseConstraintType(this.checker.getTypeOfAssignmentPattern(node.parent), this.checker); | ||
for (const { symbolName, displayName } of tsutils_1.getLateBoundPropertyNamesOfPropertyName(node.name, this.checker).names) { | ||
@@ -57,24 +57,7 @@ const symbol = tsutils_1.getPropertyOfType(type, symbolName); | ||
checkObjectBindingPattern(node) { | ||
const type = this.checker.getTypeAtLocation(node); | ||
for (const element of node.elements) { | ||
if (element.dotDotDotToken !== undefined) | ||
continue; | ||
if (element.propertyName === undefined) { | ||
const name = element.name.text; | ||
const symbol = type.getProperty(name); | ||
if (symbol !== undefined) | ||
this.checkStability(symbol, element.name, name, describeWithName); | ||
} | ||
else { | ||
const propName = tsutils_1.getPropertyName(element.propertyName); | ||
if (propName !== undefined) { | ||
const symbol = type.getProperty(propName); | ||
if (symbol !== undefined) | ||
this.checkStability(symbol, element.propertyName, propName, describeWithName); | ||
} | ||
else { | ||
for (const { symbol, name } of utils_1.propertiesOfType(type, tsutils_1.getLateBoundPropertyNames(element.propertyName.expression, this.checker).names)) | ||
this.checkStability(symbol, element.propertyName, name, describeWithName); | ||
} | ||
} | ||
const type = utils_1.tryGetBaseConstraintType(this.checker.getTypeAtLocation(node), this.checker); | ||
for (const { node: nameNode, symbolName, displayName } of utils_1.destructuredProperties(node, this.checker)) { | ||
const symbol = tsutils_1.getPropertyOfType(type, symbolName); | ||
if (symbol !== undefined) | ||
this.checkStability(symbol, nameNode, displayName, describeWithName); | ||
} | ||
@@ -81,0 +64,0 @@ } |
@@ -64,3 +64,3 @@ "use strict"; | ||
const originalType = this.checker.getTypeAtLocation(node.expression); | ||
const flags = getNullableFlags(this.checker.getBaseConstraintOfType(originalType) || originalType, ts.isOptionalChain(node) | ||
const flags = getNullableFlags(utils_1.tryGetBaseConstraintType(originalType, this.checker), ts.isOptionalChain(node) | ||
? (t) => tsutils_1.isOptionalChainingUndefinedMarkerType(this.checker, t) ? 0 : t.flags | ||
@@ -93,4 +93,4 @@ : undefined); | ||
if ((targetType.flags & (ts.TypeFlags.TypeVariable | ts.TypeFlags.Instantiable)) === 0) { | ||
targetType = this.checker.getBaseConstraintOfType(targetType) || targetType; | ||
sourceType = this.checker.getBaseConstraintOfType(sourceType) || sourceType; | ||
targetType = utils_1.tryGetBaseConstraintType(targetType, this.checker); | ||
sourceType = utils_1.tryGetBaseConstraintType(sourceType, this.checker); | ||
} | ||
@@ -97,0 +97,0 @@ let message = FAIL_MESSAGE; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const tsutils_1 = require("tsutils"); | ||
const utils_1 = require("../utils"); | ||
let Rule = class Rule extends ymir_1.AbstractRule { | ||
@@ -82,6 +83,4 @@ apply() { | ||
continue; | ||
if (type === undefined) { | ||
type = checker.getTypeOfAssignmentPattern(node); | ||
type = checker.getBaseConstraintOfType(type) || type; | ||
} | ||
if (type === undefined) | ||
type = utils_1.tryGetBaseConstraintType(checker.getTypeOfAssignmentPattern(node), checker); | ||
if (symbolMaybeUndefined(checker, type.getProperty(String(i)), node)) | ||
@@ -88,0 +87,0 @@ continue; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const tsutils_1 = require("tsutils"); | ||
const utils_1 = require("../utils"); | ||
const primitiveFlags = ts.TypeFlags.BigIntLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.NumberLike | ts.TypeFlags.StringLike | | ||
@@ -153,4 +154,3 @@ ts.TypeFlags.ESSymbolLike | ts.TypeFlags.Undefined | ts.TypeFlags.Void; | ||
else { | ||
let type = this.getTypeOfExpression(right); | ||
type = this.checker.getBaseConstraintOfType(type) || type; | ||
const type = utils_1.tryGetBaseConstraintType(this.getTypeOfExpression(right), this.checker); | ||
if ((type.flags & ts.TypeFlags.StringLiteral) === 0) | ||
@@ -191,4 +191,3 @@ return; | ||
// TODO reuse some logic from 'no-duplicate-case' to compute prefix unary expressions | ||
let type = this.getTypeOfExpression(node); | ||
type = this.checker.getBaseConstraintOfType(type) || type; | ||
const type = utils_1.tryGetBaseConstraintType(this.getTypeOfExpression(node), this.checker); | ||
for (const t of tsutils_1.intersectionTypeParts(type)) { | ||
@@ -195,0 +194,0 @@ if (tsutils_1.isLiteralType(t)) |
@@ -41,3 +41,3 @@ "use strict"; | ||
? this.isIterable(this.checker.getApparentType(type), node) | ||
: tsutils_1.unionTypeParts(this.checker.getBaseConstraintOfType(type) || type).every(this.isArrayLike, this); | ||
: tsutils_1.unionTypeParts(utils_1.tryGetBaseConstraintType(type, this.checker)).every(this.isArrayLike, this); | ||
} | ||
@@ -44,0 +44,0 @@ isIterationProtocolAvailable() { |
@@ -8,2 +8,3 @@ "use strict"; | ||
const tsutils_1 = require("tsutils"); | ||
const utils_1 = require("../utils"); | ||
let Rule = class Rule extends ymir_1.TypedRule { | ||
@@ -24,4 +25,3 @@ apply() { | ||
isCorrectArgumentType(arg) { | ||
const type = this.checker.getTypeAtLocation(arg); | ||
return tsutils_1.unionTypeParts(this.checker.getBaseConstraintOfType(type) || type).every((t) => (t.flags & ts.TypeFlags.NumberLike) !== 0); | ||
return tsutils_1.unionTypeParts(utils_1.tryGetBaseConstraintType(this.checker.getTypeAtLocation(arg), this.checker)).every((t) => (t.flags & ts.TypeFlags.NumberLike) !== 0); | ||
} | ||
@@ -28,0 +28,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isAmbientVariableDeclaration = exports.isAmbientPropertyDeclaration = exports.hasDirectivePrologue = exports.propertiesOfType = exports.elementAccessSymbols = exports.typesAreEqual = exports.objectLiteralNeedsParens = exports.expressionNeedsParensWhenReplacingNode = exports.childStatements = exports.isVariableReassignment = exports.isAsyncFunction = exports.tryStatements = exports.switchStatements = void 0; | ||
exports.destructuredProperties = exports.addNodeToPropertyNameList = exports.tryGetBaseConstraintType = exports.isAmbientVariableDeclaration = exports.isAmbientPropertyDeclaration = exports.hasDirectivePrologue = exports.propertiesOfType = exports.elementAccessSymbols = exports.typesAreEqual = exports.objectLiteralNeedsParens = exports.expressionNeedsParensWhenReplacingNode = exports.childStatements = exports.isVariableReassignment = exports.isAsyncFunction = exports.tryStatements = exports.switchStatements = void 0; | ||
const ts = require("typescript"); | ||
@@ -207,2 +207,28 @@ const tsutils_1 = require("tsutils"); | ||
exports.isAmbientVariableDeclaration = isAmbientVariableDeclaration; | ||
function tryGetBaseConstraintType(type, checker) { | ||
return checker.getBaseConstraintOfType(type) || type; | ||
} | ||
exports.tryGetBaseConstraintType = tryGetBaseConstraintType; | ||
function* addNodeToPropertyNameList(node, list) { | ||
for (const element of list) | ||
yield { node, symbolName: element.symbolName, displayName: element.displayName }; | ||
} | ||
exports.addNodeToPropertyNameList = addNodeToPropertyNameList; | ||
function* destructuredProperties(node, checker) { | ||
for (const element of node.elements) { | ||
if (element.dotDotDotToken !== undefined) | ||
continue; | ||
if (element.propertyName === undefined) { | ||
yield { | ||
node: element.name, | ||
symbolName: element.name.escapedText, | ||
displayName: element.name.text, | ||
}; | ||
} | ||
else { | ||
yield* addNodeToPropertyNameList(element.propertyName, tsutils_1.getLateBoundPropertyNamesOfPropertyName(element.propertyName, checker).names); | ||
} | ||
} | ||
} | ||
exports.destructuredProperties = destructuredProperties; | ||
//# sourceMappingURL=utils.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
432280
160
5095
91