Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rules): explicitly import rules to trigger side effects #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

atkinchris
Copy link

@atkinchris atkinchris commented Oct 6, 2024

This adds an explicit import for the rules index file, to trigger the registration side effects of each rule being imported. Each rule file module runs register - and unless imported, that registration will not happen.

This was already happening in the CLI, as it uses autoload.ts - which contained an explicit import for the rules module index. However, when using the library programmatically, rules.loadAll would not have any registered rules to load.

Work around

You can work around this issue at the moment by using import '@specfy/stack-analyser/dist/autoload.js', or including import '@specfy/stack-analyser/dist/rules/index.js' before running rules.loadAll.

import '@specfy/stack-analyser/dist/autoload.js'

// or

import { rules } from '@specfy/stack-analyser'
import '@specfy/stack-analyser/dist/rules/index.js'

rules.loadAll()

This adds an explicit import for the rules index file, to trigger the registration side effects of each rule being imported. This already happened in the CLI due to the import being present in "autoload.ts", but was missing in programmatic usage. This resulted in "rules.loadAll" loading no rules.
@bodinsamuel
Copy link
Collaborator

hey, thanks for raising this issue. It was done intentionally if devs want to use the library with custom rules only.
But I realize that the README does not reflect that requirement indeed. Do you think this process is problematic?
Maybe we should just update the readme to clarify the situation

@atkinchris
Copy link
Author

atkinchris commented Oct 7, 2024

Wouldn the loadOne API satisfy the need to use custom rules? The import side effect registers them, but in the fix proposed doesn't load them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants