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

[new-rule-option] [no-implicit-dependencies] - add whitelist (#3839) #3979

Merged

Conversation

ajcrites
Copy link
Contributor

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

@palantirtech
Copy link
Member

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.

@ajcrites
Copy link
Contributor Author

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
@ajcrites ajcrites force-pushed the no-implicit-dependencies-whitelist branch from e4b6caa to d3cfec2 Compare June 20, 2018 19:36
@@ -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[];
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 be able to do:
const whitelist = this.ruleArguments.find((arg) => Array.isArray(arg)) || [];

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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.
@suchanlee
Copy link
Contributor

alrighty lets merge it!

@suchanlee suchanlee merged commit 9d7db47 into palantir:master Jun 28, 2018
@suchanlee
Copy link
Contributor

do you want to close #3839 ?

pablobirukov pushed a commit to evolution-gaming/tslint that referenced this pull request Jul 4, 2018
…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.
@heavybeard
Copy link

The release of this option will be the main event of 2018 🎉
Thank you all guys!

pablobirukov added a commit to evolution-gaming/tslint that referenced this pull request Jul 9, 2018
johnwiseheart pushed a commit that referenced this pull request Jul 11, 2018
#4019)

* Fix CI, which became red after consequent merge #3979, #3875

* Upgrade typescript@2.9.2, tsutils@2.27.2

* Remove unneded type assertion after typescript upgrade

* Add runtime check for 'ts.unescapeIdentifier()' presence
mhadaily added a commit to mhadaily/schemastore that referenced this pull request Nov 6, 2018
based on this PR, palantir/tslint#3979 whitelist is now supported.
mhadaily added a commit to mhadaily/schemastore that referenced this pull request Nov 6, 2018
based on this PR, palantir/tslint#3979 whitelist is now supported.
mhadaily added a commit to mhadaily/schemastore that referenced this pull request Nov 6, 2018
based on this PR, palantir/tslint#3979 whitelist is now supported.
madskristensen pushed a commit to SchemaStore/schemastore that referenced this pull request Nov 6, 2018
undeadcat pushed a commit to undeadcat/schemastore that referenced this pull request Mar 5, 2019
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

4 participants