Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement format and linting ci/cd #148

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# exclude .js files from linting
/dist/
.eslintrc.cjs
15 changes: 11 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
diegoalzate marked this conversation as resolved.
Show resolved Hide resolved
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'plugin:@tanstack/eslint-plugin-query/recommended',
'prettier'
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
diegoalzate marked this conversation as resolved.
Show resolved Hide resolved
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
plugins: ['react-refresh', '@typescript-eslint'],
root: true,
rules: {
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@tanstack/query/exhaustive-deps': 'off',
diegoalzate marked this conversation as resolved.
Show resolved Hide resolved
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_ignored', ignoreRestSiblings: true },
],
},
};
35 changes: 35 additions & 0 deletions .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Check Formatting

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- develop
- main

concurrency:
# group runs by <name of the workflow>-<name of job>-<branch name>
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true

jobs:
formatting:
name: Check formatting
timeout-minutes: 2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Review formatting
run: pnpm format
36 changes: 36 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Linting

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- develop
- main

concurrency:
# group runs by <name of the workflow>-<name of job>-<branch name>
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true

jobs:
linting:
name: Check linting
timeout-minutes: 2
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Review linting
run: pnpm lint
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20
7 changes: 0 additions & 7 deletions .prettierrc

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
tabWidth: 2,
singleQuote: true,
quoteProps: 'consistent',
printWidth: 100,
};
24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
"scripts": {
"core:dev": "pnpm -r --filter core dev",
"core:build": "pnpm -r --filter core build",
"core:lint": "pnpm -r --filter core lint",
"core:format": "pnpm -r --filter core format",
"core:preview": "pnpm -r --filter core preview",
"berlin:dev": "pnpm -r --filter berlin dev",
"berlin:build": "pnpm -r --filter berlin build",
"berlin:lint": "pnpm -r --filter berlin lint",
"berlin:format": "pnpm -r --filter berlin format",
"berlin:preview": "pnpm -r --filter berlin preview"
"berlin:preview": "pnpm -r --filter berlin preview",
"format": "prettier --check \"packages/**/*.{ts,md}\"",
"format:fix": "prettier --write \"packages/**/*.{ts,md}\"",
"lint": "eslint ."
},
"keywords": [],
"author": "",
"license": "ISC",
"engines": {
"node": "^20"
},
"dependencies": {
"@hookform/resolvers": "^3.3.4",
Expand All @@ -36,13 +41,14 @@
"@tanstack/eslint-plugin-query": "^5.18.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"@vitejs/plugin-react": "^4.2.0",
"eslint": "^8.53.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"prettier": "3.1.0",
"prettier": "^3.1.1",
"typescript": "^5.2.2",
"vite": "^5.0.0",
"vite-plugin-node-polyfills": "^0.17.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/fetchEventCycles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function fetchEventCycles(eventId: string): Promise<GetCyclesResponse | nu
headers: {
'Content-Type': 'application/json',
},
}
},
);

if (!response.ok) {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/fetchForumQuestionStatistics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GetForumQuestionStatisticsResponse } from './types/ForumQuestionType';

async function fetchForumQuestionStatistics(
questionId: string
questionId: string,
): Promise<GetForumQuestionStatisticsResponse | null> {
try {
const response = await fetch(
Expand All @@ -11,7 +11,7 @@ async function fetchForumQuestionStatistics(
headers: {
'Content-Type': 'application/json',
},
}
},
);
if (!response.ok) {
throw new Error(`HTTP Error! Status: ${response.status}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/fetchRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function fetchRegistration(eventId: string): Promise<GetRegistrationRespon
headers: {
'Content-Type': 'application/json',
},
}
},
);

if (!response.ok) {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/fetchRegistrationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function fetchRegistrationData(eventId: string): Promise<GetRegistrationDa
headers: {
'Content-Type': 'application/json',
},
}
},
);

if (!response.ok) {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/fetchRegistrationFields.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GetRegistrationFieldsResponse } from './types/RegistrationFieldType';

async function fetchRegistrationFields(
eventId: string
eventId: string,
): Promise<GetRegistrationFieldsResponse | null> {
try {
const response = await fetch(
Expand All @@ -11,7 +11,7 @@ async function fetchRegistrationFields(
headers: {
'Content-Type': 'application/json',
},
}
},
);

if (!response.ok) {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/fetchUserAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function fetchUserAttributes(userId: string): Promise<GetUserAttributesRes
headers: {
'Content-Type': 'application/json',
},
}
},
);

if (!response.ok) {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/fetchUserVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GetUserVotesResponse } from './types/UserVotesType';

async function fetchUserVotes(
userId: string,
cycleId: string
cycleId: string,
): Promise<GetUserVotesResponse | null> {
try {
const response = await fetch(
Expand All @@ -12,7 +12,7 @@ async function fetchUserVotes(
headers: {
'Content-Type': 'application/json',
},
}
},
);
if (!response.ok) {
throw new Error(`HTTP Error! Status: ${response.status}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/postRegistrationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function postRegistrationData({
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
}
},
);

if (!response.ok) {
Expand Down
6 changes: 3 additions & 3 deletions packages/berlin/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useAppStore = create<AppState>()(
toggleTheme: () => set((state) => ({ theme: state.theme === 'light' ? 'dark' : 'light' })),
reset: () => set(() => ({ userStatus: 'INCOMPLETE' })),
}),
{ name: 'lexicon-store' }
)
)
{ name: 'lexicon-store' },
),
),
);
10 changes: 6 additions & 4 deletions packages/berlin/src/utils/formatGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import { GetGroupsResponse } from '../types/GroupType';
* @returns An array of formatted group objects with "Other" and "None" placed at the beginning.
*/
export const formatGroups = (groups: GetGroupsResponse[] | null | undefined) => {
return groups
return (
groups
?.sort((a, b) => a.name.localeCompare(b.name))
?.reduce((acc: { name: string; id: string; }[], group) => {
?.reduce((acc: { name: string; id: string }[], group) => {
if (group.name === 'Other' || group.name === 'None') {
acc.unshift({ name: group.name, id: group.id });
} else {
acc.push({ name: group.name, id: group.id });
}
return acc;
}, []) || [];
};
}, []) || []
);
};
6 changes: 3 additions & 3 deletions packages/core/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useAppStore = create<AppState>()(
set(() => ({ onboardingStatus: status })),
reset: () => set(() => ({ userStatus: 'INCOMPLETE' })),
}),
{ name: 'lexicon-store' }
)
)
{ name: 'lexicon-store' },
),
),
);
10 changes: 6 additions & 4 deletions packages/core/src/utils/formatGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import { GetGroupsResponse } from '../types/GroupType';
* @returns An array of formatted group objects with "Other" and "None" placed at the beginning.
*/
export const formatGroups = (groups: GetGroupsResponse[] | null | undefined) => {
return groups
return (
groups
?.sort((a, b) => a.name.localeCompare(b.name))
?.reduce((acc: { name: string; id: string; }[], group) => {
?.reduce((acc: { name: string; id: string }[], group) => {
if (group.name === 'Other' || group.name === 'None') {
acc.unshift({ name: group.name, id: group.id });
} else {
acc.push({ name: group.name, id: group.id });
}
return acc;
}, []) || [];
};
}, []) || []
);
};
2 changes: 1 addition & 1 deletion packages/core/src/utils/handleSignatureRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const handleSignatureRequest = (nonce: string | null) => {
args,
{
genericProveScreen: true,
}
},
);

openZupassPopup(POPUP_URL, constructProofUrl);
Expand Down
Loading
Loading