Tslint: Accept whitelist for no-implicit-dependencies

Created on 17 Apr 2018  路  5Comments  路  Source: palantir/tslint

I would like to specify whitelists for no-implicit-dependencies because of webpack externals options.

TypeScript code being linted

import * as i18n from 'i18n-js' // Module 'i18n-js' is not listed as dependency in package.json

// ...

webpack.config.js:

module.exports = {
  // ...

  externals: {
    'i18n-js': 'I18n',
  },

  // ...
}

I guess this rule should accept whitelists as options. However, since the current option only accepts the type of dependencies, this is breaking change.
Is such a feature accepted?

Most helpful comment

My use case is slightly different. Assume the following paths in the tsconfig.json:

"paths": {
    "@app/*": ["app/*"],
    "@config/*": ["app/_config/*"],
    "@environment/*": ["environments/*"],
    "@shared/*": ["app/_shared/*"],
    "@helpers/*": ["helpers/*"]
}

Although it won't be easy to parse the paths when linting I'd like to see the whitelist as a workaround which should be a lot easier to implement. no-submodule-imports has a similar whitelist that works for me. Here's hoping no-implicit-dependencies gets some love as well.

All 5 comments

My use case is slightly different. Assume the following paths in the tsconfig.json:

"paths": {
    "@app/*": ["app/*"],
    "@config/*": ["app/_config/*"],
    "@environment/*": ["environments/*"],
    "@shared/*": ["app/_shared/*"],
    "@helpers/*": ["helpers/*"]
}

Although it won't be easy to parse the paths when linting I'd like to see the whitelist as a workaround which should be a lot easier to implement. no-submodule-imports has a similar whitelist that works for me. Here's hoping no-implicit-dependencies gets some love as well.

i also find myself disabling no-implicit-dependencies when writing test code which imports from dev dependencies (e.g. enzyme)

The whitelist should fix this issue, however for @NearAutomata it may still be a problem because the rule handles imports starting with @ differently: https://github.com/palantir/tslint/blob/master/src/rules/noImplicitDependenciesRule.ts#L115

@ajcrites Thanks for your great works! I'm happy that this option has been added :)

I think the fix for this has been merged (and should be released shortly). Going to close this for now - feel free to reopen it if need be.

Was this page helpful?
0 / 5 - 0 ratings