@secretlint/config-loader
Config loader for secretlint.
Install
Install with npm:
npm install @secretlint/config-loader
Usage
API
loadConfig(options) returns a promise for an object containing:
ok:truewhen loading succeeds.configFilePath: the path of the loaded config file.configDescriptor: the config file contents before rule modules are loaded.config: the validated config with loaded rule modules.
loadConfigDescriptor(options) returns a promise for { ok, configFilePath, configDescriptor } without loading or validating rule modules.
Both functions accept cwd to choose the directory in which to search for a config file, or configFilePath to select a config file explicitly. See the exported SecretLintConfigLoaderOptions, SecretLintConfigLoaderResult, and SecretLintConfigLoaderRawResult types for the complete interfaces.
If the config file cannot be found or read, the promise rejects. loadConfig also rejects if the config is invalid or a rule module cannot be loaded. Handle these errors with try/catch.
Example
Use an ES module (.mjs, or .js with "type": "module" in package.json):
import { loadConfig } from "@secretlint/config-loader";
try {
// Load a config file such as <CurrentDir>/.secretlintrc.json
const { config, configFilePath } = await loadConfig({ cwd: process.cwd() });
console.log("load from configFile:" + configFilePath);
console.log("config", config);
} catch (error) {
console.error(error);
}
Terminology
- ConfigDescriptor: config file literal that is not loaded yet
- Config: loaded object
Workflow
- Validate
ConfigDescriptor - Load
ConfigDescriptorand createConfigobject - imports each rule modules - Validate Loaded
ConfigwithConfigDescriptor- Invalid option, Invalid allowMessageIds, Invalid id specify for a preset
- If all validation is passed, get a Config.
Changelog
See Releases page.
Running tests
Install devDependencies and Run npm test:
npm test
Contributing
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :D
Author
License
MIT azu