Skip to content

Commit

Permalink
style: migrate to eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Dec 18, 2023
1 parent f1f51da commit 0b150bc
Show file tree
Hide file tree
Showing 68 changed files with 1,999 additions and 307 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
"private": true,
"scripts": {
"clean": "rimraf packages/*/target packages/*/typings packages/*/buildcache packages/*/docs packages/*/coverage",
"prebuild": "tsc -b packages/facade/tsconfig.es5.json",
"_build": "yarn clean && yarn prebuild && yarn workspaces foreach -A --parallel --topological-dev --no-private --interlaced run build",
"lint": "yarn workspaces run lint",
"build": "npx zx-bulk-release --dry-run",
"lint": "yarn workspaces foreach -A --parallel --no-private --interlaced run lint",
"jest": "jest --runInBand --detectOpenHandles",
"test:report": "yarn test && yarn coveralls:push",
"test": "yarn lint && yarn jest",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"scripts": {
"test": "yarn lint && yarn jest",
"jest": "jest -w=1 --config=jest.config.json",
"lint": "tslint -p tsconfig.test.json src/**/*.ts",
"lint": "eslint -c src/test/lint/.eslintrc.json src",
"lint:fix": "yarn lint --fix",
"clean": "rimraf target typings buildcache",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn docs",
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/test/lint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": ["eslint-config-qiwi"],
"rules": {
}
}
4 changes: 2 additions & 2 deletions packages/cli/src/test/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {execSync} from 'child_process'
import {resolve} from 'path'
import {execSync} from 'node:child_process'
import {resolve} from 'node:path'

describe('masquer',() => {
it('applies @qiwi/masker to the input', () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/tslint.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"test": "yarn lint && yarn jest",
"jest": "jest -w=1 --config=jest.config.json",
"lint": "tslint -p tsconfig.test.json src/**/*.ts",
"lint": "eslint -c src/test/lint/.eslintrc.json src",
"lint:fix": "yarn lint --fix",
"clean": "rimraf target typings buildcache",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn docs",
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/main/ts/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const patchExecutor = (execHook: TExecutorHook, name: IMaskerPipeName) =>
if (ctx.pipeline.length === 0) {
ctx.pipeline = [createPipe('echo', (v: any) => v)]
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
ctx.context = undefined

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/main/ts/masker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {hook, unboxValue} from './utils'
export const createMasker = (_opts: IMaskerFactoryOpts = {}): IMasker => {
const _execute = (ctx: IMaskerOpts) =>
// NOTE unbox is enabled by default
hook(execute(ctx), (ctx.unbox ?? _opts.unbox) !== false ? unboxValue : v => v)
hook(execute(ctx), (ctx.unbox ?? _opts.unbox) === false ? v => v : unboxValue)

const masker = (value: any, opts: IRawContext = {}): Promise<any> => _execute({..._opts, ...opts, value})
masker.sync = (value: any, opts: IRawContext = {}): any => _execute({..._opts, ...opts, value, sync: true})
Expand Down
6 changes: 6 additions & 0 deletions packages/common/src/test/lint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["eslint-config-qiwi"],
"rules": {
"sonarjs/no-extra-arguments": "off"
}
}
9 changes: 4 additions & 5 deletions packages/common/src/test/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ describe('#getPipe', () => {
['raises an exception if not found', ['otherpipe', registry], undefined, new Error('Pipe not found: otherpipe')],
['supports options notation', [[pipe, opts], registry], {...pipe, opts}],
['named ref and options', [['pipe', opts], registry], {...pipe, opts}],
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
['boxed ref with no options', [['pipe'], registry], {...pipe, opts: {}}],
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
['undefined if pipe is not a function', [[undefined]], undefined, new Error('Pipe not found: undefined')],
]
Expand Down Expand Up @@ -172,7 +174,7 @@ describe('#execute', () => {

const striker = cp('striker', ({value}: IMaskerPipeInput) =>
(typeof value === 'string'
? {value: value.replace(/[^\s]/g, '*')}
? {value: value.replace(/\S/g, '*')}
: {value}))
const splitter = cp('splitter', ({value, execute, context, originPipeline}: IMaskerPipeInput) =>
(typeof value === 'object'
Expand All @@ -188,12 +190,9 @@ describe('#execute', () => {
})(value)
: {value}))

const registry = new Map()
registry.set(splitter.name, splitter)
registry.set(striker.name, striker)

it('masked output inherits proto of input', () => {
const error = new Error('1000')
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
error.baz = 'quxqux'
const value = {
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/test/ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('utils', () => {
describe('asArray', () => {
it('wraps non-array to array', () => {
expect(asArray({})).toEqual([{}])
expect(asArray(undefined)).toEqual([undefined])
expect(asArray()).toEqual([undefined])
})
it('returns array as is', () => {
expect(asArray([{}])).toEqual([{}])
Expand All @@ -26,7 +26,7 @@ describe('utils', () => {
})
it('returns undefined otherwise', () => {
expect(asRegExp(null)).toBeUndefined()
expect(asRegExp(undefined)).toBeUndefined()
expect(asRegExp()).toBeUndefined()
expect(asRegExp({})).toBeUndefined()
expect(asRegExp(1)).toBeUndefined()
})
Expand Down
3 changes: 0 additions & 3 deletions packages/common/tslint.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"test": "yarn lint && yarn jest",
"jest": "jest -w=1 --config=jest.config.json",
"lint": "tslint -p tsconfig.test.json src/**/*.ts",
"lint": "eslint -c src/test/lint/.eslintrc.json src",
"lint:fix": "yarn lint --fix",
"clean": "rimraf target typings buildcache",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn docs",
Expand Down
4 changes: 3 additions & 1 deletion packages/debug/src/main/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
IMaskerPipe, hook,
} from '@qiwi/masker-common'

export type {Debugger}


export const name: IMaskerPipeName = 'debug'

Expand Down Expand Up @@ -45,3 +45,5 @@ const exec = patchExecutor(withDebug, name)
export const pipe = createPipe(name, exec, exec)

export default pipe

export {type Debugger} from 'debug'
4 changes: 4 additions & 0 deletions packages/debug/src/test/lint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["eslint-config-qiwi"],
"rules": {}
}
3 changes: 0 additions & 3 deletions packages/debug/tslint.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/facade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"test": "yarn lint && yarn jest",
"jest": "jest -w=1 --config=jest.config.json",
"lint": "tslint -p tsconfig.test.json src/**/*.ts",
"lint": "eslint -c src/test/lint/.eslintrc.json src",
"lint:fix": "yarn lint --fix",
"clean": "rimraf target typings buildcache",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn docs",
Expand Down
6 changes: 6 additions & 0 deletions packages/facade/src/test/lint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["eslint-config-qiwi"],
"rules": {
"sonarjs/no-duplicate-string": "off"
}
}
4 changes: 2 additions & 2 deletions packages/facade/src/test/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('facade',() => {
it('example #1 (root)', () => {
const res = masker.sync({
secret: 'foo',
nested: {pans: [4111111111111111]},
nested: {pans: [4_111_111_111_111_111]},
foo: 'str with printed password=foo and smth else',
json: 'str with json inside {"secret":"bar"} {"4111111111111111":"bar"}',
}, {
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('facade',() => {
foo: 'bar',
foofoo: 'barbar',
baz: 'qux',
arr: [4111111111111111, 1234123412341234],
arr: [4_111_111_111_111_111, 1_234_123_412_341_234],
}, {
pipeline: ['schema'],
schema: {
Expand Down
3 changes: 0 additions & 3 deletions packages/facade/tslint.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"@swissquote/crafty-preset-jest": "^1.23.0",
"@types/jest": "^29.5.11",
"benchmark": "^2.1.4",
"eslint": "^8.56.0",
"eslint-config-qiwi": "^2.1.3",
"jest": "^29.7.0",
"rimraf": "^3.0.2",
"terser": "^5.26.0",
"ts-jest": "^29.1.1",
"tslint": "^6.1.3",
"tslint-config-qiwi": "^1.11.3",
"typedoc": "^0.25.4",
"typescript": "^5.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"test": "yarn lint && yarn jest",
"jest": "jest -w=1 --config=jest.config.json",
"lint": "tslint -p tsconfig.test.json src/**/*.ts",
"lint": "eslint -c src/test/lint/.eslintrc.json src",
"lint:fix": "yarn lint --fix",
"clean": "rimraf target typings buildcache",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn docs",
Expand Down
4 changes: 2 additions & 2 deletions packages/json/src/main/ts/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export const extractJsonEntries = (input: string): TExtractedEntry[] => {
}

// https://stackoverflow.com/a/3710506
export const checkJson = (str: string): boolean => /^[\],:{}\s]*$/.test(str.replace(/\\["\\\/bfnrtu]/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
export const checkJson = (str: string): boolean => /^[\s,:\]{}]*$/.test(str.replace(/\\["/\\bfnrtu]/g, '@').
replace(/"[^\n\r"\\]*"|true|false|null|-?\d+(?:\.\d*)?(?:[Ee][+-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))
4 changes: 4 additions & 0 deletions packages/json/src/test/lint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["eslint-config-qiwi"],
"rules": {}
}
6 changes: 3 additions & 3 deletions packages/json/src/test/ts/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ describe('#extractJsonStrings', () => {

expect(extractJsonEntries(input)).toEqual([
{
_value: '{\"foo\":\"bar\"}',
_value: '{"foo":"bar"}',
value: {foo: 'bar'},
end: 14,
start: 1,
},
{
_value: '{\"a\":{\"b\":\"{\\\"c\\\":\\\"d\\\"}\"}}',
_value: '{"a":{"b":"{\\"c\\":\\"d\\"}"}}',
value: {a: {b: '{"c":"d"}'}},
end: 46,
start: 19,
},
{
_value: '{\"foo\":\"baz\"}',
_value: '{"foo":"baz"}',
value: {foo: 'baz'},
end: 66,
start: 53,
Expand Down
3 changes: 0 additions & 3 deletions packages/json/tslint.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/limiter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"test": "yarn lint && yarn jest",
"jest": "jest -w=1 --config=jest.config.json",
"lint": "tslint -p tsconfig.test.json src/**/*.ts",
"lint": "eslint -c src/test/lint/.eslintrc.json src",
"lint:fix": "yarn lint --fix",
"clean": "rimraf target typings buildcache",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn docs",
Expand Down
2 changes: 1 addition & 1 deletion packages/limiter/src/main/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const name: IMaskerPipeName = 'limiter'
export const withLimiter = ({execute, opts: {pipeline, limit, duration}}: IMaskerPipeInput): IEnrichedExecutor => {
const _pipeline = pipeline || [plainPipe]
const _endsAt = duration ? Date.now() + duration : Number.POSITIVE_INFINITY
let _limit = limit !== undefined ? limit | 0 : Number.POSITIVE_INFINITY
let _limit = limit === undefined ? Number.POSITIVE_INFINITY : limit | 0

const _execute = enrichExecutor(<C extends IRawContext>(cxt: C): SyncGuard<IMaskerPipeInput, C> => {
const _cxt: IEnrichedContext = normalizeContext(cxt, _execute)
Expand Down
4 changes: 4 additions & 0 deletions packages/limiter/src/test/lint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["eslint-config-qiwi"],
"rules": {}
}
1 change: 1 addition & 0 deletions packages/limiter/src/test/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('limiter',() => {
expect(pipe.name).toBe(name)
})

// eslint-disable-next-line unicorn/consistent-function-scoping
const sleep = (n: number): string => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n)
const sleepPipe = createPipe('bar', ({value}: IMaskerPipeInput) => {
sleep(50)
Expand Down
1 change: 1 addition & 0 deletions packages/limiter/src/test/ts/readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('limiter', () => {

it('example #2', async() => {
let delay = 0
// eslint-disable-next-line unicorn/consistent-function-scoping
const sleep = (ms: number): Promise<void> => new Promise(resolve => setTimeout(resolve, ms))
const echoPipe = createPipe(
'echo',
Expand Down
3 changes: 0 additions & 3 deletions packages/limiter/tslint.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/pan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"test": "yarn lint && yarn jest",
"jest": "jest -w=1 --config=jest.config.json",
"lint": "tslint -p tsconfig.test.json src/**/*.ts",
"lint": "eslint -c src/test/lint/.eslintrc.json src",
"lint:fix": "yarn lint --fix",
"clean": "rimraf target typings buildcache",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn docs",
Expand Down
4 changes: 2 additions & 2 deletions packages/pan/src/main/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const name: IMaskerPipeName = 'pan'

export const pipe: IMaskerPipe = createPipe(name, ({value}: IMaskerPipeInput) => ({
value: (typeof value === 'string' || typeof value === 'number' || value instanceof String || value instanceof Number)
? value.toString().replace(/\d{13,19}|(\d{4}[\s\-]+){3}\d{4}([\s\-]*\d{3})?/g, v => {
const _v = v.replace(/[^\d]/g, '')
? value.toString().replace(/\d{13,19}|(\d{4}[\s-]+){3}\d{4}([\s-]*\d{3})?/g, v => {
const _v = v.replace(/\D/g, '')
return luhn(_v)
? `${_v.slice(0, 4)} **** **** ${_v.slice(-4)}`
: v
Expand Down
6 changes: 6 additions & 0 deletions packages/pan/src/test/lint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["eslint-config-qiwi"],
"rules": {
"sonarjs/no-duplicate-string": "off"
}
}
6 changes: 3 additions & 3 deletions packages/pan/src/test/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ describe('pan',() => {
'4324246524356541 4111111111111111 342gfdgdg 4111111111111111 ',
'4324246524356541 4111 **** **** 1111 342gfdgdg 4111 **** **** 1111 ',
],
[4111111111111111, '4111 **** **** 1111'],
[new Number(4111111111111111), '4111 **** **** 1111'],
[4_111_111_111_111_111, '4111 **** **** 1111'],
[Number(4_111_111_111_111_111), '4111 **** **** 1111'],
['4111111111111111', '4111 **** **** 1111'],
[new String('4111111111111111'), '4111 **** **** 1111'],
[String('4111111111111111'), '4111 **** **** 1111'],
['4111 1111 1111 1111', '4111 **** **** 1111'],
['4111-1111-1111-1111', '4111 **** **** 1111'],
[{}, {}],
Expand Down
3 changes: 0 additions & 3 deletions packages/pan/tslint.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/plain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"test": "yarn lint && yarn jest",
"jest": "jest -w=1 --config=jest.config.json",
"lint": "tslint -p tsconfig.test.json src/**/*.ts",
"lint": "eslint -c src/test/lint/.eslintrc.json src",
"lint:fix": "yarn lint --fix",
"clean": "rimraf target typings buildcache",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn docs",
Expand Down
4 changes: 4 additions & 0 deletions packages/plain/src/test/lint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["eslint-config-qiwi"],
"rules": {}
}
3 changes: 0 additions & 3 deletions packages/plain/tslint.json

This file was deleted.

6 changes: 5 additions & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"test": "yarn lint && yarn jest",
"jest": "jest -w=1 --config=jest.config.json",
"lint": "tslint -p tsconfig.test.json src/**/*.ts",
"lint": "eslint -c src/test/lint/.eslintrc.json src",
"lint:fix": "yarn lint --fix",
"clean": "rimraf target typings buildcache",
"build": "yarn build:es5 && yarn build:es6 && yarn build:ts && yarn docs",
Expand Down Expand Up @@ -49,6 +49,10 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"@qiwi/masker-pan": "workspaces:^*",
"@qiwi/masker-plain": "workspaces:^*",
"@qiwi/masker-secret-key": "workspaces:^*",
"@qiwi/masker-secret-value": "workspaces:^*",
"@qiwi/masker-strike": "workspaces:^*"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions packages/schema/src/main/ts/shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const shortCutExecute = ({context, schema, value, sync, execute}: IEnrich
}

return sync
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
? inject(_value, values as IMaskerPipeOutput[], keys as IMaskerPipeOutput[])
: Promise.all([Promise.all(values), Promise.all(keys)]).then(([values, keys]) => inject(_value, values, keys))
Expand Down
Loading

0 comments on commit 0b150bc

Please sign in to comment.