Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

no-unsafe-any: Allow import declarations #2496

Merged
merged 1 commit into from
Apr 10, 2017

Conversation

andy-hanson
Copy link
Contributor

PR checklist

Overview of change:

Always allow import statements in no-unsafe-any.

CHANGELOG.md entry:

[bugfix] no-unsafe-any: Allow import declarations

@@ -1,3 +1,10 @@
import importEquals = require("./commonjsModule");
import importAlias = modA;
Copy link
Contributor

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";

Copy link
Contributor

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

@@ -91,10 +97,12 @@ function isAllowedLocation(node: ts.Expression, { getContextualType, getTypeAtLo
return false;
Copy link
Contributor

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

@@ -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)) {
Copy link
Contributor

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(...)

blakeembrey added a commit to blakeembrey/tslint-config-standard that referenced this pull request Apr 5, 2017
@andy-hanson andy-hanson force-pushed the no-unsafe-any_import branch 2 times, most recently from 761e596 to caba22c Compare April 8, 2017 15:31
@andy-hanson
Copy link
Contributor Author

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 lint:from-global won't work).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants