Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cmd/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function lint(
{
artifactsDir,
boring,
disableLinterRules,
enterprise,
ignoreFiles,
metadata,
Expand Down Expand Up @@ -39,6 +40,7 @@ export default function lint(
metadata,
output,
boring,
disableLinterRules,
selfHosted,
enterprise,
shouldScanFile: (fileName) => fileFilter.wantFile(fileName),
Expand Down
5 changes: 5 additions & 0 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,11 @@ Example: $0 --help run.
type: 'boolean',
default: false,
},
'disable-linter-rules': {
describe: 'Disable a comma-separated list of linter rules',
type: 'string',
requiresArg: true,
},
pretty: {
describe: 'Prettify JSON output',
type: 'boolean',
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/test-cmd/test.lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ describe('lint', () => {
});
});

it('passes disableLinterRules to the linter', () => {
const { lint, createLinter } = setUp();
const disableLinterRules = 'no-implied-eval, no-unsanitized/property';
return lint({ disableLinterRules }).then(() => {
sinon.assert.calledWithMatch(createLinter, {
config: {
disableLinterRules,
},
});
});
});

it('passes disableLinterRules undefined to the linter', () => {
const { lint, createLinter } = setUp();
return lint().then(() => {
sinon.assert.calledWithMatch(createLinter, {
config: {
disableLinterRules: undefined,
},
});
});
});

it('configures the linter when verbose', () => {
const { lint, createLinter } = setUp();
return lint({ verbose: true }).then(() => {
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/test.program.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,46 @@ describe('program.main', () => {
assert.equal(options.selfHosted, configObject.lint.selfHosted);
});

it('applies disabled linter rules from the specified config file', async () => {
const fakeCommands = fake(commands, {
lint: () => Promise.resolve(),
});
const configFile = path.resolve('custom/web-ext-config.mjs');
const disableLinterRules = 'no-implied-eval, no-unsanitized/property';

await execProgram(['lint', '--config', configFile], {
commands: fakeCommands,
runOptions: {
loadJSConfigFile: makeConfigLoader({
configObjects: {
[configFile]: { lint: { disableLinterRules } },
},
}),
},
});

assert.equal(
fakeCommands.lint.firstCall.args[0].disableLinterRules,
disableLinterRules,
);
});

it('passes disabled linter rules from the CLI', async () => {
const fakeCommands = fake(commands, {
lint: () => Promise.resolve(),
});
const disableLinterRules = 'no-implied-eval,no-unsanitized/property';

await execProgram(['lint', '--disable-linter-rules', disableLinterRules], {
commands: fakeCommands,
});

assert.equal(
fakeCommands.lint.firstCall.args[0].disableLinterRules,
disableLinterRules,
);
});

it('discovers config files', async () => {
const fakeCommands = fake(commands, {
lint: () => Promise.resolve(),
Expand Down