Skip to content

Commit

Permalink
Fixed eslint warnings
Browse files Browse the repository at this point in the history
Added todo comments
  • Loading branch information
james-pre committed Oct 26, 2024
1 parent 40aa041 commit 0411bae
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 27 deletions.
1 change: 1 addition & 0 deletions eslint.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default [
'@typescript-eslint/no-redundant-type-constituents': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/no-base-to-string': 'off',
},
},
{
Expand Down
6 changes: 3 additions & 3 deletions src/backends/backend.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RequiredKeys } from 'utilium';
import type { Entries, RequiredKeys } from 'utilium';
import { ErrnoError, Errno } from '../error.js';
import type { FileSystem } from '../filesystem.js';
import { levenshtein } from '../utils.js';
Expand Down Expand Up @@ -102,7 +102,7 @@ export async function checkOptions<T extends Backend>(backend: T, options: Recor
}

// Check for required options.
for (const [optName, opt] of Object.entries(backend.options)) {
for (const [optName, opt] of Object.entries(backend.options) as Entries<OptionsConfig<Record<string, any>>>) {

Check warning on line 105 in src/backends/backend.ts

View workflow job for this annotation

GitHub Actions / CI

Unexpected any. Specify a different type
const providedValue = options?.[optName];

if (providedValue === undefined || providedValue === null) {
Expand Down Expand Up @@ -133,7 +133,7 @@ export async function checkOptions<T extends Backend>(backend: T, options: Recor
throw new ErrnoError(
Errno.EINVAL,
`${backend.name}: Value provided for option ${optName} is not the proper type. Expected ${
Array.isArray(opt.type) ? `one of {${opt.type.join(', ')}}` : opt.type
Array.isArray(opt.type) ? `one of {${opt.type.join(', ')}}` : (opt.type as string)
}, but received ${typeof providedValue}`
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/backends/file_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export abstract class IndexFS extends Readonly(FileSystem) {
if (!content.every(item => typeof item == 'string')) {
throw ErrnoError.With('ENODATA', path, 'readdir');
}
return content as string[];
return content;
}

protected abstract getData(path: string, stats: Stats): Promise<Uint8Array>;
Expand Down
16 changes: 8 additions & 8 deletions src/backends/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class UnmutexedOverlayFS extends FileSystem {

try {
await this.writable.rename(oldPath, newPath);
} catch (e) {
} catch {
if (this._deletedFiles.has(oldPath)) {
throw ErrnoError.With('ENOENT', oldPath, 'rename');
}
Expand All @@ -144,7 +144,7 @@ export class UnmutexedOverlayFS extends FileSystem {

try {
this.writable.renameSync(oldPath, newPath);
} catch (e) {
} catch {
if (this._deletedFiles.has(oldPath)) {
throw ErrnoError.With('ENOENT', oldPath, 'rename');
}
Expand All @@ -155,7 +155,7 @@ export class UnmutexedOverlayFS extends FileSystem {
this.checkInitialized();
try {
return await this.writable.stat(path);
} catch (e) {
} catch {
if (this._deletedFiles.has(path)) {
throw ErrnoError.With('ENOENT', path, 'stat');
}
Expand All @@ -170,7 +170,7 @@ export class UnmutexedOverlayFS extends FileSystem {
this.checkInitialized();
try {
return this.writable.statSync(path);
} catch (e) {
} catch {
if (this._deletedFiles.has(path)) {
throw ErrnoError.With('ENOENT', path, 'stat');
}
Expand Down Expand Up @@ -329,12 +329,12 @@ export class UnmutexedOverlayFS extends FileSystem {
const contents: string[] = [];
try {
contents.push(...(await this.writable.readdir(path)));
} catch (e) {
} catch {
// NOP.
}
try {
contents.push(...(await this.readable.readdir(path)).filter((fPath: string) => !this._deletedFiles.has(`${path}/${fPath}`)));
} catch (e) {
} catch {
// NOP.
}
const seenMap: { [name: string]: boolean } = {};
Expand All @@ -356,12 +356,12 @@ export class UnmutexedOverlayFS extends FileSystem {
let contents: string[] = [];
try {
contents = contents.concat(this.writable.readdirSync(path));
} catch (e) {
} catch {
// NOP.
}
try {
contents = contents.concat(this.readable.readdirSync(path).filter((fPath: string) => !this._deletedFiles.has(`${path}/${fPath}`)));
} catch (e) {
} catch {
// NOP.
}
const seenMap: { [name: string]: boolean } = {};
Expand Down
7 changes: 4 additions & 3 deletions src/backends/port/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export async function handleRequest(port: RPC.Port, fs: FileSystem, request: Fil
};
}
break;
case 'file':
case 'file': {
const { fd } = request;
if (!descriptors.has(fd)) {
throw new ErrnoError(Errno.EBADF);
Expand All @@ -271,11 +271,12 @@ export async function handleRequest(port: RPC.Port, fs: FileSystem, request: Fil
descriptors.delete(fd);
}
break;
}
default:
return;
}
} catch (e: any) {
value = e instanceof ErrnoError ? e.toJSON() : e.toString();
} catch (e) {
value = e instanceof ErrnoError ? e.toJSON() : (e as object).toString();
error = true;
}

Expand Down
5 changes: 3 additions & 2 deletions src/backends/port/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Errno, ErrnoError, type ErrnoErrorJSON } from '../../error.js';
import type { FileSystem } from '../../filesystem.js';
import type { Backend, FilesystemOf } from '../backend.js';
import { handleRequest, PortFile, type PortFS } from './fs.js';
import type { FileOrFSRequest } from './fs.js';
Expand Down Expand Up @@ -156,10 +157,10 @@ export function catchMessages<T extends Backend>(port: Port): (fs: FilesystemOf<
const events: _MessageEvent[] = [];
const handler = events.push.bind(events);
attach(port, handler);
return function (fs: any) {
return function (fs: FileSystem) {
detach(port, handler);
for (const event of events) {
const request: FileOrFSRequest = 'data' in event ? event.data : event;
const request = ('data' in event ? event.data : event) as FileOrFSRequest;

Check warning on line 163 in src/backends/port/rpc.ts

View workflow job for this annotation

GitHub Actions / CI

Unsafe member access .data on an `any` value
void handleRequest(port, fs, request);
}
};
Expand Down
6 changes: 4 additions & 2 deletions src/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,18 @@ export class DeviceFile extends File {
this.driver.close?.(this);
}

public async close(): Promise<void> {
public close(): Promise<void> {
this.closeSync();
return Promise.resolve();
}

public syncSync(): void {
this.driver.sync?.(this);
}

public async sync(): Promise<void> {
public sync(): Promise<void> {
this.syncSync();
return Promise.resolve();
}

public chown(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/emulation/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export function symlink(target: fs.PathLike, path: fs.PathLike, typeOrCB?: fs.sy
}
symlink satisfies Omit<typeof fs.symlink, '__promisify__'>;

export function readlink(path: fs.PathLike, callback: Callback<[string]> & any): void;
export function readlink(path: fs.PathLike, callback: Callback<[string]>): void;
export function readlink(path: fs.PathLike, options: fs.BufferEncodingOption, callback: Callback<[Uint8Array]>): void;
export function readlink(path: fs.PathLike, options: fs.EncodingOption, callback: Callback<[string | Uint8Array]>): void;
export function readlink(path: fs.PathLike, options: fs.EncodingOption, callback: Callback<[string]>): void;
Expand Down
12 changes: 8 additions & 4 deletions src/emulation/promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ export class FileHandle implements promises.FileHandle {
return new (_gt as { ReadableStream: new (...args: unknown[]) => TReadableStream<Uint8Array> }).ReadableStream({ start, type: options.type });
}

/**
* @todo Implement
*/
public readLines(options?: promises.CreateReadStreamOptions): ReadlineInterface {

Check warning on line 208 in src/emulation/promises.ts

View workflow job for this annotation

GitHub Actions / CI

'options' is defined but never used
throw ErrnoError.With('ENOSYS', this.file.path, 'FileHandle.readLines');
}
Expand Down Expand Up @@ -864,6 +867,7 @@ lutimes satisfies typeof promises.lutimes;
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. Defaults to `'utf8'`.
* @todo handle options
*/
export async function realpath(path: fs.PathLike, options: fs.BufferEncodingOption): Promise<Buffer>;
export async function realpath(path: fs.PathLike, options?: fs.EncodingOption | BufferEncoding): Promise<string>;
Expand Down Expand Up @@ -1020,9 +1024,9 @@ copyFile satisfies typeof promises.copyFile;
* @returns A `Dir` object representing the opened directory.
* @todo Use options
*/
export async function opendir(path: fs.PathLike, options?: fs.OpenDirOptions): Promise<Dir> {
export function opendir(path: fs.PathLike, options?: fs.OpenDirOptions): Promise<Dir> {

Check warning on line 1027 in src/emulation/promises.ts

View workflow job for this annotation

GitHub Actions / CI

'options' is defined but never used
path = normalizePath(path);
return new Dir(path);
return Promise.resolve(new Dir(path));
}
opendir satisfies typeof promises.opendir;

Expand Down Expand Up @@ -1087,8 +1091,8 @@ cp satisfies typeof promises.cp;
export async function statfs(path: fs.PathLike, opts?: fs.StatFsOptions & { bigint?: false }): Promise<fs.StatsFs>;
export async function statfs(path: fs.PathLike, opts: fs.StatFsOptions & { bigint: true }): Promise<fs.BigIntStatsFs>;
export async function statfs(path: fs.PathLike, opts?: fs.StatFsOptions): Promise<fs.StatsFs | fs.BigIntStatsFs>;
export async function statfs(path: fs.PathLike, opts?: fs.StatFsOptions): Promise<fs.StatsFs | fs.BigIntStatsFs> {
export function statfs(path: fs.PathLike, opts?: fs.StatFsOptions): Promise<fs.StatsFs | fs.BigIntStatsFs> {
path = normalizePath(path);
const { fs } = resolveMount(path);
return _statfs(fs, opts?.bigint);
return Promise.resolve(_statfs(fs, opts?.bigint));
}
5 changes: 3 additions & 2 deletions src/emulation/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ export function rmSync(path: fs.PathLike, options?: fs.RmOptions): void {
let stats: Stats | undefined;
try {
stats = statSync(path);
} catch (error: any) {
if (error.code != 'ENOENT' || !options?.force) throw error;
} catch (error) {
if ((error as ErrnoError).code != 'ENOENT' || !options?.force) throw error;
}

if (!stats) {
Expand Down Expand Up @@ -768,6 +768,7 @@ writevSync satisfies typeof fs.writevSync;
* @param path The path to the directory.
* @param options Options for opening the directory.
* @returns A `Dir` object representing the opened directory.
* @todo Handle options
*/
export function opendirSync(path: fs.PathLike, options?: fs.OpenDirOptions): Dir {

Check warning on line 773 in src/emulation/sync.ts

View workflow job for this annotation

GitHub Actions / CI

'options' is defined but never used
path = normalizePath(path);
Expand Down
2 changes: 1 addition & 1 deletion tests/fs/watch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ suite('Watch Features', () => {
test('fs.unwatchFile should stop watching the file', async () => {
let changeDetected = false;

const listener = (curr: fs.Stats, prev: fs.Stats) => {
const listener = () => {
changeDetected = true;
};

Expand Down

0 comments on commit 0411bae

Please sign in to comment.