Skip to content

Commit

Permalink
style(*): Apply eslint rule (#22)
Browse files Browse the repository at this point in the history
* 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 <raon0211@gmail.com>
Co-authored-by: Sojin Park <raon0211@toss.im>
  • Loading branch information
3 people authored Jun 4, 2024
1 parent 9bde10a commit 523e559
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 24 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/array/groupBy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/array/sample.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { describe, expect, it } from 'vitest';
import { partition } from './partition';
import { sample } from './sample';

describe('sample', () => {
Expand Down
1 change: 0 additions & 1 deletion src/array/shuffle.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { describe, expect, it } from 'vitest';
import { sample } from './sample';
import { shuffle } from './shuffle';

describe('shuffle', () => {
Expand Down
1 change: 0 additions & 1 deletion src/array/uniqBy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { uniq } from "./uniq";
import { uniqWith } from "./uniqWith";

/**
Expand Down
2 changes: 0 additions & 2 deletions src/array/uniqWith.ts
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down
8 changes: 4 additions & 4 deletions src/array/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(arr1: T[]): [T][];
export function zip<T, U>(arr1: T[], arr2: U[]): [T, U][];
export function zip<T, U, V>(arr1: T[], arr2: U[], arr3: V[]): [T, U, V][];
export function zip<T, U, V, W>(arr1: T[], arr2: U[], arr3: V[], arr4: W[]): [T, U, V, W][];
export function zip<T>(arr1: T[]): Array<[T]>;
export function zip<T, U>(arr1: T[], arr2: U[]): Array<[T, U]>;
export function zip<T, U, V>(arr1: T[], arr2: U[], arr3: V[]): Array<[T, U, V]>;
export function zip<T, U, V, W>(arr1: T[], arr2: U[], arr3: V[], arr4: W[]): Array<[T, U, V, W]>;
export function zip<T>(...arrs: T[][]): T[][] {
const result: T[][] = [];

Expand Down
10 changes: 5 additions & 5 deletions src/object/omitBy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
Expand Down
12 changes: 6 additions & 6 deletions src/object/pickBy.spec.ts
Original file line number Diff line number Diff line change
@@ -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' } });
});
Expand Down
2 changes: 1 addition & 1 deletion src/predicate/isNil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/predicate/isNotNil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
* // result will be [1, 3]
*/
export function isNotNil<T>(x: T | null | undefined): x is T {
return x != null && x != undefined;
return x !== null && x !== undefined;
}

0 comments on commit 523e559

Please sign in to comment.