Skip to content

Commit

Permalink
set up eslint and address some linting errors. add unix-mount test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mceachen committed Nov 10, 2024
1 parent 2a9268e commit c6d1cb9
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 133 deletions.
9 changes: 9 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ts_eslint from "typescript-eslint";

/** @type {import('eslint').Linter.Config[]} */
export default [
{
files: ["src/**/*.ts}"],
},
...ts_eslint.configs.recommended,
];
151 changes: 44 additions & 107 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"test:coverage": "jest --coverage",
"test:clear": "jest --clearCache",
"test:debug": "node --inspect-brk jest --runInBand",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"lint": "eslint",
"lint:fix": "eslint --fix",
"fmt": "prettier --write \"src/**/*.ts\" && npm run fmt:cpp",
"fmt:cpp": "clang-format --style=LLVM -i src/*/*.cpp src/*/*.h"
},
Expand All @@ -36,19 +36,20 @@
"node-addon-api": "^8.2.2"
},
"devDependencies": {
"@eslint/js": "^9.14.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.9.0",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint": "^9.14.0",
"globals": "^15.12.0",
"jest": "^29.7.0",
"node-gyp": "^10.2.0",
"prettier-plugin-organize-imports": "4.1.0",
"prettier": "^3.3.3",
"prettier-plugin-organize-imports": "4.1.0",
"ts-jest": "^29.2.5",
"typedoc": "^0.26.11",
"typescript": "^5.6.3"
"typescript": "^5.6.3",
"typescript-eslint": "^8.13.0"
}
}
37 changes: 28 additions & 9 deletions src/DeepFreeze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,46 @@

export type DeepReadonly<T> = T extends (infer R)[]
? ReadonlyArray<DeepReadonly<R>>
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
: T extends Function
? T
? T
: T extends object
? { readonly [P in keyof T]: DeepReadonly<T[P]> }
: T;

export type OrDeepReadonly<T> = T | DeepReadonly<T>;

/**
* Type guard to check if a value is an object (excluding null and arrays)
*/
function isObject(value: unknown): value is Record<string | symbol | number, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}

/**
* Recursively freezes an object and all of its properties
*/
export function deepFreeze<T>(obj: T): DeepReadonly<T> {
if (obj == null || typeof obj !== "object" || Object.isFrozen(obj)) {
return obj as any;
// Handle primitive types and frozen objects
if (obj === null || typeof obj !== 'object' || Object.isFrozen(obj)) {
return obj as DeepReadonly<T>;
}

if (Array.isArray(obj)) {
return Object.freeze(obj.map(deepFreeze)) as any;
const frozenArray = Object.freeze(obj.map(deepFreeze)) as ReadonlyArray<DeepReadonly<T extends (infer U)[] ? U : never>>;
return frozenArray as DeepReadonly<T>;
}
const result = {} as any;
for (const [key, value] of Object.entries(obj)) {
result[key] = deepFreeze(value);

if (isObject(obj)) {
const result = {} as T;

Object.entries(obj as Record<string, unknown>).forEach(([key, value]) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(result as any)[key] = deepFreeze(value);
});

return Object.freeze(result) as DeepReadonly<T>;
}
return Object.freeze(result);
}

return obj as DeepReadonly<T>;
}
3 changes: 1 addition & 2 deletions src/__tests__/async-behavior.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { describePlatform } from "../test-utils/platform";

describe("Filesystem API Async Behavior", () => {
const describeLinux = describePlatform("linux");
const describeWindows = describePlatform("win32");

// Helper to measure execution time
const timeExecution = async (fn: () => Promise<any>): Promise<number> => {
const timeExecution = async (fn: () => Promise<unknown>): Promise<number> => {
const start = process.hrtime();
await fn();
const [seconds, nanoseconds] = process.hrtime(start);
Expand Down
Loading

0 comments on commit c6d1cb9

Please sign in to comment.