You can integrate the linter directly into your Node.js applications using the createInstance method.
To prevent the linter from exiting your Node.js process when it finishes, set runAsBinary: false in the configuration object. The config object mimics the command-line arguments provided via yargs.
import addonsLinter from 'addons-linter';
const sourceDir = process.cwd();
const linter = addonsLinter.createInstance({
config: {
// The directory to the extension (mimics first CLI argument)
_: [sourceDir],
logLevel: process.env.VERBOSE ? 'debug' : 'fatal',
stack: Boolean(process.env.VERBOSE),
pretty: false,
warningsAsErrors: false,
metadata: false,
output: 'none',
boring: false,
selfHosted: false,
// Function to determine if a file should be scanned
shouldScanFile: (fileName) => true,
},
// Prevents the linter from exiting the nodejs application
runAsBinary: false,
});
linter.run()
.then((linterResults) => {
// Handle results
})
.catch((err) => console.error("addons-linter failure: ", err));
import addonsLinter from 'addons-linter';
const sourceDir = process.cwd();
const linter = addonsLinter.createInstance({
config: {
_: [sourceDir],
logLevel: process.env.VERBOSE ? 'debug' : 'fatal',
stack: Boolean(process.env.VERBOSE),
pretty: false,
warningsAsErrors: false,
metadata: false,
output: 'none',
boring: false,
selfHosted: false,
shouldScanFile: (fileName) => true,
},
runAsBinary: false,
});
linter.run()
.then((linterResults) => ...)
.catch((err) => console.error("addons-linter failure: ", err));