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 20 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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"@types/sinon": "^7.0.13",
"compute-stdev": "^1.0.0",
"easy-table": "^1.1.1",
"eslint": "^6.3.0",
"eslint-config-mrmlnc": "^1.0.0",
"execa": "^1.0.0",
"fast-glob": "^3.0.2",
"glob": "^7.1.4",
Expand All @@ -43,9 +45,7 @@
"rimraf": "^2.6.3",
"sinon": "^7.3.2",
"tiny-glob": "^0.2.6",
"tslint": "^5.18.0",
"tslint-config-mrmlnc": "^2.1.0",
"typescript": "^3.5.2"
"typescript": "^3.5.3"
},
"dependencies": {
"@nodelib/fs.stat": "^2.0.1",
Expand All @@ -56,7 +56,7 @@
},
"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
21 changes: 13 additions & 8 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 logger from './logger';
import Runner, { RunnerOptions } from './runner';
import * as utils from './utils';

interface Arguments extends RunnerOptions {
import minimist = require('minimist');

const PROCESS_FIRST_ARGUMENT_INDEX = 2;
const DEFAULT_BENCHMARK_LAUNCHES = 10;
const DEFAULT_BENCHMARK_MAX_STDEV = 3;
const DEFAULT_BENCHMARK_RETRIES = 5;

type Arguments = {
mrmlnc marked this conversation as resolved.
Show resolved Hide resolved
basedir: string;
}
} & RunnerOptions;

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,
launches: utils.getEnvAsInteger('BENCHMARK_LAUNCHES') || DEFAULT_BENCHMARK_LAUNCHES,
maxStdev: utils.getEnvAsInteger('BENCHMARK_MAX_STDEV') || DEFAULT_BENCHMARK_MAX_STDEV,
retries: utils.getEnvAsInteger('BENCHMARK_RETRIES') || DEFAULT_BENCHMARK_RETRIES,
options: utils.getEnvAsObject('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
6 changes: 4 additions & 2 deletions src/benchmark/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { SuitePackResult } from './runner';

const FRACTION_DIGITS = 3;

export default class Reporter {
constructor(private readonly _results: SuitePackResult) { }

Expand Down Expand Up @@ -28,8 +30,8 @@ export default class Reporter {

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
24 changes: 12 additions & 12 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');

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;
}
} & Record<string, Measure>;
mrmlnc marked this conversation as resolved.
Show resolved Hide resolved

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 Down
4 changes: 2 additions & 2 deletions src/benchmark/suites/product/async/node-glob.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as path from 'path';

import glob = require('glob');

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

import glob = require('glob');

const options: glob.IOptions = {
cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string),
nosort: true,
Expand Down
4 changes: 2 additions & 2 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');

const options = {
cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string),
flush: true
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/suites/product/stream/fast-glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.getMeasures([...entries].length, time, memory);

console.info(measures);
});
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,9 +1,9 @@
import * as path from 'path';

import glob = require('glob');

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

import glob = require('glob');

const options: glob.IOptions = {
cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string),
nosort: true,
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/suites/regression/async/fast-glob-previous.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as path from 'path';

import fg = require('fast-glob');

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

import fg = require('fast-glob');

const options: fg.Options = {
cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string),
unique: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.getMeasures([...entries].length, time, memory);

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

import fg = require('fast-glob');

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

import fg = require('fast-glob');

const options: fg.Options = {
cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string),
unique: false,
Expand All @@ -21,7 +21,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.getMeasures([...entries].length, time, memory);

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

import fg = require('fast-glob');

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

import fg = require('fast-glob');

const options: fg.Options = {
cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string),
unique: false,
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Benchmark → Utils', () => {
process.env.FG_TEST_ENV_OBJECT = '{ "value": true }';

process.hrtime = (() => [0, 1e7]) as NodeJS.HRTime;
process.memoryUsage = () => ({ external: 0, rss: 0, heapTotal: 0, heapUsed: 10 * 1024 * 1024 });
process.memoryUsage = () => ({ external: 0, rss: 0, heapTotal: 0, heapUsed: 10 * 1e6 });
});

after(() => {
Expand Down
18 changes: 11 additions & 7 deletions src/benchmark/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { SuiteMeasures } from './runner';

import stdev = require('compute-stdev');

import { SuiteMeasures } from './runner';
const NANOSECONDS_IN_SECOND = 1e9;
const MICROSECONDS_IN_SECOND = 1e6;
const BYTES_IN_MEGABYTE = 1e6;

export function convertHrtimeToMilliseconds(hrtime: [number, number]): number {
const nanoseconds = (hrtime[0] * 1e9) + hrtime[1];
const nanoseconds = hrtime[0] * NANOSECONDS_IN_SECOND;

return nanoseconds / 1e6;
return (nanoseconds + hrtime[1]) / MICROSECONDS_IN_SECOND;
}

export function convertBytesToMegaBytes(bytes: number): number {
return bytes / 1e6;
return bytes / MICROSECONDS_IN_SECOND;
}

export function timeStart(): [number, number] {
Expand All @@ -23,7 +27,7 @@ export function timeEnd(start: [number, number]): number {
}

export function getMemory(): number {
return process.memoryUsage().heapUsed / 1024 / 1024;
return process.memoryUsage().heapUsed / BYTES_IN_MEGABYTE;
}

export function getMeasures(matches: number, time: number, memory: number): string {
Expand All @@ -44,8 +48,8 @@ export function getEnvAsInteger(name: string): number | undefined {
return env ? parseInt(env, 10) : undefined;
}

export function getEnvAsObject(name: string): Object | undefined {
export function getEnvAsObject(name: string): object | undefined {
const env = process.env[name];

return env ? JSON.parse(env) as Object : undefined;
return env ? JSON.parse(env) as object : undefined;
}
Loading