Skip to content

Commit

Permalink
feat(build): update eslint config, remove tslint plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jul 10, 2021
1 parent 08ac252 commit d55efc5
Show file tree
Hide file tree
Showing 20 changed files with 441 additions and 662 deletions.
402 changes: 402 additions & 0 deletions .eslintrc.js

Large diffs are not rendered by default.

427 changes: 0 additions & 427 deletions config/eslint.json

This file was deleted.

3 changes: 1 addition & 2 deletions config/rollup.js
Expand Up @@ -102,7 +102,6 @@ const bundle = {
namedExports,
}),
eslint({
configFile: join('.', 'config', 'eslint.json'),
exclude: [
join('node_modules', '**'),
join('src', 'resource'),
Expand All @@ -114,7 +113,7 @@ const bundle = {
join('test', '**', '*.ts'),
],
throwOnError: true,
useEslintrc: false,
useEslintrc: true,
}),
typescript({
cacheRoot: join(targetPath, 'cache', 'rts2'),
Expand Down
4 changes: 2 additions & 2 deletions docs/api/js-utils.setorpush.md
Expand Up @@ -9,7 +9,7 @@ Set a map key to a new array or push to the existing value.
<b>Signature:</b>

```typescript
export declare function setOrPush<TKey, TVal>(map: Map<TKey, ReadonlyArray<TVal>>, key: TKey, val: TVal | ReadonlyArray<TVal>): void;
export declare function setOrPush<TKey, TVal>(map: Map<TKey, ReadonlyArray<TVal>>, key: TKey, val: TVal | ReadonlyArray<TVal>): Map<TKey, ReadonlyArray<TVal>>;
```

## Parameters
Expand All @@ -22,5 +22,5 @@ export declare function setOrPush<TKey, TVal>(map: Map<TKey, ReadonlyArray<TVal>

<b>Returns:</b>

void
Map&lt;TKey, ReadonlyArray&lt;TVal&gt;&gt;

7 changes: 0 additions & 7 deletions package.json
Expand Up @@ -59,19 +59,12 @@
"rollup-plugin-node-externals": "2.2.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-tslint": "0.2.2",
"rollup-plugin-typescript2": "0.30.0",
"rollup-plugin-yaml": "2.0.0",
"sinon": "11.1.1",
"sinon-chai": "3.7.0",
"source-map-support": "0.5.19",
"standard-version": "9.3.0",
"tslint": "6.1.3",
"tslint-clean-code": "0.2.10",
"tslint-consistent-codestyle": "1.16.0",
"tslint-etc": "1.13.10",
"tslint-microsoft-contrib": "6.2.0",
"tslint-sonarts": "1.9.0",
"typescript": "4.3.5"
},
"nyc": {
Expand Down
2 changes: 1 addition & 1 deletion src/ArrayMapper.ts
Expand Up @@ -52,7 +52,7 @@ export class ArrayMapper {
}
});

if (!result.has(this.rest)) {
if (result.has(this.rest) === false) {
result.set(this.rest, []);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Async.ts
Expand Up @@ -6,15 +6,15 @@ import { PredicateC0 } from './Predicate';
* @public
*/
export function defer(ms: number): Promise<void> {
return new Promise((res, rej) => {
return new Promise((res, _rej) => {
setTimeout(() => {
res();
}, ms);
});
}

export function deferValue<T>(ms: number, val: T): Promise<T> {
return new Promise((res, rej) => {
return new Promise((res, _rej) => {
setTimeout(() => {
res(val);
}, ms);
Expand All @@ -26,7 +26,7 @@ export function deferValue<T>(ms: number, val: T): Promise<T> {
* @public
*/
export function timeout<T>(ms: number, oper: Promise<T>): Promise<T> {
const limit = new Promise<T>((res, rej) => {
const limit = new Promise<T>((_res, rej) => {
setTimeout(() => {
rej(new TimeoutError());
}, ms);
Expand Down
2 changes: 1 addition & 1 deletion src/Checklist.ts
Expand Up @@ -29,7 +29,7 @@ export class Checklist<T> implements ChecklistOptions<T> {
}

if (this.mode === ChecklistMode.EXCLUDE) {
return !this.data.includes(value);
return (this.data.includes(value) === false);
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Env.ts
Expand Up @@ -5,6 +5,6 @@ const ENV_DEBUG = 'DEBUG';
*
* TODO: check variable value as well
*/
export function isDebug() {
export function isDebug(): boolean {
return Reflect.has(process.env, ENV_DEBUG);
}
10 changes: 7 additions & 3 deletions src/Map.ts
Expand Up @@ -59,7 +59,7 @@ export function getHead<TKey, TVal>(map: Map<TKey, ReadonlyArray<TVal>>, key: TK
* @public
*/
export function getHeadOrDefault<TKey, TVal>(map: Map<TKey, ReadonlyArray<Maybe<TVal>>>, key: TKey, defaultValue: TVal): TVal {
if (!map.has(key)) {
if (map.has(key) === false) {
return defaultValue;
}

Expand All @@ -84,21 +84,22 @@ export function getHeadOrDefault<TKey, TVal>(map: Map<TKey, ReadonlyArray<Maybe<
*
* @public
*/
export function setOrPush<TKey, TVal>(map: Map<TKey, ReadonlyArray<TVal>>, key: TKey, val: TVal | ReadonlyArray<TVal>) {
export function setOrPush<TKey, TVal>(map: Map<TKey, ReadonlyArray<TVal>>, key: TKey, val: TVal | ReadonlyArray<TVal>): Map<TKey, ReadonlyArray<TVal>> {
const prev = map.get(key);
if (doesExist(prev)) {
map.set(key, mergeArrays(prev, val));
} else {
map.set(key, toArray(val));
}
return map;
}

/**
* Merge the `source` map into the `target` map, replacing keys that already exist.
*
* @public
*/
export function mergeMap<TKey, TVal>(target: Map<TKey, TVal>, source: Map<TKey, TVal> | ReadonlyArray<[TKey, TVal]>) {
export function mergeMap<TKey, TVal>(target: Map<TKey, TVal>, source: Map<TKey, TVal> | ReadonlyArray<[TKey, TVal]>): Map<TKey, TVal> {
for (const [k, v] of source) {
target.set(k, v);
}
Expand Down Expand Up @@ -203,10 +204,13 @@ export function dictValuesToArrays<TVal>(map: MapLike<TVal>): Dict<Array<TVal>>
export function normalizeMap(map: MapLike<unknown>): Dict<Array<string>> {
const data: Dict<Array<string>> = {};
for (const [key, value] of makeMap(map)) {
// eslint-disable-next-line no-restricted-syntax
if (Array.isArray(value)) {
data[key] = value;
// eslint-disable-next-line no-restricted-syntax
} else if (typeof value === 'string') {
data[key] = [value];
// eslint-disable-next-line no-restricted-syntax
} else if (typeof value === 'number') {
data[key] = [value.toString()];
} else if (typeof value === 'object' && doesExist(value)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Maybe.ts
Expand Up @@ -22,7 +22,7 @@ export function isNone<T>(val: Maybe<T>): val is None {
}

export function isSome<T>(val: Maybe<T>): val is T {
return !isNone(val);
return isNone(val) === false;
}

/**
Expand All @@ -31,7 +31,7 @@ export function isSome<T>(val: Maybe<T>): val is T {
* @public
*/
export function doesExist<T>(val: Maybe<T>): val is T {
return !isNone(val);
return isNone(val) === false;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Reflect.ts
Expand Up @@ -11,7 +11,8 @@ type Method<TClass> = (this: TClass, ...args: Array<unknown>) => unknown;
*
* @public
*/
export function getConstructor(val: Reflectable) {
// eslint-disable-next-line @typescript-eslint/ban-types
export function getConstructor(val: Reflectable): Function {
return val.constructor;
}

Expand All @@ -36,6 +37,7 @@ export function getMethods<TValue extends Reflectable>(value: TValue): Set<Metho
}

const proto = Reflect.getPrototypeOf(value);
// eslint-disable-next-line no-restricted-syntax
if (proto !== value && doesExist(proto)) {
for (const m of getMethods(proto)) {
methods.add(m);
Expand All @@ -50,7 +52,7 @@ export function getMethods<TValue extends Reflectable>(value: TValue): Set<Metho
*
* @public
*/
export function constructorName(val: Reflectable) {
export function constructorName(val: Reflectable): string {
const proto = Reflect.getPrototypeOf(val);
if (isNone(proto)) {
throw new InvalidArgumentError('value has no prototype');
Expand Down
2 changes: 1 addition & 1 deletion src/Signal.ts
Expand Up @@ -3,7 +3,7 @@ export const SIGNAL_RESET: NodeJS.Signals = 'SIGINT';
export const SIGNAL_STOP: NodeJS.Signals = 'SIGTERM';

export function signal(...signals: Array<NodeJS.Signals>): Promise<NodeJS.Signals> {
return new Promise((res, rej) => {
return new Promise((res, _rej) => {
function handler(fired: NodeJS.Signals) {
for (const s of signals) {
process.removeListener(s, handler);
Expand Down
3 changes: 2 additions & 1 deletion src/String.ts
@@ -1,5 +1,6 @@
export const DEFAULT_TRIM = 8;

export function leftPad(val: string, min = 8, fill = '0'): string {
export function leftPad(val: string, min = DEFAULT_TRIM, fill = '0'): string {
if (val.length < min) {
const len = min - val.length;
const pre = Array(len).fill(fill).join('').slice(0, len);
Expand Down
2 changes: 1 addition & 1 deletion test/harness.ts
Expand Up @@ -12,7 +12,7 @@ sourceMapSupport.install({
/**
* This will break the whole test run if any test leaks an unhandled rejection.
*/
process.on('unhandledRejection', (reason, promise) => {
process.on('unhandledRejection', (reason, _promise) => {
// eslint-disable-next-line no-console
console.error('unhandled error during tests', reason);
process.exit(1);
Expand Down
1 change: 1 addition & 0 deletions test/utils/TestArray.ts
@@ -1,3 +1,4 @@
/* eslint-disable no-magic-numbers */
import { expect } from 'chai';
import { match, stub } from 'sinon';

Expand Down
5 changes: 3 additions & 2 deletions test/utils/TestMap.ts
@@ -1,3 +1,4 @@
/* eslint-disable no-magic-numbers */
import { expect } from 'chai';

import { NotFoundError } from '../../src/error/NotFoundError';
Expand All @@ -22,10 +23,10 @@ const mapValue = 'value';
const singleItem = new Map([[mapKey, mapValue]]);
const multiItem = new Map([
[mapKey, [mapValue]],
/* eslint-disable */
// eslint-disable-next-line no-null/no-null,@typescript-eslint/no-explicit-any
['nilKey', null as any],
// eslint-disable-next-line no-null/no-null
['nilValue', [null]],
/* eslint-enable */
]);

describe('map utils', async () => {
Expand Down
1 change: 1 addition & 0 deletions test/utils/TestMaybe.ts
@@ -1,3 +1,4 @@
/* eslint-disable no-magic-numbers */
import { expect } from 'chai';

import { NotFoundError } from '../../src/error/NotFoundError';
Expand Down
1 change: 1 addition & 0 deletions test/utils/TestString.ts
@@ -1,3 +1,4 @@
/* eslint-disable no-magic-numbers */
import { expect } from 'chai';

import { leftPad, trim } from '../../src/String';
Expand Down

0 comments on commit d55efc5

Please sign in to comment.