@fimbul/mimir
Advanced tools
Comparing version 0.12.0-dev.20180710 to 0.12.0-dev.20180711
@@ -41,1 +41,7 @@ # await-async-result | ||
``` | ||
## Related Rules | ||
* [`await-only-promise`](await-only-promise.md) | ||
* [`no-return-await`](no-return-await.md) | ||
* [`try-catch-return-await`](try-catch-return-await.md) |
@@ -43,1 +43,7 @@ # await-only-promise | ||
* MDN: [await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await) | ||
## Related Rules | ||
* [`await-async-result`](await-async-result.md) | ||
* [`no-return-await`](no-return-await.md) | ||
* [`try-catch-return-await`](try-catch-return-await.md) |
@@ -46,1 +46,6 @@ # no-duplicate-case | ||
``` | ||
## Related Rules | ||
* [`no-case-declaration`](no-case-declaration.md) | ||
* [`no-fallthrough`](no-fallthrough.md) |
@@ -54,1 +54,6 @@ # no-duplicate-spread-property | ||
``` | ||
## Related Rules | ||
* [`prefer-object-spread`](prefer-object-spread.md) | ||
* [`no-useless-spread`](no-useless-spread.md) |
@@ -92,1 +92,6 @@ # no-fallthrough | ||
``` | ||
## Related Rules | ||
* [`no-case-declaration`](no-case-declaration.md) | ||
* [`no-duplicate-case`](no-duplicate-case.md) |
@@ -47,1 +47,9 @@ # no-inferred-empty-object | ||
``` | ||
## Further Reading | ||
* TypeScript Handbook: [Generics](https://www.typescriptlang.org/docs/handbook/generics.html) | ||
## Related Rules | ||
* [`no-misused-generics`](no-misused-generics.md) |
@@ -52,1 +52,5 @@ # no-invalid-assertion | ||
``` | ||
## Related Rules | ||
* [`no-useless-assertion`](no-useless-assertion.md) |
@@ -45,1 +45,5 @@ # no-misused-generics | ||
* [Union type inference](https://github.com/Microsoft/TypeScript/issues/23312#issuecomment-380218861) | ||
## Related Rules | ||
* [`no-inferred-empty-object`](no-inferred-empty-object.md) |
@@ -50,2 +50,2 @@ # no-nan-compare | ||
* [prefer-number-isnan](prefer-number-isnan.md) | ||
* [`prefer-number-methods`](prefer-number-methods.md) |
@@ -78,3 +78,3 @@ # no-return-await | ||
* [await-only-promise](await-only-promise.md) | ||
* [try-catch-return-await](try-catch-return-await.md) | ||
* [`await-only-promise`](await-only-promise.md) | ||
* [`try-catch-return-await`](try-catch-return-await.md) |
@@ -50,1 +50,5 @@ # no-unassigned-variable | ||
``` | ||
## Related Rules | ||
* [`prefer-const`](prefer-const.md) |
@@ -94,1 +94,5 @@ # no-unreachable-code | ||
* StackOverflow: [What are the rules for JavaScript's automatic semicolon insertion (ASI)?](https://stackoverflow.com/questions/2846283/what-are-the-rules-for-javascripts-automatic-semicolon-insertion-asi) | ||
## Related Rules | ||
* [`return-never-call`](return-never-call.md) |
@@ -37,1 +37,5 @@ # no-unused-label | ||
``` | ||
## Related Rules | ||
* [`no-useless-jump-label`](no-useless-jump-label.md) |
@@ -60,1 +60,6 @@ # no-useless-assertion | ||
``` | ||
## Related Rules | ||
* [`no-invalid-assertion`](no-invalid-assertion.md) | ||
* [`type-assertion`](type-assertion.md) |
@@ -51,1 +51,5 @@ # no-useless-jump-label | ||
* MDN: [Destructuring assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) | ||
## Related Rules | ||
* [`no-unused-label`](no-unused-label.md) |
@@ -60,1 +60,6 @@ # no-useless-spread | ||
* MDN: [Spread Syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) | ||
## Related Rules | ||
* [`no-duplicate-spread-property`](no-duplicate-spread-property.md) | ||
* [`prefer-object-spread`](prefer-object-spread.md) |
@@ -120,1 +120,5 @@ # prefer-const | ||
* Mozilla Hacks: [Destructuring](https://hacks.mozilla.org/2015/05/es6-in-depth-destructuring/) | ||
## Related Rules | ||
* [`no-unassigned-variable`](no-unassigned-variable.md) |
@@ -20,2 +20,4 @@ # prefer-dot-notation | ||
obj['foo_bar']; | ||
1['toString'](); | ||
``` | ||
@@ -31,2 +33,6 @@ | ||
(1).toString(); | ||
1..toString(); // double dot is intentional to avoid parsing ambiguity | ||
1.0.toString(); | ||
// dynamic element access | ||
@@ -33,0 +39,0 @@ obj['prop' + Math.random()]; |
@@ -41,1 +41,5 @@ # return-never-call | ||
* TypeScript Deep Dive: [Never](https://basarat.gitbooks.io/typescript/content/docs/types/never.html) | ||
## Related Rules | ||
* [`no-unreachable-code`](no-unreachable-code.md) |
@@ -16,1 +16,5 @@ # syntaxcheck | ||
If you are executing the TypeScript compiler anyway, this rule is not necessary for you. It just adds additional overhead in this case. | ||
## Related Rules | ||
* [`typecheck`](typecheck.md) |
@@ -85,3 +85,4 @@ # try-catch-return-await | ||
* [await-only-promise](await-only-promise.md) | ||
* [no-return-await](no-return-await.md) | ||
* [`await-async-result`](await-async-result.md) | ||
* [`await-only-promise`](await-only-promise.md) | ||
* [`no-return-await`](no-return-await.md) |
@@ -93,1 +93,6 @@ # parameter-properties | ||
* TypeScript Deep Dive: [Type Assertion](https://basarat.gitbooks.io/typescript/content/docs/types/type-assertion.html) | ||
## Related Rules | ||
* [`no-invalid-assertion`](no-invalid-assertion.md) | ||
* [`no-useless-assertion`](no-useless-assertion.md) |
@@ -17,1 +17,5 @@ # typecheck | ||
If you are executing the TypeScript compiler anyway, this rule is not necessary for you. It just adds additional overhead in this case. | ||
## Related Rules | ||
* [`syntaxcheck`](syntaxcheck.md) |
{ | ||
"name": "@fimbul/mimir", | ||
"version": "0.12.0-dev.20180710", | ||
"version": "0.12.0-dev.20180711", | ||
"description": "Core rules of the Fimbullinter project", | ||
@@ -5,0 +5,0 @@ "main": "recommended.yaml", |
import { AbstractRule } from '@fimbul/ymir'; | ||
export declare class Rule extends AbstractRule { | ||
apply(): void; | ||
private checkElementAccess; | ||
} |
@@ -6,13 +6,23 @@ "use strict"; | ||
const tsutils_1 = require("tsutils"); | ||
const ts = require("typescript"); | ||
let Rule = class Rule extends ymir_1.AbstractRule { | ||
apply() { | ||
for (const node of this.context.getFlatAst()) { | ||
if (tsutils_1.isElementAccessExpression(node) && | ||
node.argumentExpression !== undefined && | ||
tsutils_1.isTextualLiteral(node.argumentExpression) && tsutils_1.isValidPropertyAccess(node.argumentExpression.text)) { | ||
const property = node.argumentExpression.text; | ||
this.addFailureAtNode(node.argumentExpression, `Prefer 'obj.${property}' over 'obj[${node.argumentExpression.getText(this.sourceFile)}]'.`, ymir_1.Replacement.replace(node.expression.end, node.end, '.' + property)); | ||
} | ||
} | ||
for (const node of this.context.getFlatAst()) | ||
if (node.kind === ts.SyntaxKind.ElementAccessExpression) | ||
this.checkElementAccess(node); | ||
} | ||
checkElementAccess(node) { | ||
if (node.argumentExpression === undefined || | ||
!tsutils_1.isTextualLiteral(node.argumentExpression)) | ||
return; | ||
const { text } = node.argumentExpression; | ||
if (!tsutils_1.isValidPropertyAccess(text)) | ||
return; | ||
this.addFailureAtNode(node.argumentExpression, `Prefer 'obj.${text}' over 'obj[${node.argumentExpression.getText(this.sourceFile)}]'.`, node.expression.kind === ts.SyntaxKind.NumericLiteral | ||
? [ | ||
ymir_1.Replacement.append(node.expression.getStart(this.sourceFile), '('), | ||
ymir_1.Replacement.replace(node.expression.end, node.end, ').' + text), | ||
] | ||
: ymir_1.Replacement.replace(node.expression.end, node.end, '.' + text)); | ||
} | ||
}; | ||
@@ -19,0 +29,0 @@ Rule = tslib_1.__decorate([ |
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
377709
3823