Skip to content

Commit

Permalink
Add rules that show corner cases for commonJS
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Tamura committed Mar 25, 2019
1 parent 206d676 commit be4f1c7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/src/rules/no-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ ruleTester.run('no-commonjs', require('rules/no-commonjs'), {
{ code: 'var zero = require(0);' },
{ code: 'require("x")', options: [{ allowRequire: true }] },

// commonJS doesn't care how the path is built. You can use a function to
// dynamically build the module path.t st
{ code: 'require(rootRequire("x"))', options: [{ allowRequire: true }] },
{ code: 'require(String("x"))', options: [{ allowRequire: true }] },
{ code: 'require(["x", "y", "z"].join("/"))', options: [{ allowRequire: true }] },

// commonJS rules should be scoped to commonJS spec. `rootRequire` is not
// recognized by this commonJS plugin.
{ code: 'rootRequire("x")', options: [{ allowRequire: true }] },
{ code: 'rootRequire("x")', options: [{ allowRequire: false}] },

{ code: 'module.exports = function () {}', options: ['allow-primitive-modules'] },
{ code: 'module.exports = function () {}', options: [{ allowPrimitiveModules: true }] },
{ code: 'module.exports = "foo"', options: ['allow-primitive-modules'] },
Expand Down

0 comments on commit be4f1c7

Please sign in to comment.