Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRIVIAL: use ESLint instead of TSLint #233

Merged
merged 31 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2ea218f
build(package): replace TSLint by ESLint
mrmlnc Sep 21, 2019
72fa5d0
style: fix `ban-types` rule
mrmlnc Sep 30, 2019
9a755f4
style: fix `explicit-function-return-type` rule
mrmlnc Sep 30, 2019
ad7afae
style: fix `generic-type-naming` rule
mrmlnc Sep 30, 2019
5363bd4
style: fix `member-ordering` rule
mrmlnc Sep 30, 2019
88367f9
style: fix `no-extra-parens` rule
mrmlnc Sep 30, 2019
57425a0
style: fix `no-unnecessary-condition` rule
mrmlnc Sep 30, 2019
16a9803
style: fix `no-explicit-any` rule
mrmlnc Sep 30, 2019
c5ac139
style: fix `prefer-includes` rule
mrmlnc Sep 30, 2019
1ce7952
style: fix `import/order` rule
mrmlnc Sep 30, 2019
b9e594c
style: fix `no-unused-expressions` rule
mrmlnc Sep 30, 2019
97bd53c
style: fix `no-useless-escape` rule
mrmlnc Sep 30, 2019
5bb3e0d
style: fix `custom-error-definition` rule
mrmlnc Sep 30, 2019
5855ce1
style: fix `padding-line-between-statements` rule
mrmlnc Sep 30, 2019
2aa6fe0
style: fix `unicorn/prefer-spread` rule
mrmlnc Sep 30, 2019
5540cfe
style: fix `import/first` rule
mrmlnc Sep 30, 2019
38aecef
style: fix `require-array-sort-compare` rule
mrmlnc Sep 30, 2019
e63b0cb
style: fix `capitalized-comments` rule
mrmlnc Sep 30, 2019
1858f51
style: fix `no-magic-numbers` rule
mrmlnc Sep 30, 2019
c06f89f
style: fix `consistent-type-definitions` rule
mrmlnc Sep 30, 2019
bfc3b67
style: fix `no-redeclare` rule
mrmlnc Oct 1, 2019
cbcabd0
style: fix `unicorn/import-index` rule
mrmlnc Oct 1, 2019
376b8fa
style(benchmark): rename `getMeasures` → `formatMeasures`
mrmlnc Oct 1, 2019
4a6c244
style: fix `consistent-type-assertions` rule
mrmlnc Oct 1, 2019
027dab5
style: fix `unicorn/prevent-abbreviations` rule
mrmlnc Oct 1, 2019
89266ef
style: fix `strict-boolean-expressions` rule
mrmlnc Oct 1, 2019
abdf027
style: fix `no-require-imports` rule
mrmlnc Oct 1, 2019
c59673d
style: fix `no-misused-promises` rule
mrmlnc Oct 1, 2019
ced18d3
build(package): bump dependencies
mrmlnc Oct 1, 2019
85cb787
refactor(benchmark): use an array directly
mrmlnc Oct 1, 2019
1e0d0c0
style: fix some style issues after review
mrmlnc Oct 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "mrmlnc"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ npm-debug.log*
node_modules/

# Compiled and temporary files
.eslintcache
.tmp/
.benchmark/
out/
Expand Down
7 changes: 5 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
.gitignore
.vsts
tsconfig.json
tslint.json
.eslintrc.json

# Builded files
# Log & Cache files
.eslintcache

# Build files
out/benchmark
out/tests
out/**/*.js.map
Expand Down
31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,42 @@
"implementation"
],
"devDependencies": {
"@nodelib/fs.macchiato": "^1.0.0",
"@nodelib/fs.macchiato": "^1.0.1",
"@types/compute-stdev": "^1.0.0",
"@types/easy-table": "^0.0.32",
"@types/execa": "^0.9.0",
"@types/glob": "^7.1.1",
"@types/glob-parent": "^5.1.0",
"@types/merge2": "^1.1.4",
"@types/micromatch": "^3.1.0",
"@types/minimist": "^1.2.0",
"@types/mocha": "^5.2.7",
"@types/node": "^12.0.10",
"@types/node": "^12.7.8",
"@types/rimraf": "^2.0.2",
"@types/sinon": "^7.0.13",
"@types/sinon": "^7.5.0",
"compute-stdev": "^1.0.0",
"easy-table": "^1.1.1",
"execa": "^1.0.0",
"fast-glob": "^3.0.2",
"eslint": "^6.5.1",
"eslint-config-mrmlnc": "^1.0.1",
"execa": "^2.0.4",
"fast-glob": "^3.0.4",
"glob": "^7.1.4",
"minimist": "^1.2.0",
"mocha": "^6.1.4",
"rimraf": "^2.6.3",
"sinon": "^7.3.2",
"mocha": "^6.2.1",
"rimraf": "^3.0.0",
"sinon": "^7.5.0",
"tiny-glob": "^0.2.6",
"tslint": "^5.18.0",
"tslint-config-mrmlnc": "^2.1.0",
"typescript": "^3.5.2"
"typescript": "^3.6.3"
},
"dependencies": {
"@nodelib/fs.stat": "^2.0.1",
"@nodelib/fs.walk": "^1.2.1",
"@nodelib/fs.stat": "^2.0.2",
"@nodelib/fs.walk": "^1.2.3",
"glob-parent": "^5.1.0",
"merge2": "^1.2.3",
"merge2": "^1.3.0",
"micromatch": "^4.0.2"
},
"scripts": {
"clean": "rimraf out",
"lint": "tslint \"src/**/*.ts\" -p . -t stylish",
"lint": "eslint \"src/**/*.ts\" --cache",
"compile": "tsc",
"test": "mocha \"out/**/*.spec.js\" -s 0",
"smoke": "mocha \"out/**/*.smoke.js\" -s 0",
Expand Down
27 changes: 16 additions & 11 deletions src/benchmark/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import minimist = require('minimist');
import * as minimist from 'minimist';

import * as logger from './logger';
import Runner, { RunnerOptions } from './runner';
import * as utils from './utils';

interface Arguments extends RunnerOptions {
const PROCESS_FIRST_ARGUMENT_INDEX = 2;
const DEFAULT_BENCHMARK_LAUNCHES = 10;
const DEFAULT_BENCHMARK_MAX_STDEV = 3;
const DEFAULT_BENCHMARK_RETRIES = 5;

type Arguments = RunnerOptions & {
basedir: string;
}
};

const defaultArgv: Arguments = {
basedir: '.',
type: process.env.BENCHMARK_TYPE || 'product',
mode: process.env.BENCHMARK_MODE || 'async',
pattern: process.env.BENCHMARK_PATTERN || '*',
launches: utils.getEnvAsInteger('BENCHMARK_LAUNCHES') || 10,
maxStdev: utils.getEnvAsInteger('BENCHMARK_MAX_STDEV') || 3,
retries: utils.getEnvAsInteger('BENCHMARK_RETRIES') || 5,
options: utils.getEnvAsObject('BENCHMARK_OPTIONS') || {}
type: utils.getEnvironmentAsString('BENCHMARK_TYPE', 'product'),
mode: utils.getEnvironmentAsString('BENCHMARK_MODE', 'async'),
pattern: utils.getEnvironmentAsString('BENCHMARK_PATTERN', '*'),
launches: utils.getEnvironmentAsInteger('BENCHMARK_LAUNCHES', DEFAULT_BENCHMARK_LAUNCHES),
maxStdev: utils.getEnvironmentAsInteger('BENCHMARK_MAX_STDEV', DEFAULT_BENCHMARK_MAX_STDEV),
retries: utils.getEnvironmentAsInteger('BENCHMARK_RETRIES', DEFAULT_BENCHMARK_RETRIES),
options: utils.getEnvironmentAsObject('BENCHMARK_OPTIONS', {})
};

const argv = minimist<Arguments>(process.argv.slice(2), {
const argv = minimist<Arguments>(process.argv.slice(PROCESS_FIRST_ARGUMENT_INDEX), {
default: defaultArgv
});

Expand Down
14 changes: 9 additions & 5 deletions src/benchmark/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { SuitePackResult } from './runner';
import { SuitePackResult, SuitePackMeasures } from './runner';

const FRACTION_DIGITS = 3;

export default class Reporter {
constructor(private readonly _results: SuitePackResult) { }
Expand All @@ -20,16 +22,18 @@ export default class Reporter {
}

private _formatMeasures(): string {
return Object.keys(this._results.measures).map(this._formatMeasure, this).join(' | ');
const keys = Object.keys(this._results.measures) as Array<keyof SuitePackMeasures>;

return keys.map(this._formatMeasure, this).join(' | ');
}

private _formatMeasure(name: string): string {
private _formatMeasure(name: keyof SuitePackMeasures): string {
const data = this._results.measures[name];

return [
'(' + name.toUpperCase() + ')',
this._formatValue(data.average, data.units, 3),
'±' + this._formatValue(data.stdev, '%', 3)
this._formatValue(data.average, data.units, FRACTION_DIGITS),
'±' + this._formatValue(data.stdev, '%', FRACTION_DIGITS)
].join(' ');
}

Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Benchmark → Runner', () => {

describe('.suite', () => {
it('should returns measures', () => {
const runner = new RunnerFakeProcess('basedir', {} as RunnerOptions);
const runner = new RunnerFakeProcess('basedir', runnerOptions);

const expected: SuiteMeasures = {
matches: 1,
Expand All @@ -53,7 +53,7 @@ describe('Benchmark → Runner', () => {
});

it('should throw error', () => {
const runner = new RunnerFakeProcessError('basedir', {} as RunnerOptions);
const runner = new RunnerFakeProcessError('basedir', runnerOptions);

assert.throws(() => runner.suite('suitePath'), /Ops! Broken suite run\./);
});
Expand Down
31 changes: 17 additions & 14 deletions src/benchmark/runner.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import * as fs from 'fs';
import * as path from 'path';

import execa = require('execa');

import { Options } from '../settings';
import Reporter from './reporter';
import * as utils from './utils';

export interface RunnerOptions {
import execa = require('execa'); // eslint-disable-line @typescript-eslint/no-require-imports

export type RunnerOptions = {
type: string;
mode: string;
pattern: string;
launches: number;
maxStdev: number;
retries: number;
options: Options;
}
};

export interface SuiteMeasures {
export type SuiteMeasures = {
matches: number;
time: number;
memory: number;
}
};

export interface Measure {
export type Measure = {
units: string;
raw: number[];
average: number;
stdev: number;
}
};

export interface SuitePackMeasures extends Record<string, Measure> {
export type SuitePackMeasures = {
time: Measure;
memory: Measure;
}
};

export interface SuitePackResult {
export type SuitePackResult = {
name: string;
errors: number;
entries: number;
retries: number;
measures: SuitePackMeasures;
}
};

export default class Runner {
constructor(private readonly _basedir: string, private readonly _options: RunnerOptions) { }
Expand All @@ -54,14 +54,17 @@ export default class Runner {
* Runs a single suite in the child process and returns the measurements of his work.
*/
public suite(suitePath: string): SuiteMeasures {
const env: NodeJS.ProcessEnv = {
const environment: NodeJS.ProcessEnv = {
NODE_ENV: 'production',
BENCHMARK_BASE_DIR: this._basedir,
BENCHMARK_PATTERN: this._options.pattern,
BENCHMARK_OPTIONS: JSON.stringify(this._options.options)
};

const stdout = this.execNodeProcess([suitePath], { env, extendEnv: true });
// eslint-disable-next-line unicorn/prevent-abbreviations
const execaOptions: execa.SyncOptions = { env: environment, extendEnv: true };

const stdout = this.execNodeProcess([suitePath], execaOptions);

try {
return JSON.parse(stdout) as SuiteMeasures;
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/suites/product/async/fast-glob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';

import * as glob from '../../../../index';
import * as glob from '../../../..';
import * as utils from '../../../utils';

const options: glob.Options = {
Expand All @@ -14,7 +14,7 @@ glob(process.env.BENCHMARK_PATTERN as string, options)
.then((matches) => {
const memory = utils.getMemory();
const time = utils.timeEnd(timeStart);
const measures = utils.getMeasures(matches.length, time, memory);
const measures = utils.formatMeasures(matches.length, time, memory);

console.info(measures);
})
Expand Down
6 changes: 3 additions & 3 deletions src/benchmark/suites/product/async/node-glob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';

import glob = require('glob');
import * as glob from 'glob';

import * as utils from '../../../utils';

Expand All @@ -14,13 +14,13 @@ const options: glob.IOptions = {
const timeStart = utils.timeStart();

glob(process.env.BENCHMARK_PATTERN as string, options, (error, matches) => {
if (error) {
if (error !== null) {
process.exit(0);
}

const memory = utils.getMemory();
const time = utils.timeEnd(timeStart);
const measures = utils.getMeasures(matches.length, time, memory);
const measures = utils.formatMeasures(matches.length, time, memory);

console.info(measures);
});
6 changes: 3 additions & 3 deletions src/benchmark/suites/product/async/tiny-glob.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as path from 'path';

import glob = require('tiny-glob');

import * as utils from '../../../utils';

import glob = require('tiny-glob'); // eslint-disable-line @typescript-eslint/no-require-imports

const options = {
cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string),
flush: true
Expand All @@ -15,7 +15,7 @@ glob(process.env.BENCHMARK_PATTERN as string, options)
.then((matches) => {
const memory = utils.getMemory();
const time = utils.timeEnd(timeStart);
const measures = utils.getMeasures(matches.length, time, memory);
const measures = utils.formatMeasures(matches.length, time, memory);

console.info(measures);
})
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/suites/product/stream/fast-glob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';

import * as glob from '../../../../index';
import * as glob from '../../../..';
import * as utils from '../../../utils';

const options: glob.Options = {
Expand All @@ -20,7 +20,7 @@ stream.on('data', (entry: string) => entries.push(entry));
stream.once('end', () => {
const memory = utils.getMemory();
const time = utils.timeEnd(timeStart);
const measures = utils.getMeasures(Array.from(entries).length, time, memory);
const measures = utils.formatMeasures(entries.length, time, memory);

console.info(measures);
});
4 changes: 2 additions & 2 deletions src/benchmark/suites/product/sync/fast-glob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';

import * as glob from '../../../../index';
import * as glob from '../../../..';
import * as utils from '../../../utils';

const options: glob.Options = {
Expand All @@ -14,7 +14,7 @@ try {
const matches = glob.sync(process.env.BENCHMARK_PATTERN as string, options);
const memory = utils.getMemory();
const time = utils.timeEnd(timeStart);
const measures = utils.getMeasures(matches.length, time, memory);
const measures = utils.formatMeasures(matches.length, time, memory);

console.info(measures);
} catch {
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/suites/product/sync/node-glob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';

import glob = require('glob');
import * as glob from 'glob';

import * as utils from '../../../utils';

Expand All @@ -17,7 +17,7 @@ try {
const matches = glob.sync(process.env.BENCHMARK_PATTERN as string, options);
const memory = utils.getMemory();
const time = utils.timeEnd(timeStart);
const measures = utils.getMeasures(matches.length, time, memory);
const measures = utils.formatMeasures(matches.length, time, memory);

console.info(measures);
} catch {
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/suites/regression/async/fast-glob-current.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';

import * as glob from '../../../../index';
import * as glob from '../../../..';
import * as utils from '../../../utils';

const options: glob.Options = {
Expand All @@ -15,7 +15,7 @@ glob(process.env.BENCHMARK_PATTERN as string, options)
.then((matches) => {
const memory = utils.getMemory();
const time = utils.timeEnd(timeStart);
const measures = utils.getMeasures(matches.length, time, memory);
const measures = utils.formatMeasures(matches.length, time, memory);

console.info(measures);
})
Expand Down
Loading