Skip to content

Commit ee6db2c

Browse files
Merge pull request #16 from ASCS-eV/feat/linting
Add Linting Infrastructure and CI/CD Pipeline (and Prettier reformatting)
2 parents f22d0ca + 4d10076 commit ee6db2c

46 files changed

Lines changed: 3889 additions & 1589 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Test and Build
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '22.12.0'
22+
23+
# Frontend Linting
24+
- name: Install frontend dependencies
25+
working-directory: packages/demo-app-frontend
26+
run: npm ci
27+
28+
- name: Run ESLint (Frontend)
29+
working-directory: packages/demo-app-frontend
30+
run: npm run lint
31+
32+
- name: Check Prettier formatting (Frontend)
33+
working-directory: packages/demo-app-frontend
34+
run: npx prettier --check .
35+
36+
# Solidity Linting
37+
- name: Install contract dependencies
38+
working-directory: packages/trust-anchor-did-ethr
39+
run: npm ci
40+
41+
- name: Run Solhint (Contracts)
42+
working-directory: packages/trust-anchor-did-ethr
43+
run: npx solhint 'contracts/**/*.sol'
44+
45+
test:
46+
name: Test
47+
needs: lint
48+
runs-on: ubuntu-latest
49+
50+
steps:
51+
- name: Checkout code
52+
uses: actions/checkout@v4
53+
54+
- name: Setup Node.js
55+
uses: actions/setup-node@v4
56+
with:
57+
node-version: '22.12.0'
58+
cache: 'npm'
59+
cache-dependency-path: packages/trust-anchor-did-ethr/package-lock.json
60+
61+
- name: Install dependencies
62+
working-directory: packages/trust-anchor-did-ethr
63+
run: npm ci
64+
65+
- name: Run Hardhat tests
66+
working-directory: packages/trust-anchor-did-ethr
67+
run: npx hardhat test
68+
69+
build:
70+
name: Build
71+
needs: test
72+
runs-on: ubuntu-latest
73+
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v4
77+
78+
- name: Setup Node.js
79+
uses: actions/setup-node@v4
80+
with:
81+
node-version: '22.12.0'
82+
83+
# Compile Contracts
84+
- name: Install contract dependencies
85+
working-directory: packages/trust-anchor-did-ethr
86+
run: npm ci
87+
88+
- name: Compile smart contracts
89+
working-directory: packages/trust-anchor-did-ethr
90+
run: npx hardhat compile
91+
92+
# Build Frontend
93+
- name: Install frontend dependencies
94+
working-directory: packages/demo-app-frontend
95+
run: npm ci
96+
97+
- name: Build frontend
98+
working-directory: packages/demo-app-frontend
99+
run: npm run build

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cd packages/demo-app-frontend && npx lint-staged

BUILD.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Installation](#installation)
88
- [Running the Project](#running-the-project)
99
- [Testing](#testing)
10+
- [Development Workflow](#development-workflow)
1011
- [TypeScript Configuration](#typescript-configuration)
1112
- [Platform-Specific Notes](#platform-specific-notes)
1213
- [Deployment](#deployment)
@@ -66,6 +67,14 @@ This project uses the following key dependencies:
6667

6768
## Installation
6869

70+
### Install Root Dependencies
71+
72+
First, install root dependencies (required for Husky pre-commit hooks):
73+
74+
```bash
75+
npm install
76+
```
77+
6978
### Install Dependencies for Each Package
7079

7180
#### 1. Smart Contracts (trust-anchor-did-ethr)
@@ -187,6 +196,45 @@ cd packages/demo-app-frontend
187196
npm run lint
188197
```
189198

199+
## Development Workflow
200+
201+
### Pre-commit Hooks
202+
203+
This project uses [Husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/okonet/lint-staged) to automatically lint your code before commits:
204+
205+
**What happens when you commit:**
206+
1. You stage files: `git add src/components/MyComponent.tsx`
207+
2. You commit: `git commit -m "fix: update component"`
208+
3. Pre-commit hook runs automatically:
209+
- ESLint checks code quality and fixes issues
210+
- Prettier formats code (indentation, spacing, etc.)
211+
- Both tools auto-fix and re-stage files
212+
- Unfixable errors block the commit
213+
4. If successful, commit proceeds with clean, formatted code
214+
215+
**Manual formatting:**
216+
```bash
217+
npm run format # Format all files with Prettier
218+
npm run lint # Check code quality with ESLint
219+
```
220+
221+
**Configuration:**
222+
- Hook script: `.husky/pre-commit`
223+
- Prettier rules: `packages/demo-app-frontend/.prettierrc`
224+
- ESLint rules: `packages/demo-app-frontend/eslint.config.js`
225+
- Staged file rules: `packages/demo-app-frontend/package.json``lint-staged` section
226+
227+
### Continuous Integration (GitHub Actions)
228+
229+
Pull requests and pushes to `main` trigger automated checks (`.github/workflows/ci.yml`):
230+
231+
**CI Jobs:**
232+
1. **Frontend Linting**: Runs ESLint on entire frontend codebase
233+
2. **Frontend Formatting**: Checks Prettier formatting compliance
234+
3. **Contract Validation**: Compiles smart contracts and runs full test suite
235+
236+
**All checks must pass before merging.** The CI uses Node.js 22.12.0 to match local development.
237+
190238
## TypeScript Configuration
191239

192240
### Smart Contracts (trust-anchor-did-ethr)

0 commit comments

Comments
 (0)