diff --git a/src/scanners/javascript.js b/src/scanners/javascript.js index af31cb9e211..46959ff2fa0 100644 --- a/src/scanners/javascript.js +++ b/src/scanners/javascript.js @@ -62,30 +62,39 @@ export default class JavaScriptScanner { const root = typeof appRoot !== 'undefined' ? appRoot : path.join(__dirname, '..'); const eslintConfig = { - envs: ['es6', 'webextensions', 'browser'], - // It's the default but also shouldn't change since we're using - // espree to parse javascript files below manually to figure out - // if they're modules or not - parser: 'espree', - parserOptions: { - ecmaVersion: ECMA_VERSION, - sourceType: this.sourceType, - }, - rules, - resolvePluginsRelativeTo: root, + resolvePluginsRelativeTo: path.resolve(root), // The default value for `rulePaths` is configured so that it finds the // files exported by webpack when this project is built. rulePaths: _rulePaths || [path.join(root, 'dist', 'rules', 'javascript')], - plugins: ['no-unsanitized'], allowInlineConfig: false, // 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/*', '!.*'], + env: { + browser: true, + es6: true, + webextensions: true, + }, + + // It's the default but also shouldn't change since we're using + // espree to parse javascript files below manually to figure out + // if they're modules or not + parser: 'espree', + parserOptions: { + ecmaVersion: ECMA_VERSION, + sourceType: this.sourceType, + }, + + rules, + plugins: ['no-unsanitized'], + + // Scan files in `node_modules/` as well as dotfiles. As of ESLInt 7.0, + // bower files are scanned. + // See: https://github.com/mozilla/addons-linter/issues/1288 + // See: https://eslint.org/docs/user-guide/migrating-to-7.0.0#default-ignore-patterns-have-changed + ignorePatterns: ['!node_modules/*', '!.*'], settings: { addonMetadata: this.options.addonMetadata, existingFiles: this.options.existingFiles, @@ -93,8 +102,11 @@ export default class JavaScriptScanner { }, }; - const cli = new _ESLint.CLIEngine(eslintConfig); - const { results } = cli.executeOnText(this.code, this.filename, true); + const cli = new _ESLint.ESLint(eslintConfig); + const results = await cli.lintText(this.code, { + filePath: this.filename, + warnIgnored: true, + }); // eslint prepends the filename with the current working directory, // strip that out. diff --git a/tests/unit/scanners/test.javascript.js b/tests/unit/scanners/test.javascript.js index 5cb0b7a6821..1122b1b93c1 100644 --- a/tests/unit/scanners/test.javascript.js +++ b/tests/unit/scanners/test.javascript.js @@ -225,32 +225,23 @@ describe('JavaScript Scanner', () => { }); it('should reject on missing message code', async () => { - const FakeCLIEngine = () => {}; - FakeCLIEngine.prototype = { - constructor() {}, - executeOnText: () => { - return { - results: [ - { - filePath: 'badcode.js', - messages: [ - { - fatal: false, - }, - ], - }, - ], - }; - }, - linter: { - defineRule: () => { - // no-op - }, - }, - }; + class FakeESLintClass { + async lintText() { + return Promise.resolve([ + { + filePath: 'badcode.js', + messages: [ + { + fatal: false, + }, + ], + }, + ]); + } + } const FakeESLint = { - CLIEngine: FakeCLIEngine, + ESLint: FakeESLintClass, }; const jsScanner = new JavaScriptScanner('whatever', 'badcode.js');