Skip to content

Commit c914fe2

Browse files
style: improve style of code
1 parent ac0bd21 commit c914fe2

File tree

63 files changed

+327
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+327
-179
lines changed

bin/webpack.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ if (!cli.installed) {
113113
const fs = require("graceful-fs");
114114
const readLine = require("readline");
115115

116-
const notify =
117-
"CLI for webpack must be installed.\n" + ` ${cli.name} (${cli.url})\n`;
116+
const notify = `CLI for webpack must be installed.\n ${cli.name} (${cli.url})\n`;
118117

119118
console.error(notify);
120119

eslint.config.js

+156-46
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const jsdoc = require("eslint-plugin-jsdoc");
66
const prettierConfig = require("eslint-config-prettier");
77
const globals = require("globals");
88

9+
const nodeConfig = n.configs["flat/recommended"];
910
const jsdocConfig = jsdoc.configs["flat/recommended-typescript-flavor-error"];
1011

1112
module.exports = [
@@ -36,16 +37,60 @@ module.exports = [
3637
// Ignore precompiled schemas
3738
"schemas/**/*.check.js",
3839

40+
// Auto generation
41+
"lib/util/semver.js",
42+
3943
// Ignore some examples files
4044
"examples/**/*.js",
4145
"examples/**/*.mjs",
4246
"!examples/*/webpack.config.js"
4347
]
4448
},
4549
js.configs.recommended,
46-
n.configs["flat/recommended"],
50+
{
51+
...nodeConfig,
52+
rules: {
53+
...nodeConfig.rules,
54+
"n/no-missing-require": ["error", { allowModules: ["webpack"] }],
55+
"n/no-unsupported-features/node-builtins": [
56+
"error",
57+
{
58+
ignores: ["zlib.createBrotliCompress", "zlib.createBrotliDecompress"]
59+
}
60+
],
61+
"n/exports-style": "error"
62+
}
63+
},
4764
{
4865
...jsdocConfig,
66+
settings: {
67+
jsdoc: {
68+
mode: "typescript",
69+
// supported tags https://github.com/microsoft/TypeScript-wiki/blob/master/JSDoc-support-in-JavaScript.md
70+
tagNamePreference: {
71+
...["implements", "const", "memberof", "yields"].reduce(
72+
(acc, tag) => {
73+
acc[tag] = {
74+
message: `@${tag} currently not supported in TypeScript`
75+
};
76+
return acc;
77+
},
78+
{}
79+
),
80+
extends: "extends",
81+
return: "returns",
82+
constructor: "constructor",
83+
prop: "property",
84+
arg: "param",
85+
augments: "extends",
86+
description: false,
87+
desc: false,
88+
inheritdoc: false,
89+
class: "constructor"
90+
},
91+
overrideReplacesDocs: false
92+
}
93+
},
4994
rules: {
5095
...jsdocConfig.rules,
5196
// Override recommended
@@ -98,10 +143,17 @@ module.exports = [
98143
"no-use-before-define": "off",
99144
"no-unused-vars": [
100145
"error",
101-
{ caughtErrors: "none", args: "none", ignoreRestSiblings: true }
146+
{
147+
vars: "all",
148+
varsIgnorePattern: "^_",
149+
args: "none",
150+
argsIgnorePattern: "^_",
151+
caughtErrors: "none",
152+
caughtErrorsIgnorePattern: "^_",
153+
ignoreRestSiblings: true
154+
}
102155
],
103156
"no-inner-declarations": "error",
104-
"no-loop-func": "off",
105157
"prefer-const": [
106158
"error",
107159
{
@@ -113,47 +165,110 @@ module.exports = [
113165
"no-else-return": "error",
114166
"no-lonely-if": "error",
115167
"no-undef-init": "error",
116-
"n/no-missing-require": ["error", { allowModules: ["webpack"] }],
117-
"n/no-unsupported-features/node-builtins": [
168+
// Disallow @ts-ignore directive. Use @ts-expect-error instead
169+
"no-warning-comments": [
170+
"error",
171+
{ terms: ["@ts-ignore"], location: "start" }
172+
],
173+
"no-constructor-return": "error",
174+
"symbol-description": "error",
175+
"array-callback-return": [
118176
"error",
119177
{
120-
ignores: ["zlib.createBrotliCompress", "zlib.createBrotliDecompress"]
178+
allowImplicit: true
121179
}
122180
],
123-
"n/exports-style": "error",
124-
// Disallow @ts-ignore directive. Use @ts-expect-error instead
125-
"no-warning-comments": [
181+
"no-promise-executor-return": "error",
182+
"no-undef": "error",
183+
"guard-for-in": "error",
184+
"no-constant-condition": "error",
185+
camelcase: [
126186
"error",
127-
{ terms: ["@ts-ignore"], location: "start" }
128-
]
129-
},
130-
settings: {
131-
jsdoc: {
132-
mode: "typescript",
133-
// supported tags https://github.com/microsoft/TypeScript-wiki/blob/master/JSDoc-support-in-JavaScript.md
134-
tagNamePreference: {
135-
...["implements", "const", "memberof", "yields"].reduce(
136-
(acc, tag) => {
137-
acc[tag] = {
138-
message: `@${tag} currently not supported in TypeScript`
139-
};
140-
return acc;
141-
},
142-
{}
143-
),
144-
extends: "extends",
145-
return: "returns",
146-
constructor: "constructor",
147-
prop: "property",
148-
arg: "param",
149-
augments: "extends",
150-
description: false,
151-
desc: false,
152-
inheritdoc: false,
153-
class: "constructor"
154-
},
155-
overrideReplacesDocs: false
156-
}
187+
{
188+
allow: [
189+
"__webpack_require__",
190+
"__webpack_public_path__",
191+
"__webpack_base_uri__",
192+
"__webpack_modules__",
193+
"__webpack_chunk_load__",
194+
"__non_webpack_require__",
195+
"__webpack_nonce__",
196+
"__webpack_hash__",
197+
"__webpack_chunkname__",
198+
"__webpack_get_script_filename__",
199+
"__webpack_runtime_id__",
200+
"__system_context__",
201+
"__webpack_share_scopes__",
202+
"__webpack_init_sharing__",
203+
"__webpack_require_module__",
204+
"_stream_duplex",
205+
"_stream_passthrough",
206+
"_stream_readable",
207+
"_stream_transform",
208+
"_stream_writable",
209+
"string_decoder"
210+
]
211+
}
212+
],
213+
"prefer-exponentiation-operator": "error",
214+
"no-useless-return": "error",
215+
"no-return-assign": "error",
216+
"default-case-last": "error",
217+
"default-param-last": "error",
218+
"dot-notation": "error",
219+
"grouped-accessor-pairs": "error",
220+
"id-match": [
221+
"error",
222+
"^[$a-zA-Z_][$a-zA-Z0-9_]*$",
223+
{
224+
properties: true
225+
}
226+
],
227+
"no-extra-label": "error",
228+
"no-label-var": "error",
229+
"no-lone-blocks": "error",
230+
"no-multi-str": "error",
231+
"no-new-func": "error",
232+
"no-unneeded-ternary": ["error", { defaultAssignment: false }],
233+
"no-useless-call": "error",
234+
"no-useless-concat": "error",
235+
"prefer-object-spread": "error",
236+
"prefer-regex-literals": "error",
237+
"prefer-rest-params": "error",
238+
239+
// TODO Enable
240+
"no-sequences": "off",
241+
"prefer-spread": "off",
242+
"default-case": "off",
243+
"new-cap": [
244+
"off",
245+
{
246+
newIsCap: true,
247+
newIsCapExceptions: [],
248+
capIsNew: true,
249+
capIsNewExceptions: [],
250+
properties: true
251+
}
252+
],
253+
"no-loop-func": "off",
254+
"no-implicit-coercion": "off",
255+
"arrow-body-style": "off",
256+
"no-shadow": "off",
257+
"prefer-template": "off",
258+
"prefer-destructuring": "off",
259+
"func-style": "off",
260+
"no-plusplus": "off",
261+
"no-param-reassign": "off",
262+
"no-var": "off",
263+
"one-var": "off",
264+
"vars-on-top": "off",
265+
"no-unreachable-loop": "off",
266+
"no-unmodified-loop-condition": "off",
267+
"@stylistic/lines-between-class-members": "off",
268+
"@stylistic/quotes": "off",
269+
"@stylistic/spaced-comment": "off",
270+
// TODO Disable everywhere?
271+
"no-useless-constructor": "off"
157272
}
158273
},
159274
{
@@ -225,19 +340,14 @@ module.exports = [
225340
allowExperimental: true
226341
}
227342
],
228-
"object-shorthand": "off"
343+
"object-shorthand": "off",
344+
camelcase: "off"
229345
}
230346
},
231347
{
232348
files: ["examples/**/*.js"],
233349
rules: {
234350
"n/no-missing-require": "off"
235351
}
236-
},
237-
{
238-
files: ["lib/util/semver.js"],
239-
rules: {
240-
"n/exports-style": "off"
241-
}
242352
}
243353
];

lib/CacheFacade.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class MultiItemCache {
3838
*/
3939
constructor(items) {
4040
this._items = items;
41+
// eslint-disable-next-line no-constructor-return
4142
if (items.length === 1) return /** @type {any} */ (items[0]);
4243
}
4344

lib/Compilation.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
11251125
// properties in the prototype chain
11261126
/** @type {Partial<NormalizedStatsOptions>} */
11271127
const options = {};
1128+
// eslint-disable-next-line guard-for-in
11281129
for (const key in optionsOrPreset) {
11291130
options[key] = optionsOrPreset[key];
11301131
}
@@ -2056,11 +2057,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
20562057
...contextInfo
20572058
},
20582059
resolveOptions: originModule ? originModule.resolveOptions : undefined,
2059-
context: context
2060-
? context
2061-
: originModule
2062-
? originModule.context
2063-
: this.compiler.context,
2060+
context:
2061+
context ||
2062+
(originModule ? originModule.context : this.compiler.context),
20642063
dependencies
20652064
},
20662065
(err, result) => {
@@ -4411,7 +4410,7 @@ This prevents using hashes of each other and should be avoided.`);
44114410
return;
44124411
}
44134412
const oldInfo = this.assetsInfo.get(file);
4414-
const newInfo = Object.assign({}, oldInfo, assetInfo);
4413+
const newInfo = { ...oldInfo, ...assetInfo };
44154414
this._setAssetInfo(file, newInfo, oldInfo);
44164415
return;
44174416
}

lib/ConditionalInitFragment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ConditionalInitFragment extends InitFragment {
5353
position,
5454
key,
5555
runtimeCondition = true,
56-
endContent
56+
endContent = undefined
5757
) {
5858
super(content, stage, position, key, endContent);
5959
this.runtimeCondition = runtimeCondition;

lib/ContextModule.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ class ContextModule extends Module {
565565
} else if (typeof this.options.resource === "string") {
566566
contextDependencies.add(this.options.resource);
567567
} else if (this.options.resource === false) {
568-
return;
568+
// Do nothing
569569
} else {
570570
for (const res of this.options.resource) contextDependencies.add(res);
571571
}

lib/ExportsInfo.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -877,21 +877,21 @@ class ExportInfo {
877877
}
878878

879879
// TODO webpack 5 remove
880-
/** @private */
881-
get used() {
882-
throw new Error("REMOVED");
883-
}
884-
/** @private */
885-
get usedName() {
886-
throw new Error("REMOVED");
887-
}
888880
/**
889881
* @private
890882
* @param {*} v v
891883
*/
892884
set used(v) {
893885
throw new Error("REMOVED");
894886
}
887+
888+
// TODO webpack 5 remove
889+
/** @private */
890+
get used() {
891+
throw new Error("REMOVED");
892+
}
893+
894+
// TODO webpack 5 remove
895895
/**
896896
* @private
897897
* @param {*} v v
@@ -900,6 +900,12 @@ class ExportInfo {
900900
throw new Error("REMOVED");
901901
}
902902

903+
// TODO webpack 5 remove
904+
/** @private */
905+
get usedName() {
906+
throw new Error("REMOVED");
907+
}
908+
903909
get canMangle() {
904910
switch (this.canMangleProvide) {
905911
case undefined:
@@ -1473,6 +1479,7 @@ class ExportInfo {
14731479
if (list !== undefined) list.push(runtime);
14741480
else map.set(used, [runtime]);
14751481
}
1482+
// eslint-disable-next-line array-callback-return
14761483
const specificInfo = Array.from(map, ([used, runtimes]) => {
14771484
switch (used) {
14781485
case UsageState.NoInfo:

lib/ExternalModuleFactoryPlugin.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const EMPTY_RESOLVE_OPTIONS = {};
2525
// TODO webpack 6 remove this
2626
const callDeprecatedExternals = util.deprecate(
2727
(externalsFunction, context, request, cb) => {
28+
// eslint-disable-next-line no-useless-call
2829
externalsFunction.call(null, context, request, cb);
2930
},
3031
"The externals-function should be defined like ({context, request}, cb) => { ... }",

0 commit comments

Comments
 (0)