Skip to content

Commit

Permalink
fix: web-ext lint: ignore node_modules and other artifacts (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumar303 authored Aug 4, 2016
1 parent 23e59df commit cd9adac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/cmd/lint.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* @flow */
import {createLinter as defaultLinterCreator} from '../util/es6-modules';
import {createLogger} from '../util/logger';
import {FileFilter} from './build';

const log = createLogger(__filename);

export default function lint(
{verbose, sourceDir, selfHosted, boring, output,
metadata, pretty}: Object,
{createLinter=defaultLinterCreator}: Object = {}): Promise {
{createLinter=defaultLinterCreator, fileFilter=new FileFilter()}
: Object = {}): Promise {
log.debug(`Running addons-linter on ${sourceDir}`);
const linter = createLinter({
config: {
Expand All @@ -18,6 +20,7 @@ export default function lint(
output,
boring,
selfHosted,
shouldScanFile: (fileName) => fileFilter.wantFile(fileName),
// This mimics the first command line argument from yargs,
// which should be the directory to the extension.
_: [sourceDir],
Expand Down
23 changes: 20 additions & 3 deletions tests/test-cmd/test.lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {assert} from 'chai';
import sinon from 'sinon';

import defaultLintCommand from '../../src/cmd/lint';
import {makeSureItFails} from '../helpers';
import {FileFilter} from '../../src/cmd/build';
import {fake, makeSureItFails} from '../helpers';

describe('lint', () => {

function setUp({createLinter} = {}) {
function setUp({createLinter, fileFilter}: Object = {}) {
const lintResult = '<lint.run() result placeholder>';
const runLinter = sinon.spy(() => Promise.resolve(lintResult));
if (!createLinter) {
Expand All @@ -21,7 +22,7 @@ describe('lint', () => {
createLinter,
runLinter,
lint: ({...args}) => {
return defaultLintCommand(args, {createLinter});
return defaultLintCommand(args, {createLinter, fileFilter});
},
};
}
Expand Down Expand Up @@ -99,4 +100,20 @@ describe('lint', () => {
});
});

it('passes a file filter to the linter', () => {
const fileFilter = fake(new FileFilter());
const {lint, createLinter} = setUp({fileFilter});
return lint()
.then(() => {
assert.equal(createLinter.called, true);
const config = createLinter.firstCall.args[0].config;
assert.isFunction(config.shouldScanFile);

// Simulate how the linter will use this callback.
config.shouldScanFile('manifest.json');
assert.equal(fileFilter.wantFile.called, true);
assert.equal(fileFilter.wantFile.firstCall.args[0], 'manifest.json');
});
});

});

0 comments on commit cd9adac

Please sign in to comment.