From 1edbbd03ec636469328ad59da922ed7edc8cd36d Mon Sep 17 00:00:00 2001 From: Charles Suh Date: Sun, 5 May 2019 16:47:41 -0700 Subject: [PATCH] [Fix] `no-common-js`: Also throw an error when assigning --- src/rules/no-commonjs.js | 1 + tests/src/rules/no-commonjs.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/rules/no-commonjs.js b/src/rules/no-commonjs.js index b6f11a7f0..261654bbf 100644 --- a/src/rules/no-commonjs.js +++ b/src/rules/no-commonjs.js @@ -91,6 +91,7 @@ module.exports = { if ( call.parent.type !== 'ExpressionStatement' && call.parent.type !== 'VariableDeclarator' + && call.parent.type !== 'AssignmentExpression' ) return if (call.callee.type !== 'Identifier') return diff --git a/tests/src/rules/no-commonjs.js b/tests/src/rules/no-commonjs.js index 72d5bfb19..c8155938b 100644 --- a/tests/src/rules/no-commonjs.js +++ b/tests/src/rules/no-commonjs.js @@ -60,6 +60,7 @@ ruleTester.run('no-commonjs', require('rules/no-commonjs'), { // imports { code: 'var x = require("x")', errors: [ { message: IMPORT_MESSAGE }] }, + { code: 'x = require("x")', errors: [ { message: IMPORT_MESSAGE }] }, { code: 'require("x")', errors: [ { message: IMPORT_MESSAGE }] }, // exports