@cubocicloide/stack-react-django 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +33 -0
- package/README.md +66 -0
- package/dist/commands/lint/checks/BE/001.d.ts +6 -0
- package/dist/commands/lint/checks/BE/001.js +94 -0
- package/dist/commands/lint/checks/BE/001.js.map +1 -0
- package/dist/commands/lint/checks/BE/002.d.ts +6 -0
- package/dist/commands/lint/checks/BE/002.js +136 -0
- package/dist/commands/lint/checks/BE/002.js.map +1 -0
- package/dist/commands/lint/checks/BE/003.d.ts +6 -0
- package/dist/commands/lint/checks/BE/003.js +89 -0
- package/dist/commands/lint/checks/BE/003.js.map +1 -0
- package/dist/commands/lint/checks/BE/004.d.ts +6 -0
- package/dist/commands/lint/checks/BE/004.js +68 -0
- package/dist/commands/lint/checks/BE/004.js.map +1 -0
- package/dist/commands/lint/checks/BE/005.d.ts +6 -0
- package/dist/commands/lint/checks/BE/005.js +55 -0
- package/dist/commands/lint/checks/BE/005.js.map +1 -0
- package/dist/commands/lint/checks/BE/006.d.ts +6 -0
- package/dist/commands/lint/checks/BE/006.js +95 -0
- package/dist/commands/lint/checks/BE/006.js.map +1 -0
- package/dist/commands/lint/checks/BE/007.d.ts +6 -0
- package/dist/commands/lint/checks/BE/007.js +53 -0
- package/dist/commands/lint/checks/BE/007.js.map +1 -0
- package/dist/commands/lint/checks/BE/008.d.ts +6 -0
- package/dist/commands/lint/checks/BE/008.js +70 -0
- package/dist/commands/lint/checks/BE/008.js.map +1 -0
- package/dist/commands/lint/checks/BE/009.d.ts +6 -0
- package/dist/commands/lint/checks/BE/009.js +112 -0
- package/dist/commands/lint/checks/BE/009.js.map +1 -0
- package/dist/commands/lint/checks/BE/010.d.ts +6 -0
- package/dist/commands/lint/checks/BE/010.js +76 -0
- package/dist/commands/lint/checks/BE/010.js.map +1 -0
- package/dist/commands/lint/checks/BE/011.d.ts +6 -0
- package/dist/commands/lint/checks/BE/011.js +76 -0
- package/dist/commands/lint/checks/BE/011.js.map +1 -0
- package/dist/commands/lint/checks/BE/012.d.ts +6 -0
- package/dist/commands/lint/checks/BE/012.js +61 -0
- package/dist/commands/lint/checks/BE/012.js.map +1 -0
- package/dist/commands/lint/checks/BE/013.d.ts +6 -0
- package/dist/commands/lint/checks/BE/013.js +98 -0
- package/dist/commands/lint/checks/BE/013.js.map +1 -0
- package/dist/commands/lint/checks/BE/014.d.ts +6 -0
- package/dist/commands/lint/checks/BE/014.js +64 -0
- package/dist/commands/lint/checks/BE/014.js.map +1 -0
- package/dist/commands/lint/checks/E2E/001.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/001.js +35 -0
- package/dist/commands/lint/checks/E2E/001.js.map +1 -0
- package/dist/commands/lint/checks/E2E/002.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/002.js +37 -0
- package/dist/commands/lint/checks/E2E/002.js.map +1 -0
- package/dist/commands/lint/checks/E2E/003.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/003.js +42 -0
- package/dist/commands/lint/checks/E2E/003.js.map +1 -0
- package/dist/commands/lint/checks/E2E/004.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/004.js +37 -0
- package/dist/commands/lint/checks/E2E/004.js.map +1 -0
- package/dist/commands/lint/checks/E2E/005.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/005.js +47 -0
- package/dist/commands/lint/checks/E2E/005.js.map +1 -0
- package/dist/commands/lint/checks/E2E/006.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/006.js +28 -0
- package/dist/commands/lint/checks/E2E/006.js.map +1 -0
- package/dist/commands/lint/checks/E2E/007.d.ts +6 -0
- package/dist/commands/lint/checks/E2E/007.js +47 -0
- package/dist/commands/lint/checks/E2E/007.js.map +1 -0
- package/dist/commands/lint/checks/FE/001.d.ts +6 -0
- package/dist/commands/lint/checks/FE/001.js +56 -0
- package/dist/commands/lint/checks/FE/001.js.map +1 -0
- package/dist/commands/lint/checks/FE/002.d.ts +6 -0
- package/dist/commands/lint/checks/FE/002.js +80 -0
- package/dist/commands/lint/checks/FE/002.js.map +1 -0
- package/dist/commands/lint/checks/FE/003.d.ts +6 -0
- package/dist/commands/lint/checks/FE/003.js +65 -0
- package/dist/commands/lint/checks/FE/003.js.map +1 -0
- package/dist/commands/lint/checks/FE/004.d.ts +6 -0
- package/dist/commands/lint/checks/FE/004.js +72 -0
- package/dist/commands/lint/checks/FE/004.js.map +1 -0
- package/dist/commands/lint/checks/FE/005.d.ts +6 -0
- package/dist/commands/lint/checks/FE/005.js +103 -0
- package/dist/commands/lint/checks/FE/005.js.map +1 -0
- package/dist/commands/lint/checks/FE/006.d.ts +6 -0
- package/dist/commands/lint/checks/FE/006.js +102 -0
- package/dist/commands/lint/checks/FE/006.js.map +1 -0
- package/dist/commands/lint/checks/FE/007.d.ts +6 -0
- package/dist/commands/lint/checks/FE/007.js +60 -0
- package/dist/commands/lint/checks/FE/007.js.map +1 -0
- package/dist/commands/lint/checks/FE/008.d.ts +6 -0
- package/dist/commands/lint/checks/FE/008.js +115 -0
- package/dist/commands/lint/checks/FE/008.js.map +1 -0
- package/dist/commands/lint/checks/FE/009.d.ts +6 -0
- package/dist/commands/lint/checks/FE/009.js +83 -0
- package/dist/commands/lint/checks/FE/009.js.map +1 -0
- package/dist/commands/lint/checks/FE/010.d.ts +6 -0
- package/dist/commands/lint/checks/FE/010.js +105 -0
- package/dist/commands/lint/checks/FE/010.js.map +1 -0
- package/dist/commands/lint/checks/FE/011.d.ts +6 -0
- package/dist/commands/lint/checks/FE/011.js +43 -0
- package/dist/commands/lint/checks/FE/011.js.map +1 -0
- package/dist/commands/lint/checks/FE/012.d.ts +6 -0
- package/dist/commands/lint/checks/FE/012.js +150 -0
- package/dist/commands/lint/checks/FE/012.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3436 -0
- package/dist/index.js.map +1 -0
- package/dude.stack.json +13 -0
- package/package.json +43 -0
- package/templates/aws-ecs/backend/Dockerfile.prod +34 -0
- package/templates/aws-ecs/docs/docs/deploy.md.hbs +54 -0
- package/templates/aws-ecs/frontend/Dockerfile.prod +28 -0
- package/templates/aws-ecs/frontend/nginx.conf +21 -0
- package/templates/aws-ecs/iac/README.md.hbs +75 -0
- package/templates/aws-ecs/iac/_gitignore +14 -0
- package/templates/aws-ecs/iac/runner/Dockerfile +35 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/main.tf.hbs +102 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/outputs.tf +19 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/variables.tf.hbs +17 -0
- package/templates/aws-ecs/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
- package/templates/aws-ecs/iac/terraform/environments/dev/terraform.tfvars.hbs +43 -0
- package/templates/aws-ecs/iac/terraform/main.tf.hbs +949 -0
- package/templates/aws-ecs/iac/terraform/outputs.tf.hbs +71 -0
- package/templates/aws-ecs/iac/terraform/providers.tf +19 -0
- package/templates/aws-ecs/iac/terraform/variables.tf.hbs +113 -0
- package/templates/aws-ecs/iac/terraform/versions.tf +19 -0
- package/templates/base/.claude/agents/issue-fixer.md +190 -0
- package/templates/base/.claude/agents/security-fixer.md +250 -0
- package/templates/base/.claude/rules/BE/001.md +19 -0
- package/templates/base/.claude/rules/BE/002.md +21 -0
- package/templates/base/.claude/rules/BE/003.md +19 -0
- package/templates/base/.claude/rules/BE/004.md +16 -0
- package/templates/base/.claude/rules/BE/005.md +23 -0
- package/templates/base/.claude/rules/BE/006.md +13 -0
- package/templates/base/.claude/rules/BE/007.md +24 -0
- package/templates/base/.claude/rules/BE/008.md +19 -0
- package/templates/base/.claude/rules/BE/009.md +18 -0
- package/templates/base/.claude/rules/BE/010.md +15 -0
- package/templates/base/.claude/rules/BE/011.md +17 -0
- package/templates/base/.claude/rules/BE/012.md +18 -0
- package/templates/base/.claude/rules/BE/013.md +22 -0
- package/templates/base/.claude/rules/BE/014.md +15 -0
- package/templates/base/.claude/rules/E2E/001.md +13 -0
- package/templates/base/.claude/rules/E2E/002.md +14 -0
- package/templates/base/.claude/rules/E2E/003.md +10 -0
- package/templates/base/.claude/rules/E2E/004.md +23 -0
- package/templates/base/.claude/rules/E2E/005.md +15 -0
- package/templates/base/.claude/rules/E2E/006.md +13 -0
- package/templates/base/.claude/rules/E2E/007.md +18 -0
- package/templates/base/.claude/rules/FE/001.md +22 -0
- package/templates/base/.claude/rules/FE/002.md +39 -0
- package/templates/base/.claude/rules/FE/003.md +19 -0
- package/templates/base/.claude/rules/FE/004.md +21 -0
- package/templates/base/.claude/rules/FE/005.md +33 -0
- package/templates/base/.claude/rules/FE/006.md +24 -0
- package/templates/base/.claude/rules/FE/007.md +19 -0
- package/templates/base/.claude/rules/FE/008.md +26 -0
- package/templates/base/.claude/rules/FE/009.md +30 -0
- package/templates/base/.claude/rules/FE/010.md +25 -0
- package/templates/base/.claude/rules/FE/011.md +22 -0
- package/templates/base/.claude/rules/FE/012.md +32 -0
- package/templates/base/.claude/settings.json +53 -0
- package/templates/base/.claude/skills/clean-branches/SKILL.md +100 -0
- package/templates/base/.claude/skills/create/SKILL.md +47 -0
- package/templates/base/.claude/skills/create-jira-issue/SKILL.md +174 -0
- package/templates/base/.claude/skills/create-page/SKILL.md +195 -0
- package/templates/base/.claude/skills/create-route/SKILL.md +156 -0
- package/templates/base/.claude/skills/draft-email/SKILL.md +104 -0
- package/templates/base/.claude/skills/fix-issues/SKILL.md +238 -0
- package/templates/base/.claude/skills/security-scan/SKILL.md +297 -0
- package/templates/base/.claude/skills/verify-security-fixes/SKILL.md +180 -0
- package/templates/base/.dude/commands/README.md +85 -0
- package/templates/base/.dude/commands/hello.ts +34 -0
- package/templates/base/.dude/lint/checks/PRJ/001.ts +26 -0
- package/templates/base/.dude/lint/checks/README.md +69 -0
- package/templates/base/.vscode/tasks.json +44 -0
- package/templates/base/.worktreeinclude +2 -0
- package/templates/base/CLAUDE.md.hbs +391 -0
- package/templates/base/README.md.hbs +188 -0
- package/templates/base/_env.example.hbs +39 -0
- package/templates/base/_env.hbs +35 -0
- package/templates/base/_gitignore +31 -0
- package/templates/base/_npmrc +2 -0
- package/templates/base/backend/Dockerfile +16 -0
- package/templates/base/backend/README.md.hbs +90 -0
- package/templates/base/backend/_dockerignore +12 -0
- package/templates/base/backend/apps/__init__.py +0 -0
- package/templates/base/backend/apps/core/__init__.py +0 -0
- package/templates/base/backend/apps/core/apps.py +6 -0
- package/templates/base/backend/apps/core/serializers.py +7 -0
- package/templates/base/backend/apps/core/tests/__init__.py +0 -0
- package/templates/base/backend/apps/core/tests/test_views.py +16 -0
- package/templates/base/backend/apps/core/urls.py +9 -0
- package/templates/base/backend/apps/core/views.py +24 -0
- package/templates/base/backend/apps/users/__init__.py +0 -0
- package/templates/base/backend/apps/users/admin.py +6 -0
- package/templates/base/backend/apps/users/apps.py +6 -0
- package/templates/base/backend/apps/users/migrations/0001_initial.py +41 -0
- package/templates/base/backend/apps/users/migrations/__init__.py +0 -0
- package/templates/base/backend/apps/users/models.py +15 -0
- package/templates/base/backend/apps/users/serializers.py +16 -0
- package/templates/base/backend/apps/users/services.py +25 -0
- package/templates/base/backend/apps/users/tests/__init__.py +0 -0
- package/templates/base/backend/apps/users/tests/test_models.py +30 -0
- package/templates/base/backend/apps/users/tests/test_views.py +55 -0
- package/templates/base/backend/apps/users/urls.py +10 -0
- package/templates/base/backend/apps/users/views.py +20 -0
- package/templates/base/backend/config/__init__.py.hbs +5 -0
- package/templates/base/backend/config/asgi.py +9 -0
- package/templates/base/backend/config/settings/__init__.py +0 -0
- package/templates/base/backend/config/settings/base.py.hbs +197 -0
- package/templates/base/backend/config/settings/local.py +31 -0
- package/templates/base/backend/config/settings/production.py.hbs +37 -0
- package/templates/base/backend/config/urls.py.hbs +22 -0
- package/templates/base/backend/config/wsgi.py +9 -0
- package/templates/base/backend/manage.py +23 -0
- package/templates/base/backend/pyproject.toml.hbs +48 -0
- package/templates/base/backend/start.sh +5 -0
- package/templates/base/docker-compose.yml.hbs +196 -0
- package/templates/base/docs/docs/api.md +21 -0
- package/templates/base/docs/docs/dude.md.hbs +305 -0
- package/templates/base/docs/docs/index.md.hbs +92 -0
- package/templates/base/docs/docs/mkdocs.md +231 -0
- package/templates/base/docs/mkdocs.yml.hbs +52 -0
- package/templates/base/e2e/.prettierrc.json +1 -0
- package/templates/base/e2e/_prettierignore +3 -0
- package/templates/base/e2e/cucumber.js +21 -0
- package/templates/base/e2e/eslint.config.mjs +14 -0
- package/templates/base/e2e/features/example.feature +13 -0
- package/templates/base/e2e/package.json.hbs +30 -0
- package/templates/base/e2e/pages/ExamplePage.ts +16 -0
- package/templates/base/e2e/playwright.config.ts +27 -0
- package/templates/base/e2e/steps/common.steps.ts +32 -0
- package/templates/base/e2e/steps/example.steps.ts +4 -0
- package/templates/base/e2e/support/hooks.ts +72 -0
- package/templates/base/e2e/support/world.ts +24 -0
- package/templates/base/e2e/tsconfig.json +22 -0
- package/templates/base/frontend/.prettierrc.json +6 -0
- package/templates/base/frontend/Dockerfile +10 -0
- package/templates/base/frontend/_dockerignore +4 -0
- package/templates/base/frontend/eslint.config.js +32 -0
- package/templates/base/frontend/index.html.hbs +13 -0
- package/templates/base/frontend/package.json.hbs +38 -0
- package/templates/base/frontend/public/favicon.svg +5 -0
- package/templates/base/frontend/src/$components/Layout/$assets/logo.svg +5 -0
- package/templates/base/frontend/src/$components/Layout/constants.tsx +8 -0
- package/templates/base/frontend/src/$components/Layout/index.tsx +80 -0
- package/templates/base/frontend/src/$components/Layout/types.tsx +9 -0
- package/templates/base/frontend/src/$components/index.tsx +1 -0
- package/templates/base/frontend/src/$hooks/index.tsx +2 -0
- package/templates/base/frontend/src/$hooks/useCounterStore/index.tsx +28 -0
- package/templates/base/frontend/src/$hooks/useCounterStore/types.tsx +7 -0
- package/templates/base/frontend/src/$hooks/usePageTitle/index.tsx +21 -0
- package/templates/base/frontend/src/$types/vite-env.d.ts +10 -0
- package/templates/base/frontend/src/App.tsx +36 -0
- package/templates/base/frontend/src/main.tsx +10 -0
- package/templates/base/frontend/src/openapi/utils/openapi.yaml.hbs +129 -0
- package/templates/base/frontend/src/pages/constants.tsx +31 -0
- package/templates/base/frontend/src/pages/index.tsx +192 -0
- package/templates/base/frontend/src/pages/types.tsx +6 -0
- package/templates/base/frontend/src/pages/users/[id]/index.tsx +53 -0
- package/templates/base/frontend/src/pages/users/index.tsx +57 -0
- package/templates/base/frontend/src/pages/users/types.tsx +4 -0
- package/templates/base/frontend/src/styles.module.css +7 -0
- package/templates/base/frontend/src/utils/constants.tsx +11 -0
- package/templates/base/frontend/src/utils/formatters/index.tsx +49 -0
- package/templates/base/frontend/src/utils/functions.tsx +70 -0
- package/templates/base/frontend/src/utils/index.tsx +3 -0
- package/templates/base/frontend/tsconfig.json +24 -0
- package/templates/base/frontend/vite.config.ts +20 -0
- package/templates/base/package.json.hbs +11 -0
- package/templates/base/security/baseline.json +4 -0
- package/templates/celery/backend/apps/core/tasks.py +14 -0
- package/templates/celery/backend/apps/core/tests/test_tasks.py +6 -0
- package/templates/celery/backend/config/celery.py.hbs +26 -0
- package/templates/celerybeat/backend/apps/core/tasks_scheduled.py +18 -0
- package/templates/celerybeat/backend/apps/core/tests/test_tasks_scheduled.py +6 -0
- package/templates/postgres/.dude/commands/reset.ts +83 -0
- package/templates/s3/backend/apps/files/__init__.py +0 -0
- package/templates/s3/backend/apps/files/admin.py +9 -0
- package/templates/s3/backend/apps/files/apps.py +6 -0
- package/templates/s3/backend/apps/files/migrations/0001_initial.py +29 -0
- package/templates/s3/backend/apps/files/migrations/__init__.py +0 -0
- package/templates/s3/backend/apps/files/models.py +21 -0
- package/templates/s3/backend/apps/files/serializers.py +27 -0
- package/templates/s3/backend/apps/files/services.py +19 -0
- package/templates/s3/backend/apps/files/tests/__init__.py +0 -0
- package/templates/s3/backend/apps/files/tests/test_models.py +10 -0
- package/templates/s3/backend/apps/files/tests/test_views.py +32 -0
- package/templates/s3/backend/apps/files/urls.py +10 -0
- package/templates/s3/backend/apps/files/views.py +29 -0
- package/templates/s3/frontend/src/openapi/utils/openapi.yaml.hbs +253 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/commands/lint/checks/E2E/007.ts
|
|
2
|
+
import { readdirSync, readFileSync, existsSync } from "fs";
|
|
3
|
+
import path from "pathe";
|
|
4
|
+
var HARDCODED_URL_RE = /https?:\/\//;
|
|
5
|
+
function collectFiles(dir, ext) {
|
|
6
|
+
if (!existsSync(dir)) return [];
|
|
7
|
+
const results = [];
|
|
8
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
9
|
+
const full = path.join(dir, entry.name);
|
|
10
|
+
if (entry.isDirectory()) results.push(...collectFiles(full, ext));
|
|
11
|
+
else if (entry.name.endsWith(ext)) results.push(full);
|
|
12
|
+
}
|
|
13
|
+
return results;
|
|
14
|
+
}
|
|
15
|
+
function check(root) {
|
|
16
|
+
const stepsDir = path.join(root, "e2e", "steps");
|
|
17
|
+
if (!existsSync(stepsDir)) return [];
|
|
18
|
+
const diagnostics = [];
|
|
19
|
+
for (const file of collectFiles(stepsDir, ".steps.ts")) {
|
|
20
|
+
let lines;
|
|
21
|
+
try {
|
|
22
|
+
lines = readFileSync(file, "utf8").split("\n");
|
|
23
|
+
} catch {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
for (let i = 0; i < lines.length; i++) {
|
|
27
|
+
const line = lines[i];
|
|
28
|
+
if (line === void 0) continue;
|
|
29
|
+
const stripped = line.trim();
|
|
30
|
+
if (stripped.startsWith("//") || stripped.startsWith("*")) continue;
|
|
31
|
+
if (HARDCODED_URL_RE.test(line)) {
|
|
32
|
+
diagnostics.push({
|
|
33
|
+
file: path.relative(root, file),
|
|
34
|
+
line: i + 1,
|
|
35
|
+
col: 1,
|
|
36
|
+
severity: "warning",
|
|
37
|
+
message: `Hardcoded URL detected. Use this.baseUrl from CustomWorld instead.`
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return diagnostics;
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
check as default
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=007.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/commands/lint/checks/E2E/007.ts"],"sourcesContent":["import { readdirSync, readFileSync, existsSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\n\nconst HARDCODED_URL_RE = /https?:\\/\\//\n\nfunction collectFiles(dir: string, ext: string): string[] {\n if (!existsSync(dir)) return []\n const results: string[] = []\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n const full = path.join(dir, entry.name)\n if (entry.isDirectory()) results.push(...collectFiles(full, ext))\n else if (entry.name.endsWith(ext)) results.push(full)\n }\n return results\n}\n\n/** ET007 — step files must not contain hardcoded URLs (use this.baseUrl from CustomWorld) */\nexport default function check(root: string): RawDiagnostic[] {\n const stepsDir = path.join(root, 'e2e', 'steps')\n if (!existsSync(stepsDir)) return []\n\n const diagnostics: RawDiagnostic[] = []\n\n for (const file of collectFiles(stepsDir, '.steps.ts')) {\n let lines: string[]\n try {\n lines = readFileSync(file, 'utf8').split('\\n')\n } catch {\n continue\n }\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]\n if (line === undefined) continue\n const stripped = line.trim()\n if (stripped.startsWith('//') || stripped.startsWith('*')) continue\n if (HARDCODED_URL_RE.test(line)) {\n diagnostics.push({\n file: path.relative(root, file),\n line: i + 1,\n col: 1,\n severity: 'warning',\n message: `Hardcoded URL detected. Use this.baseUrl from CustomWorld instead.`,\n })\n }\n }\n }\n\n return diagnostics\n}\n"],"mappings":";AAAA,SAAS,aAAa,cAAc,kBAAkB;AACtD,OAAO,UAAU;AAGjB,IAAM,mBAAmB;AAEzB,SAAS,aAAa,KAAa,KAAuB;AACxD,MAAI,CAAC,WAAW,GAAG,EAAG,QAAO,CAAC;AAC9B,QAAM,UAAoB,CAAC;AAC3B,aAAW,SAAS,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAAG;AAC7D,UAAM,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI;AACtC,QAAI,MAAM,YAAY,EAAG,SAAQ,KAAK,GAAG,aAAa,MAAM,GAAG,CAAC;AAAA,aACvD,MAAM,KAAK,SAAS,GAAG,EAAG,SAAQ,KAAK,IAAI;AAAA,EACtD;AACA,SAAO;AACT;AAGe,SAAR,MAAuB,MAA+B;AAC3D,QAAM,WAAW,KAAK,KAAK,MAAM,OAAO,OAAO;AAC/C,MAAI,CAAC,WAAW,QAAQ,EAAG,QAAO,CAAC;AAEnC,QAAM,cAA+B,CAAC;AAEtC,aAAW,QAAQ,aAAa,UAAU,WAAW,GAAG;AACtD,QAAI;AACJ,QAAI;AACF,cAAQ,aAAa,MAAM,MAAM,EAAE,MAAM,IAAI;AAAA,IAC/C,QAAQ;AACN;AAAA,IACF;AAEA,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,YAAM,OAAO,MAAM,CAAC;AACpB,UAAI,SAAS,OAAW;AACxB,YAAM,WAAW,KAAK,KAAK;AAC3B,UAAI,SAAS,WAAW,IAAI,KAAK,SAAS,WAAW,GAAG,EAAG;AAC3D,UAAI,iBAAiB,KAAK,IAAI,GAAG;AAC/B,oBAAY,KAAK;AAAA,UACf,MAAM,KAAK,SAAS,MAAM,IAAI;AAAA,UAC9B,MAAM,IAAI;AAAA,UACV,KAAK;AAAA,UACL,UAAU;AAAA,UACV,SAAS;AAAA,QACX,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/commands/lint/checks/FE/001.ts
|
|
2
|
+
import { readdirSync as readdirSync2 } from "fs";
|
|
3
|
+
import path2 from "pathe";
|
|
4
|
+
|
|
5
|
+
// src/commands/lint/frontend-structure.ts
|
|
6
|
+
import { readdirSync, existsSync } from "fs";
|
|
7
|
+
import path from "pathe";
|
|
8
|
+
var PASCAL_CASE = /^[A-Z][a-zA-Z0-9]*$/;
|
|
9
|
+
function frontendSrc(root) {
|
|
10
|
+
return path.join(root, "frontend", "src");
|
|
11
|
+
}
|
|
12
|
+
function diag(root, absPath, severity, message) {
|
|
13
|
+
return { file: path.relative(root, absPath), line: 1, col: 1, severity, message };
|
|
14
|
+
}
|
|
15
|
+
function findDirsNamed(dir, name) {
|
|
16
|
+
const found = [];
|
|
17
|
+
if (!existsSync(dir)) return found;
|
|
18
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
19
|
+
if (!entry.isDirectory() || entry.name === "node_modules") continue;
|
|
20
|
+
const full = path.join(dir, entry.name);
|
|
21
|
+
if (entry.name === name) found.push(full);
|
|
22
|
+
if (entry.name === "$misc") continue;
|
|
23
|
+
found.push(...findDirsNamed(full, name));
|
|
24
|
+
}
|
|
25
|
+
return found;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/commands/lint/checks/FE/001.ts
|
|
29
|
+
function check(root) {
|
|
30
|
+
const results = [];
|
|
31
|
+
for (const componentsDir of findDirsNamed(frontendSrc(root), "$components")) {
|
|
32
|
+
for (const entry of readdirSync2(componentsDir, { withFileTypes: true })) {
|
|
33
|
+
if (!entry.isDirectory()) continue;
|
|
34
|
+
const full = path2.join(componentsDir, entry.name);
|
|
35
|
+
if (entry.name.startsWith("$")) {
|
|
36
|
+
results.push(
|
|
37
|
+
diag(
|
|
38
|
+
root,
|
|
39
|
+
full,
|
|
40
|
+
"error",
|
|
41
|
+
`Privileged directory "${entry.name}" is not allowed directly inside $components/ \u2014 it belongs inside a component directory`
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
} else if (!PASCAL_CASE.test(entry.name)) {
|
|
45
|
+
results.push(
|
|
46
|
+
diag(root, full, "error", `Component directory "${entry.name}" must be PascalCase`)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return results;
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
check as default
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=001.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/commands/lint/checks/FE/001.ts","../../../../../src/commands/lint/frontend-structure.ts"],"sourcesContent":["import { readdirSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\nimport { PASCAL_CASE, diag, findDirsNamed, frontendSrc } from '../../frontend-structure'\n\n/** FE001 — every directory inside any $components/ must be PascalCase */\nexport default function check(root: string): RawDiagnostic[] {\n const results: RawDiagnostic[] = []\n\n for (const componentsDir of findDirsNamed(frontendSrc(root), '$components')) {\n for (const entry of readdirSync(componentsDir, { withFileTypes: true })) {\n if (!entry.isDirectory()) continue\n const full = path.join(componentsDir, entry.name)\n if (entry.name.startsWith('$')) {\n results.push(\n diag(\n root,\n full,\n 'error',\n `Privileged directory \"${entry.name}\" is not allowed directly inside $components/ — it belongs inside a component directory`,\n ),\n )\n } else if (!PASCAL_CASE.test(entry.name)) {\n results.push(\n diag(root, full, 'error', `Component directory \"${entry.name}\" must be PascalCase`),\n )\n }\n }\n }\n return results\n}\n","/**\n * Shared vocabulary for the FE lint checks (frontend `$`-structure).\n *\n * The frontend tree is organised in \"scopes\" (components, hooks, pages, utils\n * domains). Every scope owns the same file set (SCOPE_FILES) plus privileged\n * `$`-prefixed subdirectories ($components, $hooks, $assets, $misc). The `$`\n * prefix sorts these folders on top and makes them impossible to confuse with\n * a route segment or a domain name.\n *\n * Not a check module: it lives outside `checks/` so the runner never tries to\n * load it; tsup inlines it into each check entry.\n */\nimport { readdirSync, existsSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic, Severity } from '@cubocicloide/dude'\n\n/** Files every scope (component, hook, page, utils domain) may contain. */\nexport const SCOPE_FILES = new Set([\n 'index.tsx',\n 'styles.module.css',\n 'types.tsx',\n 'constants.tsx',\n 'functions.tsx',\n])\n\n/** Human-readable version of SCOPE_FILES for messages. */\nexport const SCOPE_FILES_LABEL = 'index.tsx, styles.module.css, types.tsx, constants.tsx, functions.tsx'\n\n/** The full set of privileged directory names. */\nexport const PRIVILEGED_DIRS = new Set(['$components', '$hooks', '$assets', '$misc', '$types'])\n\nexport const PASCAL_CASE = /^[A-Z][a-zA-Z0-9]*$/\nexport const KEBAB_CASE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/\nexport const HOOK_NAME = /^use[A-Z][a-zA-Z0-9]*$/\n/** Dynamic route segment: [id], [userId], … */\nexport const DYNAMIC_SEGMENT = /^\\[[a-z][a-zA-Z0-9]*\\]$/\n\nexport function frontendSrc(root: string): string {\n return path.join(root, 'frontend', 'src')\n}\n\nexport function diag(\n root: string,\n absPath: string,\n severity: Severity,\n message: string,\n): RawDiagnostic {\n return { file: path.relative(root, absPath), line: 1, col: 1, severity, message }\n}\n\n/**\n * Recursively collect directories named `name` under `dir`.\n * Never descends into `$misc` (exempt from checks) or `node_modules`,\n * but a `$misc` directory itself is still reported when it matches `name`.\n */\nexport function findDirsNamed(dir: string, name: string): string[] {\n const found: string[] = []\n if (!existsSync(dir)) return found\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name === 'node_modules') continue\n const full = path.join(dir, entry.name)\n if (entry.name === name) found.push(full)\n if (entry.name === '$misc') continue\n found.push(...findDirsNamed(full, name))\n }\n return found\n}\n\n/**\n * Collect page nodes under `pagesDir` as route paths relative to pages/\n * ('' = pages root). A page node is a directory whose index.tsx defines a\n * route. `$`-prefixed directories are structural, never route segments.\n */\nexport function collectPageNodes(pagesDir: string): string[] {\n const nodes: string[] = []\n if (!existsSync(pagesDir)) return nodes\n\n function walk(dir: string, route: string): void {\n if (existsSync(path.join(dir, 'index.tsx'))) nodes.push(route)\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name.startsWith('$')) continue\n wal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AAA,UACrC;AAAA,QACF;AAAA,MACF,WAAW,CAAC,YAAY,KAAK,MAAM,IAAI,GAAG;AACxC,gBAAQ;AAAA,UACN,KAAK,MAAM,MAAM,SAAS,wBAAwB,MAAM,IAAI,sBAAsB;AAAA,QACpF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["readdirSync","path","readdirSync","path"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/commands/lint/checks/FE/002.ts
|
|
2
|
+
import { readdirSync as readdirSync2, existsSync as existsSync2 } from "fs";
|
|
3
|
+
import path2 from "pathe";
|
|
4
|
+
|
|
5
|
+
// src/commands/lint/frontend-structure.ts
|
|
6
|
+
import { readdirSync, existsSync } from "fs";
|
|
7
|
+
import path from "pathe";
|
|
8
|
+
var SCOPE_FILES = /* @__PURE__ */ new Set([
|
|
9
|
+
"index.tsx",
|
|
10
|
+
"styles.module.css",
|
|
11
|
+
"types.tsx",
|
|
12
|
+
"constants.tsx",
|
|
13
|
+
"functions.tsx"
|
|
14
|
+
]);
|
|
15
|
+
var SCOPE_FILES_LABEL = "index.tsx, styles.module.css, types.tsx, constants.tsx, functions.tsx";
|
|
16
|
+
var PASCAL_CASE = /^[A-Z][a-zA-Z0-9]*$/;
|
|
17
|
+
function frontendSrc(root) {
|
|
18
|
+
return path.join(root, "frontend", "src");
|
|
19
|
+
}
|
|
20
|
+
function diag(root, absPath, severity, message) {
|
|
21
|
+
return { file: path.relative(root, absPath), line: 1, col: 1, severity, message };
|
|
22
|
+
}
|
|
23
|
+
function findDirsNamed(dir, name) {
|
|
24
|
+
const found = [];
|
|
25
|
+
if (!existsSync(dir)) return found;
|
|
26
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
27
|
+
if (!entry.isDirectory() || entry.name === "node_modules") continue;
|
|
28
|
+
const full = path.join(dir, entry.name);
|
|
29
|
+
if (entry.name === name) found.push(full);
|
|
30
|
+
if (entry.name === "$misc") continue;
|
|
31
|
+
found.push(...findDirsNamed(full, name));
|
|
32
|
+
}
|
|
33
|
+
return found;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/commands/lint/checks/FE/002.ts
|
|
37
|
+
var ALLOWED_DIRS = /* @__PURE__ */ new Set(["$components", "$hooks", "$assets", "$misc"]);
|
|
38
|
+
function check(root) {
|
|
39
|
+
const results = [];
|
|
40
|
+
for (const componentsDir of findDirsNamed(frontendSrc(root), "$components")) {
|
|
41
|
+
for (const entry of readdirSync2(componentsDir, { withFileTypes: true })) {
|
|
42
|
+
if (!entry.isDirectory() || !PASCAL_CASE.test(entry.name)) continue;
|
|
43
|
+
const componentDir = path2.join(componentsDir, entry.name);
|
|
44
|
+
if (!existsSync2(path2.join(componentDir, "index.tsx"))) {
|
|
45
|
+
results.push(
|
|
46
|
+
diag(root, componentDir, "error", `Component "${entry.name}" is missing its index.tsx`)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
for (const child of readdirSync2(componentDir, { withFileTypes: true })) {
|
|
50
|
+
const childPath = path2.join(componentDir, child.name);
|
|
51
|
+
if (child.isDirectory()) {
|
|
52
|
+
if (!ALLOWED_DIRS.has(child.name)) {
|
|
53
|
+
results.push(
|
|
54
|
+
diag(
|
|
55
|
+
root,
|
|
56
|
+
childPath,
|
|
57
|
+
"error",
|
|
58
|
+
`Unexpected directory "${child.name}" in component directory. Allowed: $components/, $hooks/, $assets/, $misc/`
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
} else if (!SCOPE_FILES.has(child.name)) {
|
|
63
|
+
results.push(
|
|
64
|
+
diag(
|
|
65
|
+
root,
|
|
66
|
+
childPath,
|
|
67
|
+
"error",
|
|
68
|
+
`Unexpected file "${child.name}" in component directory. Allowed: ${SCOPE_FILES_LABEL}`
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return results;
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
check as default
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=002.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/commands/lint/checks/FE/002.ts","../../../../../src/commands/lint/frontend-structure.ts"],"sourcesContent":["import { readdirSync, existsSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\nimport {\n PASCAL_CASE,\n SCOPE_FILES,\n SCOPE_FILES_LABEL,\n diag,\n findDirsNamed,\n frontendSrc,\n} from '../../frontend-structure'\n\nconst ALLOWED_DIRS = new Set(['$components', '$hooks', '$assets', '$misc'])\n\n/** FE002 — component dirs contain only the scope files and $components/$hooks/$assets/$misc */\nexport default function check(root: string): RawDiagnostic[] {\n const results: RawDiagnostic[] = []\n\n for (const componentsDir of findDirsNamed(frontendSrc(root), '$components')) {\n for (const entry of readdirSync(componentsDir, { withFileTypes: true })) {\n if (!entry.isDirectory() || !PASCAL_CASE.test(entry.name)) continue\n const componentDir = path.join(componentsDir, entry.name)\n\n if (!existsSync(path.join(componentDir, 'index.tsx'))) {\n results.push(\n diag(root, componentDir, 'error', `Component \"${entry.name}\" is missing its index.tsx`),\n )\n }\n\n for (const child of readdirSync(componentDir, { withFileTypes: true })) {\n const childPath = path.join(componentDir, child.name)\n if (child.isDirectory()) {\n if (!ALLOWED_DIRS.has(child.name)) {\n results.push(\n diag(\n root,\n childPath,\n 'error',\n `Unexpected directory \"${child.name}\" in component directory. Allowed: $components/, $hooks/, $assets/, $misc/`,\n ),\n )\n }\n } else if (!SCOPE_FILES.has(child.name)) {\n results.push(\n diag(\n root,\n childPath,\n 'error',\n `Unexpected file \"${child.name}\" in component directory. Allowed: ${SCOPE_FILES_LABEL}`,\n ),\n )\n }\n }\n }\n }\n return results\n}\n","/**\n * Shared vocabulary for the FE lint checks (frontend `$`-structure).\n *\n * The frontend tree is organised in \"scopes\" (components, hooks, pages, utils\n * domains). Every scope owns the same file set (SCOPE_FILES) plus privileged\n * `$`-prefixed subdirectories ($components, $hooks, $assets, $misc). The `$`\n * prefix sorts these folders on top and makes them impossible to confuse with\n * a route segment or a domain name.\n *\n * Not a check module: it lives outside `checks/` so the runner never tries to\n * load it; tsup inlines it into each check entry.\n */\nimport { readdirSync, existsSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic, Severity } from '@cubocicloide/dude'\n\n/** Files every scope (component, hook, page, utils domain) may contain. */\nexport const SCOPE_FILES = new Set([\n 'index.tsx',\n 'styles.module.css',\n 'types.tsx',\n 'constants.tsx',\n 'functions.tsx',\n])\n\n/** Human-readable version of SCOPE_FILES for messages. */\nexport const SCOPE_FILES_LABEL = 'index.tsx, styles.module.css, types.tsx, constants.tsx, functions.tsx'\n\n/** The full set of privileged directory names. */\nexport const PRIVILEGED_DIRS = new Set(['$components', '$hooks', '$assets', '$misc', '$types'])\n\nexport const PASCAL_CASE = /^[A-Z][a-zA-Z0-9]*$/\nexport const KEBAB_CASE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/\nexport const HOOK_NAME = /^use[A-Z][a-zA-Z0-9]*$/\n/** Dynamic route segment: [id], [userId], … */\nexport const DYNAMIC_SEGMENT = /^\\[[a-z][a-zA-Z0-9]*\\]$/\n\nexport function frontendSrc(root: string): string {\n return path.join(root, 'frontend', 'src')\n}\n\nexport function diag(\n root: string,\n absPath: string,\n severity: Severity,\n message: string,\n): RawDiagnostic {\n return { file: path.relative(root, absPath), line: 1, col: 1, severity, message }\n}\n\n/**\n * Recursively collect directories named `name` under `dir`.\n * Never descends into `$misc` (exempt from checks) or `node_modules`,\n * but a `$misc` directory itself is still reported when it matches `name`.\n */\nexport function findDirsNamed(dir: string, name: string): string[] {\n const found: string[] = []\n if (!existsSync(dir)) return found\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name === 'node_modules') continue\n const full = path.join(dir, entry.name)\n if (entry.name === name) found.push(full)\n if (entry.name === '$misc') continue\n found.push(...findDirsNamed(full, name))\n }\n return found\n}\n\n/**\n * Collect page nodes under `pagesDir` as route paths relative to pages/\n * ('' = pages root). A page node is a directory whose index.tsx defines a\n * route. `$`-prefixed directories are structural, never route segments.\n */\nexport function collectPageNodes(pagesDir: string): string[] {\n const nodes: string[] = []\n if (!existsSync(pagesDir)) return nodes\n\n function walk(dir: string, route: string): void {\n if (existsSync(path.join(dir, 'index.tsx'))) nodes.push(route)\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name.startsWith('$')) continue\n walk(path.join(dir, entry.name), route === '' ? entry.name : `${route}/${entry.name}`)\n }\n }\n\n walk(pagesDir, '')\n return nodes\n}\n"],"mappings":";AAAA,SAAS,eAAAA,cAAa,cAAAC,mBAAkB;AACxC,OAAOC,WAAU;;;ACWjB,SAAS,aAAa,kBAAkB;AACxC,OAAO,UAAU;AAIV,IAAM,cAAc,oBAAI,IAAI;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,IAAM,oBAAoB;AAK1B,IAAM,cAAc;AAMpB,SAAS,YAAY,MAAsB;AAChD,SAAO,KAAK,KAAK,MAAM,YAAY,KAAK;AAC1C;AAEO,SAAS,KACd,MACA,SACA,UACA,SACe;AACf,SAAO,EAAE,MAAM,KAAK,SAAS,MAAM,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,UAAU,QAAQ;AAClF;AAOO,SAAS,cAAc,KAAa,MAAwB;AACjE,QAAM,QAAkB,CAAC;AACzB,MAAI,CAAC,WAAW,GAAG,EAAG,QAAO;AAC7B,aAAW,SAAS,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAAG;AAC7D,QAAI,CAAC,MAAM,YAAY,KAAK,MAAM,SAAS,eAAgB;AAC3D,UAAM,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI;AACtC,QAAI,MAAM,SAAS,KAAM,OAAM,KAAK,IAAI;AACxC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 -0,0 +1,65 @@
|
|
|
1
|
+
// src/commands/lint/checks/FE/003.ts
|
|
2
|
+
import { readdirSync as readdirSync2, existsSync as existsSync2, readFileSync } from "fs";
|
|
3
|
+
import path2 from "pathe";
|
|
4
|
+
|
|
5
|
+
// src/commands/lint/frontend-structure.ts
|
|
6
|
+
import { readdirSync, existsSync } from "fs";
|
|
7
|
+
import path from "pathe";
|
|
8
|
+
var PASCAL_CASE = /^[A-Z][a-zA-Z0-9]*$/;
|
|
9
|
+
function frontendSrc(root) {
|
|
10
|
+
return path.join(root, "frontend", "src");
|
|
11
|
+
}
|
|
12
|
+
function diag(root, absPath, severity, message) {
|
|
13
|
+
return { file: path.relative(root, absPath), line: 1, col: 1, severity, message };
|
|
14
|
+
}
|
|
15
|
+
function findDirsNamed(dir, name) {
|
|
16
|
+
const found = [];
|
|
17
|
+
if (!existsSync(dir)) return found;
|
|
18
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
19
|
+
if (!entry.isDirectory() || entry.name === "node_modules") continue;
|
|
20
|
+
const full = path.join(dir, entry.name);
|
|
21
|
+
if (entry.name === name) found.push(full);
|
|
22
|
+
if (entry.name === "$misc") continue;
|
|
23
|
+
found.push(...findDirsNamed(full, name));
|
|
24
|
+
}
|
|
25
|
+
return found;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/commands/lint/checks/FE/003.ts
|
|
29
|
+
function check(root) {
|
|
30
|
+
const results = [];
|
|
31
|
+
for (const componentsDir of findDirsNamed(frontendSrc(root), "$components")) {
|
|
32
|
+
const componentNames = readdirSync2(componentsDir, { withFileTypes: true }).filter((e) => e.isDirectory() && PASCAL_CASE.test(e.name)).map((e) => e.name);
|
|
33
|
+
if (componentNames.length === 0) continue;
|
|
34
|
+
const barrelFile = path2.join(componentsDir, "index.tsx");
|
|
35
|
+
if (!existsSync2(barrelFile)) {
|
|
36
|
+
results.push(
|
|
37
|
+
diag(
|
|
38
|
+
root,
|
|
39
|
+
componentsDir,
|
|
40
|
+
"error",
|
|
41
|
+
`$components/ is missing its index.tsx barrel (must export: ${componentNames.join(", ")})`
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const barrel = readFileSync(barrelFile, "utf8");
|
|
47
|
+
for (const name of componentNames) {
|
|
48
|
+
if (!barrel.includes(`from './${name}'`) && !barrel.includes(`from "./${name}"`)) {
|
|
49
|
+
results.push(
|
|
50
|
+
diag(
|
|
51
|
+
root,
|
|
52
|
+
barrelFile,
|
|
53
|
+
"error",
|
|
54
|
+
`$components/index.tsx is missing a barrel export for "${name}"`
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return results;
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
check as default
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=003.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/commands/lint/checks/FE/003.ts","../../../../../src/commands/lint/frontend-structure.ts"],"sourcesContent":["import { readdirSync, existsSync, readFileSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\nimport { PASCAL_CASE, diag, findDirsNamed, frontendSrc } from '../../frontend-structure'\n\n/** FE003 — every $components/ has an index.tsx barrel exporting all component directories */\nexport default function check(root: string): RawDiagnostic[] {\n const results: RawDiagnostic[] = []\n\n for (const componentsDir of findDirsNamed(frontendSrc(root), '$components')) {\n const componentNames = readdirSync(componentsDir, { withFileTypes: true })\n .filter((e) => e.isDirectory() && PASCAL_CASE.test(e.name))\n .map((e) => e.name)\n if (componentNames.length === 0) continue\n\n const barrelFile = path.join(componentsDir, 'index.tsx')\n if (!existsSync(barrelFile)) {\n results.push(\n diag(\n root,\n componentsDir,\n 'error',\n `$components/ is missing its index.tsx barrel (must export: ${componentNames.join(', ')})`,\n ),\n )\n continue\n }\n\n const barrel = readFileSync(barrelFile, 'utf8')\n for (const name of componentNames) {\n if (!barrel.includes(`from './${name}'`) && !barrel.includes(`from \"./${name}\"`)) {\n results.push(\n diag(\n root,\n barrelFile,\n 'error',\n `$components/index.tsx is missing a barrel export for \"${name}\"`,\n ),\n )\n }\n }\n }\n return results\n}\n","/**\n * Shared vocabulary for the FE lint checks (frontend `$`-structure).\n *\n * The frontend tree is organised in \"scopes\" (components, hooks, pages, utils\n * domains). Every scope owns the same file set (SCOPE_FILES) plus privileged\n * `$`-prefixed subdirectories ($components, $hooks, $assets, $misc). The `$`\n * prefix sorts these folders on top and makes them impossible to confuse with\n * a route segment or a domain name.\n *\n * Not a check module: it lives outside `checks/` so the runner never tries to\n * load it; tsup inlines it into each check entry.\n */\nimport { readdirSync, existsSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic, Severity } from '@cubocicloide/dude'\n\n/** Files every scope (component, hook, page, utils domain) may contain. */\nexport const SCOPE_FILES = new Set([\n 'index.tsx',\n 'styles.module.css',\n 'types.tsx',\n 'constants.tsx',\n 'functions.tsx',\n])\n\n/** Human-readable version of SCOPE_FILES for messages. */\nexport const SCOPE_FILES_LABEL = 'index.tsx, styles.module.css, types.tsx, constants.tsx, functions.tsx'\n\n/** The full set of privileged directory names. */\nexport const PRIVILEGED_DIRS = new Set(['$components', '$hooks', '$assets', '$misc', '$types'])\n\nexport const PASCAL_CASE = /^[A-Z][a-zA-Z0-9]*$/\nexport const KEBAB_CASE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/\nexport const HOOK_NAME = /^use[A-Z][a-zA-Z0-9]*$/\n/** Dynamic route segment: [id], [userId], … */\nexport const DYNAMIC_SEGMENT = /^\\[[a-z][a-zA-Z0-9]*\\]$/\n\nexport function frontendSrc(root: string): string {\n return path.join(root, 'frontend', 'src')\n}\n\nexport function diag(\n root: string,\n absPath: string,\n severity: Severity,\n message: string,\n): RawDiagnostic {\n return { file: path.relative(root, absPath), line: 1, col: 1, severity, message }\n}\n\n/**\n * Recursively collect directories named `name` under `dir`.\n * Never descends into `$misc` (exempt from checks) or `node_modules`,\n * but a `$misc` directory itself is still reported when it matches `name`.\n */\nexport function findDirsNamed(dir: string, name: string): string[] {\n const found: string[] = []\n if (!existsSync(dir)) return found\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name === 'node_modules') continue\n const full = path.join(dir, entry.name)\n if (entry.name === name) found.push(full)\n if (entry.name === '$misc') continue\n found.push(...findDirsNamed(full, name))\n }\n return found\n}\n\n/**\n * Collect page nodes under `pagesDir` as route paths relative to pages/\n * ('' = pages root). A page node is a directory whose index.tsx defines a\n * route. `$`-prefixed directories are structural, never route segments.\n */\nexport function collectPageNodes(pagesDir: string): string[] {\n const nodes: string[] = []\n if (!existsSync(pagesDir)) return nodes\n\n function walk(dir: string, route: string): void {\n if (existsSync(path.join(dir, 'index.tsx'))) nodes.push(route)\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name.startsWith('$')) continue\n walk(path.join(dir, entry.name), route === '' ? entry.name : `${route}/${entry.name}`)\n }\n }\n\n walk(pagesDir, '')\n return nodes\n}\n"],"mappings":";AAAA,SAAS,eAAAA,cAAa,cAAAC,aAAY,oBAAoB;AACtD,OAAOC,WAAU;;;ACWjB,SAAS,aAAa,kBAAkB;AACxC,OAAO,UAAU;AAkBV,IAAM,cAAc;AAMpB,SAAS,YAAY,MAAsB;AAChD,SAAO,KAAK,KAAK,MAAM,YAAY,KAAK;AAC1C;AAEO,SAAS,KACd,MACA,SACA,UACA,SACe;AACf,SAAO,EAAE,MAAM,KAAK,SAAS,MAAM,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,UAAU,QAAQ;AAClF;AAOO,SAAS,cAAc,KAAa,MAAwB;AACjE,QAAM,QAAkB,CAAC;AACzB,MAAI,CAAC,WAAW,GAAG,EAAG,QAAO;AAC7B,aAAW,SAAS,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAAG;AAC7D,QAAI,CAAC,MAAM,YAAY,KAAK,MAAM,SAAS,eAAgB;AAC3D,UAAM,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI;AACtC,QAAI,MAAM,SAAS,KAAM,OAAM,KAAK,IAAI;AACxC,QAAI,MAAM,SAAS,QAAS;AAC5B,UAAM,KAAK,GAAG,cAAc,MAAM,IAAI,CAAC;AAAA,EACzC;AACA,SAAO;AACT;;;AD5De,SAAR,MAAuB,MAA+B;AAC3D,QAAM,UAA2B,CAAC;AAElC,aAAW,iBAAiB,cAAc,YAAY,IAAI,GAAG,aAAa,GAAG;AAC3E,UAAM,iBAAiBC,aAAY,eAAe,EAAE,eAAe,KAAK,CAAC,EACtE,OAAO,CAAC,MAAM,EAAE,YAAY,KAAK,YAAY,KAAK,EAAE,IAAI,CAAC,EACzD,IAAI,CAAC,MAAM,EAAE,IAAI;AACpB,QAAI,eAAe,WAAW,EAAG;AAEjC,UAAM,aAAaC,MAAK,KAAK,eAAe,WAAW;AACvD,QAAI,CAACC,YAAW,UAAU,GAAG;AAC3B,cAAQ;AAAA,QACN;AAAA,UACE;AAAA,UACA;AAAA,UACA;AAAA,UACA,8DAA8D,eAAe,KAAK,IAAI,CAAC;AAAA,QACzF;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,SAAS,aAAa,YAAY,MAAM;AAC9C,eAAW,QAAQ,gBAAgB;AACjC,UAAI,CAAC,OAAO,SAAS,WAAW,IAAI,GAAG,KAAK,CAAC,OAAO,SAAS,WAAW,IAAI,GAAG,GAAG;AAChF,gBAAQ;AAAA,UACN;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,YACA,yDAAyD,IAAI;AAAA,UAC/D;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["readdirSync","existsSync","path","readdirSync","path","existsSync"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/commands/lint/checks/FE/004.ts
|
|
2
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
3
|
+
import path2 from "pathe";
|
|
4
|
+
|
|
5
|
+
// src/commands/lint/frontend-structure.ts
|
|
6
|
+
import { readdirSync, existsSync } from "fs";
|
|
7
|
+
import path from "pathe";
|
|
8
|
+
function frontendSrc(root) {
|
|
9
|
+
return path.join(root, "frontend", "src");
|
|
10
|
+
}
|
|
11
|
+
function diag(root, absPath, severity, message) {
|
|
12
|
+
return { file: path.relative(root, absPath), line: 1, col: 1, severity, message };
|
|
13
|
+
}
|
|
14
|
+
function collectPageNodes(pagesDir) {
|
|
15
|
+
const nodes = [];
|
|
16
|
+
if (!existsSync(pagesDir)) return nodes;
|
|
17
|
+
function walk(dir, route) {
|
|
18
|
+
if (existsSync(path.join(dir, "index.tsx"))) nodes.push(route);
|
|
19
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
20
|
+
if (!entry.isDirectory() || entry.name.startsWith("$")) continue;
|
|
21
|
+
walk(path.join(dir, entry.name), route === "" ? entry.name : `${route}/${entry.name}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
walk(pagesDir, "");
|
|
25
|
+
return nodes;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/commands/lint/checks/FE/004.ts
|
|
29
|
+
var PAGE_IMPORT_RE = /from\s+['"](?:@|\.\.?)\/pages((?:\/[^'"]+)?)['"]/g;
|
|
30
|
+
function check(root) {
|
|
31
|
+
const src = frontendSrc(root);
|
|
32
|
+
const pagesDir = path2.join(src, "pages");
|
|
33
|
+
const appFile = path2.join(src, "App.tsx");
|
|
34
|
+
if (!existsSync2(pagesDir) || !existsSync2(appFile)) return [];
|
|
35
|
+
const pageNodes = new Set(collectPageNodes(pagesDir));
|
|
36
|
+
const appContent = readFileSync(appFile, "utf8");
|
|
37
|
+
const importedPages = /* @__PURE__ */ new Set();
|
|
38
|
+
for (const m of appContent.matchAll(PAGE_IMPORT_RE)) {
|
|
39
|
+
importedPages.add(m[1].replace(/^\//, ""));
|
|
40
|
+
}
|
|
41
|
+
const results = [];
|
|
42
|
+
const label = (route) => route === "" ? "pages" : `pages/${route}`;
|
|
43
|
+
for (const imported of importedPages) {
|
|
44
|
+
if (!pageNodes.has(imported)) {
|
|
45
|
+
results.push(
|
|
46
|
+
diag(
|
|
47
|
+
root,
|
|
48
|
+
appFile,
|
|
49
|
+
"error",
|
|
50
|
+
`App.tsx imports page "@/pages${imported ? `/${imported}` : ""}" but frontend/src/${label(imported)}/index.tsx does not exist`
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (const route of pageNodes) {
|
|
56
|
+
if (!importedPages.has(route)) {
|
|
57
|
+
results.push(
|
|
58
|
+
diag(
|
|
59
|
+
root,
|
|
60
|
+
path2.join(pagesDir, route),
|
|
61
|
+
"warning",
|
|
62
|
+
`${label(route)}/index.tsx exists but is not imported in App.tsx`
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return results;
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
check as default
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=004.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/commands/lint/checks/FE/004.ts","../../../../../src/commands/lint/frontend-structure.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\nimport { collectPageNodes, diag, frontendSrc } from '../../frontend-structure'\n\nconst PAGE_IMPORT_RE = /from\\s+['\"](?:@|\\.\\.?)\\/pages((?:\\/[^'\"]+)?)['\"]/g\n\n/** FE004 — imports of @/pages/... in App.tsx must match page nodes (dirs with index.tsx) 1-to-1 */\nexport default function check(root: string): RawDiagnostic[] {\n const src = frontendSrc(root)\n const pagesDir = path.join(src, 'pages')\n const appFile = path.join(src, 'App.tsx')\n if (!existsSync(pagesDir) || !existsSync(appFile)) return []\n\n const pageNodes = new Set(collectPageNodes(pagesDir))\n\n const appContent = readFileSync(appFile, 'utf8')\n const importedPages = new Set<string>()\n for (const m of appContent.matchAll(PAGE_IMPORT_RE)) {\n importedPages.add(m[1]!.replace(/^\\//, ''))\n }\n\n const results: RawDiagnostic[] = []\n const label = (route: string) => (route === '' ? 'pages' : `pages/${route}`)\n\n for (const imported of importedPages) {\n if (!pageNodes.has(imported)) {\n results.push(\n diag(\n root,\n appFile,\n 'error',\n `App.tsx imports page \"@/pages${imported ? `/${imported}` : ''}\" but frontend/src/${label(imported)}/index.tsx does not exist`,\n ),\n )\n }\n }\n for (const route of pageNodes) {\n if (!importedPages.has(route)) {\n results.push(\n diag(\n root,\n path.join(pagesDir, route),\n 'warning',\n `${label(route)}/index.tsx exists but is not imported in App.tsx`,\n ),\n )\n }\n }\n return results\n}\n","/**\n * Shared vocabulary for the FE lint checks (frontend `$`-structure).\n *\n * The frontend tree is organised in \"scopes\" (components, hooks, pages, utils\n * domains). Every scope owns the same file set (SCOPE_FILES) plus privileged\n * `$`-prefixed subdirectories ($components, $hooks, $assets, $misc). The `$`\n * prefix sorts these folders on top and makes them impossible to confuse with\n * a route segment or a domain name.\n *\n * Not a check module: it lives outside `checks/` so the runner never tries to\n * load it; tsup inlines it into each check entry.\n */\nimport { readdirSync, existsSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic, Severity } from '@cubocicloide/dude'\n\n/** Files every scope (component, hook, page, utils domain) may contain. */\nexport const SCOPE_FILES = new Set([\n 'index.tsx',\n 'styles.module.css',\n 'types.tsx',\n 'constants.tsx',\n 'functions.tsx',\n])\n\n/** Human-readable version of SCOPE_FILES for messages. */\nexport const SCOPE_FILES_LABEL = 'index.tsx, styles.module.css, types.tsx, constants.tsx, functions.tsx'\n\n/** The full set of privileged directory names. */\nexport const PRIVILEGED_DIRS = new Set(['$components', '$hooks', '$assets', '$misc', '$types'])\n\nexport const PASCAL_CASE = /^[A-Z][a-zA-Z0-9]*$/\nexport const KEBAB_CASE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/\nexport const HOOK_NAME = /^use[A-Z][a-zA-Z0-9]*$/\n/** Dynamic route segment: [id], [userId], … */\nexport const DYNAMIC_SEGMENT = /^\\[[a-z][a-zA-Z0-9]*\\]$/\n\nexport function frontendSrc(root: string): string {\n return path.join(root, 'frontend', 'src')\n}\n\nexport function diag(\n root: string,\n absPath: string,\n severity: Severity,\n message: string,\n): RawDiagnostic {\n return { file: path.relative(root, absPath), line: 1, col: 1, severity, message }\n}\n\n/**\n * Recursively collect directories named `name` under `dir`.\n * Never descends into `$misc` (exempt from checks) or `node_modules`,\n * but a `$misc` directory itself is still reported when it matches `name`.\n */\nexport function findDirsNamed(dir: string, name: string): string[] {\n const found: string[] = []\n if (!existsSync(dir)) return found\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name === 'node_modules') continue\n const full = path.join(dir, entry.name)\n if (entry.name === name) found.push(full)\n if (entry.name === '$misc') continue\n found.push(...findDirsNamed(full, name))\n }\n return found\n}\n\n/**\n * Collect page nodes under `pagesDir` as route paths relative to pages/\n * ('' = pages root). A page node is a directory whose index.tsx defines a\n * route. `$`-prefixed directories are structural, never route segments.\n */\nexport function collectPageNodes(pagesDir: string): string[] {\n const nodes: string[] = []\n if (!existsSync(pagesDir)) return nodes\n\n function walk(dir: string, route: string): void {\n if (existsSync(path.join(dir, 'index.tsx'))) nodes.push(route)\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name.startsWith('$')) continue\n walk(path.join(dir, entry.name), route === '' ? entry.name : `${route}/${entry.name}`)\n }\n }\n\n walk(pagesDir, '')\n return nodes\n}\n"],"mappings":";AAAA,SAAS,cAAAA,aAAY,oBAAoB;AACzC,OAAOC,WAAU;;;ACWjB,SAAS,aAAa,kBAAkB;AACxC,OAAO,UAAU;AAwBV,SAAS,YAAY,MAAsB;AAChD,SAA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UAAU,SAAS,KAAK;AAEzE,aAAW,YAAY,eAAe;AACpC,QAAI,CAAC,UAAU,IAAI,QAAQ,GAAG;AAC5B,cAAQ;AAAA,QACN;AAAA,UACE;AAAA,UACA;AAAA,UACA;AAAA,UACA,gCAAgC,WAAW,IAAI,QAAQ,KAAK,EAAE,sBAAsB,MAAM,QAAQ,CAAC;AAAA,QACrG;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,aAAW,SAAS,WAAW;AAC7B,QAAI,CAAC,cAAc,IAAI,KAAK,GAAG;AAC7B,cAAQ;AAAA,QACN;AAAA,UACE;AAAA,UACAD,MAAK,KAAK,UAAU,KAAK;AAAA,UACzB;AAAA,UACA,GAAG,MAAM,KAAK,CAAC;AAAA,QACjB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["existsSync","path","path","existsSync"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// src/commands/lint/checks/FE/005.ts
|
|
2
|
+
import { readdirSync as readdirSync2, existsSync as existsSync2 } from "fs";
|
|
3
|
+
import path2 from "pathe";
|
|
4
|
+
|
|
5
|
+
// src/commands/lint/frontend-structure.ts
|
|
6
|
+
import { readdirSync, existsSync } from "fs";
|
|
7
|
+
import path from "pathe";
|
|
8
|
+
var SCOPE_FILES = /* @__PURE__ */ new Set([
|
|
9
|
+
"index.tsx",
|
|
10
|
+
"styles.module.css",
|
|
11
|
+
"types.tsx",
|
|
12
|
+
"constants.tsx",
|
|
13
|
+
"functions.tsx"
|
|
14
|
+
]);
|
|
15
|
+
var SCOPE_FILES_LABEL = "index.tsx, styles.module.css, types.tsx, constants.tsx, functions.tsx";
|
|
16
|
+
var KEBAB_CASE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
17
|
+
var DYNAMIC_SEGMENT = /^\[[a-z][a-zA-Z0-9]*\]$/;
|
|
18
|
+
function frontendSrc(root) {
|
|
19
|
+
return path.join(root, "frontend", "src");
|
|
20
|
+
}
|
|
21
|
+
function diag(root, absPath, severity, message) {
|
|
22
|
+
return { file: path.relative(root, absPath), line: 1, col: 1, severity, message };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/commands/lint/checks/FE/005.ts
|
|
26
|
+
var ALLOWED_DIRS = /* @__PURE__ */ new Set(["$components", "$hooks", "$assets", "$misc"]);
|
|
27
|
+
var RESERVED_SEGMENTS = /* @__PURE__ */ new Set(["components", "hooks", "assets", "misc"]);
|
|
28
|
+
function check(root) {
|
|
29
|
+
const pagesDir = path2.join(frontendSrc(root), "pages");
|
|
30
|
+
if (!existsSync2(pagesDir)) return [];
|
|
31
|
+
const results = [];
|
|
32
|
+
function walk(dir) {
|
|
33
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
34
|
+
const entryPath = path2.join(dir, entry.name);
|
|
35
|
+
if (!entry.isDirectory()) {
|
|
36
|
+
if (!SCOPE_FILES.has(entry.name)) {
|
|
37
|
+
results.push(
|
|
38
|
+
diag(
|
|
39
|
+
root,
|
|
40
|
+
entryPath,
|
|
41
|
+
"error",
|
|
42
|
+
`Unexpected file "${entry.name}" in page directory. Allowed: ${SCOPE_FILES_LABEL}`
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (entry.name.startsWith("$")) {
|
|
49
|
+
if (!ALLOWED_DIRS.has(entry.name)) {
|
|
50
|
+
results.push(
|
|
51
|
+
diag(
|
|
52
|
+
root,
|
|
53
|
+
entryPath,
|
|
54
|
+
"error",
|
|
55
|
+
`Unknown privileged directory "${entry.name}" in page directory. Allowed: $components/, $hooks/, $assets/, $misc/`
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (RESERVED_SEGMENTS.has(entry.name)) {
|
|
62
|
+
results.push(
|
|
63
|
+
diag(
|
|
64
|
+
root,
|
|
65
|
+
entryPath,
|
|
66
|
+
"error",
|
|
67
|
+
`Route segment "${entry.name}" conflicts with the structural directories \u2014 use the privileged "$${entry.name}" folder, or pick a different route name`
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
} else if (!KEBAB_CASE.test(entry.name) && !DYNAMIC_SEGMENT.test(entry.name)) {
|
|
71
|
+
results.push(
|
|
72
|
+
diag(
|
|
73
|
+
root,
|
|
74
|
+
entryPath,
|
|
75
|
+
"error",
|
|
76
|
+
`Route segment "${entry.name}" must be kebab-case (e.g. "user-settings") or a dynamic [param] segment (e.g. "[id]")`
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const hasIndex = existsSync2(path2.join(entryPath, "index.tsx"));
|
|
81
|
+
const hasNestedRoutes = readdirSync2(entryPath, { withFileTypes: true }).some(
|
|
82
|
+
(e) => e.isDirectory() && !e.name.startsWith("$")
|
|
83
|
+
);
|
|
84
|
+
if (!hasIndex && !hasNestedRoutes) {
|
|
85
|
+
results.push(
|
|
86
|
+
diag(
|
|
87
|
+
root,
|
|
88
|
+
entryPath,
|
|
89
|
+
"warning",
|
|
90
|
+
`Route directory "${entry.name}" has no index.tsx and no nested routes`
|
|
91
|
+
)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
walk(entryPath);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
walk(pagesDir);
|
|
98
|
+
return results;
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
check as default
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=005.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/commands/lint/checks/FE/005.ts","../../../../../src/commands/lint/frontend-structure.ts"],"sourcesContent":["import { readdirSync, existsSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\nimport {\n DYNAMIC_SEGMENT,\n KEBAB_CASE,\n SCOPE_FILES,\n SCOPE_FILES_LABEL,\n diag,\n frontendSrc,\n} from '../../frontend-structure'\n\nconst ALLOWED_DIRS = new Set(['$components', '$hooks', '$assets', '$misc'])\n/** Unprefixed names that would shadow the privileged directories. */\nconst RESERVED_SEGMENTS = new Set(['components', 'hooks', 'assets', 'misc'])\n\n/** FE005 — page dirs contain only scope files + privileged dirs; route segments are kebab-case or [param] */\nexport default function check(root: string): RawDiagnostic[] {\n const pagesDir = path.join(frontendSrc(root), 'pages')\n if (!existsSync(pagesDir)) return []\n\n const results: RawDiagnostic[] = []\n\n function walk(dir: string): void {\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n const entryPath = path.join(dir, entry.name)\n\n if (!entry.isDirectory()) {\n if (!SCOPE_FILES.has(entry.name)) {\n results.push(\n diag(\n root,\n entryPath,\n 'error',\n `Unexpected file \"${entry.name}\" in page directory. Allowed: ${SCOPE_FILES_LABEL}`,\n ),\n )\n }\n continue\n }\n\n if (entry.name.startsWith('$')) {\n if (!ALLOWED_DIRS.has(entry.name)) {\n results.push(\n diag(\n root,\n entryPath,\n 'error',\n `Unknown privileged directory \"${entry.name}\" in page directory. Allowed: $components/, $hooks/, $assets/, $misc/`,\n ),\n )\n }\n continue\n }\n\n // Any other directory is a route segment.\n if (RESERVED_SEGMENTS.has(entry.name)) {\n results.push(\n diag(\n root,\n entryPath,\n 'error',\n `Route segment \"${entry.name}\" conflicts with the structural directories — use the privileged \"$${entry.name}\" folder, or pick a different route name`,\n ),\n )\n } else if (!KEBAB_CASE.test(entry.name) && !DYNAMIC_SEGMENT.test(entry.name)) {\n results.push(\n diag(\n root,\n entryPath,\n 'error',\n `Route segment \"${entry.name}\" must be kebab-case (e.g. \"user-settings\") or a dynamic [param] segment (e.g. \"[id]\")`,\n ),\n )\n }\n\n const hasIndex = existsSync(path.join(entryPath, 'index.tsx'))\n const hasNestedRoutes = readdirSync(entryPath, { withFileTypes: true }).some(\n (e) => e.isDirectory() && !e.name.startsWith('$'),\n )\n if (!hasIndex && !hasNestedRoutes) {\n results.push(\n diag(\n root,\n entryPath,\n 'warning',\n `Route directory \"${entry.name}\" has no index.tsx and no nested routes`,\n ),\n )\n }\n\n walk(entryPath)\n }\n }\n\n walk(pagesDir)\n return results\n}\n","/**\n * Shared vocabulary for the FE lint checks (frontend `$`-structure).\n *\n * The frontend tree is organised in \"scopes\" (components, hooks, pages, utils\n * domains). Every scope owns the same file set (SCOPE_FILES) plus privileged\n * `$`-prefixed subdirectories ($components, $hooks, $assets, $misc). The `$`\n * prefix sorts these folders on top and makes them impossible to confuse with\n * a route segment or a domain name.\n *\n * Not a check module: it lives outside `checks/` so the runner never tries to\n * load it; tsup inlines it into each check entry.\n */\nimport { readdirSync, existsSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic, Severity } from '@cubocicloide/dude'\n\n/** Files every scope (component, hook, page, utils domain) may contain. */\nexport const SCOPE_FILES = new Set([\n 'index.tsx',\n 'styles.module.css',\n 'types.tsx',\n 'constants.tsx',\n 'functions.tsx',\n])\n\n/** Human-readable version of SCOPE_FILES for messages. */\nexport const SCOPE_FILES_LABEL = 'index.tsx, styles.module.css, types.tsx, constants.tsx, functions.tsx'\n\n/** The full set of privileged directory names. */\nexport const PRIVILEGED_DIRS = new Set(['$components', '$hooks', '$assets', '$misc', '$types'])\n\nexport const PASCAL_CASE = /^[A-Z][a-zA-Z0-9]*$/\nexport const KEBAB_CASE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/\nexport const HOOK_NAME = /^use[A-Z][a-zA-Z0-9]*$/\n/** Dynamic route segment: [id], [userId], … */\nexport const DYNAMIC_SEGMENT = /^\\[[a-z][a-zA-Z0-9]*\\]$/\n\nexport function frontendSrc(root: string): string {\n return path.join(root, 'frontend', 'src')\n}\n\nexport function diag(\n root: string,\n absPath: string,\n severity: Severity,\n message: string,\n): RawDiagnostic {\n return { file: path.relative(root, absPath), line: 1, col: 1, severity, message }\n}\n\n/**\n * Recursively collect directories named `name` under `dir`.\n * Never descends into `$misc` (exempt from checks) or `node_modules`,\n * but a `$misc` directory itself is still reported when it matches `name`.\n */\nexport function findDirsNamed(dir: string, name: string): string[] {\n const found: string[] = []\n if (!existsSync(dir)) return found\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name === 'node_modules') continue\n const full = path.join(dir, entry.name)\n if (entry.name === name) found.push(full)\n if (entry.name === '$misc') continue\n found.push(...findDirsNamed(full, name))\n }\n return found\n}\n\n/**\n * Collect page nodes under `pagesDir` as route paths relative to pages/\n * ('' = pages root). A page node is a directory whose index.tsx defines a\n * route. `$`-prefixed directories are structural, never route segments.\n */\nexport function collectPageNodes(pagesDir: string): string[] {\n const nodes: string[] = []\n if (!existsSync(pagesDir)) return nodes\n\n function walk(dir: string, route: string): void {\n if (existsSync(path.join(dir, 'index.tsx'))) nodes.push(route)\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n if (!entry.isDirectory() || entry.name.startsWith('$')) continue\n walk(path.join(dir, entry.name), route === '' ? entry.name : `${route}/${entry.name}`)\n }\n }\n\n walk(pagesDir, '')\n return nodes\n}\n"],"mappings":";AAAA,SAAS,eAAAA,cAAa,cAAAC,mBAAkB;AACxC,OAAOC,WAAU;;;ACWjB,SAAS,aAAa,kBAAkB;AACxC,OAAO,UAAU;AAIV,IAAM,cAAc,oBAAI,IAAI;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,IAAM,oBAAoB;AAM1B,IAAM,aAAa;AAGnB,IAAM,kBAAkB;AAExB,SAAS,YAAY,MAAsB;AAChD,SAAO,KAAK,KAAK,MAAM,YAAY,KAAK;AAC1C;AAEO,SAAS,KACd,MACA,SACA,UACA,SACe;AACf,SAAO,EAAE,MAAM,KAAK,SAAS,MAAM,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,UAAU,QAAQ;AAClF;;;ADpCA,IAAM,eAAe,oBAAI,IAAI,CAAC,eAAe,UAAU,WAAW,OAAO,CAAC;AAE1E,IA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