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 6871d6f commit 1e6ea9e
Show file tree
Hide file tree
Showing 26 changed files with 99 additions and 117 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
20 changes: 10 additions & 10 deletions turbopack/crates/turbo-tasks-memory/tests/all_in_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,26 @@ async fn all_in_one() {
let vc_42 = Vc::cell(42);

let option: Vc<Option<Vc<u32>>> = Vc::cell(Some(vc_42));
assert_eq!(*option.is_some().await?, true);
assert_eq!(*option.is_none().await?, false);
assert!(*option.is_some().await?);
assert!(!(*option.is_none().await?));
assert_eq!(&*option.await?, &Some(vc_42));
assert_eq!(option.dbg().await?.to_string(), "Some(\n 42,\n)");

let option: Vc<Option<Vc<u32>>> = Default::default();
assert_eq!(*option.is_some().await?, false);
assert_eq!(*option.is_none().await?, true);
assert!(!(*option.is_some().await?));
assert!(*option.is_none().await?);
assert_eq!(&*option.await?, &None);
assert_eq!(option.dbg().await?.to_string(), "None");

let vec: Vc<Vec<Vc<u32>>> = Vc::cell(vec![vc_42]);
assert_eq!(*vec.len().await?, 1);
assert_eq!(*vec.is_empty().await?, false);
assert!(!(*vec.is_empty().await?));
assert_eq!(&*vec.await?, &[vc_42]);
assert_eq!(vec.dbg().await?.to_string(), "[\n 42,\n]");

let vec: Vc<Vec<Vc<u32>>> = Default::default();
assert_eq!(*vec.len().await?, 0);
assert_eq!(*vec.is_empty().await?, true);
assert!(*vec.is_empty().await?);
assert_eq!(vec.dbg().await?.to_string(), "[]");

let vec: Vc<Vec<Vc<Vec<Vc<u32>>>>> = Default::default();
Expand All @@ -88,25 +88,25 @@ async fn all_in_one() {

let set: Vc<IndexSet<Vc<u32>>> = Vc::cell(IndexSet::from([vc_42]));
assert_eq!(*set.len().await?, 1);
assert_eq!(*set.is_empty().await?, false);
assert!(!(*set.is_empty().await?));
assert_eq!(&*set.await?, &IndexSet::from([vc_42]));
assert_eq!(set.dbg().await?.to_string(), "{\n 42,\n}");

let set: Vc<IndexSet<Vc<u32>>> = Default::default();
assert_eq!(*set.len().await?, 0);
assert_eq!(*set.is_empty().await?, true);
assert!(*set.is_empty().await?);
assert_eq!(&*set.await?, &IndexSet::<Vc<u32>>::default());
assert_eq!(set.dbg().await?.to_string(), "{}");

let map: Vc<IndexMap<_, _>> = Vc::cell(IndexMap::from([(vc_42, vc_42)]));
assert_eq!(*map.len().await?, 1);
assert_eq!(*map.is_empty().await?, false);
assert!(!(*map.is_empty().await?));
assert_eq!(&*map.await?, &IndexMap::from([(vc_42, vc_42)]));
assert_eq!(map.dbg().await?.to_string(), "{\n 42: 42,\n}");

let map: Vc<IndexMap<Vc<u32>, Vc<u32>>> = Default::default();
assert_eq!(*map.len().await?, 0);
assert_eq!(*map.is_empty().await?, true);
assert!(*map.is_empty().await?);
assert_eq!(&*map.await?, &IndexMap::<Vc<u32>, Vc<u32>>::default());
assert_eq!(map.dbg().await?.to_string(), "{}");

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
9 changes: 9 additions & 0 deletions turbopack/crates/turbopack-node/js/src/ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function createIpc<TIncoming, TOutgoing>(
}
break;
}
default:
invariant(state, (state) => `Unknown state type: ${state?.type}`);
}
}
});
Expand Down Expand Up @@ -207,3 +209,10 @@ improveConsole("timeEnd", "stdout", true);
improveConsole("timeLog", "stdout", true);
improveConsole("timeStamp", "stdout", true);
improveConsole("assert", "stderr", true);

/**
* 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)}`);
}
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
Loading

0 comments on commit 1e6ea9e

Please sign in to comment.