From 523e55926f79d68f41ffd829bd081ff144586e36 Mon Sep 17 00:00:00 2001 From: Minsoo Kim <57122180+minsoo-web@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:00:12 +0900 Subject: [PATCH] style(*): Apply eslint rule (#22) * chore: apply eslint rule for src/ files * chore: add eslint script for checking lint * chore: update typescript-eslint rule with error to warn * Update src/predicate/isNil.ts * Update src/predicate/isNotNil.ts * Update package.json --------- Co-authored-by: Sojin Park Co-authored-by: Sojin Park --- .eslintrc.js | 1 + package.json | 3 ++- src/array/groupBy.spec.ts | 2 +- src/array/sample.spec.ts | 1 - src/array/shuffle.spec.ts | 1 - src/array/uniqBy.ts | 1 - src/array/uniqWith.ts | 2 -- src/array/zip.ts | 8 ++++---- src/object/omitBy.spec.ts | 10 +++++----- src/object/pickBy.spec.ts | 12 ++++++------ src/predicate/isNil.ts | 2 +- src/predicate/isNotNil.ts | 2 +- 12 files changed, 21 insertions(+), 24 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f92f5c904..d3d8d741d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -28,6 +28,7 @@ module.exports = { curly: ['error', 'all'], eqeqeq: ['error', 'always', { null: 'ignore' }], + '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/no-empty-interface': 'off', '@typescript-eslint/explicit-function-return-type': 'off', diff --git a/package.json b/package.json index 4428b4953..12d279774 100644 --- a/package.json +++ b/package.json @@ -126,6 +126,7 @@ "scripts": { "prepack": "yarn build", "build": "tsup && ./.scripts/postbuild.sh", - "test": "vitest run --coverage --typecheck" + "test": "vitest run --coverage --typecheck", + "lint": "eslint ./src --ext .ts" } } diff --git a/src/array/groupBy.spec.ts b/src/array/groupBy.spec.ts index 288bbbcdd..1d9a31716 100644 --- a/src/array/groupBy.spec.ts +++ b/src/array/groupBy.spec.ts @@ -27,7 +27,7 @@ describe('groupBy', () => { }); it('should handle an empty array', () => { - const array: { category: string, name: string }[] = []; + const array: Array<{ category: string, name: string }> = []; const result = groupBy(array, item => item.category); diff --git a/src/array/sample.spec.ts b/src/array/sample.spec.ts index b037a102d..1141666f5 100644 --- a/src/array/sample.spec.ts +++ b/src/array/sample.spec.ts @@ -1,5 +1,4 @@ import { describe, expect, it } from 'vitest'; -import { partition } from './partition'; import { sample } from './sample'; describe('sample', () => { diff --git a/src/array/shuffle.spec.ts b/src/array/shuffle.spec.ts index 2e9aca66a..3a0aa69b3 100644 --- a/src/array/shuffle.spec.ts +++ b/src/array/shuffle.spec.ts @@ -1,5 +1,4 @@ import { describe, expect, it } from 'vitest'; -import { sample } from './sample'; import { shuffle } from './shuffle'; describe('shuffle', () => { diff --git a/src/array/uniqBy.ts b/src/array/uniqBy.ts index aa369b25a..05bc93172 100644 --- a/src/array/uniqBy.ts +++ b/src/array/uniqBy.ts @@ -1,4 +1,3 @@ -import { uniq } from "./uniq"; import { uniqWith } from "./uniqWith"; /** diff --git a/src/array/uniqWith.ts b/src/array/uniqWith.ts index 47a91bcf4..66572f06c 100644 --- a/src/array/uniqWith.ts +++ b/src/array/uniqWith.ts @@ -1,5 +1,3 @@ -import { uniq } from "./uniq"; - /** * The `uniqWith` function takes an array as its first argument and a 'comparator' function as the second. * diff --git a/src/array/zip.ts b/src/array/zip.ts index 4e8b7c500..3fb2733a4 100644 --- a/src/array/zip.ts +++ b/src/array/zip.ts @@ -19,10 +19,10 @@ * const result2 = zip(arr1, arr2, arr3); * // result2 will be [[1, 'a', true], [2, 'b', false], [3, 'c', undefined]] */ -export function zip(arr1: T[]): [T][]; -export function zip(arr1: T[], arr2: U[]): [T, U][]; -export function zip(arr1: T[], arr2: U[], arr3: V[]): [T, U, V][]; -export function zip(arr1: T[], arr2: U[], arr3: V[], arr4: W[]): [T, U, V, W][]; +export function zip(arr1: T[]): Array<[T]>; +export function zip(arr1: T[], arr2: U[]): Array<[T, U]>; +export function zip(arr1: T[], arr2: U[], arr3: V[]): Array<[T, U, V]>; +export function zip(arr1: T[], arr2: U[], arr3: V[], arr4: W[]): Array<[T, U, V, W]>; export function zip(...arrs: T[][]): T[][] { const result: T[][] = []; diff --git a/src/object/omitBy.spec.ts b/src/object/omitBy.spec.ts index e46b4fc75..952220fb8 100644 --- a/src/object/omitBy.spec.ts +++ b/src/object/omitBy.spec.ts @@ -4,35 +4,35 @@ import { omitBy } from './omitBy'; describe('omitBy', () => { it('should omit properties based on the predicate function', () => { const obj = { a: 1, b: 'omit', c: 3 }; - const shouldOmit = (value: number | string, key: string) => typeof value === 'string'; + const shouldOmit = (value: number | string) => typeof value === 'string'; const result = omitBy(obj, shouldOmit); expect(result).toEqual({ a: 1, c: 3 }); }); it('should return an empty object if all properties are omitted', () => { const obj = { a: 'omit', b: 'omit' }; - const shouldOmit = (value: string, key: string) => typeof value === 'string'; + const shouldOmit = (value: string) => typeof value === 'string'; const result = omitBy(obj, shouldOmit); expect(result).toEqual({}); }); it('should return the same object if no properties are omitted', () => { const obj = { a: 1, b: 2, c: 3 }; - const shouldOmit = (value: number, key: string) => typeof value === 'string'; + const shouldOmit = (value: number) => typeof value === 'string'; const result = omitBy(obj, shouldOmit); expect(result).toEqual(obj); }); it('should work with an empty object', () => { const obj = {}; - const shouldOmit = (value: never, key: string) => true; + const shouldOmit = (value: never) => value; const result = omitBy(obj, shouldOmit); expect(result).toEqual({}); }); it('should work with nested objects', () => { const obj = { a: 1, b: { nested: 'omit' }, c: 3 }; - const shouldOmit = (value: any, key: string) => key === 'b'; + const shouldOmit = (_: number | { nested: string }, key: string) => key === 'b'; const result = omitBy(obj, shouldOmit); expect(result).toEqual({ a: 1, c: 3 }); }); diff --git a/src/object/pickBy.spec.ts b/src/object/pickBy.spec.ts index 18a0b606d..ab35550f7 100644 --- a/src/object/pickBy.spec.ts +++ b/src/object/pickBy.spec.ts @@ -1,38 +1,38 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; import { pickBy } from './pickBy'; describe('pickBy', () => { it('should pick properties based on the predicate function', () => { const obj = { a: 1, b: 'pick', c: 3 }; - const shouldPick = (value: any, key: string) => typeof value === 'string'; + const shouldPick = (value: string | number) => typeof value === 'string'; const result = pickBy(obj, shouldPick); expect(result).toEqual({ b: 'pick' }); }); it('should return an empty object if no properties satisfy the predicate', () => { const obj = { a: 1, b: 2, c: 3 }; - const shouldPick = (value: any, key: string) => typeof value === 'string'; + const shouldPick = (value: number) => typeof value === 'string'; const result = pickBy(obj, shouldPick); expect(result).toEqual({}); }); it('should return the same object if all properties satisfy the predicate', () => { const obj = { a: 'pick', b: 'pick', c: 'pick' }; - const shouldPick = (value: any, key: string) => typeof value === 'string'; + const shouldPick = (value: string) => typeof value === 'string'; const result = pickBy(obj, shouldPick); expect(result).toEqual(obj); }); it('should work with an empty object', () => { const obj = {}; - const shouldPick = (value: any, key: string) => true; + const shouldPick = (value: never) => value; const result = pickBy(obj, shouldPick); expect(result).toEqual({}); }); it('should work with nested objects', () => { const obj = { a: 1, b: { nested: 'pick' }, c: 3 }; - const shouldPick = (value: any, key: string) => key === 'b'; + const shouldPick = (value: number | { nested: string }, key: string) => key === 'b'; const result = pickBy(obj, shouldPick); expect(result).toEqual({ b: { nested: 'pick' } }); }); diff --git a/src/predicate/isNil.ts b/src/predicate/isNil.ts index 19406396e..9fbf91019 100644 --- a/src/predicate/isNil.ts +++ b/src/predicate/isNil.ts @@ -18,5 +18,5 @@ * const result3 = isNil(value3); // false */ export function isNil(x: unknown): x is null | undefined { - return x == null || x == undefined; + return x === null || x === undefined; } \ No newline at end of file diff --git a/src/predicate/isNotNil.ts b/src/predicate/isNotNil.ts index be3dbae31..25f3272ed 100644 --- a/src/predicate/isNotNil.ts +++ b/src/predicate/isNotNil.ts @@ -14,5 +14,5 @@ * // result will be [1, 3] */ export function isNotNil(x: T | null | undefined): x is T { - return x != null && x != undefined; + return x !== null && x !== undefined; }