-
Notifications
You must be signed in to change notification settings - Fork 889
no-unsafe-any: Allow import declarations #2496
Conversation
@@ -1,3 +1,10 @@ | |||
import importEquals = require("./commonjsModule"); | |||
import importAlias = modA; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is modA
coming from?
import importQualifiedName = N.x; | ||
import * as namespaceImport from "./commonjsModule"; | ||
import defaultExport, { namedExport } from "./es6Module"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should add a test to ensure that using imported variables like defaultExport
or namedExport
in property access etc. still results in an error
src/rules/noUnsafeAnyRule.ts
Outdated
@@ -91,10 +97,12 @@ function isAllowedLocation(node: ts.Expression, { getContextualType, getTypeAtLo | |||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you probably need to add a case for CommaToken
src/rules/noUnsafeAnyRule.ts
Outdated
@@ -47,14 +47,13 @@ export class Rule extends Lint.Rules.TypedRule { | |||
const isExpression: (node: ts.Node) => node is ts.Expression = (ts as any).isExpression; | |||
|
|||
function walk(ctx: Lint.WalkContext<void>, checker: ts.TypeChecker): void { | |||
return ts.forEachChild(ctx.sourceFile, recur); | |||
function recur(node: ts.Node): void { | |||
return ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void { | |||
if (isExpression(node) && isAny(checker.getTypeAtLocation(node)) && !isAllowedLocation(node, checker)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would increase performance if you swap the calls to isAny(...)
and isAllowedLocation(...)
761e596
to
caba22c
Compare
Did a complete rewrite. I also have a branch testing out applying the rule to tslint itself, but that will have to wait until the fixes are published globally (else |
caba22c
to
b86de64
Compare
PR checklist
Overview of change:
Always allow import statements in
no-unsafe-any
.CHANGELOG.md entry:
[bugfix]
no-unsafe-any
: Allow import declarations