@cubocicloide/stack-react-fastapi 13.0.6
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 +95 -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 +30 -0
- package/dist/commands/lint/checks/BE/002.js.map +1 -0
- package/dist/commands/lint/checks/BE/003.d.ts +11 -0
- package/dist/commands/lint/checks/BE/003.js +46 -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 +27 -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 +107 -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 +27 -0
- package/dist/commands/lint/checks/BE/006.js.map +1 -0
- package/dist/commands/lint/checks/BE/007.d.ts +31 -0
- package/dist/commands/lint/checks/BE/007.js +109 -0
- package/dist/commands/lint/checks/BE/007.js.map +1 -0
- package/dist/commands/lint/checks/BE/008.d.ts +12 -0
- package/dist/commands/lint/checks/BE/008.js +57 -0
- package/dist/commands/lint/checks/BE/008.js.map +1 -0
- package/dist/commands/lint/checks/BE/009.d.ts +12 -0
- package/dist/commands/lint/checks/BE/009.js +104 -0
- package/dist/commands/lint/checks/BE/009.js.map +1 -0
- package/dist/commands/lint/checks/BE/010.d.ts +12 -0
- package/dist/commands/lint/checks/BE/010.js +54 -0
- package/dist/commands/lint/checks/BE/010.js.map +1 -0
- package/dist/commands/lint/checks/BE/011.d.ts +16 -0
- package/dist/commands/lint/checks/BE/011.js +46 -0
- package/dist/commands/lint/checks/BE/011.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 +3491 -0
- package/dist/index.js.map +1 -0
- package/dude.stack.json +7 -0
- package/package.json +43 -0
- package/templates/aws-eks/backend/Dockerfile.prod.hbs +22 -0
- package/templates/aws-eks/docs/docs/deploy.md.hbs +159 -0
- package/templates/aws-eks/frontend/Dockerfile.prod +28 -0
- package/templates/aws-eks/frontend/nginx.conf +19 -0
- package/templates/aws-eks/iac/README.md.hbs +311 -0
- package/templates/aws-eks/iac/_gitignore +24 -0
- package/templates/aws-eks/iac/helm/app/.helmignore +7 -0
- package/templates/aws-eks/iac/helm/app/Chart.yaml.hbs +6 -0
- package/templates/aws-eks/iac/helm/app/templates/NOTES.txt +23 -0
- package/templates/aws-eks/iac/helm/app/templates/backend-deployment.yaml +44 -0
- package/templates/aws-eks/iac/helm/app/templates/backend-service.yaml +16 -0
- package/templates/aws-eks/iac/helm/app/templates/celery-beat-deployment.yaml +34 -0
- package/templates/aws-eks/iac/helm/app/templates/celery-worker-deployment.yaml +31 -0
- package/templates/aws-eks/iac/helm/app/templates/configmap.yaml +15 -0
- package/templates/aws-eks/iac/helm/app/templates/flower-deployment.yaml +28 -0
- package/templates/aws-eks/iac/helm/app/templates/flower-service.yaml +19 -0
- package/templates/aws-eks/iac/helm/app/templates/frontend-deployment.yaml +34 -0
- package/templates/aws-eks/iac/helm/app/templates/frontend-service.yaml +16 -0
- package/templates/aws-eks/iac/helm/app/templates/helpers.tpl +90 -0
- package/templates/aws-eks/iac/helm/app/templates/hpa.yaml +23 -0
- package/templates/aws-eks/iac/helm/app/templates/ingress.yaml +30 -0
- package/templates/aws-eks/iac/helm/app/templates/migration-job.yaml +38 -0
- package/templates/aws-eks/iac/helm/app/templates/redis-deployment.yaml +33 -0
- package/templates/aws-eks/iac/helm/app/templates/redis-service.yaml +18 -0
- package/templates/aws-eks/iac/helm/app/templates/secret.yaml +17 -0
- package/templates/aws-eks/iac/helm/app/templates/serviceaccount.yaml +12 -0
- package/templates/aws-eks/iac/helm/app/values-dev.yaml.hbs +35 -0
- package/templates/aws-eks/iac/helm/app/values.yaml.hbs +130 -0
- package/templates/aws-eks/iac/runner/Dockerfile +53 -0
- package/templates/aws-eks/iac/terraform/bootstrap/main.tf.hbs +101 -0
- package/templates/aws-eks/iac/terraform/bootstrap/outputs.tf +19 -0
- package/templates/aws-eks/iac/terraform/bootstrap/variables.tf.hbs +17 -0
- package/templates/aws-eks/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
- package/templates/aws-eks/iac/terraform/environments/dev/terraform.tfvars.hbs +32 -0
- package/templates/aws-eks/iac/terraform/main.tf.hbs +305 -0
- package/templates/aws-eks/iac/terraform/outputs.tf.hbs +52 -0
- package/templates/aws-eks/iac/terraform/providers.tf +47 -0
- package/templates/aws-eks/iac/terraform/variables.tf.hbs +181 -0
- package/templates/aws-eks/iac/terraform/versions.tf +27 -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 +25 -0
- package/templates/base/.claude/rules/BE/002.md +15 -0
- package/templates/base/.claude/rules/BE/003.md +18 -0
- package/templates/base/.claude/rules/BE/004.md +14 -0
- package/templates/base/.claude/rules/BE/005.md +15 -0
- package/templates/base/.claude/rules/BE/006.md +17 -0
- package/templates/base/.claude/rules/BE/007.md +21 -0
- package/templates/base/.claude/rules/BE/008.md +19 -0
- package/templates/base/.claude/rules/BE/009.md +27 -0
- package/templates/base/.claude/rules/BE/010.md +16 -0
- package/templates/base/.claude/rules/BE/011.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 +199 -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 +364 -0
- package/templates/base/README.md.hbs +187 -0
- package/templates/base/_env.example.hbs +29 -0
- package/templates/base/_env.hbs +25 -0
- package/templates/base/_gitignore +31 -0
- package/templates/base/_npmrc +2 -0
- package/templates/base/backend/Dockerfile.hbs +22 -0
- package/templates/base/backend/README.md.hbs +74 -0
- package/templates/base/backend/_dockerignore +11 -0
- package/templates/base/backend/app/__init__.py +1 -0
- package/templates/base/backend/app/core/__init__.py +0 -0
- package/templates/base/backend/app/core/config.py.hbs +23 -0
- package/templates/base/backend/app/fixtures/__init__.py +0 -0
- package/templates/base/backend/app/main.py.hbs +41 -0
- package/templates/base/backend/app/management/__init__.py +0 -0
- package/templates/base/backend/app/models/__init__.py +0 -0
- package/templates/base/backend/app/queries/__init__.py +0 -0
- package/templates/base/backend/app/routers/__init__.py +0 -0
- package/templates/base/backend/app/routers/health.py +13 -0
- package/templates/base/backend/app/schemas/__init__.py +0 -0
- package/templates/base/backend/app/schemas/health.py +7 -0
- package/templates/base/backend/app/tasks/__init__.py +1 -0
- package/templates/base/backend/app/tests/__init__.py +0 -0
- package/templates/base/backend/app/tests/conftest.py +13 -0
- package/templates/base/backend/app/tests/models/__init__.py +0 -0
- package/templates/base/backend/app/tests/queries/__init__.py +0 -0
- package/templates/base/backend/app/tests/routers/__init__.py +0 -0
- package/templates/base/backend/app/tests/routers/test_health.py +10 -0
- package/templates/base/backend/app/tests/tasks/__init__.py +1 -0
- package/templates/base/backend/app/tests/utils/__init__.py +0 -0
- package/templates/base/backend/app/utils/__init__.py +0 -0
- package/templates/base/backend/pyproject.toml.hbs +40 -0
- package/templates/base/docker-compose.yml.hbs +128 -0
- package/templates/base/docs/docs/api.md +21 -0
- package/templates/base/docs/docs/dude.md.hbs +316 -0
- package/templates/base/docs/docs/index.md.hbs +100 -0
- package/templates/base/docs/docs/mkdocs.md +238 -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.hbs +10 -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.hbs +40 -0
- package/templates/base/frontend/src/main.tsx +10 -0
- package/templates/base/frontend/src/openapi/utils/openapi.yaml.hbs +28 -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/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/app/tasks/__init__.py +1 -0
- package/templates/celery/backend/app/tasks/example.py +21 -0
- package/templates/celery/backend/app/tests/tasks/test_example.py +7 -0
- package/templates/celery/backend/app/worker.py.hbs +33 -0
- package/templates/celerybeat/backend/app/tasks/scheduled.py +16 -0
- package/templates/celerybeat/backend/app/tests/tasks/test_scheduled.py +7 -0
- package/templates/postgres/.dude/commands/reset.ts +76 -0
- package/templates/postgres/backend/alembic/env.py +55 -0
- package/templates/postgres/backend/alembic/script.py.mako +27 -0
- package/templates/postgres/backend/alembic/versions/0001_create_user_table.py +38 -0
- package/templates/postgres/backend/alembic.ini +42 -0
- package/templates/postgres/backend/app/core/database.py +15 -0
- package/templates/postgres/backend/app/models/__init__.py +5 -0
- package/templates/postgres/backend/app/models/user.py +15 -0
- package/templates/postgres/backend/app/queries/__init__.py +5 -0
- package/templates/postgres/backend/app/queries/users.py +18 -0
- package/templates/postgres/backend/app/routers/users.py +19 -0
- package/templates/postgres/backend/app/routers/users__id.py +20 -0
- package/templates/postgres/backend/app/tests/conftest.py +33 -0
- package/templates/postgres/backend/app/tests/models/test_user.py +12 -0
- package/templates/postgres/backend/app/tests/queries/test_users.py +12 -0
- package/templates/postgres/backend/app/tests/routers/test_users.py +10 -0
- package/templates/postgres/backend/app/tests/routers/test_users__id.py +9 -0
- package/templates/postgres/backend/start.sh +32 -0
- package/templates/postgres/frontend/src/openapi/utils/openapi.yaml.hbs +138 -0
- package/templates/postgres/frontend/src/pages/users/[id]/index.tsx +51 -0
- package/templates/postgres/frontend/src/pages/users/index.tsx +54 -0
- package/templates/postgres/frontend/src/pages/users/types.tsx +4 -0
|
@@ -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,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;AAyBO,SAAS,iBAAiB,UAA4B;AAC3D,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,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,IAAM,oBAAoB,oBAAI,IAAI,CAAC,cAAc,SAAS,UAAU,MAAM,CAAC;AAG5D,SAAR,MAAuB,MAA+B;AAC3D,QAAM,WAAWC,MAAK,KAAK,YAAY,IAAI,GAAG,OAAO;AACrD,MAAI,CAACC,YAAW,QAAQ,EAAG,QAAO,CAAC;AAEnC,QAAM,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,CAAC,YAAY,CAAC,iBAAiB;AACjC,gBAAQ;AAAA,UACN;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,YACA,oBAAoB,MAAM,IAAI;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAEA,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AAEA,OAAK,QAAQ;AACb,SAAO;AACT;","names":["readdirSync","existsSync","path","path","existsSync","readdirSync"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// src/commands/lint/checks/FE/006.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 HOOK_NAME = /^use[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/006.ts
|
|
37
|
+
var ALLOWED_DIRS = /* @__PURE__ */ new Set(["$assets", "$misc"]);
|
|
38
|
+
function check(root) {
|
|
39
|
+
const results = [];
|
|
40
|
+
for (const hooksDir of findDirsNamed(frontendSrc(root), "$hooks")) {
|
|
41
|
+
for (const entry of readdirSync2(hooksDir, { withFileTypes: true })) {
|
|
42
|
+
if (!entry.isDirectory()) continue;
|
|
43
|
+
const hookDir = path2.join(hooksDir, entry.name);
|
|
44
|
+
if (entry.name.startsWith("$")) {
|
|
45
|
+
results.push(
|
|
46
|
+
diag(
|
|
47
|
+
root,
|
|
48
|
+
hookDir,
|
|
49
|
+
"error",
|
|
50
|
+
`Privileged directory "${entry.name}" is not allowed directly inside $hooks/ \u2014 it belongs inside a hook directory`
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (!HOOK_NAME.test(entry.name)) {
|
|
56
|
+
results.push(
|
|
57
|
+
diag(
|
|
58
|
+
root,
|
|
59
|
+
hookDir,
|
|
60
|
+
"error",
|
|
61
|
+
`Hook directory "${entry.name}" must match use[A-Z]\u2026 (e.g. useAttachments)`
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (!existsSync2(path2.join(hookDir, "index.tsx"))) {
|
|
67
|
+
results.push(
|
|
68
|
+
diag(root, hookDir, "error", `Hook "${entry.name}" is missing its index.tsx`)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
for (const child of readdirSync2(hookDir, { withFileTypes: true })) {
|
|
72
|
+
const childPath = path2.join(hookDir, child.name);
|
|
73
|
+
if (child.isDirectory()) {
|
|
74
|
+
if (!ALLOWED_DIRS.has(child.name)) {
|
|
75
|
+
results.push(
|
|
76
|
+
diag(
|
|
77
|
+
root,
|
|
78
|
+
childPath,
|
|
79
|
+
"error",
|
|
80
|
+
`Unexpected directory "${child.name}" in hook directory. Allowed: $assets/, $misc/`
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
} else if (!SCOPE_FILES.has(child.name)) {
|
|
85
|
+
results.push(
|
|
86
|
+
diag(
|
|
87
|
+
root,
|
|
88
|
+
childPath,
|
|
89
|
+
"error",
|
|
90
|
+
`Unexpected file "${child.name}" in hook directory. Allowed: ${SCOPE_FILES_LABEL}`
|
|
91
|
+
)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return results;
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
check as default
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=006.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/commands/lint/checks/FE/006.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 HOOK_NAME,\n SCOPE_FILES,\n SCOPE_FILES_LABEL,\n diag,\n findDirsNamed,\n frontendSrc,\n} from '../../frontend-structure'\n\nconst ALLOWED_DIRS = new Set(['$assets', '$misc'])\n\n/** FE006 — $hooks/ holds use* dirs; each hook dir has index.tsx + scope files + $assets/$misc */\nexport default function check(root: string): RawDiagnostic[] {\n const results: RawDiagnostic[] = []\n\n for (const hooksDir of findDirsNamed(frontendSrc(root), '$hooks')) {\n for (const entry of readdirSync(hooksDir, { withFileTypes: true })) {\n if (!entry.isDirectory()) continue\n const hookDir = path.join(hooksDir, entry.name)\n\n if (entry.name.startsWith('$')) {\n results.push(\n diag(\n root,\n hookDir,\n 'error',\n `Privileged directory \"${entry.name}\" is not allowed directly inside $hooks/ — it belongs inside a hook directory`,\n ),\n )\n continue\n }\n if (!HOOK_NAME.test(entry.name)) {\n results.push(\n diag(\n root,\n hookDir,\n 'error',\n `Hook directory \"${entry.name}\" must match use[A-Z]… (e.g. useAttachments)`,\n ),\n )\n continue\n }\n\n if (!existsSync(path.join(hookDir, 'index.tsx'))) {\n results.push(\n diag(root, hookDir, 'error', `Hook \"${entry.name}\" is missing its index.tsx`),\n )\n }\n\n for (const child of readdirSync(hookDir, { withFileTypes: true })) {\n const childPath = path.join(hookDir, 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 hook directory. Allowed: $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 hook 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;;;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AA,YACA,yBAAyB,MAAM,IAAI;AAAA,UACrC;AAAA,QACF;AACA;AAAA,MACF;AACA,UAAI,CAAC,UAAU,KAAK,MAAM,IAAI,GAAG;AAC/B,gBAAQ;AAAA,UACN;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,YACA,mBAAmB,MAAM,IAAI;AAAA,UAC/B;AAAA,QACF;AACA;AAAA,MACF;AAEA,UAAI,CAACC,YAAWD,MAAK,KAAK,SAAS,WAAW,CAAC,GAAG;AAChD,gBAAQ;AAAA,UACN,KAAK,MAAM,SAAS,SAAS,SAAS,MAAM,IAAI,4BAA4B;AAAA,QAC9E;AAAA,MACF;AAEA,iBAAW,SAASD,aAAY,SAAS,EAAE,eAAe,KAAK,CAAC,GAAG;AACjE,cAAM,YAAYC,MAAK,KAAK,SAAS,MAAM,IAAI;AAC/C,YAAI,MAAM,YAAY,GAAG;AACvB,cAAI,CAAC,aAAa,IAAI,MAAM,IAAI,GAAG;AACjC,oBAAQ;AAAA,cACN;AAAA,gBACE;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA,yBAAyB,MAAM,IAAI;AAAA,cACrC;AAAA,YACF;AAAA,UACF;AAAA,QACF,WAAW,CAAC,YAAY,IAAI,MAAM,IAAI,GAAG;AACvC,kBAAQ;AAAA,YACN;AAAA,cACE;AAAA,cACA;AAAA,cACA;AAAA,cACA,oBAAoB,MAAM,IAAI,iCAAiC,iBAAiB;AAAA,YAClF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["readdirSync","existsSync","path","readdirSync","path","existsSync"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/commands/lint/checks/FE/007.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 HOOK_NAME = /^use[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/007.ts
|
|
29
|
+
function check(root) {
|
|
30
|
+
const results = [];
|
|
31
|
+
for (const hooksDir of findDirsNamed(frontendSrc(root), "$hooks")) {
|
|
32
|
+
const hookNames = readdirSync2(hooksDir, { withFileTypes: true }).filter((e) => e.isDirectory() && HOOK_NAME.test(e.name)).map((e) => e.name);
|
|
33
|
+
if (hookNames.length === 0) continue;
|
|
34
|
+
const barrelFile = path2.join(hooksDir, "index.tsx");
|
|
35
|
+
if (!existsSync2(barrelFile)) {
|
|
36
|
+
results.push(
|
|
37
|
+
diag(
|
|
38
|
+
root,
|
|
39
|
+
hooksDir,
|
|
40
|
+
"error",
|
|
41
|
+
`$hooks/ is missing its index.tsx barrel (must export: ${hookNames.join(", ")})`
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const barrel = readFileSync(barrelFile, "utf8");
|
|
47
|
+
for (const name of hookNames) {
|
|
48
|
+
if (!barrel.includes(`from './${name}'`) && !barrel.includes(`from "./${name}"`)) {
|
|
49
|
+
results.push(
|
|
50
|
+
diag(root, barrelFile, "error", `$hooks/index.tsx is missing a barrel export for "${name}"`)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return results;
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
check as default
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=007.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/commands/lint/checks/FE/007.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 { HOOK_NAME, diag, findDirsNamed, frontendSrc } from '../../frontend-structure'\n\n/** FE007 — every $hooks/ has an index.tsx barrel exporting all use* directories */\nexport default function check(root: string): RawDiagnostic[] {\n const results: RawDiagnostic[] = []\n\n for (const hooksDir of findDirsNamed(frontendSrc(root), '$hooks')) {\n const hookNames = readdirSync(hooksDir, { withFileTypes: true })\n .filter((e) => e.isDirectory() && HOOK_NAME.test(e.name))\n .map((e) => e.name)\n if (hookNames.length === 0) continue\n\n const barrelFile = path.join(hooksDir, 'index.tsx')\n if (!existsSync(barrelFile)) {\n results.push(\n diag(\n root,\n hooksDir,\n 'error',\n `$hooks/ is missing its index.tsx barrel (must export: ${hookNames.join(', ')})`,\n ),\n )\n continue\n }\n\n const barrel = readFileSync(barrelFile, 'utf8')\n for (const name of hookNames) {\n if (!barrel.includes(`from './${name}'`) && !barrel.includes(`from \"./${name}\"`)) {\n results.push(\n diag(root, barrelFile, 'error', `$hooks/index.tsx is missing a barrel export for \"${name}\"`),\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;AAoBV,IAAM,YAAY;AAIlB,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,YAAY,cAAc,YAAY,IAAI,GAAG,QAAQ,GAAG;AACjE,UAAM,YAAYC,aAAY,UAAU,EAAE,eAAe,KAAK,CAAC,EAC5D,OAAO,CAAC,MAAM,EAAE,YAAY,KAAK,UAAU,KAAK,EAAE,IAAI,CAAC,EACvD,IAAI,CAAC,MAAM,EAAE,IAAI;AACpB,QAAI,UAAU,WAAW,EAAG;AAE5B,UAAM,aAAaC,MAAK,KAAK,UAAU,WAAW;AAClD,QAAI,CAACC,YAAW,UAAU,GAAG;AAC3B,cAAQ;AAAA,QACN;AAAA,UACE;AAAA,UACA;AAAA,UACA;AAAA,UACA,yDAAyD,UAAU,KAAK,IAAI,CAAC;AAAA,QAC/E;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,SAAS,aAAa,YAAY,MAAM;AAC9C,eAAW,QAAQ,WAAW;AAC5B,UAAI,CAAC,OAAO,SAAS,WAAW,IAAI,GAAG,KAAK,CAAC,OAAO,SAAS,WAAW,IAAI,GAAG,GAAG;AAChF,gBAAQ;AAAA,UACN,KAAK,MAAM,YAAY,SAAS,oDAAoD,IAAI,GAAG;AAAA,QAC7F;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["readdirSync","existsSync","path","readdirSync","path","existsSync"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// src/commands/lint/checks/FE/008.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 KEBAB_CASE = /^[a-z][a-z0-9]*(?:-[a-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
|
+
|
|
16
|
+
// src/commands/lint/checks/FE/008.ts
|
|
17
|
+
var ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
18
|
+
".svg",
|
|
19
|
+
".png",
|
|
20
|
+
".jpg",
|
|
21
|
+
".jpeg",
|
|
22
|
+
".gif",
|
|
23
|
+
".webp",
|
|
24
|
+
".avif",
|
|
25
|
+
".ico",
|
|
26
|
+
".pdf",
|
|
27
|
+
".json",
|
|
28
|
+
".txt",
|
|
29
|
+
".csv",
|
|
30
|
+
".mp4",
|
|
31
|
+
".webm",
|
|
32
|
+
".mp3",
|
|
33
|
+
".wav",
|
|
34
|
+
".ogg",
|
|
35
|
+
".woff",
|
|
36
|
+
".woff2",
|
|
37
|
+
".ttf",
|
|
38
|
+
".otf",
|
|
39
|
+
".eot"
|
|
40
|
+
]);
|
|
41
|
+
var ASSET_NAME = /^[a-z0-9]+(?:[-.][a-z0-9]+)*\.[a-z0-9]+$/;
|
|
42
|
+
function check(root) {
|
|
43
|
+
const srcDir = frontendSrc(root);
|
|
44
|
+
if (!existsSync2(srcDir)) return [];
|
|
45
|
+
const results = [];
|
|
46
|
+
function walkAssets(dir) {
|
|
47
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
48
|
+
const entryPath = path2.join(dir, entry.name);
|
|
49
|
+
if (entry.isDirectory()) {
|
|
50
|
+
if (!KEBAB_CASE.test(entry.name)) {
|
|
51
|
+
results.push(
|
|
52
|
+
diag(
|
|
53
|
+
root,
|
|
54
|
+
entryPath,
|
|
55
|
+
"warning",
|
|
56
|
+
`Asset subdirectory "${entry.name}" should be kebab-case`
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
walkAssets(entryPath);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const ext = path2.extname(entry.name).toLowerCase();
|
|
64
|
+
if (!ASSET_EXTENSIONS.has(ext)) {
|
|
65
|
+
results.push(
|
|
66
|
+
diag(
|
|
67
|
+
root,
|
|
68
|
+
entryPath,
|
|
69
|
+
"error",
|
|
70
|
+
`"${entry.name}" is not a static asset \u2014 $assets/ may only contain asset files (images, fonts, media, documents, data), never code`
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
} else if (!ASSET_NAME.test(entry.name)) {
|
|
74
|
+
results.push(
|
|
75
|
+
diag(
|
|
76
|
+
root,
|
|
77
|
+
entryPath,
|
|
78
|
+
"warning",
|
|
79
|
+
`Asset "${entry.name}" should be kebab-case with a lowercase extension (e.g. "user-guide.pdf")`
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function walk(dir) {
|
|
86
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
87
|
+
const entryPath = path2.join(dir, entry.name);
|
|
88
|
+
if (entry.isDirectory()) {
|
|
89
|
+
if (entry.name === "$misc" || entry.name === "node_modules") continue;
|
|
90
|
+
if (entry.name === "$assets") {
|
|
91
|
+
walkAssets(entryPath);
|
|
92
|
+
} else {
|
|
93
|
+
walk(entryPath);
|
|
94
|
+
}
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (ASSET_EXTENSIONS.has(path2.extname(entry.name).toLowerCase())) {
|
|
98
|
+
results.push(
|
|
99
|
+
diag(
|
|
100
|
+
root,
|
|
101
|
+
entryPath,
|
|
102
|
+
"error",
|
|
103
|
+
`Asset "${entry.name}" must live in a $assets/ directory of its owning scope (found in ${path2.relative(root, dir)})`
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
walk(srcDir);
|
|
110
|
+
return results;
|
|
111
|
+
}
|
|
112
|
+
export {
|
|
113
|
+
check as default
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=008.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/commands/lint/checks/FE/008.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 { KEBAB_CASE, diag, frontendSrc } from '../../frontend-structure'\n\n/** Non-code file extensions that belong in a $assets/ directory. */\nconst ASSET_EXTENSIONS = new Set([\n '.svg',\n '.png',\n '.jpg',\n '.jpeg',\n '.gif',\n '.webp',\n '.avif',\n '.ico',\n '.pdf',\n '.json',\n '.txt',\n '.csv',\n '.mp4',\n '.webm',\n '.mp3',\n '.wav',\n '.ogg',\n '.woff',\n '.woff2',\n '.ttf',\n '.otf',\n '.eot',\n])\n\n/** kebab-case base name (dots allowed as extra separators), lowercase extension. */\nconst ASSET_NAME = /^[a-z0-9]+(?:[-.][a-z0-9]+)*\\.[a-z0-9]+$/\n\n/** FE008 — static assets live only in $assets/ folders; $assets/ contains only kebab-case asset files */\nexport default function check(root: string): RawDiagnostic[] {\n const srcDir = frontendSrc(root)\n if (!existsSync(srcDir)) return []\n\n const results: RawDiagnostic[] = []\n\n function walkAssets(dir: string): void {\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n const entryPath = path.join(dir, entry.name)\n if (entry.isDirectory()) {\n if (!KEBAB_CASE.test(entry.name)) {\n results.push(\n diag(\n root,\n entryPath,\n 'warning',\n `Asset subdirectory \"${entry.name}\" should be kebab-case`,\n ),\n )\n }\n walkAssets(entryPath)\n continue\n }\n const ext = path.extname(entry.name).toLowerCase()\n if (!ASSET_EXTENSIONS.has(ext)) {\n results.push(\n diag(\n root,\n entryPath,\n 'error',\n `\"${entry.name}\" is not a static asset — $assets/ may only contain asset files (images, fonts, media, documents, data), never code`,\n ),\n )\n } else if (!ASSET_NAME.test(entry.name)) {\n results.push(\n diag(\n root,\n entryPath,\n 'warning',\n `Asset \"${entry.name}\" should be kebab-case with a lowercase extension (e.g. \"user-guide.pdf\")`,\n ),\n )\n }\n }\n }\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 if (entry.isDirectory()) {\n if (entry.name === '$misc' || entry.name === 'node_modules') continue\n if (entry.name === '$assets') {\n walkAssets(entryPath)\n } else {\n walk(entryPath)\n }\n continue\n }\n if (ASSET_EXTENSIONS.has(path.extname(entry.name).toLowerCase())) {\n results.push(\n diag(\n root,\n entryPath,\n 'error',\n `Asset \"${entry.name}\" must live in a $assets/ directory of its owning scope (found in ${path.relative(root, dir)})`,\n ),\n )\n }\n }\n }\n\n walk(srcDir)\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;AAmBV,IAAM,aAAa;AAKnB,SAAS,YAAY,MAAsB;AAChD,SAAO,KAAK,KAAK,MAAM,YAAY,KAAK;AAC1C;AAEO,SAAS,KACd,MACA,SACA,UACA,SACe;A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AAA,YACA,UAAU,MAAM,IAAI;AAAA,UACtB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,WAAS,KAAK,KAAmB;AAC/B,eAAW,SAASD,aAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAAG;AAC7D,YAAM,YAAYC,MAAK,KAAK,KAAK,MAAM,IAAI;AAC3C,UAAI,MAAM,YAAY,GAAG;AACvB,YAAI,MAAM,SAAS,WAAW,MAAM,SAAS,eAAgB;AAC7D,YAAI,MAAM,SAAS,WAAW;AAC5B,qBAAW,SAAS;AAAA,QACtB,OAAO;AACL,eAAK,SAAS;AAAA,QAChB;AACA;AAAA,MACF;AACA,UAAI,iBAAiB,IAAIA,MAAK,QAAQ,MAAM,IAAI,EAAE,YAAY,CAAC,GAAG;AAChE,gBAAQ;AAAA,UACN;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,YACA,UAAU,MAAM,IAAI,qEAAqEA,MAAK,SAAS,MAAM,GAAG,CAAC;AAAA,UACnH;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,OAAK,MAAM;AACX,SAAO;AACT;","names":["readdirSync","existsSync","path","existsSync","readdirSync","path"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// src/commands/lint/checks/FE/009.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
|
+
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
|
+
|
|
24
|
+
// src/commands/lint/checks/FE/009.ts
|
|
25
|
+
var ALLOWED_DIRS = /* @__PURE__ */ new Set(["$assets", "$misc"]);
|
|
26
|
+
function check(root) {
|
|
27
|
+
const utilsDir = path2.join(frontendSrc(root), "utils");
|
|
28
|
+
if (!existsSync2(utilsDir)) return [];
|
|
29
|
+
const results = [];
|
|
30
|
+
function walk(dir) {
|
|
31
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
32
|
+
const entryPath = path2.join(dir, entry.name);
|
|
33
|
+
if (!entry.isDirectory()) {
|
|
34
|
+
if (!SCOPE_FILES.has(entry.name)) {
|
|
35
|
+
results.push(
|
|
36
|
+
diag(
|
|
37
|
+
root,
|
|
38
|
+
entryPath,
|
|
39
|
+
"error",
|
|
40
|
+
`Unexpected file "${entry.name}" in utils. Allowed: ${SCOPE_FILES_LABEL}`
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (entry.name.startsWith("$")) {
|
|
47
|
+
if (!ALLOWED_DIRS.has(entry.name)) {
|
|
48
|
+
results.push(
|
|
49
|
+
diag(
|
|
50
|
+
root,
|
|
51
|
+
entryPath,
|
|
52
|
+
"error",
|
|
53
|
+
`Unknown privileged directory "${entry.name}" in utils. Allowed: $assets/, $misc/`
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (!KEBAB_CASE.test(entry.name)) {
|
|
60
|
+
results.push(
|
|
61
|
+
diag(
|
|
62
|
+
root,
|
|
63
|
+
entryPath,
|
|
64
|
+
"error",
|
|
65
|
+
`Utils domain "${entry.name}" must be kebab-case (e.g. "date-helpers")`
|
|
66
|
+
)
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
if (!existsSync2(path2.join(entryPath, "index.tsx"))) {
|
|
70
|
+
results.push(
|
|
71
|
+
diag(root, entryPath, "error", `Utils domain "${entry.name}" is missing its index.tsx`)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
walk(entryPath);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
walk(utilsDir);
|
|
78
|
+
return results;
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
check as default
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=009.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/commands/lint/checks/FE/009.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 KEBAB_CASE,\n SCOPE_FILES,\n SCOPE_FILES_LABEL,\n diag,\n frontendSrc,\n} from '../../frontend-structure'\n\nconst ALLOWED_DIRS = new Set(['$assets', '$misc'])\n\n/** FE009 — utils/ is organised in kebab-case domain dirs, each with the scope files + $assets/$misc */\nexport default function check(root: string): RawDiagnostic[] {\n const utilsDir = path.join(frontendSrc(root), 'utils')\n if (!existsSync(utilsDir)) 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 utils. 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 utils. Allowed: $assets/, $misc/`,\n ),\n )\n }\n continue\n }\n\n // Any other directory is a utils domain.\n if (!KEBAB_CASE.test(entry.name)) {\n results.push(\n diag(\n root,\n entryPath,\n 'error',\n `Utils domain \"${entry.name}\" must be kebab-case (e.g. \"date-helpers\")`,\n ),\n )\n }\n if (!existsSync(path.join(entryPath, 'index.tsx'))) {\n results.push(\n diag(root, entryPath, 'error', `Utils domain \"${entry.name}\" is missing its index.tsx`),\n )\n }\n walk(entryPath)\n }\n }\n\n walk(utilsDir)\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;AAK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K,KAAK,WAAW,WAAW,CAAC,GAAG;AAClD,gBAAQ;AAAA,UACN,KAAK,MAAM,WAAW,SAAS,iBAAiB,MAAM,IAAI,4BAA4B;AAAA,QACxF;AAAA,MACF;AACA,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AAEA,OAAK,QAAQ;AACb,SAAO;AACT;","names":["readdirSync","existsSync","path","path","existsSync","readdirSync"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RawDiagnostic } from '@cubocicloide/dude';
|
|
2
|
+
|
|
3
|
+
/** FE010 — src root contains only the app entry files + $types/$components/$hooks/openapi/pages/utils; *.d.ts live in $types/ */
|
|
4
|
+
declare function check(root: string): RawDiagnostic[];
|
|
5
|
+
|
|
6
|
+
export { check as default };
|