Skip to content

Commit

Permalink
Add format script, format repo + tests, check format in ci (#128)
Browse files Browse the repository at this point in the history
* Add format + check to ci

* run formatting on testing and remove from ignore
  • Loading branch information
sodiray authored Oct 26, 2022
1 parent 76f453b commit 43d4b35
Show file tree
Hide file tree
Showing 18 changed files with 558 additions and 528 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/test-on-pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Test Pull Request
name: Check Pull Request
on:
pull_request:
branches: [master]
Expand All @@ -16,3 +16,12 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: yarn
- run: yarn test
check-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.x'
- run: yarn
- run: yarn format:check
1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

2 changes: 0 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"_docs": "https://prettier.io/docs/en/options.html",
"tabWidth": 2,
"tabs": false,
"semi": false,
"singleQuote": true,
"printWidth": 80,
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"test": "jest --coverage",
"check": "yarn lint && yarn test && yarn build",
"build": "yarn tsc --noEmit && yarn rollup -c",
"lint": "tslint -p tsconfig.json"
"lint": "tslint -p tsconfig.json",
"format": "prettier --write \"./**/*.ts\"",
"format:check": "prettier --check \"**/*.ts\" --ignore-unknown"
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.5.0",
Expand Down
10 changes: 5 additions & 5 deletions src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,12 @@ export const diff = <T>(
* If n > 0 items will shift n steps to the right
* If n < 0 items will shift n steps to the left
*/
export function shift<T>(arr: Array<T>, n: number) {
if (arr.length === 0) return arr;
export function shift<T>(arr: Array<T>, n: number) {
if (arr.length === 0) return arr

const shiftNumber = n % arr.length;
const shiftNumber = n % arr.length

if(shiftNumber === 0) return arr;
if (shiftNumber === 0) return arr

return [...arr.slice(-shiftNumber, arr.length), ...arr.slice(0, -shiftNumber)];
return [...arr.slice(-shiftNumber, arr.length), ...arr.slice(0, -shiftNumber)]
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export {
replace,
replaceOrAppend,
select,
shift,
sift,
sort,
sum,
unique,
shift
unique
} from './array'
export {
defer,
Expand Down
5 changes: 2 additions & 3 deletions src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ export const pick = <T extends Record<string, unknown>, TKeys extends keyof T>(
): Pick<T, TKeys> => {
if (!obj) return {} as Pick<T, TKeys>
return keys.reduce((acc, key) => {
if(obj.hasOwnProperty(key))
acc[key] = obj[key]
return acc;
if (obj.hasOwnProperty(key)) acc[key] = obj[key]
return acc
}, {} as Pick<T, TKeys>)
}

Expand Down
27 changes: 15 additions & 12 deletions src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ export const capitalize = (str: string): string => {
* camel('helloWorld') -> 'helloWorld'
*/
export const camel = (str: string): string => {
const parts = str
?.replace(/([A-Z])+/g, capitalize)
?.split(/(?=[A-Z])|[\.\-\s_]/)
.map(x => x.toLowerCase()) ?? []
const parts =
str
?.replace(/([A-Z])+/g, capitalize)
?.split(/(?=[A-Z])|[\.\-\s_]/)
.map(x => x.toLowerCase()) ?? []
if (parts.length === 0) return ''
if (parts.length === 1) return parts[0]
return parts.reduce((acc, part) => {
Expand All @@ -37,10 +38,11 @@ export const camel = (str: string): string => {
* snake('helloWord') -> 'hello_world'
*/
export const snake = (str: string): string => {
const parts = str
?.replace(/([A-Z])+/g, capitalize)
.split(/(?=[A-Z])|[\.\-\s_]/)
.map(x => x.toLowerCase()) ?? []
const parts =
str
?.replace(/([A-Z])+/g, capitalize)
.split(/(?=[A-Z])|[\.\-\s_]/)
.map(x => x.toLowerCase()) ?? []
if (parts.length === 0) return ''
if (parts.length === 1) return parts[0]
return parts.reduce((acc, part) => {
Expand All @@ -56,10 +58,11 @@ export const snake = (str: string): string => {
* dash('helloWord') -> 'hello-word'
*/
export const dash = (str: string): string => {
const parts = str
?.replace(/([A-Z])+/g, capitalize)
?.split(/(?=[A-Z])|[\.\-\s_]/)
.map(x => x.toLowerCase()) ?? []
const parts =
str
?.replace(/([A-Z])+/g, capitalize)
?.split(/(?=[A-Z])|[\.\-\s_]/)
.map(x => x.toLowerCase()) ?? []
if (parts.length === 0) return ''
if (parts.length === 1) return parts[0]
return parts.reduce((acc, part) => {
Expand Down
Loading

0 comments on commit 43d4b35

Please sign in to comment.