Skip to content

Commit

Permalink
Merge pull request #49 from nodelib/update_lint_rules
Browse files Browse the repository at this point in the history
Fix linter issues after config updation
  • Loading branch information
mrmlnc committed Dec 29, 2019
2 parents 3b1ef75 + 17d48cd commit 8e0d8b8
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 85 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"@types/rimraf": "^2.0.2",
"@types/run-parallel": "^1.1.0",
"@types/sinon": "^7.0.11",
"eslint": "^6.5.1",
"eslint-config-mrmlnc": "^1.0.1",
"eslint": "^6.8.0",
"eslint-config-mrmlnc": "^1.1.0",
"gh-pages": "^2.0.1",
"lerna": "^3.13.1",
"mocha": "^6.1.0",
"rimraf": "^2.6.3",
"sinon": "^7.3.1",
"typescript": "^3.4.2"
"typescript": "^3.7.4"
}
}
16 changes: 8 additions & 8 deletions packages/fs/fs.macchiato/src/dirent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ import * as fs from 'fs';
import { PrepareOptionsFromClass } from './types';

export default class Dirent implements fs.Dirent {
public readonly name: string = this._options.name === undefined ? 'unknown.txt' : this._options.name;
public readonly name: string = this._options.name ?? 'unknown.txt';

constructor(private readonly _options: PrepareOptionsFromClass<fs.Dirent> = {}) { }

public isFile(): boolean {
return 'isFile' in this._options ? this._options.isFile as boolean : true;
return this._options.isFile ?? true;
}

public isDirectory(): boolean {
return 'isDirectory' in this._options ? this._options.isDirectory as boolean : false;
return this._options.isDirectory ?? false;
}

public isBlockDevice(): boolean {
return 'isBlockDevice' in this._options ? this._options.isBlockDevice as boolean : false;
return this._options.isBlockDevice ?? false;
}

public isCharacterDevice(): boolean {
return 'isCharacterDevice' in this._options ? this._options.isCharacterDevice as boolean : false;
return this._options.isCharacterDevice ?? false;
}

public isSymbolicLink(): boolean {
return 'isSymbolicLink' in this._options ? this._options.isSymbolicLink as boolean : false;
return this._options.isSymbolicLink ?? false;
}

public isFIFO(): boolean {
return 'isFIFO' in this._options ? this._options.isFIFO as boolean : false;
return this._options.isFIFO ?? false;
}

public isSocket(): boolean {
return 'isSocket' in this._options ? this._options.isSocket as boolean : false;
return this._options.isSocket ?? false;
}
}
10 changes: 5 additions & 5 deletions packages/fs/fs.macchiato/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as assert from 'assert';

import * as pkg from '.';
import { Dirent, Stats } from '.';

describe('Package', () => {
it('should create a fake instance of fs.Stats', () => {
const actual = new pkg.Stats();
const actual = new Stats();

assert.ok(actual instanceof pkg.Stats);
assert.ok(actual instanceof Stats);
});

it('should create a fake instance of fs.Dirent', () => {
const actual = new pkg.Dirent();
const actual = new Dirent();

assert.ok(actual instanceof pkg.Dirent);
assert.ok(actual instanceof Dirent);
});
});
2 changes: 1 addition & 1 deletion packages/fs/fs.macchiato/src/stats.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('Stats', () => {
const date = new Date();

const stats = new Stats({
dev: 1, // eslint-disable-line unicorn/prevent-abbreviations
dev: 1,
ino: 1,
mode: 1,
nlink: 1,
Expand Down
51 changes: 25 additions & 26 deletions packages/fs/fs.macchiato/src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,52 @@ const gid = process.platform === 'win32' ? undefined : process.getgid();
export default class Stats implements fs.Stats {
public readonly _date: Date = new Date();

// eslint-disable-next-line unicorn/prevent-abbreviations
public readonly dev: number = 'dev' in this._options ? this._options.dev as number : 0;
public readonly ino: number = 'ino' in this._options ? this._options.ino as number : 0;
public readonly mode: number = 'mode' in this._options ? this._options.mode as number : 0;
public readonly nlink: number = 'nlink' in this._options ? this._options.nlink as number : 0;
public readonly uid: number = 'uid' in this._options ? this._options.uid as number : uid as number;
public readonly gid: number = 'gid' in this._options ? this._options.gid as number : gid as number;
public readonly rdev: number = 'rdev' in this._options ? this._options.rdev as number : 0;
public readonly size: number = 'size' in this._options ? this._options.size as number : 0;
public readonly blksize: number = 'blksize' in this._options ? this._options.blksize as number : 0;
public readonly blocks: number = 'blocks' in this._options ? this._options.blocks as number : 0;
public readonly atimeMs: number = 'atimeMs' in this._options ? this._options.atimeMs as number : this._date.getTime();
public readonly mtimeMs: number = 'mtimeMs' in this._options ? this._options.mtimeMs as number : this._date.getTime();
public readonly ctimeMs: number = 'ctimeMs' in this._options ? this._options.ctimeMs as number : this._date.getTime();
public readonly birthtimeMs: number = 'birthtimeMs' in this._options ? this._options.birthtimeMs as number : this._date.getTime();
public readonly atime: Date = 'atime' in this._options ? this._options.atime as Date : this._date;
public readonly mtime: Date = 'mtime' in this._options ? this._options.mtime as Date : this._date;
public readonly ctime: Date = 'ctime' in this._options ? this._options.ctime as Date : this._date;
public readonly birthtime: Date = 'birthtime' in this._options ? this._options.birthtime as Date : this._date;
public readonly dev: number = this._options.dev ?? 0;
public readonly ino: number = this._options.ino ?? 0;
public readonly mode: number = this._options.mode ?? 0;
public readonly nlink: number = this._options.nlink ?? 0;
public readonly uid: number = ('uid' in this._options ? this._options.uid : uid) as number;
public readonly gid: number = ('gid' in this._options ? this._options.gid : gid) as number;
public readonly rdev: number = this._options.rdev ?? 0;
public readonly size: number = this._options.size ?? 0;
public readonly blksize: number = this._options.blksize ?? 0;
public readonly blocks: number = this._options.blocks ?? 0;
public readonly atimeMs: number = this._options.atimeMs ?? this._date.getTime();
public readonly mtimeMs: number = this._options.mtimeMs ?? this._date.getTime();
public readonly ctimeMs: number = this._options.ctimeMs ?? this._date.getTime();
public readonly birthtimeMs: number = this._options.birthtimeMs ?? this._date.getTime();
public readonly atime: Date = this._options.atime ?? this._date;
public readonly mtime: Date = this._options.mtime ?? this._date;
public readonly ctime: Date = this._options.ctime ?? this._date;
public readonly birthtime: Date = this._options.birthtime ?? this._date;

constructor(private readonly _options: PrepareOptionsFromClass<fs.Stats> = {}) { }

public isFile(): boolean {
return 'isFile' in this._options ? this._options.isFile as boolean : true;
return this._options.isFile ?? true;
}

public isDirectory(): boolean {
return 'isDirectory' in this._options ? this._options.isDirectory as boolean : false;
return this._options.isDirectory ?? false;
}

public isBlockDevice(): boolean {
return 'isBlockDevice' in this._options ? this._options.isBlockDevice as boolean : false;
return this._options.isBlockDevice ?? false;
}

public isCharacterDevice(): boolean {
return 'isCharacterDevice' in this._options ? this._options.isCharacterDevice as boolean : false;
return this._options.isCharacterDevice ?? false;
}

public isSymbolicLink(): boolean {
return 'isSymbolicLink' in this._options ? this._options.isSymbolicLink as boolean : false;
return this._options.isSymbolicLink ?? false;
}

public isFIFO(): boolean {
return 'isFIFO' in this._options ? this._options.isFIFO as boolean : false;
return this._options.isFIFO ?? false;
}

public isSocket(): boolean {
return 'isSocket' in this._options ? this._options.isSocket as boolean : false;
return this._options.isSocket ?? false;
}
}
18 changes: 9 additions & 9 deletions packages/fs/fs.scandir/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs';

import * as rimraf from 'rimraf';

import * as pkg from '.';
import { scandir, scandirSync, Settings } from '.';

describe('Package', () => {
before(() => {
Expand All @@ -19,7 +19,7 @@ describe('Package', () => {

describe('.scandir', () => {
it('should work without options or settings', (done) => {
pkg.scandir('fixtures', (error, entries) => {
scandir('fixtures', (error, entries) => {
assert.strictEqual(error, null);
assert.ok(entries[0].name);
assert.ok(entries[0].path);
Expand All @@ -29,7 +29,7 @@ describe('Package', () => {
});

it('should work with options', (done) => {
pkg.scandir('fixtures', { stats: true }, (error, entries) => {
scandir('fixtures', { stats: true }, (error, entries) => {
assert.strictEqual(error, null);
assert.ok(entries[0].name);
assert.ok(entries[0].path);
Expand All @@ -40,9 +40,9 @@ describe('Package', () => {
});

it('should work with settings', (done) => {
const settings = new pkg.Settings({ stats: true });
const settings = new Settings({ stats: true });

pkg.scandir('fixtures', settings, (error, entries) => {
scandir('fixtures', settings, (error, entries) => {
assert.strictEqual(error, null);
assert.ok(entries[0].name);
assert.ok(entries[0].path);
Expand All @@ -55,15 +55,15 @@ describe('Package', () => {

describe('.scandirSync', () => {
it('should work without options or settings', () => {
const actual = pkg.scandirSync('fixtures');
const actual = scandirSync('fixtures');

assert.ok(actual[0].name);
assert.ok(actual[0].path);
assert.ok(actual[0].dirent);
});

it('should work with options', () => {
const actual = pkg.scandirSync('fixtures', { stats: true });
const actual = scandirSync('fixtures', { stats: true });

assert.ok(actual[0].name);
assert.ok(actual[0].path);
Expand All @@ -72,9 +72,9 @@ describe('Package', () => {
});

it('should work with settings', () => {
const settings = new pkg.Settings({ stats: true });
const settings = new Settings({ stats: true });

const actual = pkg.scandirSync('fixtures', settings);
const actual = scandirSync('fixtures', settings);

assert.ok(actual[0].name);
assert.ok(actual[0].path);
Expand Down
2 changes: 1 addition & 1 deletion packages/fs/fs.scandir/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export default class Settings {
constructor(private readonly _options: Options = {}) { }

private _getValue<T>(option: T | undefined, value: T): T {
return option === undefined ? value : option;
return option ?? value;
}
}
18 changes: 9 additions & 9 deletions packages/fs/fs.stat/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs';

import * as rimraf from 'rimraf';

import * as pkg from '.';
import { stat, statSync, Settings } from '.';

describe('Package', () => {
before(() => {
Expand All @@ -20,25 +20,25 @@ describe('Package', () => {

describe('.stat', () => {
it('should work without options or settings', (done) => {
pkg.stat('fixtures/b', (error, stats) => {
stat('fixtures/b', (error, stats) => {
assert.strictEqual(error, null);
assert.ok(stats);
done();
});
});

it('should work with options', (done) => {
pkg.stat('fixtures/b', { markSymbolicLink: true }, (error, stats) => {
stat('fixtures/b', { markSymbolicLink: true }, (error, stats) => {
assert.strictEqual(error, null);
assert.strictEqual(stats.isSymbolicLink(), true);
done();
});
});

it('should work with settings', (done) => {
const settings = new pkg.Settings({ markSymbolicLink: true });
const settings = new Settings({ markSymbolicLink: true });

pkg.stat('fixtures/b', settings, (error, stats) => {
stat('fixtures/b', settings, (error, stats) => {
assert.strictEqual(error, null);
assert.strictEqual(stats.isSymbolicLink(), true);
done();
Expand All @@ -48,21 +48,21 @@ describe('Package', () => {

describe('.statSync', () => {
it('should work without options or settings', () => {
const actual = pkg.statSync('fixtures/b');
const actual = statSync('fixtures/b');

assert.ok(actual);
});

it('should work with options', () => {
const actual = pkg.statSync('fixtures/b', { markSymbolicLink: true });
const actual = statSync('fixtures/b', { markSymbolicLink: true });

assert.strictEqual(actual.isSymbolicLink(), true);
});

it('should work with settings', () => {
const settings = new pkg.Settings({ markSymbolicLink: true });
const settings = new Settings({ markSymbolicLink: true });

const actual = pkg.statSync('fixtures/b', settings);
const actual = statSync('fixtures/b', settings);

assert.strictEqual(actual.isSymbolicLink(), true);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/fs/fs.stat/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export default class Settings {
constructor(private readonly _options: Options = {}) { }

private _getValue<T>(option: T | undefined, value: T): T {
return option === undefined ? value : option;
return option ?? value;
}
}

0 comments on commit 8e0d8b8

Please sign in to comment.