Skip to content

Commit 47b529e

Browse files
MhMadHamsterljharb
authored andcommitted
[Fix] dynamic-import-chunkname: add handling webpack magic comments
1 parent 404f482 commit 47b529e

File tree

3 files changed

+971
-55
lines changed

3 files changed

+971
-55
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2020
- [`order`]: require with member expression could not be fixed if alphabetize.order was used ([#2490], thanks [@msvab])
2121
- [`order`]: leave more space in rankings for consecutive path groups ([#2506], thanks [@Pearce-Ropion])
2222
- [`no-cycle`]: add ExportNamedDeclaration statements to dependencies ([#2511], thanks [@BenoitZugmeyer])
23+
- [`dynamic-import-chunkname`]: prevent false report on a valid webpack magic comment ([#2330], thanks [@mhmadhamster])
2324

2425
### Changed
2526
- [Tests] `named`: Run all TypeScript test ([#2427], thanks [@ProdigySim])
@@ -1027,6 +1028,7 @@ for info on changes for earlier releases.
10271028
[#2358]: https://github.com/import-js/eslint-plugin-import/pull/2358
10281029
[#2341]: https://github.com/import-js/eslint-plugin-import/pull/2341
10291030
[#2334]: https://github.com/import-js/eslint-plugin-import/pull/2334
1031+
[#2330]: https://github.com/import-js/eslint-plugin-import/pull/2330
10301032
[#2305]: https://github.com/import-js/eslint-plugin-import/pull/2305
10311033
[#2299]: https://github.com/import-js/eslint-plugin-import/pull/2299
10321034
[#2297]: https://github.com/import-js/eslint-plugin-import/pull/2297
@@ -1652,6 +1654,7 @@ for info on changes for earlier releases.
16521654
[@maxkomarychev]: https://github.com/maxkomarychev
16531655
[@maxmalov]: https://github.com/maxmalov
16541656
[@mgwalker]: https://github.com/mgwalker
1657+
[@mhmadhamster]: https://github.com/MhMadHamster
16551658
[@MikeyBeLike]: https://github.com/MikeyBeLike
16561659
[@mplewis]: https://github.com/mplewis
16571660
[@mrmckeb]: https://github.com/mrmckeb

Diff for: src/rules/dynamic-import-chunkname.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ module.exports = {
2727
create(context) {
2828
const config = context.options[0];
2929
const { importFunctions = [] } = config || {};
30-
const { webpackChunknameFormat = '[0-9a-zA-Z-_/.]+' } = config || {};
30+
const { webpackChunknameFormat = '([0-9a-zA-Z-_/.]|\\[(request|index)\\])+' } = config || {};
3131

3232
const paddedCommentRegex = /^ (\S[\s\S]+\S) $/;
33-
const commentStyleRegex = /^( \w+: (["'][^"']*["']|\d+|false|true),?)+ $/;
33+
const commentStyleRegex = /^( ((webpackChunkName: .+)|((webpackPrefetch|webpackPreload): (true|false|-?[0-9]+))|(webpackIgnore: (true|false))|((webpackInclude|webpackExclude): \/.*\/)|(webpackMode: ["'](lazy|lazy-once|eager|weak)["'])|(webpackExports: (['"]\w+['"]|\[(['"]\w+['"], *)+(['"]\w+['"]*)\]))),?)+ $/;
3434
const chunkSubstrFormat = ` webpackChunkName: ["']${webpackChunknameFormat}["'],? `;
3535
const chunkSubstrRegex = new RegExp(chunkSubstrFormat);
3636

@@ -83,7 +83,7 @@ module.exports = {
8383
context.report({
8484
node,
8585
message:
86-
`dynamic imports require a leading comment in the form /*${chunkSubstrFormat}*/`,
86+
`dynamic imports require a "webpack" comment with valid syntax`,
8787
});
8888
return;
8989
}

0 commit comments

Comments
 (0)