Skip to content

Commit

Permalink
chore: remove unused vars & prefer const & remove default generic value
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowingFox committed Sep 1, 2023
1 parent fb2de95 commit 1005ec6
Show file tree
Hide file tree
Showing 27 changed files with 77 additions and 104 deletions.
4 changes: 1 addition & 3 deletions crates/node_binding/tests/binding.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import assert from 'assert'
import path from 'path'
import log from 'why-is-node-running'
import binding from '..'
import { RawOptions } from '../binding.d'
import { RawOptions } from '../binding'

describe('binding', () => {
it('work', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/cases/hooks/asset-emitted/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test("asset emitted hook should only emit modified assets", async ({
fileAction,
rspack
}) => {
let assets: string[] = [];
const assets: string[] = [];
rspack.compiler.hooks.assetEmitted.tap("test", function (name) {
if (name.includes(".hot-update.")) {
return;
Expand Down Expand Up @@ -55,7 +55,7 @@ test("asset emitted should not emit removed assets", async ({
rspack,
fileAction
}) => {
let assets: string[] = [];
const assets: string[] = [];
rspack.compiler.hooks.assetEmitted.tap("test", function (name) {
if (name.includes(".hot-update.")) {
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class BuildCommand implements RspackCommand {
}
};

let rspackOptions = { ...options, argv: { ...options } };
const rspackOptions = { ...options, argv: { ...options } };

const errorHandler = (err, Stats) => {
callback(err, Stats);
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-cli/src/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class PreviewCommand implements RspackCommand {

const devServerOptions = config.devServer as DevServer;

let compiler = rspack({ entry: {} });
const compiler = rspack({ entry: {} });
if (!compiler) return;
try {
const server = new RspackDevServer(devServerOptions, compiler);
Expand Down
6 changes: 3 additions & 3 deletions packages/rspack-cli/src/rspack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { PreviewCommand } from "./commands/preview";
import {
RspackOptions,
MultiCompiler,
Compiler,
rspack,
MultiRspackOptions,
Stats,
MultiStats
MultiStats,
Compiler
} from "@rspack/core";
import { normalizeEnv } from "./utils/options";
import { loadRspackConfig } from "./utils/loadConfig";
Expand All @@ -31,7 +31,7 @@ type Command = "serve" | "build";
const defaultEntry = "src/index";
export class RspackCLI {
colors: RspackCLIColors;
program: yargs.Argv<{}>;
program: yargs.Argv;
constructor() {
this.colors = this.createColors();
this.program = yargs();
Expand Down
1 change: 0 additions & 1 deletion packages/rspack-cli/src/utils/loadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { RspackOptions, MultiRspackOptions } from "@rspack/core";
import findConfig from "./findConfig";
import rechoir from "rechoir";
import interpret from "interpret";
import { pathToFileURL } from "url";
import isEsmFile from "./isEsmFile";
import isTsFile from "./isTsFile";
import crossImport from "./crossImport";
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-cli/src/utils/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import yargs from "yargs";
export const commonOptions = (yargs: yargs.Argv<{}>) => {
export const commonOptions = (yargs: yargs.Argv) => {
return yargs.options({
config: {
g: true,
Expand Down Expand Up @@ -40,7 +40,7 @@ export const commonOptions = (yargs: yargs.Argv<{}>) => {
});
};

export const previewOptions = (yargs: yargs.Argv<{}>) => {
export const previewOptions = (yargs: yargs.Argv) => {
return yargs
.positional("dir", {
type: "string",
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-cli/src/utils/readPackageUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const readPackageUp = (cwd = process.cwd()): { type?: "module" } | null => {
let packageJsonPath = path.join(currentDir, "package.json");

while (!fs.existsSync(packageJsonPath)) {
let parentDir = path.dirname(currentDir);
const parentDir = path.dirname(currentDir);
if (parentDir === currentDir) {
return null;
}
Expand Down
15 changes: 5 additions & 10 deletions packages/rspack-cli/tests/build/config/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { run } from "../../utils/test-utils";
import { writeFileSync, mkdirSync, unlinkSync } from "fs";
import { rm, readFile } from "fs/promises";
import { join, resolve } from "path";
import { readFile } from "fs/promises";
import { resolve } from "path";

describe("rspack cli", () => {
describe("should config not found", () => {
Expand Down Expand Up @@ -129,13 +128,9 @@ describe("rspack cli", () => {
describe("should load moonrepo config", () => {
const cwd = resolve(__dirname, "./moonrepo");
it("should load moonrepo config.ts file", async () => {
const { exitCode, stderr, stdout } = await run(
cwd,
["-c", "rspack.config.ts"],
{
nodeOptions: ["--experimental-loader=ts-node/esm"]
}
);
const { exitCode, stdout } = await run(cwd, ["-c", "rspack.config.ts"], {
nodeOptions: ["--experimental-loader=ts-node/esm"]
});
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-cli/tests/serve/basic/serve-basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { normalizeStderr, runWatch } from "../../utils/test-utils";

describe("basic serve usage", () => {
it.skip("should work", async () => {
const { stderr, stdout } = await runWatch(__dirname, ["serve"]);
const { stderr } = await runWatch(__dirname, ["serve"]);

// @todo current server implementation is too buggy to test
expect(normalizeStderr(stderr)).toBeTruthy;
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-dev-server/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function getRspackMemoryAssets(
const filename = path.startsWith(publicPath)
? path.slice(publicPath.length)
: path.slice(1);
let buffer =
const buffer =
compiler.getAsset(filename) ??
(() => {
const { index } = rdm.context.options;
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-dev-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export class RspackDevServer extends WebpackDevServer {
compilers.forEach(compiler => {
if (compiler.options.experiments.lazyCompilation) {
middlewares.push({
middleware: (req, res, next) => {
middleware: (req, res) => {
if (req.url.indexOf("/lazy-compilation-web/") > -1) {
const path = req.url.replace("/lazy-compilation-web/", "");
if (fs.existsSync(path)) {
Expand Down
26 changes: 13 additions & 13 deletions packages/rspack/src/Compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class Compilation {
this.name = undefined;
this.startTime = undefined;
this.endTime = undefined;
let processAssetsHooks = createFakeProcessAssetsHook(this);
const processAssetsHooks = createFakeProcessAssetsHook(this);
this.hooks = {
processAssets: processAssetsHooks,
// TODO: webpack 6 deprecate, keep it just for compatibility
Expand Down Expand Up @@ -178,7 +178,7 @@ export class Compilation {
return this.__internal__getAssetSource(property);
}
},
set: (target, p, newValue, receiver) => {
set: (target, p, newValue) => {
if (typeof p === "string") {
this.__internal__setAssetSource(p, newValue);
return true;
Expand Down Expand Up @@ -437,12 +437,12 @@ export class Compilation {
}

get errors() {
let inner = this.#inner;
const inner = this.#inner;
return {
push: (...errs: (Error | JsStatsError)[]) => {
// compatible for javascript array
for (let i = 0; i < errs.length; i++) {
let error = errs[i];
const error = errs[i];
this.#inner.pushDiagnostic(
"error",
isJsStatsError(error) ? error.title : error.name,
Expand All @@ -452,7 +452,7 @@ export class Compilation {
},
[Symbol.iterator]() {
// TODO: this is obviously a bad design, optimize this after finishing angular prototype
let errors = inner.getStats().getErrors();
const errors = inner.getStats().getErrors();
let index = 0;
return {
next() {
Expand All @@ -470,14 +470,14 @@ export class Compilation {
}

get warnings() {
let inner = this.#inner;
const inner = this.#inner;
return {
// compatible for javascript array
push: (...warns: (Error | JsStatsError)[]) => {
// TODO: find a way to make JsStatsError be actual errors
warns = this.hooks.processWarnings.call(warns as any);
for (let i = 0; i < warns.length; i++) {
let warn = warns[i];
const warn = warns[i];
this.#inner.pushDiagnostic(
"warning",
isJsStatsError(warn) ? warn.title : warn.name,
Expand All @@ -487,7 +487,7 @@ export class Compilation {
},
[Symbol.iterator]() {
// TODO: this is obviously a bad design, optimize this after finishing angular prototype
let warnings = inner.getStats().getWarnings();
const warnings = inner.getStats().getWarnings();
let index = 0;
return {
next() {
Expand Down Expand Up @@ -656,7 +656,7 @@ export class Compilation {

// FIXME: This is not aligned with Webpack.
get chunks() {
var stats = this.getStats().toJson({
const stats = this.getStats().toJson({
all: false,
chunks: true,
chunkModules: true,
Expand All @@ -683,13 +683,13 @@ export class Compilation {
* @internal
*/
__internal__getAssociatedModules(chunk: JsStatsChunk): any[] | undefined {
let modules = this.__internal__getModules();
let moduleMap: Map<string, JsModule> = new Map();
for (let module of modules) {
const modules = this.__internal__getModules();
const moduleMap: Map<string, JsModule> = new Map();
for (const module of modules) {
moduleMap.set(module.moduleIdentifier, module);
}
return chunk.modules?.flatMap(chunkModule => {
let jsModule = this.__internal__findJsModule(
const jsModule = this.__internal__findJsModule(
chunkModule.issuer ?? chunkModule.identifier,
moduleMap
);
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Stats } from "./Stats";
import { Compilation, CompilationParams } from "./Compilation";
import { ContextModuleFactory } from "./ContextModuleFactory";
import ResolverFactory from "./ResolverFactory";
import { getRawOptions } from "./config/adapter";
import { getRawOptions } from "./config";
import { LoaderContext, LoaderResult } from "./config/adapterRuleUse";
import ConcurrentCompilationError from "./error/ConcurrentCompilationError";
import { createThreadsafeNodeFSFromRaw } from "./fileSystem";
Expand Down
16 changes: 4 additions & 12 deletions packages/rspack/src/MultiCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,23 @@
* https://github.com/webpack/webpack/blob/main/LICENSE
*/

import {
Compilation,
Compiler,
RspackOptions,
RspackOptionsNormalized,
Stats
} from ".";
import { Compiler, RspackOptions, Stats } from ".";
import ResolverFactory from "./ResolverFactory";
import { WatchFileSystem } from "./util/fs";
import Watching from "./Watching";
import tapable, {
import {
AsyncSeriesHook,
Callback,
MultiHook,
SyncHook
SyncHook,
SyncBailHook
} from "tapable";
import MultiStats from "./MultiStats";
import asyncLib from "neo-async";
import ArrayQueue from "./util/ArrayQueue";
import ConcurrentCompilationError from "./error/ConcurrentCompilationError";
import MultiWatching from "./MultiWatching";
import { WatchOptions } from "./config";
import { IFs } from "memfs";
import assert from "assert";
import { isNil } from "./util";

type Any = any;

Expand Down
1 change: 0 additions & 1 deletion packages/rspack/src/MultiStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

import { KnownCreateStatsOptionsContext } from ".";
import { SnapshotOptions } from "./config";
import { StatsCompilation } from "./stats/statsFactoryUtils";
import { Stats } from "./Stats";
import { indent } from "./util";
Expand Down
5 changes: 2 additions & 3 deletions packages/rspack/src/builtin-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
RawBuiltins,
RawCssModulesConfig
} from "@rspack/binding";
import { termlink, deprecatedWarn } from "../util";
import { deprecatedWarn } from "../util";
import { Compiler, RspackOptionsNormalized } from "..";
import {
HtmlPluginOptions,
Expand All @@ -35,8 +35,7 @@ import {
CopyPlugin,
BannerPlugin,
SwcJsMinimizerPlugin,
SwcCssMinimizerPlugin,
RspackBuiltinPlugin
SwcCssMinimizerPlugin
} from ".";
import { loadConfig } from "browserslist";
import path from "path";
Expand Down
2 changes: 0 additions & 2 deletions packages/rspack/src/config/adapterRuleUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
RawModuleRuleUse,
RawOptions
} from "@rspack/binding";
import assert from "assert";
import { ResolveRequest } from "enhanced-resolve";

import { Compiler } from "../Compiler";
Expand All @@ -13,7 +12,6 @@ import Hash from "../util/hash";
import {
Mode,
Resolve,
RuleSetUse,
RuleSetUseItem,
RuleSetLoaderWithOptions
} from "./types";
Expand Down
5 changes: 1 addition & 4 deletions packages/rspack/src/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import fs from "fs";
import path from "path";
import { isNil } from "../util";
import { cleverMerge } from "../util/cleverMerge";
import { deprecated_resolveBuiltins } from "../builtin-plugin";
import {
getDefaultTarget,
getTargetProperties,
Expand All @@ -22,8 +21,6 @@ import {
import type {
AvailableTarget,
Context,
Entry,
EntryDescription,
EntryDescriptionNormalized,
EntryNormalized,
ExperimentsNormalized,
Expand Down Expand Up @@ -653,7 +650,7 @@ const applyNodeDefaults = (

const applyOptimizationDefaults = (
optimization: Optimization,
{ production, development }: { production: boolean; development: boolean }
{ production }: { production: boolean; development: boolean }
) => {
D(optimization, "removeAvailableModules", true);
D(optimization, "removeEmptyChunks", true);
Expand Down
1 change: 0 additions & 1 deletion packages/rspack/src/config/normalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
EntryStatic,
EntryStaticNormalized,
LibraryOptions,
OptimizationRuntimeChunk,
OptimizationRuntimeChunkNormalized,
RspackOptions,
RspackOptionsNormalized
Expand Down
1 change: 0 additions & 1 deletion packages/rspack/src/config/zod/optimization/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { z } from "zod";
import { Compiler } from "../../../Compiler";
import { splitChunks } from "./split-chunks";

const rspackPluginInstance = z.any();
Expand Down
Loading

0 comments on commit 1005ec6

Please sign in to comment.