@fimbul/mimir
Advanced tools
Comparing version 0.19.0-dev.20190111 to 0.19.0-dev.20190119
{ | ||
"name": "@fimbul/mimir", | ||
"version": "0.19.0-dev.20190111", | ||
"version": "0.19.0-dev.20190119", | ||
"description": "Core rules of the Fimbullinter project", | ||
@@ -32,3 +32,3 @@ "main": "recommended.yaml", | ||
"tslib": "^1.8.1", | ||
"tsutils": "^3.5.1" | ||
"tsutils": "^3.7.0" | ||
}, | ||
@@ -35,0 +35,0 @@ "peerDependencies": { |
@@ -61,2 +61,3 @@ # Mímir | ||
[`no-useless-strict`](docs/no-useless-strict.md) | :mag_right: :wrench: Disallows redundant `'use strict';` directives. | TSLint had a rule to enforce `'use strict'` everywhere. | ||
[`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. | ||
[`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. | ||
@@ -63,0 +64,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. |
@@ -104,2 +104,3 @@ "use strict"; | ||
checkCondition(node) { | ||
node = utils_1.unwrapParens(node); | ||
if (tsutils_1.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.ExclamationToken || | ||
@@ -132,7 +133,10 @@ tsutils_1.isBinaryExpression(node) && isEqualityOperator(node.operatorToken.kind)) | ||
} | ||
else if (tsutils_1.isParenthesizedExpression(node)) { | ||
return this.isTruthyFalsy(node.expression); | ||
} | ||
return this.executePredicate(this.getTypeOfExpression(node), truthyFalsy); | ||
} | ||
isConstantComparison(left, right, operator) { | ||
left = unwrapParens(left); | ||
right = unwrapParens(right); | ||
left = utils_1.unwrapParens(left); | ||
right = utils_1.unwrapParens(right); | ||
const equals = { | ||
@@ -150,3 +154,3 @@ negated: operator === ts.SyntaxKind.ExclamationEqualsEqualsToken || operator === ts.SyntaxKind.ExclamationEqualsToken, | ||
if (tsutils_1.isTypeOfExpression(left)) { | ||
left = unwrapParens(left.expression); | ||
left = utils_1.unwrapParens(left.expression); | ||
if (right.kind === ts.SyntaxKind.NullKeyword || isUndefined(right)) | ||
@@ -276,7 +280,2 @@ return equals.negated; | ||
} | ||
function unwrapParens(node) { | ||
while (tsutils_1.isParenthesizedExpression(node)) | ||
node = node.expression; | ||
return node; | ||
} | ||
function isLogicalOperator(kind) { | ||
@@ -283,0 +282,0 @@ return kind === ts.SyntaxKind.AmpersandAmpersandToken || kind === ts.SyntaxKind.BarBarToken; |
@@ -14,9 +14,4 @@ "use strict"; | ||
apply() { | ||
const re = /\btry\s*[/{]/g; | ||
let wrappedAst; | ||
for (let match = re.exec(this.sourceFile.text); match !== null; match = re.exec(this.sourceFile.text)) { | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst || (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (tsutils_1.isTryStatement(node) && | ||
match.index === node.tryBlock.pos - 'try'.length && | ||
!this.reported.has(node.pos) && | ||
for (const node of utils_1.tryStatements(this.context)) { | ||
if (!this.reported.has(node.pos) && | ||
isInAsyncFunction(node)) { | ||
@@ -23,0 +18,0 @@ node.tryBlock.statements.forEach(this.visitStatement, this); |
@@ -5,2 +5,3 @@ import * as ts from 'typescript'; | ||
export declare function switchStatements(context: RuleContext): IterableIterator<ts.SwitchStatement>; | ||
export declare function tryStatements(context: RuleContext): IterableIterator<ts.TryStatement>; | ||
export declare function isAsyncFunction(node: ts.Node): node is ts.FunctionLikeDeclaration & { | ||
@@ -34,1 +35,2 @@ body: ts.Block; | ||
export declare function formatPseudoBigInt(v: ts.PseudoBigInt): string; | ||
export declare function unwrapParens(node: ts.Expression): ts.Expression; |
@@ -16,2 +16,13 @@ "use strict"; | ||
exports.switchStatements = switchStatements; | ||
function* tryStatements(context) { | ||
const { text } = context.sourceFile; | ||
const re = /\btry\s*[{/]/g; | ||
let wrappedAst; | ||
for (let match = re.exec(text); match !== null; match = re.exec(text)) { | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst || (wrappedAst = context.getWrappedAst()), match.index); | ||
if (node.kind === ts.SyntaxKind.TryStatement && node.tryBlock.pos - 'try'.length === match.index) | ||
yield node; | ||
} | ||
} | ||
exports.tryStatements = tryStatements; | ||
function isAsyncFunction(node) { | ||
@@ -212,2 +223,8 @@ switch (node.kind) { | ||
exports.formatPseudoBigInt = formatPseudoBigInt; | ||
function unwrapParens(node) { | ||
while (node.kind === ts.SyntaxKind.ParenthesizedExpression) | ||
node = node.expression; | ||
return node; | ||
} | ||
exports.unwrapParens = unwrapParens; | ||
//# 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
385266
153
4548
89
Updatedtsutils@^3.7.0