Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Jun 23, 2020
1 parent 09f3a5a commit 3cd311b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
9 changes: 3 additions & 6 deletions src/scanners/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,13 @@ export default class JavaScriptScanner {
plugins: ['no-unsanitized'],
allowInlineConfig: false,

// Disable ignore-mode and overwrite eslint default ignore patterns
// so an add-on's bower and node module folders are included in
// the scan. See: https://github.com/mozilla/addons-linter/issues/1288
ignore: false,
patterns: ['!bower_components/*', '!node_modules/*'],

// Avoid loading the addons-linter .eslintrc file
useEslintrc: false,

baseConfig: {
// Scan files in `bower_components/`, `node_modules/` as well as
// dotfiles. See: https://github.com/mozilla/addons-linter/issues/1288
ignorePatterns: ['!bower_components/*', '!node_modules/*', '!.*'],
settings: {
addonMetadata: this.options.addonMetadata,
existingFiles: this.options.existingFiles,
Expand Down
37 changes: 35 additions & 2 deletions tests/unit/scanners/test.javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,39 @@ describe('JavaScript Scanner', () => {
expect(linterMessages.length).toEqual(0);
});

it('should scan node modules', async () => {
const code = oneLine`var a;`;

const jsScanner = new JavaScriptScanner(
code,
'node_modules/module/code.js'
);

const { linterMessages } = await jsScanner.scan();
expect(linterMessages.length).toEqual(0);
});

it('should scan bower components', async () => {
const code = oneLine`var a;`;

const jsScanner = new JavaScriptScanner(
code,
'bower_components/component/code.js'
);

const { linterMessages } = await jsScanner.scan();
expect(linterMessages.length).toEqual(0);
});

it('should scan dotfiles', async () => {
const code = oneLine`var a;`;

const jsScanner = new JavaScriptScanner(code, '.code.js');

const { linterMessages } = await jsScanner.scan();
expect(linterMessages.length).toEqual(0);
});

it('should create an error message when encountering a syntax error', async () => {
let code = 'var m = "d;';
let jsScanner = new JavaScriptScanner(code, 'badcode.js');
Expand Down Expand Up @@ -218,7 +251,6 @@ describe('JavaScript Scanner', () => {
expect(ok).toBeTruthy();
});

// eslint-disable-next-line jest/no-disabled-tests
it('should pass addon metadata to rules', async () => {
const fakeMessages = {
METADATA_NOT_PASSED: {
Expand Down Expand Up @@ -262,6 +294,8 @@ describe('JavaScript Scanner', () => {
const jsScanner = new JavaScriptScanner('', 'badcode.js');

await runJsScanner(jsScanner);
// This is the number of custom ESLint rules we have in addons-linter. When
// adding a new rule, please increase this value.
expect(jsScanner._rulesProcessed).toEqual(16);
});

Expand Down Expand Up @@ -295,7 +329,6 @@ describe('JavaScript Scanner', () => {
});
});

// eslint-disable-next-line jest/no-disabled-tests
it('treats a non-code string message as the message', async () => {
const _ruleMapping = { 'message-rule': ESLINT_ERROR };
const fakeMetadata = { addonMetadata: validMetadata({}) };
Expand Down
9 changes: 3 additions & 6 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');

module.exports = {
// Set the webpack4 mode 'none' for compatibility with the behavior
// of the webpack3 bundling step.
// Set the webpack4 mode 'none' for compatibility with the behavior of the
// webpack3 bundling step.
mode: 'none',
entry: {
'addons-linter': './src/main.js',
...glob.sync('./src/rules/javascript/*.js').reduce((acc, file) => {
acc[file.replace(/^\.\/src\//, '').replace('.js', '')] = file;
return acc;
}, {}),
'addons-linter': './src/main.js',
},
target: 'node',
output: {
Expand Down Expand Up @@ -57,7 +57,4 @@ module.exports = {
modules: ['src', 'node_modules'],
},
devtool: 'sourcemap',
node: {
__dirname: false,
},
};

0 comments on commit 3cd311b

Please sign in to comment.