diff --git a/.github/CONTRIBUTING.ko.md b/.github/CONTRIBUTING.ko.md index c8f167e..7a92eea 100644 --- a/.github/CONTRIBUTING.ko.md +++ b/.github/CONTRIBUTING.ko.md @@ -3,11 +3,23 @@ 커뮤니티의 모든 분들의 Contribution을 환영합니다. [영어](https://github.com/Rapiders/react-hooks/tree/main/.github/CONTRIBUTING.md)와 한국어 중 편한 언어를 사용하면 됩니다. +## 테스트 코드 정책 + +라이브러리의 품질을 보증하기위해 다음의 정책이 적용됩니다. +하나의 기능에 대해 + +1. branches의 coverage는 80%를 넘어야합니다. (추후 개선 100%로 변경예정) +2. functions의 coverage는 80%를 넘어야합니다. (추후 개선 100%로 변경예정) +3. lines는 반드시 100%여야합니다. + +해당 정책을 만족하지 못하는 경우 `git push`가 이뤄지지 않습니다. + ## Fork 1. 기여하고 싶은 경우 우선 이 레포지토리를 fork 합니다. -2. 작업이 완료되었다면 main 브랜치로 PR을 오픈합니다. -3. merge 되기 위해서는 반드시 maintainer 중 한 명이 이상의 approve를 받아야 합니다. +2. npm install을 진행합니다. +3. 작업이 완료되었다면 main 브랜치로 PR을 오픈합니다. +4. merge 되기 위해서는 반드시 maintainer 중 한 명이 이상의 approve를 받아야 합니다. ## Issue diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 22018e4..aff67a2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -3,11 +3,22 @@ We welcome contribution from everyone in the community. you can use English and [Korean](https://github.com/Rapiders/react-hooks/tree/main/.github/CONTRIBUTING.ko.md) +## Test Code Policy + +To ensure the quality of the library, the following policy is applied for each feature: + +1. Branch coverage must exceed 80%. +2. Function coverage must exceed 80%. +3. Line coverage must be 100%. + +If these requirements are not met, `git push` will not be allowed. + ## Fork 1. If you wish to contribute, first fork this repository. -2. Once your work is complete, open a PR to the main branch. -3. To be merged, it must receive at least one approval from a maintainer. +2. npm install +3. Once your work is complete, open a PR to the main branch. +4. To be merged, it must receive at least one approval from a maintainer. ## Issue diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 0000000..42706ac --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1 @@ +npm run test:coverage \ No newline at end of file diff --git a/jest.config.ts b/jest.config.ts index b29931e..2e43c2f 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -15,4 +15,11 @@ module.exports = { moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '', }), + coverageThreshold: { + 'src/**/*.{ts,tsx}': { + branches: 80, + functions: 80, + lines: 100, + }, + }, }; diff --git a/src/index.ts b/src/index.ts index 7410274..b0e0793 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,6 @@ import useAnimation from './useAnimation/useAnimation'; import useFocusAnimation from './useFocusAnimation/useFocusAnimation'; import useDragIndexCarousel from './useDragIndexCarousel/useDragIndexCarousel'; import useCarousel from './useCarousel/useCarousel'; -import useScrollRatio from './useScrollRatio'; import useInterval from './useInterval/useInterval'; import useAfterMountEffect from './useAfterMountEffect/useAfterMountEffect'; import useRadio from './useRadio/useRadio'; @@ -19,7 +18,6 @@ export { useFocusAnimation, useDragIndexCarousel, useCarousel, - useScrollRatio, useInterval, useAfterMountEffect, useRadio, diff --git a/src/useScrollRatio.ts b/src/useScrollRatio.ts deleted file mode 100644 index c581801..0000000 --- a/src/useScrollRatio.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { useRef, useState } from 'react'; - -let timer: NodeJS.Timeout | null; - -export default function useScrollRatio() { - const [scrollRatio, setScrollRatio] = useState(100); - const ref = useRef(null); - - const handleScroll = () => { - if (!timer) { - timer = setTimeout(() => { - timer = null; - - if (!ref.current) return; - - const { scrollTop, clientHeight, scrollHeight } = ref.current; - setScrollRatio(((scrollTop + clientHeight) / scrollHeight) * 100); - }, 200); - } - }; - - const moveToBottom = () => { - if (ref.current) ref.current.scrollTop = ref.current.scrollHeight; - setScrollRatio(100); - }; - - return { ref, scrollRatio, handleScroll, moveToBottom }; -}