Skip to content

Commit cd9adac

Browse files
authored
fix: web-ext lint: ignore node_modules and other artifacts (#405)
1 parent 23e59df commit cd9adac

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/cmd/lint.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/* @flow */
22
import {createLinter as defaultLinterCreator} from '../util/es6-modules';
33
import {createLogger} from '../util/logger';
4+
import {FileFilter} from './build';
45

56
const log = createLogger(__filename);
67

78
export default function lint(
89
{verbose, sourceDir, selfHosted, boring, output,
910
metadata, pretty}: Object,
10-
{createLinter=defaultLinterCreator}: Object = {}): Promise {
11+
{createLinter=defaultLinterCreator, fileFilter=new FileFilter()}
12+
: Object = {}): Promise {
1113
log.debug(`Running addons-linter on ${sourceDir}`);
1214
const linter = createLinter({
1315
config: {
@@ -18,6 +20,7 @@ export default function lint(
1820
output,
1921
boring,
2022
selfHosted,
23+
shouldScanFile: (fileName) => fileFilter.wantFile(fileName),
2124
// This mimics the first command line argument from yargs,
2225
// which should be the directory to the extension.
2326
_: [sourceDir],

tests/test-cmd/test.lint.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import {assert} from 'chai';
44
import sinon from 'sinon';
55

66
import defaultLintCommand from '../../src/cmd/lint';
7-
import {makeSureItFails} from '../helpers';
7+
import {FileFilter} from '../../src/cmd/build';
8+
import {fake, makeSureItFails} from '../helpers';
89

910
describe('lint', () => {
1011

11-
function setUp({createLinter} = {}) {
12+
function setUp({createLinter, fileFilter}: Object = {}) {
1213
const lintResult = '<lint.run() result placeholder>';
1314
const runLinter = sinon.spy(() => Promise.resolve(lintResult));
1415
if (!createLinter) {
@@ -21,7 +22,7 @@ describe('lint', () => {
2122
createLinter,
2223
runLinter,
2324
lint: ({...args}) => {
24-
return defaultLintCommand(args, {createLinter});
25+
return defaultLintCommand(args, {createLinter, fileFilter});
2526
},
2627
};
2728
}
@@ -99,4 +100,20 @@ describe('lint', () => {
99100
});
100101
});
101102

103+
it('passes a file filter to the linter', () => {
104+
const fileFilter = fake(new FileFilter());
105+
const {lint, createLinter} = setUp({fileFilter});
106+
return lint()
107+
.then(() => {
108+
assert.equal(createLinter.called, true);
109+
const config = createLinter.firstCall.args[0].config;
110+
assert.isFunction(config.shouldScanFile);
111+
112+
// Simulate how the linter will use this callback.
113+
config.shouldScanFile('manifest.json');
114+
assert.equal(fileFilter.wantFile.called, true);
115+
assert.equal(fileFilter.wantFile.firstCall.args[0], 'manifest.json');
116+
});
117+
});
118+
102119
});

0 commit comments

Comments
 (0)