Skip to content

Commit

Permalink
Merge pull request #142 from mrmlnc/update_tslint_config
Browse files Browse the repository at this point in the history
Update "tslint-config-mrmlnc" to 2.0.0
  • Loading branch information
mrmlnc authored Jan 6, 2019
2 parents ddb47f3 + 0a1e006 commit 7bffb0c
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 67 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"mocha": "^5.2.0",
"rimraf": "^2.6.2",
"tiny-glob": "^0.2.3",
"tslint": "^5.11.0",
"tslint-config-mrmlnc": "^1.0.0",
"tslint": "^5.12.0",
"tslint-config-mrmlnc": "^2.0.1",
"typescript": "^3.1.3"
},
"dependencies": {
Expand Down
5 changes: 3 additions & 2 deletions src/adapters/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ export default abstract class FileSystem<T> {
* Return an implementation of the Entry interface.
*/
public makeEntry(stat: fs.Stats, pattern: Pattern): Entry {
return Object.assign<fs.Stats, Entry>(stat, {
return {
...stat,
path: pattern,
depth: pattern.split('/').length
} as Entry);
} as unknown as Entry;
}
}
4 changes: 2 additions & 2 deletions src/benchmark/reporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Benchmark → Reporter', () => {
it('should returns report', () => {
const reporter = new Reporter(results);

const expected: string = 'name\n(TIME) 1.000ms ±0.000% | (MEMORY) 1.000MB ±0.000% | Entries: 1 | Errors: 0 | Retries: 1';
const expected = 'name\n(TIME) 1.000ms ±0.000% | (MEMORY) 1.000MB ±0.000% | Entries: 1 | Errors: 0 | Retries: 1';

const actual = reporter.toString();

Expand All @@ -35,7 +35,7 @@ describe('Benchmark → Reporter', () => {

const reporter = new Reporter(results);

const expected: string = 'name\n(TIME) 1.000ms ±0.000% | (MEMORY) 1.000MB ±0.000% | Entries: 1 | Errors: 1 | Retries: 1';
const expected = 'name\n(TIME) 1.000ms ±0.000% | (MEMORY) 1.000MB ±0.000% | Entries: 1 | Errors: 1 | Retries: 1';

const actual = reporter.toString();

Expand Down
10 changes: 5 additions & 5 deletions src/benchmark/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Benchmark → Utils', () => {
it('should returns milliseconds', () => {
const hrtime: [number, number] = [0, 1e7];

const expected: number = 10;
const expected = 10;

const actual = utils.convertHrtimeToMilliseconds(hrtime);

Expand All @@ -34,7 +34,7 @@ describe('Benchmark → Utils', () => {

describe('.convertBytesToMegaBytes', () => {
it('should returns megabytes', () => {
const expected: number = 1;
const expected = 1;

const actual = utils.convertBytesToMegaBytes(1e6);

Expand All @@ -54,7 +54,7 @@ describe('Benchmark → Utils', () => {

describe('.timeEnd', () => {
it('should returns diff between hrtime\'s', () => {
const expected: number = 10;
const expected = 10;

const actual = utils.timeEnd([0, 1e7]);

Expand All @@ -64,7 +64,7 @@ describe('Benchmark → Utils', () => {

describe('.getMemory', () => {
it('should returns memory usage in megabytes', () => {
const expected: number = 10;
const expected = 10;

const actual = utils.getMemory();

Expand Down Expand Up @@ -104,7 +104,7 @@ describe('Benchmark → Utils', () => {

describe('.getEnvAsInteger', () => {
it('should returns integer', () => {
const expected: number = 1;
const expected = 1;

const actual = utils.getEnvAsInteger('FG_TEST_ENV_INTEGER');

Expand Down
32 changes: 21 additions & 11 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ describe('Package', () => {

const actual = pkg.sync(['fixtures/**/*.md']);

assert.deepStrictEqual(actual.sort(), expected);
actual.sort();

assert.deepStrictEqual(actual, expected);
});

it('should returns entries (two sources)', () => {
Expand All @@ -40,7 +42,9 @@ describe('Package', () => {

const actual = pkg.sync(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']);

assert.deepStrictEqual(actual.sort(), expected);
actual.sort();

assert.deepStrictEqual(actual, expected);
});
});

Expand All @@ -51,7 +55,7 @@ describe('Package', () => {
await pkg.async(null as any);
throw new Error('An unexpected error was found.');
} catch (error) {
assert.strictEqual(error.toString(), 'TypeError: Patterns must be a string or an array of strings');
assert.strictEqual((error as Error).toString(), 'TypeError: Patterns must be a string or an array of strings');
}
});

Expand All @@ -68,7 +72,9 @@ describe('Package', () => {

const actual = await pkg.async(['fixtures/**/*.md']);

assert.deepStrictEqual(actual.sort(), expected);
actual.sort();

assert.deepStrictEqual(actual, expected);
});

it('should returns entries (two sources)', async () => {
Expand All @@ -83,7 +89,9 @@ describe('Package', () => {

const actual = await pkg.async(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']);

assert.deepStrictEqual(actual.sort(), expected);
actual.sort();

assert.deepStrictEqual(actual, expected);
});
});

Expand All @@ -108,10 +116,11 @@ describe('Package', () => {

const stream = pkg.stream(['fixtures/**/*.md']);

stream.on('data', (entry) => actual.push(entry));
stream.on('error', (err) => assert.fail(err));
stream.on('data', (entry: EntryItem) => actual.push(entry));
stream.on('error', (err: Error) => assert.fail(err));
stream.on('end', () => {
assert.deepStrictEqual(actual.sort(), expected);
actual.sort();
assert.deepStrictEqual(actual, expected);
done();
});
});
Expand All @@ -130,10 +139,11 @@ describe('Package', () => {

const stream = pkg.stream(['fixtures/first/**/*.md', 'fixtures/second/**/*.md']);

stream.on('data', (entry) => actual.push(entry));
stream.on('error', (err) => assert.fail(err));
stream.on('data', (entry: EntryItem) => actual.push(entry));
stream.on('error', (err: Error) => assert.fail(err));
stream.on('end', () => {
assert.deepStrictEqual(actual.sort(), expected);
actual.sort();
assert.deepStrictEqual(actual, expected);
done();
});
});
Expand Down
7 changes: 4 additions & 3 deletions src/managers/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from 'assert';
import * as manager from './options';

function getOptions(options?: manager.IPartialOptions): manager.IOptions {
return Object.assign<manager.IOptions, manager.IPartialOptions | undefined>({
return {
cwd: process.cwd(),
deep: true,
ignore: [],
Expand All @@ -24,8 +24,9 @@ function getOptions(options?: manager.IPartialOptions): manager.IOptions {
nocase: false,
case: true,
matchBase: false,
transform: null
}, options);
transform: null,
...options
};
}

describe('Managers → Options', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/managers/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface IOptions<T = EntryItem> {
export type IPartialOptions<T = EntryItem> = Partial<IOptions<T>>;

export function prepare(options?: IPartialOptions): IOptions {
const opts = Object.assign<IOptions, IPartialOptions | undefined>({
const opts = {
cwd: process.cwd(),
deep: true,
ignore: [],
Expand All @@ -117,8 +117,9 @@ export function prepare(options?: IPartialOptions): IOptions {
nocase: false,
case: true,
matchBase: false,
transform: null
}, options);
transform: null,
...options
};

if (opts.onlyDirectories) {
opts.onlyFiles = false;
Expand Down
4 changes: 2 additions & 2 deletions src/managers/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export function convertPatternGroupToTask(base: string, positive: Pattern[], neg
return {
base,
dynamic,
patterns: ([] as Pattern[]).concat(positive, negative.map(patternUtils.convertToNegativePattern)),
positive,
negative
negative,
patterns: ([] as Pattern[]).concat(positive, negative.map(patternUtils.convertToNegativePattern))
};
}
2 changes: 1 addition & 1 deletion src/providers/filters/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FilterFunction } from '@mrmlnc/readdir-enhanced';
import { Entry } from '../../types/entries';
import { Pattern, PatternRe } from '../../types/patterns';

export default class DeepFilter {
export default class EntryFilter {
public readonly index: Map<string, undefined> = new Map();

constructor(private readonly options: IOptions, private readonly micromatchOptions: micromatch.Options) { }
Expand Down
4 changes: 2 additions & 2 deletions src/providers/reader-async.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class ReaderAsyncFakeThrowErrno extends ReaderAsyncFake {

function getTask(dynamic: boolean = true): ITask {
return {
base: 'fixtures',
dynamic,
base: 'fixtures',
patterns: ['**/*'],
positive: ['**/*'],
negative: []
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('Providers → ReaderAsync', () => {

throw new Error('Wow');
} catch (err) {
assert.strictEqual(err.message, 'Boom');
assert.strictEqual((err as Error).message, 'Boom');
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/providers/reader-async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class ReaderAsync extends Reader<Promise<EntryItem[]>> {
return new Promise((resolve, reject) => {
const stream: NodeJS.ReadableStream = this.api(root, task, options);

stream.on('error', (err) => {
stream.on('error', (err: NodeJS.ErrnoException) => {
this.isEnoentCodeError(err) ? resolve([]) : reject(err);
stream.pause();
});
Expand Down
4 changes: 2 additions & 2 deletions src/providers/reader-stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const getEntries = (options: IOptions, task: ITask, api: typeof ReaderStreamFake

function getTask(dynamic: boolean = true): ITask {
return {
base: 'fixtures',
dynamic,
base: 'fixtures',
patterns: ['**/*'],
positive: ['**/*'],
negative: []
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('Providers → ReaderStream', () => {

throw new Error('Wow');
} catch (err) {
assert.strictEqual(err.message, 'Boom');
assert.strictEqual((err as Error).message, 'Boom');
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/providers/reader-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class ReaderStream extends Reader<NodeJS.ReadableStream> {
const readable: NodeJS.ReadableStream = this.api(root, task, options);

return readable
.on('error', (err) => this.isEnoentCodeError(err) ? null : transform.emit('error', err))
.on('error', (err: NodeJS.ErrnoException) => this.isEnoentCodeError(err) ? null : transform.emit('error', err))
.pipe(transform);
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/reader-sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class ReaderSyncFakeThrowErrno extends ReaderSyncFake {

function getTask(dynamic: boolean = true): ITask {
return {
base: 'fixtures',
dynamic,
base: 'fixtures',
patterns: ['**/*'],
positive: ['**/*'],
negative: []
Expand Down
2 changes: 1 addition & 1 deletion src/providers/reader-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class ReaderSync extends Reader<EntryItem[]> {

return entries.map<EntryItem>(this.transform, this);
} catch (err) {
if (this.isEnoentCodeError(err)) {
if (this.isEnoentCodeError(err as NodeJS.ErrnoException)) {
return [];
}

Expand Down
20 changes: 10 additions & 10 deletions src/providers/reader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('Providers → Reader', () => {
const reader = getReader({ markDirectories: true });
const entry = tests.getDirectoryEntry(false /** dot */, false /** isSymbolicLink */);

const expected: string = 'fixtures/directory/';
const expected = 'fixtures/directory/';

const actual = reader.transform(entry);

Expand All @@ -126,8 +126,8 @@ describe('Providers → Reader', () => {
const reader = getReader({ markDirectories: true, absolute: true });
const entry = tests.getDirectoryEntry(false /** dot */, false /** isSymbolicLink */);

const fullpath: string = path.join(process.cwd(), 'fixtures/directory/');
const expected: string = pathUtil.normalize(fullpath);
const fullpath = path.join(process.cwd(), 'fixtures/directory/');
const expected = pathUtil.normalize(fullpath);

const actual = reader.transform(entry);

Expand All @@ -138,7 +138,7 @@ describe('Providers → Reader', () => {
const reader = getReader({ markDirectories: true });
const entry = tests.getFileEntry(false /** dot */);

const expected: string = 'fixtures/file.txt';
const expected = 'fixtures/file.txt';

const actual = reader.transform(entry);

Expand All @@ -149,7 +149,7 @@ describe('Providers → Reader', () => {
const reader = getReader();
const entry = tests.getDirectoryEntry(false /** dot */, false /** isSymbolicLink */);

const expected: string = 'fixtures/directory';
const expected = 'fixtures/directory';

const actual = reader.transform(entry);

Expand All @@ -162,8 +162,8 @@ describe('Providers → Reader', () => {
const reader = getReader({ absolute: true });
const entry = tests.getFileEntry(false /** dot */);

const fullpath: string = path.join(process.cwd(), 'fixtures/file.txt');
const expected: string = pathUtil.normalize(fullpath);
const fullpath = path.join(process.cwd(), 'fixtures/file.txt');
const expected = pathUtil.normalize(fullpath);

const actual = reader.transform(entry);

Expand All @@ -174,7 +174,7 @@ describe('Providers → Reader', () => {
const reader = getReader();
const entry = tests.getFileEntry(false /** dot */);

const expected: string = 'fixtures/file.txt';
const expected = 'fixtures/file.txt';

const actual = reader.transform(entry);

Expand All @@ -187,7 +187,7 @@ describe('Providers → Reader', () => {
const reader = getReader({ transform: () => 'cake' });
const entry = tests.getDirectoryEntry(false /** dot */, false /** isSymbolicLink */);

const expected: string = 'cake';
const expected = 'cake';

const actual = reader.transform(entry);

Expand All @@ -198,7 +198,7 @@ describe('Providers → Reader', () => {
const reader = getReader();
const entry = tests.getDirectoryEntry(false /** dot */, false /** isSymbolicLink */);

const expected: string = 'fixtures/directory';
const expected = 'fixtures/directory';

const actual = reader.transform(entry);

Expand Down
Loading

0 comments on commit 7bffb0c

Please sign in to comment.