@fimbul/mimir
Advanced tools
Comparing version 0.23.0-dev.20210111 to 0.23.0-dev.20210112
{ | ||
"name": "@fimbul/mimir", | ||
"version": "0.23.0-dev.20210111", | ||
"version": "0.23.0-dev.20210112", | ||
"description": "Core rules of the Fimbullinter project", | ||
@@ -5,0 +5,0 @@ "main": "recommended.yaml", |
@@ -10,7 +10,14 @@ "use strict"; | ||
apply() { | ||
this.context.getWrappedAst().children.forEach(this.checkNode, this); | ||
let wrap = this.context.getWrappedAst().next; | ||
while (wrap.next !== undefined) { | ||
if (tsutils_1.isTypeNodeKind(wrap.kind)) { | ||
wrap = wrap.skip; | ||
} | ||
else { | ||
this.checkNode(wrap.node); | ||
wrap = wrap.next; | ||
} | ||
} | ||
} | ||
checkNode({ node, children }) { | ||
if (tsutils_1.isTypeNodeKind(node.kind)) | ||
return; | ||
checkNode(node) { | ||
if (tsutils_1.isExpression(node)) { | ||
@@ -32,3 +39,2 @@ if (!tsutils_1.isIdentifier(node) || tsutils_1.getUsageDomain(node) !== undefined) | ||
} | ||
return children.forEach(this.checkNode, this); | ||
} | ||
@@ -35,0 +41,0 @@ checkAssignment(node) { |
@@ -14,3 +14,3 @@ "use strict"; | ||
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); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (node.kind !== ts.SyntaxKind.AsyncKeyword || node.end !== re.lastIndex) | ||
@@ -17,0 +17,0 @@ continue; |
@@ -14,3 +14,3 @@ "use strict"; | ||
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); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (tsutils_1.isAwaitExpression(node)) { | ||
@@ -17,0 +17,0 @@ if (node.expression.pos !== re.lastIndex || |
@@ -14,3 +14,3 @@ "use strict"; | ||
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); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (!tsutils_1.isDeleteExpression(node) || node.expression.pos !== re.lastIndex) | ||
@@ -17,0 +17,0 @@ continue; |
import { AbstractRule } from '@fimbul/ymir'; | ||
export declare class Rule extends AbstractRule { | ||
private containsYield; | ||
apply(): void; | ||
private iterate; | ||
private visitNode; | ||
private shouldFail; | ||
private visitGeneratorBodyLookingForYield; | ||
private fail; | ||
} |
@@ -9,6 +9,2 @@ "use strict"; | ||
let Rule = class Rule extends ymir_1.AbstractRule { | ||
constructor() { | ||
super(...arguments); | ||
this.containsYield = false; | ||
} | ||
apply() { | ||
@@ -20,5 +16,3 @@ return this.iterate(this.context.getWrappedAst().next, undefined); | ||
if (wrap.kind === ts.SyntaxKind.Block && isGenerator(wrap.node.parent)) { | ||
this.containsYield = false; | ||
wrap.children.forEach(this.visitNode, this); // walk the function body recursively | ||
if (this.shouldFail()) // call as method so CFA doesn't infer `this.containsYield` as always false | ||
if (!this.visitGeneratorBodyLookingForYield(wrap.next, wrap.skip)) | ||
this.fail(wrap.node.parent); | ||
@@ -32,21 +26,18 @@ wrap = wrap.skip; // continue right after the function body | ||
} | ||
visitNode(wrap) { | ||
if (wrap.node.kind === ts.SyntaxKind.YieldExpression) { | ||
this.containsYield = true; | ||
if (wrap.children.length === 0) | ||
return; | ||
return this.visitNode(wrap.children[0]); | ||
visitGeneratorBodyLookingForYield(wrap, end) { | ||
let containsYield = false; | ||
while (wrap !== end) { | ||
if (wrap.node.kind === ts.SyntaxKind.YieldExpression) | ||
containsYield = true; | ||
if (tsutils_1.isFunctionScopeBoundary(wrap.node)) { | ||
// can iterate as linked list again for nested functions | ||
this.iterate(wrap.next, wrap.skip); | ||
wrap = wrap.skip; | ||
} | ||
else { | ||
wrap = wrap.next; | ||
} | ||
} | ||
if (tsutils_1.isFunctionScopeBoundary(wrap.node)) { | ||
const saved = this.containsYield; | ||
// can iterate as linked list again for nested functions | ||
this.iterate(wrap.next, wrap.skip); | ||
this.containsYield = saved; | ||
return; | ||
} | ||
return wrap.children.forEach(this.visitNode, this); | ||
return containsYield; | ||
} | ||
shouldFail() { | ||
return !this.containsYield; | ||
} | ||
fail({ asteriskToken, name }) { | ||
@@ -53,0 +44,0 @@ this.addFinding(asteriskToken.end - 1, asteriskToken.end, `Generator ${name === undefined ? '' : `'${name.getText(this.sourceFile).replace(/'/g, "\\'")}' `}contains no 'yield'.`); |
@@ -14,3 +14,3 @@ "use strict"; | ||
for (let match = re.exec(text); match !== null; match = re.exec(text)) { | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst || (wrappedAst = this.context.getWrappedAst()), match.index); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (node.kind === ts.SyntaxKind.NewExpression && | ||
@@ -17,0 +17,0 @@ text[node.end - 1] !== ')' && |
@@ -14,3 +14,3 @@ "use strict"; | ||
for (let match = re.exec(text); match !== null; match = re.exec(text)) { | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst || (wrappedAst = this.context.getWrappedAst()), match.index); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (node.kind === ts.SyntaxKind.DebuggerStatement) { | ||
@@ -17,0 +17,0 @@ const start = node.getStart(this.sourceFile); |
@@ -13,3 +13,3 @@ "use strict"; | ||
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); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (!tsutils_1.isIdentifier(node) || node.text !== 'NaN' || node.end !== match.index + 3) | ||
@@ -16,0 +16,0 @@ continue; |
@@ -15,3 +15,3 @@ "use strict"; | ||
continue; | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst || (wrappedAst = this.context.getWrappedAst()), match.index); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
switch (node.kind) { | ||
@@ -18,0 +18,0 @@ case ts.SyntaxKind.StringLiteral: |
@@ -15,3 +15,3 @@ "use strict"; | ||
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()), re.lastIndex - 1); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), re.lastIndex - 1); | ||
if (tsutils_1.isAwaitExpression(node) && re.lastIndex === node.expression.pos && isUnnecessaryAwait(node)) { | ||
@@ -18,0 +18,0 @@ const keywordStart = node.expression.pos - 'await'.length; |
@@ -12,3 +12,3 @@ "use strict"; | ||
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); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (tsutils_1.isTryStatement(node) && node.finallyBlock !== undefined && node.finallyBlock.pos === match.index + 'finally'.length) | ||
@@ -15,0 +15,0 @@ for (const statement of tsutils_1.getControlFlowEnd(node.finallyBlock).statements) |
@@ -69,3 +69,3 @@ "use strict"; | ||
function maybeUndefined({ symbolName }) { | ||
return symbolMaybeUndefined(checker, tsutils_1.getPropertyOfType(type || (type = checker.getApparentType(checker.getTypeOfAssignmentPattern(node))), symbolName), node); | ||
return symbolMaybeUndefined(checker, tsutils_1.getPropertyOfType(type !== null && type !== void 0 ? type : (type = checker.getApparentType(checker.getTypeOfAssignmentPattern(node))), symbolName), node); | ||
} | ||
@@ -109,3 +109,3 @@ } | ||
function maybeUndefined({ symbolName }) { | ||
return symbolMaybeUndefined(checker, tsutils_1.getPropertyOfType(type || (type = checker.getApparentType(checker.getTypeAtLocation(node))), symbolName), node); | ||
return symbolMaybeUndefined(checker, tsutils_1.getPropertyOfType(type !== null && type !== void 0 ? type : (type = checker.getApparentType(checker.getTypeAtLocation(node))), symbolName), node); | ||
} | ||
@@ -112,0 +112,0 @@ } |
@@ -14,3 +14,3 @@ "use strict"; | ||
for (let match = re.exec(text); match !== null; match = re.exec(text)) { | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst || (wrappedAst = this.context.getWrappedAst()), match.index); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (tsutils_1.isBreakOrContinueStatement(node) && | ||
@@ -17,0 +17,0 @@ node.label !== undefined && |
@@ -14,3 +14,3 @@ "use strict"; | ||
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); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
switch (node.kind) { | ||
@@ -17,0 +17,0 @@ case ts.SyntaxKind.SpreadElement: |
@@ -22,3 +22,3 @@ "use strict"; | ||
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); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (node.end === re.lastIndex && | ||
@@ -25,0 +25,0 @@ tsutils_1.isStringLiteral(node) && |
@@ -13,3 +13,3 @@ "use strict"; | ||
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); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), match.index); | ||
if (!tsutils_1.isIdentifier(node) || node.text !== 'isNaN' && node.text !== 'isFinite' || node.end - node.text.length !== match.index) | ||
@@ -16,0 +16,0 @@ continue; |
@@ -14,3 +14,3 @@ "use strict"; | ||
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()), re.lastIndex - 1); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = this.context.getWrappedAst()), re.lastIndex - 1); | ||
if (node.kind !== ts.SyntaxKind.Identifier || node.end !== re.lastIndex) | ||
@@ -17,0 +17,0 @@ continue; |
@@ -29,3 +29,3 @@ "use strict"; | ||
for (let match = re.exec(context.sourceFile.text); match !== null; match = re.exec(context.sourceFile.text)) { | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst || (wrappedAst = context.getWrappedAst()), match.index); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = context.getWrappedAst()), match.index); | ||
if (!tsutils_1.isAsExpression(node) || node.type.pos !== re.lastIndex) | ||
@@ -32,0 +32,0 @@ continue; |
@@ -11,3 +11,3 @@ "use strict"; | ||
for (let match = re.exec(text); match !== null; match = re.exec(text)) { | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst || (wrappedAst = context.getWrappedAst()), match.index); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = context.getWrappedAst()), match.index); | ||
if (node.kind === ts.SyntaxKind.SwitchStatement && node.getStart(context.sourceFile) === match.index) | ||
@@ -23,3 +23,3 @@ yield node; | ||
for (let match = re.exec(text); match !== null; match = re.exec(text)) { | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst || (wrappedAst = context.getWrappedAst()), match.index); | ||
const { node } = tsutils_1.getWrappedNodeAtPosition(wrappedAst !== null && wrappedAst !== void 0 ? wrappedAst : (wrappedAst = context.getWrappedAst()), match.index); | ||
if (node.kind === ts.SyntaxKind.TryStatement && node.tryBlock.pos - 'try'.length === match.index) | ||
@@ -26,0 +26,0 @@ yield node; |
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
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
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
425881
5026