Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Jul 25, 2024
1 parent 6fd6b97 commit 81415c9
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 107 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"files": ["**/*.ts", "**/*.tsx"],
// Linting with type-checked rules is very slow and needs a lot of memory,
// so we exclude non-essential files.
"excludedFiles": ["examples/**/*", "test/**/*", "**/*.d.ts"],
"excludedFiles": [
"examples/**/*",
"test/**/*",
"**/*.d.ts",
"turbopack/**/*"
],
"parserOptions": {
"project": true
},
Expand Down
9 changes: 7 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"commonjs": true,
"es6": true,
"node": true,
"jest": true
"jest": true,
"es2020": true
},
"parserOptions": {
"requireConfigFile": false,
Expand Down Expand Up @@ -101,7 +102,11 @@
"error",
{
"args": "none",
"ignoreRestSiblings": true
"ignoreRestSiblings": true,
"argsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_",
"varsIgnorePattern": "^_"
}
],
"no-use-before-define": "off",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ struct NodeGuard {
impl NodeGuard {
unsafe fn new(guard: MutexGuard<'_, NodeInner>, node: Arc<Node>) -> Self {
NodeGuard {
guard: unsafe { std::mem::transmute(guard) },
// #[allow(clippy::missing_transmute_annotations, reason = "this is a test")]
guard: unsafe {
std::mem::transmute::<MutexGuard<'_, NodeInner>, MutexGuard<'_, NodeInner>>(guard)
},
node,
}
}
Expand Down
10 changes: 5 additions & 5 deletions turbopack/crates/turbo-tasks-memory/src/aggregation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ fn find_root(mut node: NodeRef) -> NodeRef {
}
}

fn check_invariants<'a>(
ctx: &NodeAggregationContext<'a>,
node_ids: impl IntoIterator<Item = NodeRef>,
) {
fn check_invariants(ctx: &NodeAggregationContext<'_>, node_ids: impl IntoIterator<Item = NodeRef>) {
let mut queue = node_ids.into_iter().collect::<Vec<_>>();
// print(ctx, &queue[0], true);
#[allow(clippy::mutable_key_type, reason = "this is a test")]
let mut visited = HashSet::new();
while let Some(node_id) = queue.pop() {
assert_eq!(node_id.0.atomic.load(Ordering::SeqCst), 0);
Expand Down Expand Up @@ -428,7 +426,9 @@ struct NodeGuard {
impl NodeGuard {
unsafe fn new(guard: MutexGuard<'_, NodeInner>, node: Arc<Node>) -> Self {
NodeGuard {
guard: unsafe { std::mem::transmute(guard) },
guard: unsafe {
std::mem::transmute::<MutexGuard<'_, NodeInner>, MutexGuard<'_, NodeInner>>(guard)
},
node,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* This interface will be implemented by runtime backends.
*/

/* eslint-disable @typescript-eslint/no-unused-vars */

/// <reference path="../../../../shared/require-type.d.ts" />

declare var BACKEND: RuntimeBackend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* shared runtime utils.
*/

/* eslint-disable @next/next/no-assign-module-variable */
/* eslint-disable @typescript-eslint/no-unused-vars */

/// <reference path="../../../../shared/runtime-utils.ts" />
/// <reference path="./globals.d.ts" />
Expand Down Expand Up @@ -197,7 +197,7 @@ async function loadChunk(
if (moduleChunksPromises.length > 0) {
// Some module chunks are already loaded or loading.

if (moduleChunksPromises.length == includedModuleChunksList.length) {
if (moduleChunksPromises.length === includedModuleChunksList.length) {
// When all included module chunks are already loaded or loading, we can skip loading ourselves
return Promise.all(moduleChunksPromises);
}
Expand Down Expand Up @@ -258,6 +258,8 @@ async function loadChunkPath(
case SourceType.Update:
loadReason = "from an HMR update";
break;
default:
invariant(source, (source) => `Unknown source type: ${source?.type}`);
}
throw new Error(
`Failed to load chunk ${chunkPath} ${loadReason}${
Expand Down Expand Up @@ -301,6 +303,8 @@ function instantiateModule(id: ModuleId, source: SourceInfo): Module {
case SourceType.Update:
instantiationReason = "because of an HMR update";
break;
default:
invariant(source, (source) => `Unknown source type: ${source?.type}`);
}
throw new Error(
`Module ${id} was instantiated ${instantiationReason}, but the module factory is not available. It might have been deleted in an HMR update.`
Expand All @@ -324,7 +328,10 @@ function instantiateModule(id: ModuleId, source: SourceInfo): Module {
case SourceType.Update:
parents = source.parents || [];
break;
default:
invariant(source, (source) => `Unknown source type: ${source?.type}`);
}

const module: Module = {
exports: {},
error: undefined,
Expand Down Expand Up @@ -571,6 +578,8 @@ function computedInvalidatedModules(
}
break;
// TODO(alexkirsz) Dependencies: handle dependencies effects.
default:
invariant(effect, (effect) => `Unknown effect type: ${effect?.type}`);
}
}

Expand Down Expand Up @@ -752,13 +761,6 @@ function applyPhase(
}
}

/**
* Utility function to ensure all variants of an enum are handled.
*/
function invariant(never: never, computeMessage: (arg: any) => string): never {
throw new Error(`Invariant: ${computeMessage(never)}`);
}

function applyUpdate(update: PartialUpdate) {
switch (update.type) {
case "ChunkListUpdate":
Expand Down Expand Up @@ -800,6 +802,7 @@ function applyChunkListUpdate(update: ChunkListUpdate) {
(instruction) =>
`Unknown partial instruction: ${JSON.stringify(instruction)}.`
);
break;
default:
invariant(
chunkUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* It will be appended to the base development runtime code.
*/

/* eslint-disable @typescript-eslint/no-unused-vars */

/// <reference path="../base/runtime-base.ts" />
/// <reference path="../../../../shared/require-type.d.ts" />

Expand Down Expand Up @@ -124,7 +126,7 @@ async function loadWebAssemblyModule(
`link[rel=stylesheet][href="${chunkUrl}"],link[rel=stylesheet][href^="${chunkUrl}?"],link[rel=stylesheet][href="${decodedChunkUrl}"],link[rel=stylesheet][href^="${decodedChunkUrl}?"]`
);

if (previousLinks.length == 0) {
if (previousLinks.length === 0) {
reject(new Error(`No link element found for chunk ${chunkPath}`));
return;
}
Expand Down Expand Up @@ -299,5 +301,6 @@ function _eval({ code, url, map }: EcmascriptModuleEntry): ModuleFactory {
)}`;
}

// eslint-disable-next-line no-eval
return eval(code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* It will be appended to the base development runtime code.
*/

/* eslint-disable @typescript-eslint/no-unused-vars */

/// <reference path="../base/runtime-base.ts" />
/// <reference path="../../../../shared-node/base-externals-utils.ts" />
/// <reference path="../../../../shared/require-type.d.ts" />
Expand Down Expand Up @@ -50,7 +52,7 @@ function getFileStem(path: string): string {

const stem = fileName.split(".").shift()!;

if (stem == "") {
if (stem === "") {
return fileName;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

/// <reference path="../shared/runtime-utils.ts" />
/// <reference path="../shared-node/base-externals-utils.ts" />
/// <reference path="../shared-node/node-externals-utils.ts" />
Expand Down Expand Up @@ -31,6 +33,8 @@ function stringifySourceInfo(source: SourceInfo): string {
return `runtime for chunk ${source.chunkPath}`;
case SourceType.Parent:
return `parent module ${source.parentId}`;
default:
invariant(source, (source) => `Unknown source type: ${source?.type}`);
}
}

Expand Down Expand Up @@ -187,6 +191,8 @@ function instantiateModule(id: ModuleId, source: SourceInfo): Module {
case SourceType.Parent:
instantiationReason = `because it was required from module ${source.parentId}`;
break;
default:
invariant(source, (source) => `Unknown source type: ${source?.type}`);
}
throw new Error(
`Module ${id} was instantiated ${instantiationReason}, but the module factory is not available. It might have been deleted in an HMR update.`
Expand All @@ -203,6 +209,8 @@ function instantiateModule(id: ModuleId, source: SourceInfo): Module {
// has already been taken care of in `getOrInstantiateModuleFromParent`.
parents = [source.parentId];
break;
default:
invariant(source, (source) => `Unknown source type: ${source?.type}`);
}

const module: Module = {
Expand Down Expand Up @@ -242,7 +250,7 @@ function instantiateModule(id: ModuleId, source: SourceInfo): Module {
P: resolveAbsolutePath,
U: relativeURL,
R: createResolvePathFromModule(r),
__dirname: module.id.replace(/(^|\/)[\/]+$/, ""),
__dirname: module.id.replace(/(^|\/)\/+$/, ""),
});
} catch (error) {
module.error = error as any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

/// <reference path="../shared/runtime-utils.ts" />

/// A 'base' utilities to support runtime can have externals.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

declare var RUNTIME_PUBLIC_PATH: string;
declare var OUTPUT_ROOT: string;
declare var ASSET_PREFIX: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

/// <reference path="../shared/runtime-utils.ts" />

function readWebAssemblyAsResponse(path: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

/**
* This file acts as a dummy implementor for the interface that
* `runtime-utils.ts` expects to be available in the global scope.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* It will be prepended to the runtime code of each runtime.
*/

/* eslint-disable @next/next/no-assign-module-variable */
/* eslint-disable @typescript-eslint/no-unused-vars */

/// <reference path="./runtime-types.d.ts" />

Expand Down Expand Up @@ -514,3 +514,10 @@ const relativeURL = function relativeURL(this: any, inputUrl: string) {
};

relativeURL.prototype = URL.prototype;

/**
* Utility function to ensure all variants of an enum are handled.
*/
function invariant(never: never, computeMessage: (arg: any) => string): never {
throw new Error(`Invariant: ${computeMessage(never)}`);
}
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-node/js/src/ipc/evaluate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IPC, StructuredError } from "./index";
import { IPC } from "./index";
import type { Ipc as GenericIpc } from "./index";

type IpcIncomingMessage =
Expand Down
3 changes: 3 additions & 0 deletions turbopack/crates/turbopack-node/js/src/ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createConnection } from "node:net";
import type { StackFrame } from "../compiled/stacktrace-parser";
import { parse as parseStackTrace } from "../compiled/stacktrace-parser";
import { getProperError } from "./error";
import { invariant } from '../invariant'

export type StructuredError = {
name: string;
Expand Down Expand Up @@ -80,6 +81,8 @@ function createIpc<TIncoming, TOutgoing>(
}
break;
}
default:
invariant(state, (state) => `Unknown state type: ${state?.type}`);
}
}
});
Expand Down
3 changes: 3 additions & 0 deletions turbopack/crates/turbopack-node/js/src/transforms/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ export default async function transform(
glob: "**",
});
break;
default:
// TODO: do we need to do anything here?
break;
}
}
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,6 @@ type ResolveOptions = {
roots?: string[];
importFields?: string[];
};
const SUPPORTED_RESOLVE_OPTIONS = new Set([
"alias",
"aliasFields",
"conditionNames",
"descriptionFiles",
"extensions",
"exportsFields",
"mainFields",
"mainFiles",
"modules",
"restrictions",
"preferRelative",
"dependencyType",
]);

const transform = (
ipc: Ipc<IpcInfoMessage, IpcRequestMessage>,
Expand Down Expand Up @@ -356,6 +342,9 @@ const transform = (
.join("\n")
);
break;
default:
// TODO: do we need to handle this?
break
}

ipc.sendInfo({
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-trace-utils/src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ mod tests {
});

receiver.run_exit_handler().await;
assert_eq!(called.load(Ordering::SeqCst), true);
assert!(called.load(Ordering::SeqCst));
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ will hide that async and error in the `XxxVc`.

### Tasks

A combination of a function and its arguments is called a Task (basically an
A combination of a function and its arguments is called a Task (essentially an
invocation of a function).

It's also possible to store data in a Task via `XxxVc::cell(value: Xxx)`.
Expand Down
Loading

0 comments on commit 81415c9

Please sign in to comment.