Skip to content

Commit

Permalink
chore: update detect circular reference docs and add it to recommende…
Browse files Browse the repository at this point in the history
…d rules
  • Loading branch information
thiagomini committed Jan 25, 2024
1 parent d95cd9e commit 5b5a707
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 0 additions & 2 deletions docs/rules/detect-circular-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ description: 'Detects usage of `forwardRef()` function commonly used to handle c

[Forward references](https://docs.nestjs.com/fundamentals/circular-dependency#forward-reference) are commonly used to handle circular dependencies between services or modules. For example, if `FooService` and `BarService` depend on each other, you can use `forwardRef()` to resolve the circular dependency. However, `forwardRef()` must be a last resort, and we generally recommend changing your code to avoid circular dependencies. This rule detects usage of the `forwardRef()` method so you can keep track of what potentially needs refactoring.

One strategy to avoid circular dependencies between services is to make each responsible for a single use case. That way you decrease the interface and likelihood of circular dependencies. You can also avoid using services as facades for data repositories. Instead, services should be usually used to encapsulate business logic (commands). Leave query responsibilities to repositories.

## Options

This rule has no additional options yet.
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import enforceCloseTestingModuleRule from './rules/enforce-close-testing-module.rule';
import checkInjectDecoratorRule from './rules/check-inject-decorator.rule';
import detectCircularReferenceRule from './rules/detect-circular-reference.rule';
// TODO: we should type this as ESLint.Plugin but there's a type incompatibilities with the utils package
const plugin = {
configs: {
recommended: {
rules: {
'@trilon/enforce-close-testing-module': 'error',
'@trilon/check-inject-decorator': 'error',
'@trilon/detect-circular-reference': 'warn',
},
},
},
rules: {
'enforce-close-testing-module': enforceCloseTestingModuleRule,
'check-inject-decorator': checkInjectDecoratorRule,
'detect-circular-reference': detectCircularReferenceRule,
},
};

Expand Down

0 comments on commit 5b5a707

Please sign in to comment.