-
Notifications
You must be signed in to change notification settings - Fork 889
[new-rule-option] [no-implicit-dependencies] - add whitelist (#3839) #3979
[new-rule-option] [no-implicit-dependencies] - add whitelist (#3839) #3979
Conversation
Thanks for your interest in palantir/tslint, @ajcrites! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
I believe this also covers #3483 |
This allows you to specify a whitelist of modules that will not be part of package.json such as project-relative aliases
e4b6caa
to
d3cfec2
Compare
@@ -64,9 +76,15 @@ export class Rule extends Lint.Rules.AbstractRule { | |||
} | |||
|
|||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | |||
let whitelist = this.ruleArguments.find((arg) => Array.isArray(arg)) as string[]; |
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 be able to do:
const whitelist = this.ruleArguments.find((arg) => Array.isArray(arg)) || [];
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.
This gives a couple of errors:
ERROR: 79:83 strict-boolean-expressions This type is not allowed in the operand for the '||' operator because it is always truthy. Allowed types are boolean or boolean-or-undefined.
ERROR: 84:13 no-unsafe-any Unsafe use of expression of type 'any'.
@@ -77,7 +95,7 @@ function walk(ctx: Lint.WalkContext<Options>) { | |||
for (const name of findImports(ctx.sourceFile, ImportKind.All)) { | |||
if (!ts.isExternalModuleNameRelative(name.text)) { | |||
const packageName = getPackageName(name.text); | |||
if (builtins.indexOf(packageName) === -1 && !hasDependency(packageName)) { | |||
if (options.whitelist.indexOf(packageName) === -1 && builtins.indexOf(packageName) === -1 && !hasDependency(packageName)) { |
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.
it would be a good idea to create a Set
outside of the for loop to make the check faster.
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.
Done
Use Set for whitelist package name comparison instead of Array.
alrighty lets merge it! |
do you want to close #3839 ? |
…r#3839) (palantir#3979) * feature - no-implicit-dependencies - add whitelist (palantir#3839) This allows you to specify a whitelist of modules that will not be part of package.json such as project-relative aliases * feature - no-implicit-dependencies - add whitelist (palantir#3839) Use Set for whitelist package name comparison instead of Array.
The release of this option will be the main event of 2018 🎉 |
based on this PR, palantir/tslint#3979 whitelist is now supported.
based on this PR, palantir/tslint#3979 whitelist is now supported.
based on this PR, palantir/tslint#3979 whitelist is now supported.
based on this PR, palantir/tslint#3979 whitelist is now supported.
based on this PR, palantir/tslint#3979 whitelist is now supported.
This allows you to specify a whitelist of modules that will not be part of package.json such as project-relative aliases
PR checklist
Overview of change:
This adds an option to
no-implicit-dependencies
to specify dependencies that will be known not to be included in package.json such as project-relative imports.CHANGELOG.md entry:
[new-rule-option] [no-implicit-dependencies] whitelist