I've created a es lint plugin that provides me with a rule which checks that provided import is not in a dynamic list of blacklisted imports.
The list is loaded from a JSON file.
Currently I am loading this file in the create method of a rule, but the rule is being recreated for each file, which in turn makes the linter slow.
I've found the following text in the ESLint documentation, but no other mention of a way to share some global object within an invocation of the linter.
https://eslint.org/docs/latest/user-guide/configuring/configuration-files#adding-shared-settings
ESLint supports adding shared settings into configuration files. Plugins use settings to specify information that should be shared across all of its rules. You can add settings object to ESLint configuration file and it will be supplied to every rule being executed. This may be useful if you are adding custom rules and want them to have access to the same information and be easily configurable.
Is this supported? I've tried exporting a settings object in the index.js of the plugin, but it is not being picked up at all.
module.exports.settings = {
"sharedData": "Hello"
}
Looks like I already have a workaround, but wondering if someone will come up with a better solution.
What I did in the end was to load the configuration in the index of the rule itself, which is loaded at the start of ESLint.
Instead of depending on context.getCwd() I've fallen back to _dirname. Which proved to be enough for my use case.