Skip to content

Commit d4e37b1

Browse files
enforce code formatting and linting (#175)
* enforce code formatting and linting * swap pre-hook script order * keep fixes unstaged
1 parent aa18b1f commit d4e37b1

11 files changed

Lines changed: 447 additions & 234 deletions

File tree

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_size = 4
9+
10+
[*.{js,jsx,json,yml,yaml,md,css,scss}]
11+
indent_style = space
12+
13+
[{**/*.{yml,yaml,json}}]
14+
indent_size = 2
15+
16+
[*.md]
17+
trim_trailing_whitespace = false

.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,5 @@ dist
107107
keycloak.json
108108
!tests/integration/kind/fixtures/secrets/keycloak.json
109109

110-
# js config file
111-
jsconfig.json
112-
113-
# Prettier format
114-
.prettierrc
115-
116110
# AutoTab config
117111
.autotab.d/

.husky/pre-commit

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env sh
2+
set -e
3+
4+
# Staged files only (Added, Copied, Modified, Renamed — skip deletions).
5+
STAGED_JS=$(git diff --cached --name-only --diff-filter=ACMR -- '*.js' '*.jsx' || true)
6+
STAGED_PRETTIER=$(git diff --cached --name-only --diff-filter=ACMR -- \
7+
'*.js' '*.jsx' '*.json' '*.md' '*.yml' '*.yaml' '*.css' '*.scss' || true)
8+
9+
if [ -n "$STAGED_JS" ]; then
10+
echo "$STAGED_JS" | tr '\n' '\0' | xargs -0 pnpm exec eslint --fix --
11+
fi
12+
13+
if [ -n "$STAGED_PRETTIER" ]; then
14+
echo "$STAGED_PRETTIER" | tr '\n' '\0' | xargs -0 pnpm exec prettier --write --
15+
fi

.prettierignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules/
2+
dist/
3+
coverage/
4+
pnpm-lock.yaml
5+
6+
# Build / generated
7+
components/console/dist/
8+
9+
# Helm / templating — Prettier can break Go-template syntax
10+
charts/**/templates/**
11+
charts/**/*.gotmpl
12+
13+
# Large or generated assets
14+
*.min.js

components/console/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ components/console/
3535
│ ├── App.test.jsx
3636
│ ├── index.jsx # Application entry point
3737
│ └── index.css
38-
├── eslint.config.js
3938
├── index.html # Vite HTML entry
4039
├── vite.config.js
4140
├── package.json
@@ -87,8 +86,16 @@ node index.js
8786

8887
### Lint
8988

89+
ESLint is configured at the **repository root** (`eslint.config.js`). From the repo root:
90+
91+
```bash
92+
pnpm lint
93+
```
94+
95+
To lint only console sources:
96+
9097
```bash
91-
pnpm --filter vms-console lint
98+
pnpm exec eslint components/console
9299
```
93100

94101
## Dependencies
@@ -105,15 +112,17 @@ pnpm --filter vms-console lint
105112
### Theme Configuration
106113

107114
The Carbon theme can be customized in `src/theme/theme.scss`. Currently using the g100 (dark) theme. Available themes:
115+
108116
- `white` - Light theme
109117
- `g10` - Light gray theme
110118
- `g90` - Dark gray theme
111119
- `g100` - Dark theme (current)
112120

113121
To change the theme, modify the `$theme` parameter in `src/theme/theme.scss`:
122+
114123
```scss
115-
@use '@carbon/react/scss/theme' with (
116-
$theme: themes.$white // Change to desired theme
124+
@use "@carbon/react/scss/theme" with (
125+
$theme: themes.$white // Change to desired theme
117126
);
118127
```
119128

@@ -126,6 +135,7 @@ To change the theme, modify the `$theme` parameter in `src/theme/theme.scss`:
126135
## Development Status
127136

128137
All core features are implemented:
138+
129139
- ✅ Project initialization
130140
- ✅ Carbon Design System integration
131141
- ✅ Navigation structure
@@ -137,6 +147,7 @@ All core features are implemented:
137147
## Future Development
138148

139149
Each page includes a blank panel ready for content development:
150+
140151
- Dashboard metrics and widgets
141152
- Network configuration interfaces
142153
- TLS certificate management
@@ -146,6 +157,7 @@ Each page includes a blank panel ready for content development:
146157
## Browser Support
147158

148159
Supports all modern browsers:
160+
149161
- Chrome (latest)
150162
- Firefox (latest)
151163
- Safari (latest)
@@ -158,6 +170,7 @@ This project is part of the VMS Console application.
158170
## Contributing
159171

160172
When adding new features:
173+
161174
1. Follow Carbon Design System guidelines
162175
2. Maintain consistent component structure
163176
3. Update navigation as needed

components/console/eslint.config.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

components/console/package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"scripts": {
77
"dev": "vite",
88
"build": "vite build",
9-
"lint": "eslint .",
109
"preview": "vite preview"
1110
},
1211
"dependencies": {
@@ -21,14 +20,9 @@
2120
"vite-express": "^0.22.1"
2221
},
2322
"devDependencies": {
24-
"@eslint/js": "^9.39.4",
2523
"@types/react": "^19.2.14",
2624
"@types/react-dom": "^19.2.3",
2725
"@vitejs/plugin-react": "^6.0.1",
28-
"eslint": "^9.39.4",
29-
"eslint-plugin-react-hooks": "^7.1.1",
30-
"eslint-plugin-react-refresh": "^0.5.2",
31-
"globals": "^17.5.0",
3226
"vite": "^8.0.9"
3327
}
3428
}

eslint.config.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
import vitest from "@vitest/eslint-plugin";
4+
import reactHooks from "eslint-plugin-react-hooks";
5+
import reactRefresh from "eslint-plugin-react-refresh";
6+
import eslintConfigPrettier from "eslint-config-prettier";
7+
import { defineConfig, globalIgnores } from "eslint/config";
8+
9+
const unusedVarsRule = ["error", { varsIgnorePattern: "^[A-Z_]|^_", argsIgnorePattern: "^_" }];
10+
const commonRules = {
11+
"no-unused-vars": unusedVarsRule,
12+
"prefer-const": "error",
13+
"no-var": "error",
14+
};
15+
16+
export default defineConfig([
17+
globalIgnores(["**/dist/**", "**/coverage/**", "**/node_modules/**", "charts/**/templates/**"]),
18+
19+
// controllers + shared modules
20+
{
21+
files: [
22+
"modules/**/*.{js,jsx}",
23+
"components/management-controller/**/*.{js,jsx}",
24+
"components/site-controller/**/*.{js,jsx}",
25+
"tests/**/*.{js,jsx}",
26+
"*.js",
27+
],
28+
extends: [js.configs.recommended],
29+
languageOptions: {
30+
ecmaVersion: "latest",
31+
sourceType: "module",
32+
globals: globals.node,
33+
},
34+
rules: {
35+
...commonRules,
36+
},
37+
},
38+
39+
// Console
40+
{
41+
files: ["components/console/**/*.{js,jsx}"],
42+
extends: [
43+
js.configs.recommended,
44+
reactHooks.configs.flat.recommended,
45+
reactRefresh.configs.vite,
46+
],
47+
languageOptions: {
48+
ecmaVersion: 2020,
49+
globals: globals.browser,
50+
parserOptions: {
51+
ecmaVersion: "latest",
52+
ecmaFeatures: { jsx: true },
53+
sourceType: "module",
54+
},
55+
},
56+
rules: {
57+
...commonRules,
58+
"react-hooks/immutability": "off",
59+
"react-hooks/set-state-in-effect": "off",
60+
"react-hooks/rules-of-hooks": "error",
61+
},
62+
},
63+
64+
// Vitest tests
65+
{
66+
files: ["**/*.test.js"],
67+
extends: [js.configs.recommended, vitest.configs.recommended],
68+
languageOptions: {
69+
ecmaVersion: "latest",
70+
sourceType: "module",
71+
globals: {
72+
...globals.node,
73+
...vitest.environments.env.globals,
74+
},
75+
},
76+
rules: {
77+
...commonRules,
78+
},
79+
},
80+
81+
eslintConfigPrettier,
82+
]);

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"private": true,
66
"type": "module",
77
"scripts": {
8+
"format": "prettier --write .",
9+
"format:check": "prettier --check .",
10+
"lint": "eslint .",
11+
"lint:fix": "eslint . --fix",
12+
"prepare": "husky",
813
"test": "vitest run",
914
"test:watch": "vitest",
1015
"test:unit": "vitest run --project unit",
@@ -15,10 +20,19 @@
1520
"cluster:down": "tests/integration/kind/scripts/cluster-down.sh"
1621
},
1722
"devDependencies": {
23+
"@eslint/js": "^10.0.1",
24+
"@vitest/eslint-plugin": "^1.6.23",
1825
"@vitest/coverage-v8": "^4.1.9",
1926
"@vitest/ui": "4.1.9",
27+
"eslint": "^10.7.0",
28+
"eslint-config-prettier": "^10.1.8",
29+
"eslint-plugin-react-hooks": "^7.1.1",
30+
"eslint-plugin-react-refresh": "^0.5.3",
2031
"express": "^4.22.1",
32+
"globals": "^17.7.0",
33+
"husky": "^9.1.7",
2134
"js-yaml": "^4.1.1",
35+
"prettier": "^3.9.5",
2236
"supertest": "^7.1.4",
2337
"vitest": "^4.1.0"
2438
}

0 commit comments

Comments
 (0)