Code Smell for "Dependencies should be explicit" in NX Project

106 views Asked by At

Project Structure

I have structured my Angular application in an NX project. Within NX the code is structured in libraries.

Nx automatically creates TypeScript path mappings in the tsconfig.base.json file, such that they can be easily consumed by other apps or libs.: https://nx.dev/concepts/more-concepts/applications-and-libraries

I can import from these libraries with:

import { MylibModule } from '@libs/mylib/ui';
src/
|___app
|   |...
|___libs
|   |___mylib
|   |...
package.json
tsconfig.base.json

The Problem

In the code analysis Sonar says Either remove this import or add it as a dependency. The rule typescript:S4328 (Dependencies should be explicit) wants me to add all imported dependencies in the package.json.

Conclusion

Because the module is imported from my own library within the same repo, this is a false positive. How can I fix this?

  1. I dont want to flag every smell as false positive, there are already over 300 of them
  2. I dont want to disable the rule entirely, because it can be useful if a developer misses to declare a transitive dependency in the package.json

Any ideas? Is there some kind of configuration I could adjust to such a monorepo project?

0

There are 0 answers