Skip to content

Commit 9a770a6

Browse files
Joshua Kaminetskyjkaminetsky
andauthored
fix(lint): lint (#95)
Co-authored-by: kami <[email protected]>
1 parent 1316d7e commit 9a770a6

File tree

4 files changed

+51
-42
lines changed

4 files changed

+51
-42
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"import/no-extraneous-dependencies": "off",
2323
"no-nested-ternary": "off",
2424
"prefer-destructuring": "warn",
25-
"consistent-return": "warn",
25+
"consistent-return": "off",
2626
"eqeqeq": "warn",
2727
"no-new-func": "warn",
2828
"no-underscore-dangle": "off",

src/webpack/index.js

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ class URLImportPlugin {
6969
}
7070

7171
getFileType(str) {
72-
str = str.replace(/\?.*/, "");
73-
const split = str.split(".");
72+
const split = str.replace(/\?.*/, "").Errorsplit(".");
7473
let ext = split.pop();
7574
if (this.opts.transformExtensions.test(ext)) {
7675
ext = `${split.pop()}.${ext}`;
@@ -197,15 +196,15 @@ class URLImportPlugin {
197196
}
198197

199198
let files = compilation.chunks.reduce(
200-
(files, chunk) =>
201-
chunk.files.reduce((files, path) => {
199+
(f, chunk) =>
200+
chunk.files.reduce((fx, filePath) => {
202201
let name = chunk.name ? chunk.name : null;
203202
const dependencyChains = {};
204203
if (name) {
205-
name = `${name}.${this.getFileType(path)}`;
204+
name = `${name}.${this.getFileType(filePath)}`;
206205
} else {
207206
// For nameless chunks, just map the files directly.
208-
name = path;
207+
name = filePath;
209208
}
210209

211210
if (externalModules[chunk.id] || externalModules[chunk.name]) {
@@ -257,7 +256,7 @@ class URLImportPlugin {
257256
});
258257

259258
// eslint-disable-next-line no-restricted-syntax
260-
for (const module of dependencyModuleSet.chunksIterable) {
259+
for (const dependencyModule of dependencyModuleSet.chunksIterable) {
261260
if (this.opts.debug) {
262261
console.groupCollapsed(
263262
"Dependency Reference Iterable",
@@ -266,14 +265,14 @@ class URLImportPlugin {
266265
console.groupEnd();
267266
}
268267

269-
if (module && module.files) {
268+
if (dependencyModule && dependencyModule.files) {
270269
if (dependencyChains[chunk.id]) {
271270
dependencyChainMap.sourceFiles =
272271
dependencyChainMap?.sourceFiles?.concat?.(
273-
module.files
272+
dependencyModule.files
274273
) || null;
275274
} else {
276-
// Object.assign(dependencyChains, { [chunk.id]: module.files });
275+
// Object.assign(dependencyChains, { [chunk.id]: dependencyModule.files });
277276
}
278277
}
279278
}
@@ -312,8 +311,8 @@ class URLImportPlugin {
312311
// getMeta(modules[i]);
313312
// i++;
314313
// }
315-
return files.concat({
316-
path,
314+
return fx.concat({
315+
filePath,
317316
chunk,
318317
name,
319318
dependencies: dependencyChains?.[chunk.id]
@@ -334,10 +333,10 @@ class URLImportPlugin {
334333

335334
// module assets don't show up in assetsByChunkName.
336335
// we're getting them this way;
337-
files = stats.assets.reduce((files, asset) => {
336+
files = stats.assets.reduce((fx, asset) => {
338337
const name = moduleAssets[asset.name];
339338
if (name) {
340-
return files.concat({
339+
return fx.concat({
341340
path: asset.name,
342341
name,
343342
isInitial: false,
@@ -349,10 +348,10 @@ class URLImportPlugin {
349348

350349
const isEntryAsset = asset.chunks.length > 0;
351350
if (isEntryAsset) {
352-
return files;
351+
return fx;
353352
}
354353

355-
return files.concat({
354+
return fx.concat({
356355
path: asset.name,
357356
name: asset.name,
358357
isInitial: false,
@@ -379,27 +378,27 @@ class URLImportPlugin {
379378
// Append optional basepath onto all references.
380379
// This allows output path to be reflected in the manifest.
381380
if (this.opts.basePath) {
382-
files = files.map(file => {
383-
file.name = this.opts.basePath + file.name;
384-
return file;
385-
});
381+
files = files.map(file => ({
382+
...file,
383+
name: this.opts.basePath + file.name
384+
}));
386385
}
387386

388387
if (publicPath) {
389388
// Similar to basePath but only affects the value (similar to how
390389
// output.publicPath turns require('foo/bar') into '/public/foo/bar', see
391390
// https://github.com/webpack/docs/wiki/configuration#outputpublicpath
392-
files = files.map(file => {
393-
file.path = publicPath + file.path;
394-
return file;
395-
});
391+
files = files.map(file => ({
392+
...file,
393+
path: publicPath + file.path
394+
}));
396395
}
397396

398-
files = files.map(file => {
399-
file.name = file.name.replace(/\\/g, "/");
400-
file.path = file.path.replace(/\\/g, "/");
401-
return file;
402-
});
397+
files = files.map(file => ({
398+
...file,
399+
name: file.name.replace(/\\/g, "/"),
400+
path: file.path.replace(/\\/g, "/")
401+
}));
403402

404403
if (this.opts.filter) {
405404
files = files.filter(this.opts.filter);
@@ -422,14 +421,17 @@ class URLImportPlugin {
422421
if (this.opts.generate) {
423422
manifest = this.opts.generate(seed, files);
424423
} else {
425-
manifest = files.reduce((manifest, file) => {
426-
manifest[file.name] = {
427-
path: file.path,
428-
dependencies: file?.dependencies || null,
429-
isInitial: file?.isInitial || null
430-
};
431-
return manifest;
432-
}, seed);
424+
manifest = files.reduce(
425+
(m, file) => ({
426+
...m,
427+
[file.name]: {
428+
path: file.path,
429+
dependencies: file?.dependencies || null,
430+
isInitial: file?.isInitial || null
431+
}
432+
}),
433+
seed
434+
);
433435
}
434436
if (this.opts.debug) {
435437
console.log("Manifest:", manifest);
@@ -451,6 +453,8 @@ class URLImportPlugin {
451453
if (this.opts.debug) {
452454
console.log("Output:", output);
453455
}
456+
457+
// eslint-disable-next-line no-param-reassign
454458
compilation.assets[outputName] = {
455459
source() {
456460
return output;
@@ -476,7 +480,7 @@ class URLImportPlugin {
476480
}
477481
};
478482

479-
function beforeRun(compiler, callback) {
483+
function beforeRun(comp, callback) {
480484
const emitCount = emitCountMap.get(outputFile) || 0;
481485
emitCountMap.set(outputFile, emitCount + 1);
482486

@@ -491,6 +495,8 @@ class URLImportPlugin {
491495
name: "URLImportPlugin",
492496
stage: Infinity
493497
};
498+
499+
// eslint-disable-next-line no-param-reassign
494500
compiler.hooks.webpackURLImportPluginAfterEmit = new SyncWaterfallHook([
495501
"manifest"
496502
]);
@@ -554,7 +560,7 @@ class URLImportPlugin {
554560

555561
let resourcePath = module.resource;
556562
if (resourcePath.indexOf("?") > -1) {
557-
resourcePath = resourcePath.split("?")[0];
563+
[resourcePath] = resourcePath.split("?");
558564
}
559565

560566
try {

src/webpack/optimizeChunk.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function wrapFile(compilation, fileName, allModulesNeeded, chunkKeys) {
1313
]);
1414

1515
// add chunk registration code that will push all chunk requirements into webpack
16+
// eslint-disable-next-line no-param-reassign
1617
compilation.assets[fileName] = new ConcatSource(
1718
String(
1819
`(window["webpackRegister"] = window["webpackRegister"] || []).push(${pushArguments});\n`

src/webpack/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-param-reassign */
12
export function mergeDeep(...objects) {
23
const isObject = obj => obj && typeof obj === "object";
34

@@ -18,6 +19,7 @@ export function mergeDeep(...objects) {
1819
return prev;
1920
}, {});
2021
}
22+
/* eslint-enable no-param-reassign */
2123

2224
// TODO: delete this function in V2
2325
export function removeNull() {
@@ -33,15 +35,15 @@ export function removeNull() {
3335
return this;
3436
}
3537
// all items are null
36-
if (nullCount == length) {
38+
if (nullCount === length) {
3739
this.length = 0;
3840
return this;
3941
}
4042
// mix of null // non-null
4143
let idest = 0;
4244
let isrc = length - 1;
4345
length -= nullCount;
44-
while (true) {
46+
while (nullCount) {
4547
while (!this[isrc]) {
4648
isrc--;
4749
nullCount--;

0 commit comments

Comments
 (0)