@fimbul/wotan
Advanced tools
Comparing version 0.4.0-dev.20180228 to 0.4.0-dev.20180301
{ | ||
"name": "@fimbul/wotan", | ||
"version": "0.4.0-dev.20180228", | ||
"version": "0.4.0-dev.20180301", | ||
"description": "Pluggable TypeScript and JavaScript linter", | ||
@@ -63,3 +63,3 @@ "bin": "bin/main.js", | ||
"tslib": "^1.8.1", | ||
"tsutils": "^2.20.0" | ||
"tsutils": "^2.22.0" | ||
}, | ||
@@ -66,0 +66,0 @@ "peerDependencies": { |
@@ -47,3 +47,2 @@ # wotan | ||
`await-promise` | Finds uses of `await` on non-Promise values. Also checks `for await` loops. *requires type information* | Works for all `PromiseLike` and `Thenable` types out of the box without any configuration. | ||
`deprecation` | Finds uses of deprecated variables, classes, properties, functions, signatures, ... *requires type information* | This rule checks element accesses (`foo[bar]`), JSX elements, chained function calls (`getFn()()`) in addition to what the TSLint rule does and has more useful error reporting. | ||
`generator-yield` | Require at least one `yield` inside generator functions. | There's no similar TSLint rule. | ||
@@ -55,2 +54,3 @@ `no-debugger` | Ban `debugger;` statements from your production code. | Performance! | ||
`no-unsafe-finally` | Forbids control flow statements `return`, `throw`, `break` and `continue` inside the `finally` block of a try statement. | Performance! | ||
`no-unstable-api-use` | Finds uses of deprecated and experimental variables, classes, properties, functions, signatures, ... *requires type information* | This rule checks element accesses (`foo[bar]`), JSX elements, chained function calls (`getFn()()`) in addition to what TSLint's `deprecation` rule does and has more useful error reporting. | ||
`no-unused-expression` | Warns about side-effect free expressions whose value is not used | This one is a bit stricter than TSLint's `no-unused-expression` and checks `for` loops in addition. | ||
@@ -62,3 +62,3 @@ `no-unused-label` | Warns about labels that are never used or at the wrong position. | TSLint only has `label-position` which doesn't check for unused labels. | ||
`prefer-number-isnan` | Prefer ES2015's `Number.isNaN` over the global `isNaN` mainly for performance. *requires type information* | No similar rule in TSLint. | ||
`prefer-object-spread` | Prefer object spread over `Object.assign` for copying properties to a new object. | Performance, and better handling of parens in fixer. | ||
`prefer-object-spread` | Prefer object spread over `Object.assign` for copying properties to a new object. *requires type information* | Performance, and better handling of parens in fixer and avoids false positives that would cause a compile error when fixed. | ||
`syntaxcheck` | Reports syntax errors as lint errors. This rule is **not** enabled in `wotan:recommended`. *requires type information* | Used to be part of the deprecated `tslint --type-check` | ||
@@ -65,0 +65,0 @@ `trailing-newline` | Requires a line break at the end of each file. | Nothing fancy here :( |
@@ -1,6 +0,7 @@ | ||
import { AbstractRule } from '../types'; | ||
import { TypedRule } from '../types'; | ||
import * as ts from 'typescript'; | ||
export declare class Rule extends AbstractRule { | ||
export declare class Rule extends TypedRule { | ||
static supports(sourceFile: ts.SourceFile): boolean; | ||
apply(): void; | ||
private isSpreadableObject(node, i); | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
const tsutils_1 = require("tsutils"); | ||
class Rule extends types_1.AbstractRule { | ||
class Rule extends types_1.TypedRule { | ||
static supports(sourceFile) { | ||
@@ -29,3 +29,3 @@ return !sourceFile.isDeclarationFile; | ||
} | ||
else if (grandParent.arguments.every(isSpreadableObject)) { | ||
else if (grandParent.arguments.every(this.isSpreadableObject, this)) { | ||
this.addFailureAtNode(grandParent, "Prefer object spread over 'Object.assign'.", createFix(grandParent, this.sourceFile)); | ||
@@ -35,2 +35,21 @@ } | ||
} | ||
isSpreadableObject(node, i) { | ||
if (i === 0) | ||
return true; | ||
if (node.kind === ts.SyntaxKind.ThisKeyword || node.kind === ts.SyntaxKind.SpreadElement) | ||
return false; | ||
const type = this.checker.getTypeAtLocation(node); | ||
if (type.flags & ts.TypeFlags.Any) | ||
return true; | ||
let seenObject = false; | ||
for (const t of tsutils_1.unionTypeParts(type)) { | ||
if (t.flags & (ts.TypeFlags.Object | ts.TypeFlags.NonPrimitive)) { | ||
seenObject = true; | ||
} | ||
else if (!tsutils_1.isFalsyType(t)) { | ||
return false; | ||
} | ||
} | ||
return seenObject; | ||
} | ||
} | ||
@@ -72,11 +91,2 @@ exports.Rule = Rule; | ||
} | ||
function isSpreadableObject(node) { | ||
switch (node.kind) { | ||
case ts.SyntaxKind.ThisKeyword: | ||
case ts.SyntaxKind.SpreadElement: | ||
return false; | ||
default: | ||
return true; | ||
} | ||
} | ||
//# sourceMappingURL=prefer-object-spread.js.map |
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
407746
5182
Updatedtsutils@^2.22.0