Skip to content

Commit 3d18469

Browse files
committed
Test pre-commit formatting
1 parent fb2e0fd commit 3d18469

File tree

7 files changed

+988
-257
lines changed

7 files changed

+988
-257
lines changed

.husky/pre-commit

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env sh
2+
3+
bun run scripts/pre-commit-lint.js

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,15 @@ We now have a [paper](https://arxiv.org/pdf/2501.06781) you can cite for the Eli
185185
## Star History
186186

187187
[![Star History Chart](https://api.star-history.com/svg?repos=elizaos/eliza&type=Date)](https://star-history.com/#elizaos/eliza&Date)
188+
189+
## Git Hooks
190+
191+
This project uses git hooks to ensure code quality:
192+
193+
- **pre-commit**: Automatically formats staged files using Prettier before committing
194+
195+
To run the pre-commit hook manually:
196+
197+
```bash
198+
bun run pre-commit
199+
```

bun.lock

+916-90
Large diffs are not rendered by default.

formatting-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This file has intentional formatting issues for testing the pre-commit hook
2+
function badlyFormattedFunction() {
3+
const greeting = 'hello world';
4+
console.log(greeting);
5+
return 1 + 1;
6+
}

package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"lint:format": "bun run format && bun run format:check",
1616
"format": "prettier --write .",
1717
"format:check": "prettier --check .",
18+
"pre-commit": "bun run scripts/pre-commit-lint.js",
1819
"release": "bun run build && bun lint && lerna publish --no-private --force-publish && bun lint",
1920
"release:alpha": "lerna publish prerelease --preid alpha --dist-tag alpha --no-private --force-publish --loglevel verbose",
2021
"migrate": "turbo run migrate --filter=./packages/plugin-sql --force",
@@ -25,27 +26,29 @@
2526
"docker:start": "bash ./scripts/docker.sh start",
2627
"docker": "bun docker:build && bun docker:run && bun docker:bash",
2728
"test": "turbo run test --concurrency 20 --filter=!./packages/plugin-starter --filter=!./packages/project-starter --filter=!./packages/the-org --filter=!./packages/docs --filter=!./packages/plugin-video-understanding",
28-
"test:app": "turbo run test --concurrency 20 --filter=./packages/app"
29+
"test:app": "turbo run test --concurrency 20 --filter=./packages/app",
30+
"prepare": "husky"
2931
},
3032
"devDependencies": {
3133
"@types/bun": "latest",
3234
"@types/node": "^22.13.10",
35+
"@types/uuid": "^9.0.8",
3336
"@vitest/eslint-plugin": "1.0.1",
3437
"bun": "1.2.5",
3538
"concurrently": "9.1.0",
3639
"cross-env": "7.0.3",
37-
"husky": "9.1.7",
40+
"husky": "^9.1.7",
3841
"lerna": "8.1.4",
42+
"lint-staged": "^15.5.0",
3943
"only-allow": "^1.2.1",
4044
"prettier": "3.5.3",
4145
"sharp": "0.33.5",
46+
"tsup": "8.4.0",
4247
"turbo": "^2.4.4",
4348
"typedoc": "0.27.9",
4449
"typescript": "5.8.2",
4550
"vite": "5.4.12",
46-
"vitest": "3.0.5",
47-
"@types/uuid": "^9.0.8",
48-
"tsup": "8.4.0"
51+
"vitest": "3.0.5"
4952
},
5053
"bun": {
5154
"overrides": {

packages/docs/README_RO.md

-162
This file was deleted.

scripts/pre-commit-lint.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
3+
import { execSync } from 'node:child_process';
4+
import { existsSync } from 'node:fs';
5+
6+
// Get all staged files
7+
const stagedFiles = execSync('git diff --cached --name-only --diff-filter=ACMR')
8+
.toString()
9+
.trim()
10+
.split('\n')
11+
.filter(Boolean);
12+
13+
if (stagedFiles.length === 0) {
14+
console.log('No staged files to lint');
15+
process.exit(0);
16+
}
17+
18+
// Filter for files we want to process
19+
const filesToLint = stagedFiles.filter((file) => {
20+
const extensions = ['.js', '.jsx', '.ts', '.tsx', '.json', '.css', '.md'];
21+
return extensions.some((ext) => file.endsWith(ext));
22+
});
23+
24+
if (filesToLint.length === 0) {
25+
console.log('No matching files to lint');
26+
process.exit(0);
27+
}
28+
29+
// Run prettier on the files
30+
try {
31+
console.log('Running prettier on staged files...');
32+
const fileList = filesToLint.join(' ');
33+
execSync(`bun prettier --write ${fileList}`, { stdio: 'inherit' });
34+
35+
// Add the formatted files back to staging
36+
execSync(`git add ${fileList}`, { stdio: 'inherit' });
37+
38+
console.log('Pre-commit linting completed successfully');
39+
process.exit(0);
40+
} catch (error) {
41+
console.error('Error during pre-commit linting:', error.message);
42+
process.exit(1);
43+
}

0 commit comments

Comments
 (0)