Skip to content

Commit c44a309

Browse files
committed
chore: add linting, formatting, and pre-commit setup for backend
1 parent da35803 commit c44a309

File tree

11 files changed

+552
-36
lines changed

11 files changed

+552
-36
lines changed

.eslintrc.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
es2021: true,
6+
node: true,
7+
},
8+
extends: [
9+
'eslint:recommended',
10+
'plugin:react/recommended',
11+
'plugin:react-hooks/recommended',
12+
'plugin:jsx-a11y/recommended',
13+
'plugin:import/recommended',
14+
'prettier', // Must be last to override other configs
15+
],
16+
parser: '@babel/eslint-parser',
17+
parserOptions: {
18+
ecmaFeatures: {
19+
jsx: true,
20+
},
21+
ecmaVersion: 'latest',
22+
sourceType: 'module',
23+
requireConfigFile: false,
24+
babelOptions: {
25+
presets: ['@babel/preset-react'],
26+
},
27+
},
28+
plugins: ['react', 'react-hooks', 'jsx-a11y', 'import'],
29+
rules: {
30+
// React specific rules
31+
'react/react-in-jsx-scope': 'off', // Not needed with React 17+
32+
'react/prop-types': 'off', // Using TypeScript for prop validation
33+
'react/jsx-uses-react': 'off',
34+
'react/jsx-uses-vars': 'error',
35+
'react/jsx-key': 'error',
36+
'react/no-unescaped-entities': 'warn',
37+
38+
// React Hooks rules
39+
'react-hooks/rules-of-hooks': 'error',
40+
'react-hooks/exhaustive-deps': 'warn',
41+
42+
// Import rules
43+
'import/order': [
44+
'error',
45+
{
46+
groups: [
47+
'builtin',
48+
'external',
49+
'internal',
50+
'parent',
51+
'sibling',
52+
'index',
53+
],
54+
'newlines-between': 'always',
55+
alphabetize: {
56+
order: 'asc',
57+
caseInsensitive: true,
58+
},
59+
},
60+
],
61+
'import/no-unresolved': 'off', // Docusaurus handles this
62+
'import/no-duplicates': 'error',
63+
64+
// General rules
65+
'no-console': 'warn',
66+
'no-debugger': 'error',
67+
'no-unused-vars': 'warn',
68+
'prefer-const': 'error',
69+
'no-var': 'error',
70+
71+
// Accessibility rules
72+
'jsx-a11y/anchor-is-valid': 'off', // Docusaurus Link components handle this
73+
'jsx-a11y/click-events-have-key-events': 'warn',
74+
'jsx-a11y/no-static-element-interactions': 'warn',
75+
},
76+
settings: {
77+
react: {
78+
version: 'detect',
79+
},
80+
},
81+
overrides: [
82+
{
83+
files: ['docusaurus.config.ts', '*.config.js', '*.config.ts'],
84+
rules: {
85+
'no-console': 'off',
86+
'import/no-default-export': 'off',
87+
},
88+
},
89+
],
90+
ignorePatterns: [
91+
'build/',
92+
'.docusaurus/',
93+
'node_modules/',
94+
'*.min.js',
95+
'static/',
96+
'**/*.ts',
97+
'**/*.tsx',
98+
],
99+
};

.github/workflows/ci.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Code Quality & Build
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
lint-and-format:
11+
name: Lint & Format Check
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: '18'
22+
cache: 'npm'
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Run ESLint
28+
run: npm run lint
29+
30+
- name: Check Prettier formatting
31+
run: npm run format:check
32+
33+
- name: TypeScript type check
34+
run: npm run typecheck
35+
36+
build:
37+
name: Build Project
38+
runs-on: ubuntu-latest
39+
needs: lint-and-format
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Setup Node.js
46+
uses: actions/setup-node@v4
47+
with:
48+
node-version: '18'
49+
cache: 'npm'
50+
51+
- name: Install dependencies
52+
run: npm ci
53+
54+
- name: Build project
55+
run: npm run build
56+
57+
- name: Upload build artifacts
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: build-files
61+
path: build/
62+
retention-days: 7
63+
64+
test:
65+
name: Run Tests
66+
runs-on: ubuntu-latest
67+
needs: lint-and-format
68+
if: false # Disable until tests are added
69+
70+
steps:
71+
- name: Checkout code
72+
uses: actions/checkout@v4
73+
74+
- name: Setup Node.js
75+
uses: actions/setup-node@v4
76+
with:
77+
node-version: '18'
78+
cache: 'npm'
79+
80+
- name: Install dependencies
81+
run: npm ci
82+
83+
- name: Run tests
84+
run: npm test

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

.lintstagedrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"*.{js,jsx,ts,tsx}": [
3+
"eslint --fix",
4+
"prettier --write"
5+
],
6+
"*.{json,md,yml,yaml}": [
7+
"prettier --write"
8+
],
9+
"*.{css,scss,less}": [
10+
"prettier --write"
11+
]
12+
}

.prettierignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build outputs
5+
build/
6+
.docusaurus/
7+
dist/
8+
9+
# Static files
10+
static/
11+
12+
# Logs
13+
*.log
14+
npm-debug.log*
15+
yarn-debug.log*
16+
yarn-error.log*
17+
18+
# IDE files
19+
.vscode/
20+
.idea/
21+
22+
# OS files
23+
.DS_Store
24+
Thumbs.db
25+
26+
# Environment files
27+
.env
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# Lock files
34+
package-lock.json
35+
yarn.lock
36+
pnpm-lock.yaml
37+
38+
# Generated files
39+
*.min.js
40+
*.min.css
41+
42+
# Documentation build
43+
docs/.vuepress/dist/
44+
45+
# Temporary files
46+
*.tmp
47+
*.temp

.prettierrc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"singleQuote": true,
5+
"printWidth": 80,
6+
"tabWidth": 2,
7+
"useTabs": false,
8+
"quoteProps": "as-needed",
9+
"bracketSpacing": true,
10+
"bracketSameLine": false,
11+
"arrowParens": "avoid",
12+
"endOfLine": "lf",
13+
"embeddedLanguageFormatting": "auto",
14+
"htmlWhitespaceSensitivity": "css",
15+
"insertPragma": false,
16+
"jsxSingleQuote": false,
17+
"proseWrap": "preserve",
18+
"requirePragma": false,
19+
"overrides": [
20+
{
21+
"files": "*.md",
22+
"options": {
23+
"printWidth": 100,
24+
"proseWrap": "always"
25+
}
26+
},
27+
{
28+
"files": "*.json",
29+
"options": {
30+
"printWidth": 100
31+
}
32+
}
33+
]
34+
}

.vscode/extensions.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode",
4+
"dbaeumer.vscode-eslint",
5+
"bradlc.vscode-tailwindcss",
6+
"ms-vscode.vscode-typescript-next",
7+
"formulahendry.auto-rename-tag",
8+
"christian-kohler.path-intellisense",
9+
"ms-vscode.vscode-json",
10+
"redhat.vscode-yaml",
11+
"yzhang.markdown-all-in-one",
12+
"GitHub.copilot",
13+
"GitHub.copilot-chat"
14+
]
15+
}

.vscode/settings.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll.eslint": "explicit",
5+
"source.organizeImports": "explicit"
6+
},
7+
"eslint.validate": [
8+
"javascript",
9+
"javascriptreact",
10+
"typescript",
11+
"typescriptreact"
12+
],
13+
"typescript.preferences.importModuleSpecifier": "relative",
14+
"files.exclude": {
15+
"**/.git": true,
16+
"**/.svn": true,
17+
"**/.hg": true,
18+
"**/CVS": true,
19+
"**/.DS_Store": true,
20+
"**/Thumbs.db": true,
21+
"**/node_modules": true,
22+
"**/.docusaurus": true,
23+
"**/build": true
24+
},
25+
"search.exclude": {
26+
"**/node_modules": true,
27+
"**/build": true,
28+
"**/.docusaurus": true,
29+
"**/yarn.lock": true,
30+
"**/package-lock.json": true
31+
}
32+
}

0 commit comments

Comments
 (0)