@fimbul/mimir
Advanced tools
Comparing version 0.11.0-dev.20180609 to 0.11.0-dev.20180610
{ | ||
"name": "@fimbul/mimir", | ||
"version": "0.11.0-dev.20180609", | ||
"version": "0.11.0-dev.20180610", | ||
"description": "Core rules of the Fimbullinter project", | ||
@@ -5,0 +5,0 @@ "main": "recommended.yaml", |
@@ -55,6 +55,6 @@ "use strict"; | ||
hasSymbolAsyncIterator(type) { | ||
return type.getProperties().some((prop) => symbolName(prop) === '__@asyncIterator'); | ||
return type.getProperties().some((prop) => prop.escapedName === '__@asyncIterator'); | ||
} | ||
isIterableOfPromises(type, node) { | ||
const symbol = type.getProperties().find((prop) => symbolName(prop) === '__@iterator'); | ||
const symbol = type.getProperties().find((prop) => prop.escapedName === '__@iterator'); | ||
if (symbol === undefined) | ||
@@ -91,5 +91,2 @@ return false; | ||
exports.Rule = Rule; | ||
function symbolName(s) { | ||
return s.escapedName === undefined ? s.name : s.escapedName; | ||
} | ||
//# sourceMappingURL=await-only-promise.js.map |
@@ -33,3 +33,3 @@ "use strict"; | ||
if (literals.every((v) => valuesSeen.has(v))) | ||
this.addFailureAtNode(clause.expression, `Duplicate 'case ${literals.map(formatPrimitive).join(' | ')}'.`); | ||
this.addFailureAtNode(clause.expression, `Duplicate 'case ${literals.map(formatPrimitive).sort().join(' | ')}'.`); | ||
} | ||
@@ -36,0 +36,0 @@ } |
@@ -15,3 +15,3 @@ "use strict"; | ||
static supports(_sourceFile, context) { | ||
return !ts.version.startsWith('2.4.') && utils_1.isStrictNullChecksEnabled(context.program.getCompilerOptions()); | ||
return utils_1.isStrictNullChecksEnabled(context.program.getCompilerOptions()); | ||
} | ||
@@ -18,0 +18,0 @@ apply() { |
import { TypedRule } from '@fimbul/ymir'; | ||
export declare class Rule extends TypedRule { | ||
private scanner; | ||
apply(): void; | ||
@@ -8,4 +7,3 @@ private checkCallExpression; | ||
private checkInferredTypeParameters; | ||
private scannerFallback; | ||
private handleEmptyTypeParameter; | ||
} |
@@ -7,9 +7,4 @@ "use strict"; | ||
const tsutils_1 = require("tsutils"); | ||
const typescriptPre270 = /^2\.[456]\./.test(ts.version); | ||
const typescriptPre290 = typescriptPre270 || /^2\.[78]\./.test(ts.version); | ||
const typescriptPre290 = /^2\.[78]\./.test(ts.version); | ||
let Rule = class Rule extends ymir_1.TypedRule { | ||
constructor() { | ||
super(...arguments); | ||
this.scanner = undefined; | ||
} | ||
apply() { | ||
@@ -65,4 +60,2 @@ for (const node of this.context.getFlatAst()) { | ||
checkInferredTypeParameters(signature, typeParameters, node) { | ||
if (typescriptPre270) | ||
return this.scannerFallback(signature, typeParameters, node); | ||
const { typeArguments } = this.checker.signatureToSignatureDeclaration(signature, ts.SyntaxKind.CallExpression, undefined, ts.NodeBuilderFlags.WriteTypeArgumentsOfSignature | ts.NodeBuilderFlags.IgnoreErrors); | ||
@@ -77,41 +70,2 @@ if (typeArguments === undefined) | ||
} | ||
scannerFallback(signature, typeParameters, node) { | ||
const scanner = this.scanner || (this.scanner = ts.createScanner(ts.ScriptTarget.ESNext, true)); | ||
scanner.setText(this.checker.signatureToString(signature, undefined, ts.TypeFormatFlags.WriteTypeArgumentsOfSignature | ts.TypeFormatFlags.NoTruncation), 1); | ||
let param = 0; | ||
let token = scanner.scan(); | ||
if (token === ts.SyntaxKind.OpenBraceToken && scanner.scan() === ts.SyntaxKind.CloseBraceToken) { | ||
token = scanner.scan(); | ||
if (token === ts.SyntaxKind.CommaToken || token === ts.SyntaxKind.GreaterThanToken) | ||
this.handleEmptyTypeParameter(typeParameters[0], node); | ||
} | ||
let level = 0; | ||
while (true) { | ||
switch (token) { | ||
case ts.SyntaxKind.CommaToken: | ||
if (level === 0) { | ||
++param; | ||
token = scanner.scan(); | ||
if (token === ts.SyntaxKind.OpenBraceToken && scanner.scan() === ts.SyntaxKind.CloseBraceToken) { | ||
token = scanner.scan(); | ||
if (token === ts.SyntaxKind.CommaToken || token === ts.SyntaxKind.GreaterThanToken) | ||
this.handleEmptyTypeParameter(typeParameters[param], node); | ||
} | ||
continue; | ||
} | ||
break; | ||
case ts.SyntaxKind.GreaterThanToken: | ||
if (level === 0) | ||
return; | ||
--level; | ||
break; | ||
case ts.SyntaxKind.LessThanToken: | ||
++level; | ||
break; | ||
case ts.SyntaxKind.EndOfFileToken: | ||
return; | ||
} | ||
token = scanner.scan(); | ||
} | ||
} | ||
handleEmptyTypeParameter(typeParameter, node) { | ||
@@ -118,0 +72,0 @@ if (typeParameter.default === undefined) |
@@ -43,3 +43,3 @@ "use strict"; | ||
if (literals.boolean !== undefined) | ||
result.push(literals.boolean.join(' | ')); | ||
result.push(`${literals.boolean}`); | ||
return result.join(' | '); | ||
@@ -52,3 +52,3 @@ } | ||
a.number = b.number = undefined; | ||
if (a.boolean === undefined || b.boolean === undefined || intersects(a.boolean, b.boolean)) | ||
if (a.boolean === undefined || b.boolean === undefined || a.boolean === b.boolean) | ||
a.boolean = b.boolean = undefined; | ||
@@ -79,3 +79,5 @@ } | ||
else if (type.flags & ts.TypeFlags.BooleanLiteral) { | ||
result.boolean = append(result.boolean, type.intrinsicName === 'true'); | ||
const current = type.intrinsicName === 'true'; | ||
if (result.boolean !== current) | ||
result.boolean = result.boolean === undefined ? current : undefined; | ||
} | ||
@@ -82,0 +84,0 @@ } |
@@ -46,5 +46,3 @@ "use strict"; | ||
checkSignature(node) { | ||
const signature = this.checker.getResolvedSignature(node); | ||
if (signature !== undefined) | ||
return this.checkStability(signature, node, undefined, signatureToString); | ||
return this.checkStability(this.checker.getResolvedSignature(node), node, undefined, signatureToString); | ||
} | ||
@@ -51,0 +49,0 @@ checkObjectBindingPattern(node) { |
@@ -12,3 +12,2 @@ "use strict"; | ||
const FAIL_DEFINITE_ASSIGNMENT = 'This assertion is unnecessary as it has no effect on this declaration.'; | ||
const typescriptPre270 = /^2\.[456]\./.test(ts.version); | ||
const typeFormat = ts.TypeFormatFlags.NoTruncation | ||
@@ -59,4 +58,3 @@ | ts.TypeFormatFlags.UseFullyQualifiedType | ||
const originalType = this.checker.getTypeAtLocation(node.expression); | ||
const flags = getNullableFlags((!typescriptPre270 || originalType.flags & ts.TypeFlags.IndexedAccess) && | ||
this.checker.getBaseConstraintOfType(originalType) || originalType); | ||
const flags = getNullableFlags(this.checker.getBaseConstraintOfType(originalType) || originalType); | ||
if (flags !== 0) { | ||
@@ -183,3 +181,3 @@ const contextualType = this.getSafeContextualType(node); | ||
for (; i < properties.length; ++i) { | ||
const name = properties[i].name; | ||
const name = properties[i].escapedName; | ||
if (String(i) !== name) { | ||
@@ -192,3 +190,3 @@ if (i === 0) | ||
for (; i < properties.length; ++i) | ||
if (String(+properties[i].name) === properties[i].name) | ||
if (String(+properties[i].escapedName) === properties[i].escapedName) | ||
return false; | ||
@@ -195,0 +193,0 @@ return true; |
@@ -133,3 +133,3 @@ "use strict"; | ||
function symbolMaybeUndefined(checker, symbol, node) { | ||
if (symbol.flags & (ts.SymbolFlags.Optional | (Number.isNaN(+symbol.name) ? 0 : ts.SymbolFlags.Transient))) | ||
if (symbol.flags & (ts.SymbolFlags.Optional | (Number.isNaN(+symbol.escapedName) ? 0 : ts.SymbolFlags.Transient))) | ||
return true; | ||
@@ -136,0 +136,0 @@ return tsutils_1.unionTypeParts(checker.getTypeOfSymbolAtLocation(symbol, node)) |
@@ -193,3 +193,3 @@ "use strict"; | ||
for (let t of tsutils_1.unionTypeParts(type)) { | ||
if (t.flags & ts.TypeFlags.TypeVariable) { | ||
if (t.flags & (ts.TypeFlags.TypeVariable | ts.TypeFlags.Instantiable)) { | ||
const constraint = this.checker.getBaseConstraintOfType(t); | ||
@@ -260,3 +260,3 @@ if (constraint === undefined) | ||
return true; | ||
return type.symbol !== undefined && type.symbol.name === 'Function' && | ||
return type.symbol !== undefined && type.symbol.escapedName === 'Function' && | ||
hasPropertyOfKind(type, 'apply', ts.SymbolFlags.Method) && | ||
@@ -263,0 +263,0 @@ hasPropertyOfKind(type, 'arguments', ts.SymbolFlags.Property) && |
@@ -5,3 +5,2 @@ "use strict"; | ||
const ymir_1 = require("@fimbul/ymir"); | ||
const ts = require("typescript"); | ||
const tsutils_1 = require("tsutils"); | ||
@@ -14,3 +13,3 @@ let Rule = class Rule extends ymir_1.AbstractRule { | ||
tsutils_1.isTextualLiteral(node.argumentExpression) && tsutils_1.isValidPropertyAccess(node.argumentExpression.text)) { | ||
const property = ts.unescapeIdentifier(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)); | ||
@@ -17,0 +16,0 @@ } |
@@ -50,3 +50,3 @@ "use strict"; | ||
return this.sourceFile.languageVersion >= ts.ScriptTarget.ES5; | ||
if (type.symbol !== undefined && /^(Concat|Readonly)?Array$/.test(type.symbol.name) && | ||
if (type.symbol !== undefined && /^(Concat|Readonly)?Array$/.test(type.symbol.escapedName) && | ||
type.symbol.declarations !== undefined && type.symbol.declarations.some(this.isDeclaredInDefaultLib, this)) | ||
@@ -69,3 +69,3 @@ return true; | ||
function isIterable(type) { | ||
return type.getProperties().some((p) => p.name === '__@iterator'); | ||
return type.getProperties().some((p) => p.escapedName === '__@iterator'); | ||
} | ||
@@ -72,0 +72,0 @@ function isReadonlyArrayAccess(uses, arrayVariable, statement, sourceFile) { |
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
340739
3633