Skip to content

Commit

Permalink
replace includes() with an indexOf() call, add test cases for multipl…
Browse files Browse the repository at this point in the history
…e import functions
  • Loading branch information
byteme980 committed Apr 10, 2018
1 parent e6e4e98 commit 9be016f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rules/dynamic-import-chunkname.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
properties: {
importFunctions: {
type: 'array',
uniqueItems: true,
items: {
type: 'string',
},
Expand All @@ -32,7 +33,7 @@ module.exports = {
return {
[`CallExpression[callee.type="Import"],CallExpression[callee.name]`](node) {
const { callee: { name }} = node
if (name && !importFunctions.includes(name)) {
if (name && importFunctions.indexOf(name) < 0) {
return
}

Expand Down
25 changes: 25 additions & 0 deletions tests/src/rules/dynamic-import-chunkname.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const pickyCommentOptions = [{
importFunctions: ['dynamicImport'],
webpackChunknameFormat: pickyCommentFormat,
}]
const multipleImportFunctionOptions = [{
importFunctions: ['dynamicImport', 'definitelyNotStaticImport'],
}]
const parser = 'babel-eslint'

const noLeadingCommentError = 'dynamic imports require a leading comment with the webpack chunkname'
Expand Down Expand Up @@ -173,6 +176,28 @@ ruleTester.run('dynamic-import-chunkname', rule, {
type: 'CallExpression',
}],
},
{
code: `dynamicImport(
/* webpackChunkName "someModule" */
'someModule'
)`,
options: multipleImportFunctionOptions,
errors: [{
message: commentFormatError,
type: 'CallExpression',
}],
},
{
code: `definitelyNotStaticImport(
/* webpackChunkName "someModule" */
'someModule'
)`,
options: multipleImportFunctionOptions,
errors: [{
message: commentFormatError,
type: 'CallExpression',
}],
},
{
code: `dynamicImport(
// webpackChunkName: "someModule"
Expand Down

0 comments on commit 9be016f

Please sign in to comment.