Skip to content

Commit

Permalink
feat: Support warnings-as-errors
Browse files Browse the repository at this point in the history
This patch adds support for using --warnings-as-errors as a parameter
for the lint command.

This complements the PR mozilla/addons-linter#1016
and completes the issue mozilla/addons-linter#1014.
  • Loading branch information
josteink committed Nov 2, 2016
1 parent 36989b4 commit 4ded9b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cmd/lint.js
Expand Up @@ -16,6 +16,7 @@ export type LinterCreatorParams = {
logLevel: 'debug' | 'fatal',
stack: boolean,
pretty?: boolean,
warningsAsErrors?: boolean,
metadata?: boolean,
output?: LinterOutputType,
boring?: boolean,
Expand All @@ -42,6 +43,7 @@ export type LintCmdParams = {
output?: LinterOutputType,
metadata?: boolean,
pretty?: boolean,
warningsAsErrors?: boolean,
};

export type LintCmdOptions = {
Expand All @@ -52,7 +54,7 @@ export type LintCmdOptions = {
export default function lint(
{
verbose, sourceDir, selfHosted, boring, output,
metadata, pretty,
metadata, pretty, warningsAsErrors,
}: LintCmdParams,
{
createLinter = defaultLinterCreator,
Expand All @@ -65,6 +67,7 @@ export default function lint(
logLevel: verbose ? 'debug' : 'fatal',
stack: Boolean(verbose),
pretty,
warningsAsErrors,
metadata,
output,
boring,
Expand Down
6 changes: 6 additions & 0 deletions src/program.js
Expand Up @@ -297,6 +297,12 @@ Example: $0 --help run.
type: 'boolean',
default: false,
},
'warnings-as-errors': {
describe: 'Treat warnings as errors',
alias: 'w',
type: 'boolean',
default: false,
},
'pretty': {
describe: 'Prettify JSON output',
type: 'boolean',
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test-cmd/test.lint.js
Expand Up @@ -65,6 +65,22 @@ describe('lint', () => {
});
});

it('passes warningsAsErrors to the linter', () => {
const {lint, createLinter} = setUp();
return lint({warningsAsErrors: true}).then(() => {
const config = createLinter.firstCall.args[0].config;
assert.equal(config.warningsAsErrors, true);
});
});

it('passes warningsAsErrors undefined to the linter', () => {
const {lint, createLinter} = setUp();
return lint({}).then(() => {
const config = createLinter.firstCall.args[0].config;
assert.equal(config.warningsAsErrors, undefined);
});
});

it('configures the linter when verbose', () => {
const {lint, createLinter} = setUp();
return lint({verbose: true}).then(() => {
Expand Down

0 comments on commit 4ded9b9

Please sign in to comment.