Skip to content

Commit

Permalink
chore(prettier): Add prettier, pr template (#3)
Browse files Browse the repository at this point in the history
* add prettier

* add prettier

* add max-len

* add pr template

* no semi

* add lint step
  • Loading branch information
alvinsj authored Jun 8, 2024
1 parent 0a768d1 commit 71b2853
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ module.exports = {
'warn',
{ allowConstantExport: true },
],
'max-len': ['error', { code: 100 }],
'no-console': 'error',
'semi': ['error', 'never']
},
}
17 changes: 17 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Story: ...

1. Why this change is required?
- ...
2. What problem does it solve?
- ...

## Implementation
1.
2.
3.

## Checklist
- [x] Fulfilled specs
- [x] Ensured code is readable
- [x] Consistency in architecture
- [x] Added Test
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ jobs:
with:
node-version: '20.x'
- run: npm ci
- run: npm run lint
- run: npm run test
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"arrowParens": "avoid",
"printWidth": 100
}
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"happy-dom": "^14.12.0",
"prettier": "^3.3.1",
"typescript": "^5.2.2",
"vite": "^5.2.0",
"vitest": "^1.6.0",
Expand Down
23 changes: 12 additions & 11 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@

import { render } from '@testing-library/react';
import App from './App';
import { test, expect } from 'vitest'
import { render } from '@testing-library/react'
import App from './App'

it('runs vitest', () => {
expect(1).toBe(1);
});
test('runs vitest', () => {
expect(1).toBe(1)
})

it('renders text', () => {
const wrapper = render(<App />);
expect(wrapper).toBeTruthy();
test('renders text', () => {
const wrapper = render(<App />)
expect(wrapper).toBeTruthy()

const { getByText } = wrapper;
expect(getByText('Vite + React')).toBeTruthy();
});
const { getByText } = wrapper
expect(getByText('Vite + React')).toBeTruthy()
})
42 changes: 21 additions & 21 deletions src/lib/pkce.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import { Sha256 } from '@aws-crypto/sha256-js';
import { Sha256 } from '@aws-crypto/sha256-js'

export const toSha256 = async (data: string): Promise<Uint8Array> => {
if (!data) throw new Error('data is required');
if (!data) throw new Error('data is required')

const hash = new Sha256();
hash.update(data);
const hash = new Sha256()
hash.update(data)

const hashed = await hash.digest();
return hashed;
const hashed = await hash.digest()
return hashed
}

// refer to base64url-encoding in RFC 7636
// https://datatracker.ietf.org/doc/html/rfc7636#appendix-A
export const toBase64Url = (bytes: Uint8Array) => {
if (bytes.length === 0) throw new Error('bytes must not be empty');

const charCodes = Array.from(bytes);
let str = btoa(String.fromCharCode.apply(null, charCodes));
str = str.split('=')[0];
str = str.replace(/\+/g, '-');
str = str.replace(/\//g, '_');
return str;
if (bytes.length === 0) throw new Error('bytes must not be empty')

const charCodes = Array.from(bytes)
let str = btoa(String.fromCharCode.apply(null, charCodes))
str = str.split('=')[0]
str = str.replace(/\+/g, '-')
str = str.replace(/\//g, '_')
return str
}

// refer to random string generation in RFC 7636
// https://datatracker.ietf.org/doc/html/rfc7636#section-4.1
export const createRandomString = (length: number = 34): string => {
if (length === 0) throw new Error('length must be greater than 0');
if (length === 0) throw new Error('length must be greater than 0')

const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
let randomString = '';
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~'
let randomString = ''
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
randomString += charset[randomIndex];
const randomIndex = Math.floor(Math.random() * charset.length)
randomString += charset[randomIndex]
}
return randomString;
return randomString
}

export const createPKCECodeChallenge = async (codeVerifier: string): string => {
const hashed: Uint8Array = await toSha256(codeVerifier)
const codeChallenge = toBase64Url(hashed)
return codeChallenge;
return codeChallenge
}

0 comments on commit 71b2853

Please sign in to comment.