@cubocicloide/stack-frappe 2.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.
Files changed (122) hide show
  1. package/LICENSE +33 -0
  2. package/README.md +37 -0
  3. package/dist/commands/lint/checks/APP/001.d.ts +13 -0
  4. package/dist/commands/lint/checks/APP/001.js +73 -0
  5. package/dist/commands/lint/checks/APP/001.js.map +1 -0
  6. package/dist/commands/lint/checks/APP/002.d.ts +12 -0
  7. package/dist/commands/lint/checks/APP/002.js +94 -0
  8. package/dist/commands/lint/checks/APP/002.js.map +1 -0
  9. package/dist/commands/lint/checks/APP/003.d.ts +12 -0
  10. package/dist/commands/lint/checks/APP/003.js +94 -0
  11. package/dist/commands/lint/checks/APP/003.js.map +1 -0
  12. package/dist/commands/lint/checks/APP/004.d.ts +12 -0
  13. package/dist/commands/lint/checks/APP/004.js +117 -0
  14. package/dist/commands/lint/checks/APP/004.js.map +1 -0
  15. package/dist/commands/lint/checks/DT/001.d.ts +11 -0
  16. package/dist/commands/lint/checks/DT/001.js +57 -0
  17. package/dist/commands/lint/checks/DT/001.js.map +1 -0
  18. package/dist/commands/lint/checks/DT/002.d.ts +12 -0
  19. package/dist/commands/lint/checks/DT/002.js +74 -0
  20. package/dist/commands/lint/checks/DT/002.js.map +1 -0
  21. package/dist/commands/lint/checks/DT/003.d.ts +13 -0
  22. package/dist/commands/lint/checks/DT/003.js +96 -0
  23. package/dist/commands/lint/checks/DT/003.js.map +1 -0
  24. package/dist/commands/lint/checks/DT/004.d.ts +12 -0
  25. package/dist/commands/lint/checks/DT/004.js +101 -0
  26. package/dist/commands/lint/checks/DT/004.js.map +1 -0
  27. package/dist/commands/lint/checks/PY/001.d.ts +12 -0
  28. package/dist/commands/lint/checks/PY/001.js +87 -0
  29. package/dist/commands/lint/checks/PY/001.js.map +1 -0
  30. package/dist/commands/lint/checks/PY/002.d.ts +12 -0
  31. package/dist/commands/lint/checks/PY/002.js +80 -0
  32. package/dist/commands/lint/checks/PY/002.js.map +1 -0
  33. package/dist/commands/lint/checks/PY/003.d.ts +11 -0
  34. package/dist/commands/lint/checks/PY/003.js +56 -0
  35. package/dist/commands/lint/checks/PY/003.js.map +1 -0
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.js +1987 -0
  38. package/dist/index.js.map +1 -0
  39. package/dude.stack.json +12 -0
  40. package/package.json +41 -0
  41. package/templates/aws-ecs/_dockerignore +11 -0
  42. package/templates/aws-ecs/docker/Dockerfile.prod.hbs +80 -0
  43. package/templates/aws-ecs/docker/nginx-entrypoint.sh +17 -0
  44. package/templates/aws-ecs/docker/nginx-template.conf +95 -0
  45. package/templates/aws-ecs/docs/docs/deploy.md.hbs +53 -0
  46. package/templates/aws-ecs/iac/README.md.hbs +113 -0
  47. package/templates/aws-ecs/iac/_gitignore +14 -0
  48. package/templates/aws-ecs/iac/runner/Dockerfile +35 -0
  49. package/templates/aws-ecs/iac/terraform/bootstrap/main.tf.hbs +93 -0
  50. package/templates/aws-ecs/iac/terraform/bootstrap/outputs.tf +14 -0
  51. package/templates/aws-ecs/iac/terraform/bootstrap/variables.tf.hbs +17 -0
  52. package/templates/aws-ecs/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
  53. package/templates/aws-ecs/iac/terraform/environments/dev/terraform.tfvars.hbs +32 -0
  54. package/templates/aws-ecs/iac/terraform/main.tf.hbs +1205 -0
  55. package/templates/aws-ecs/iac/terraform/outputs.tf.hbs +103 -0
  56. package/templates/aws-ecs/iac/terraform/providers.tf +19 -0
  57. package/templates/aws-ecs/iac/terraform/variables.tf.hbs +139 -0
  58. package/templates/aws-ecs/iac/terraform/versions.tf +19 -0
  59. package/templates/base/.claude/rules/APP/001.md +26 -0
  60. package/templates/base/.claude/rules/APP/002.md +26 -0
  61. package/templates/base/.claude/rules/APP/003.md +25 -0
  62. package/templates/base/.claude/rules/APP/004.md +27 -0
  63. package/templates/base/.claude/rules/DT/001.md +25 -0
  64. package/templates/base/.claude/rules/DT/002.md +25 -0
  65. package/templates/base/.claude/rules/DT/003.md +24 -0
  66. package/templates/base/.claude/rules/DT/004.md +22 -0
  67. package/templates/base/.claude/rules/PY/001.md +30 -0
  68. package/templates/base/.claude/rules/PY/002.md +31 -0
  69. package/templates/base/.claude/rules/PY/003.md +29 -0
  70. package/templates/base/.claude/settings.json +42 -0
  71. package/templates/base/.claude/skills/create-doctype/SKILL.md +99 -0
  72. package/templates/base/.dude/commands/README.md +85 -0
  73. package/templates/base/.dude/commands/hello.ts +34 -0
  74. package/templates/base/.dude/lint/checks/PRJ/001.ts +26 -0
  75. package/templates/base/.dude/lint/checks/README.md +69 -0
  76. package/templates/base/.vscode/tasks.json +44 -0
  77. package/templates/base/CLAUDE.md.hbs +49 -0
  78. package/templates/base/README.md.hbs +68 -0
  79. package/templates/base/_env.example.hbs +5 -0
  80. package/templates/base/_env.hbs +12 -0
  81. package/templates/base/_gitignore +26 -0
  82. package/templates/base/_npmrc +2 -0
  83. package/templates/base/apps/README.md +24 -0
  84. package/templates/base/apps/ticketing/README.md +43 -0
  85. package/templates/base/apps/ticketing/pyproject.toml +34 -0
  86. package/templates/base/apps/ticketing/ticketing/__init__.py +1 -0
  87. package/templates/base/apps/ticketing/ticketing/api.py +35 -0
  88. package/templates/base/apps/ticketing/ticketing/events/__init__.py +0 -0
  89. package/templates/base/apps/ticketing/ticketing/events/hd_ticket.py +32 -0
  90. package/templates/base/apps/ticketing/ticketing/fixtures/workflow.json +55 -0
  91. package/templates/base/apps/ticketing/ticketing/fixtures/workflow_action_master.json +12 -0
  92. package/templates/base/apps/ticketing/ticketing/fixtures/workflow_state.json +20 -0
  93. package/templates/base/apps/ticketing/ticketing/hooks.py +54 -0
  94. package/templates/base/apps/ticketing/ticketing/modules.txt +1 -0
  95. package/templates/base/apps/ticketing/ticketing/patches/__init__.py +0 -0
  96. package/templates/base/apps/ticketing/ticketing/patches/v1_0/__init__.py +0 -0
  97. package/templates/base/apps/ticketing/ticketing/patches/v1_0/set_default_branding.py +26 -0
  98. package/templates/base/apps/ticketing/ticketing/patches.txt +5 -0
  99. package/templates/base/apps/ticketing/ticketing/public/images/favicon.png +0 -0
  100. package/templates/base/apps/ticketing/ticketing/public/images/logo.png +0 -0
  101. package/templates/base/apps/ticketing/ticketing/tasks.py +99 -0
  102. package/templates/base/apps/ticketing/ticketing/templates/__init__.py +0 -0
  103. package/templates/base/apps/ticketing/ticketing/templates/pages/__init__.py +0 -0
  104. package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.html +30 -0
  105. package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.py +14 -0
  106. package/templates/base/apps/ticketing/ticketing/ticketing/__init__.py +0 -0
  107. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/__init__.py +0 -0
  108. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/__init__.py +0 -0
  109. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/test_ticket_escalation_rule.py +32 -0
  110. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.js +23 -0
  111. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.json +99 -0
  112. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.py +18 -0
  113. package/templates/base/docker/init.sh +114 -0
  114. package/templates/base/docker-compose.yml.hbs +62 -0
  115. package/templates/base/docs/docs/api.md +21 -0
  116. package/templates/base/docs/docs/dude.md.hbs +220 -0
  117. package/templates/base/docs/docs/extending.md +238 -0
  118. package/templates/base/docs/docs/frappe.md.hbs +223 -0
  119. package/templates/base/docs/docs/index.md.hbs +101 -0
  120. package/templates/base/docs/docs/mkdocs.md +235 -0
  121. package/templates/base/docs/mkdocs.yml.hbs +54 -0
  122. package/templates/base/package.json.hbs +11 -0
@@ -0,0 +1,12 @@
1
+ import { RawDiagnostic } from '@cubocicloide/dude';
2
+
3
+ /**
4
+ * DT002 — Permissions declared.
5
+ *
6
+ * Every DocType schema must carry a non-empty `permissions` array with at
7
+ * least one role. A DocType without permissions is invisible/unusable for
8
+ * every user except Administrator.
9
+ */
10
+ declare function check(root: string): RawDiagnostic[];
11
+
12
+ export { check as default };
@@ -0,0 +1,74 @@
1
+ // src/commands/lint/checks/DT/002.ts
2
+ import { existsSync, readdirSync, readFileSync } from "fs";
3
+ import path from "pathe";
4
+ function listApps(root) {
5
+ const appsDir = path.join(root, "apps");
6
+ try {
7
+ return readdirSync(appsDir, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, "pyproject.toml"))).map((e) => e.name);
8
+ } catch {
9
+ return [];
10
+ }
11
+ }
12
+ function listDoctypeDirs(root) {
13
+ const out = [];
14
+ for (const app of listApps(root)) {
15
+ const pkg = path.join(root, "apps", app, app);
16
+ let moduleDirs = [];
17
+ try {
18
+ moduleDirs = readdirSync(pkg, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(path.join(pkg, e.name, "doctype"))).map((e) => e.name);
19
+ } catch {
20
+ continue;
21
+ }
22
+ for (const mod of moduleDirs) {
23
+ let names = [];
24
+ try {
25
+ names = readdirSync(path.join(pkg, mod, "doctype"), { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "__pycache__").map((e) => e.name);
26
+ } catch {
27
+ continue;
28
+ }
29
+ for (const name of names) {
30
+ out.push({ app, module: mod, name, rel: `apps/${app}/${app}/${mod}/doctype/${name}` });
31
+ }
32
+ }
33
+ }
34
+ return out;
35
+ }
36
+ function check(root) {
37
+ const diagnostics = [];
38
+ for (const dt of listDoctypeDirs(root)) {
39
+ const jsonRel = `${dt.rel}/${dt.name}.json`;
40
+ const jsonAbs = path.join(root, jsonRel);
41
+ if (!existsSync(jsonAbs)) continue;
42
+ let schema;
43
+ try {
44
+ schema = JSON.parse(readFileSync(jsonAbs, "utf8"));
45
+ } catch {
46
+ diagnostics.push({
47
+ file: jsonRel,
48
+ line: 1,
49
+ col: 1,
50
+ severity: "error",
51
+ message: `${dt.name}.json is not valid JSON \u2014 cannot verify DocType permissions`
52
+ });
53
+ continue;
54
+ }
55
+ const permissions = schema["permissions"];
56
+ const hasRole = Array.isArray(permissions) && permissions.some(
57
+ (p) => p && typeof p === "object" && typeof p["role"] === "string" && p["role"] !== ""
58
+ );
59
+ if (!hasRole) {
60
+ diagnostics.push({
61
+ file: jsonRel,
62
+ line: 1,
63
+ col: 1,
64
+ severity: "error",
65
+ message: `DocType "${dt.name}" declares no permissions (need a non-empty "permissions" array with at least one "role") \u2014 without them the DocType is invisible to every non-Administrator user`
66
+ });
67
+ }
68
+ }
69
+ return diagnostics;
70
+ }
71
+ export {
72
+ check as default
73
+ };
74
+ //# sourceMappingURL=002.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/commands/lint/checks/DT/002.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\n\n/** Apps under apps/ that have a pyproject.toml (valid bench apps). */\nfunction listApps(root: string): string[] {\n const appsDir = path.join(root, 'apps')\n try {\n return readdirSync(appsDir, { withFileTypes: true })\n .filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, 'pyproject.toml')))\n .map((e) => e.name)\n } catch {\n return []\n }\n}\n\ninterface DoctypeDir {\n app: string\n module: string\n name: string\n rel: string // repo-relative doctype directory\n}\n\n/** Every apps/<app>/<app>/<module>/doctype/<d>/ directory. */\nfunction listDoctypeDirs(root: string): DoctypeDir[] {\n const out: DoctypeDir[] = []\n for (const app of listApps(root)) {\n const pkg = path.join(root, 'apps', app, app)\n let moduleDirs: string[] = []\n try {\n moduleDirs = readdirSync(pkg, { withFileTypes: true })\n .filter((e) => e.isDirectory() && existsSync(path.join(pkg, e.name, 'doctype')))\n .map((e) => e.name)\n } catch {\n continue\n }\n for (const mod of moduleDirs) {\n let names: string[] = []\n try {\n names = readdirSync(path.join(pkg, mod, 'doctype'), { withFileTypes: true })\n .filter((e) => e.isDirectory() && !e.name.startsWith('.') && e.name !== '__pycache__')\n .map((e) => e.name)\n } catch {\n continue\n }\n for (const name of names) {\n out.push({ app, module: mod, name, rel: `apps/${app}/${app}/${mod}/doctype/${name}` })\n }\n }\n }\n return out\n}\n\n/**\n * DT002 — Permissions declared.\n *\n * Every DocType schema must carry a non-empty `permissions` array with at\n * least one role. A DocType without permissions is invisible/unusable for\n * every user except Administrator.\n */\nexport default function check(root: string): RawDiagnostic[] {\n const diagnostics: RawDiagnostic[] = []\n\n for (const dt of listDoctypeDirs(root)) {\n const jsonRel = `${dt.rel}/${dt.name}.json`\n const jsonAbs = path.join(root, jsonRel)\n if (!existsSync(jsonAbs)) continue // DT001 reports the missing schema\n\n let schema: Record<string, unknown>\n try {\n schema = JSON.parse(readFileSync(jsonAbs, 'utf8')) as Record<string, unknown>\n } catch {\n diagnostics.push({\n file: jsonRel,\n line: 1,\n col: 1,\n severity: 'error',\n message: `${dt.name}.json is not valid JSON — cannot verify DocType permissions`,\n })\n continue\n }\n\n const permissions = schema['permissions']\n const hasRole =\n Array.isArray(permissions) &&\n permissions.some(\n (p) => p && typeof p === 'object' && typeof (p as Record<string, unknown>)['role'] === 'string' && (p as Record<string, unknown>)['role'] !== '',\n )\n\n if (!hasRole) {\n diagnostics.push({\n file: jsonRel,\n line: 1,\n col: 1,\n severity: 'error',\n message: `DocType \"${dt.name}\" declares no permissions (need a non-empty \"permissions\" array with at least one \"role\") — without them the DocType is invisible to every non-Administrator user`,\n })\n }\n }\n\n return diagnostics\n}\n"],"mappings":";AAAA,SAAS,YAAY,aAAa,oBAAoB;AACtD,OAAO,UAAU;AAIjB,SAAS,SAAS,MAAwB;AACxC,QAAM,UAAU,KAAK,KAAK,MAAM,MAAM;AACtC,MAAI;AACF,WAAO,YAAY,SAAS,EAAE,eAAe,KAAK,CAAC,EAChD,OAAO,CAAC,MAAM,EAAE,YAAY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M,OAAO;AACvC,QAAI,CAAC,WAAW,OAAO,EAAG;AAE1B,QAAI;AACJ,QAAI;AACF,eAAS,KAAK,MAAM,aAAa,SAAS,MAAM,CAAC;AAAA,IACnD,QAAQ;AACN,kBAAY,KAAK;AAAA,QACf,MAAM;AAAA,QACN,MAAM;AAAA,QACN,KAAK;AAAA,QACL,UAAU;AAAA,QACV,SAAS,GAAG,GAAG,IAAI;AAAA,MACrB,CAAC;AACD;AAAA,IACF;AAEA,UAAM,cAAc,OAAO,aAAa;AACxC,UAAM,UACJ,MAAM,QAAQ,WAAW,KACzB,YAAY;AAAA,MACV,CAAC,MAAM,KAAK,OAAO,MAAM,YAAY,OAAQ,EAA8B,MAAM,MAAM,YAAa,EAA8B,MAAM,MAAM;AAAA,IAChJ;AAEF,QAAI,CAAC,SAAS;AACZ,kBAAY,KAAK;AAAA,QACf,MAAM;AAAA,QACN,MAAM;AAAA,QACN,KAAK;AAAA,QACL,UAAU;AAAA,QACV,SAAS,YAAY,GAAG,IAAI;AAAA,MAC9B,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,13 @@
1
+ import { RawDiagnostic } from '@cubocicloide/dude';
2
+
3
+ /**
4
+ * DT003 — Naming and module registration.
5
+ *
6
+ * For every DocType schema: scrub(name) must equal its directory name, its
7
+ * `module` must be listed in modules.txt, and scrub(module) must equal the
8
+ * module directory that contains doctype/. Any mismatch and `bench migrate`
9
+ * either cannot find the DocType or files it under a module that does not exist.
10
+ */
11
+ declare function check(root: string): RawDiagnostic[];
12
+
13
+ export { check as default };
@@ -0,0 +1,96 @@
1
+ // src/commands/lint/checks/DT/003.ts
2
+ import { existsSync, readdirSync, readFileSync } from "fs";
3
+ import path from "pathe";
4
+ function scrub(name) {
5
+ return name.toLowerCase().replace(/ /g, "_");
6
+ }
7
+ function listApps(root) {
8
+ const appsDir = path.join(root, "apps");
9
+ try {
10
+ return readdirSync(appsDir, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, "pyproject.toml"))).map((e) => e.name);
11
+ } catch {
12
+ return [];
13
+ }
14
+ }
15
+ function listDoctypeDirs(root) {
16
+ const out = [];
17
+ for (const app of listApps(root)) {
18
+ const pkg = path.join(root, "apps", app, app);
19
+ let moduleDirs = [];
20
+ try {
21
+ moduleDirs = readdirSync(pkg, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(path.join(pkg, e.name, "doctype"))).map((e) => e.name);
22
+ } catch {
23
+ continue;
24
+ }
25
+ for (const mod of moduleDirs) {
26
+ let names = [];
27
+ try {
28
+ names = readdirSync(path.join(pkg, mod, "doctype"), { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "__pycache__").map((e) => e.name);
29
+ } catch {
30
+ continue;
31
+ }
32
+ for (const name of names) {
33
+ out.push({ app, module: mod, name, rel: `apps/${app}/${app}/${mod}/doctype/${name}` });
34
+ }
35
+ }
36
+ }
37
+ return out;
38
+ }
39
+ function readModules(root, app) {
40
+ try {
41
+ return readFileSync(path.join(root, "apps", app, app, "modules.txt"), "utf8").split("\n").map((l) => l.trim()).filter(Boolean);
42
+ } catch {
43
+ return [];
44
+ }
45
+ }
46
+ function check(root) {
47
+ const diagnostics = [];
48
+ const modulesByApp = /* @__PURE__ */ new Map();
49
+ for (const dt of listDoctypeDirs(root)) {
50
+ const jsonRel = `${dt.rel}/${dt.name}.json`;
51
+ const jsonAbs = path.join(root, jsonRel);
52
+ if (!existsSync(jsonAbs)) continue;
53
+ let schema;
54
+ try {
55
+ schema = JSON.parse(readFileSync(jsonAbs, "utf8"));
56
+ } catch {
57
+ continue;
58
+ }
59
+ const docName = typeof schema["name"] === "string" ? schema["name"] : "";
60
+ const docModule = typeof schema["module"] === "string" ? schema["module"] : "";
61
+ if (scrub(docName) !== dt.name) {
62
+ diagnostics.push({
63
+ file: jsonRel,
64
+ line: 1,
65
+ col: 1,
66
+ severity: "error",
67
+ message: `DocType name "${docName}" does not match its directory: expected the directory to be named "${scrub(docName)}", found "${dt.name}"`
68
+ });
69
+ }
70
+ if (!modulesByApp.has(dt.app)) modulesByApp.set(dt.app, readModules(root, dt.app));
71
+ const modules = modulesByApp.get(dt.app);
72
+ if (!modules.includes(docModule)) {
73
+ diagnostics.push({
74
+ file: jsonRel,
75
+ line: 1,
76
+ col: 1,
77
+ severity: "error",
78
+ message: `DocType "${docName}" declares module "${docModule}", which is not listed in apps/${dt.app}/${dt.app}/modules.txt \u2014 unregistered modules break \`bench migrate\``
79
+ });
80
+ }
81
+ if (scrub(docModule) !== dt.module) {
82
+ diagnostics.push({
83
+ file: jsonRel,
84
+ line: 1,
85
+ col: 1,
86
+ severity: "error",
87
+ message: `DocType "${docName}" declares module "${docModule}" but lives under the "${dt.module}" module directory \u2014 expected "${scrub(docModule)}/doctype/${dt.name}/"`
88
+ });
89
+ }
90
+ }
91
+ return diagnostics;
92
+ }
93
+ export {
94
+ check as default
95
+ };
96
+ //# sourceMappingURL=003.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/commands/lint/checks/DT/003.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\n\n/** Frappe's scrub(): lowercase, spaces → underscores. */\nfunction scrub(name: string): string {\n return name.toLowerCase().replace(/ /g, '_')\n}\n\n/** Apps under apps/ that have a pyproject.toml (valid bench apps). */\nfunction listApps(root: string): string[] {\n const appsDir = path.join(root, 'apps')\n try {\n return readdirSync(appsDir, { withFileTypes: true })\n .filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, 'pyproject.toml')))\n .map((e) => e.name)\n } catch {\n return []\n }\n}\n\ninterface DoctypeDir {\n app: string\n module: string\n name: string\n rel: string // repo-relative doctype directory\n}\n\n/** Every apps/<app>/<app>/<module>/doctype/<d>/ directory. */\nfunction listDoctypeDirs(root: string): DoctypeDir[] {\n const out: DoctypeDir[] = []\n for (const app of listApps(root)) {\n const pkg = path.join(root, 'apps', app, app)\n let moduleDirs: string[] = []\n try {\n moduleDirs = readdirSync(pkg, { withFileTypes: true })\n .filter((e) => e.isDirectory() && existsSync(path.join(pkg, e.name, 'doctype')))\n .map((e) => e.name)\n } catch {\n continue\n }\n for (const mod of moduleDirs) {\n let names: string[] = []\n try {\n names = readdirSync(path.join(pkg, mod, 'doctype'), { withFileTypes: true })\n .filter((e) => e.isDirectory() && !e.name.startsWith('.') && e.name !== '__pycache__')\n .map((e) => e.name)\n } catch {\n continue\n }\n for (const name of names) {\n out.push({ app, module: mod, name, rel: `apps/${app}/${app}/${mod}/doctype/${name}` })\n }\n }\n }\n return out\n}\n\n/** Modules listed in apps/<app>/<app>/modules.txt (one per line). */\nfunction readModules(root: string, app: string): string[] {\n try {\n return readFileSync(path.join(root, 'apps', app, app, 'modules.txt'), 'utf8')\n .split('\\n')\n .map((l) => l.trim())\n .filter(Boolean)\n } catch {\n return []\n }\n}\n\n/**\n * DT003 — Naming and module registration.\n *\n * For every DocType schema: scrub(name) must equal its directory name, its\n * `module` must be listed in modules.txt, and scrub(module) must equal the\n * module directory that contains doctype/. Any mismatch and `bench migrate`\n * either cannot find the DocType or files it under a module that does not exist.\n */\nexport default function check(root: string): RawDiagnostic[] {\n const diagnostics: RawDiagnostic[] = []\n const modulesByApp = new Map<string, string[]>()\n\n for (const dt of listDoctypeDirs(root)) {\n const jsonRel = `${dt.rel}/${dt.name}.json`\n const jsonAbs = path.join(root, jsonRel)\n if (!existsSync(jsonAbs)) continue // DT001 reports the missing schema\n\n let schema: Record<string, unknown>\n try {\n schema = JSON.parse(readFileSync(jsonAbs, 'utf8')) as Record<string, unknown>\n } catch {\n continue // DT002 reports the unparseable schema\n }\n\n const docName = typeof schema['name'] === 'string' ? (schema['name'] as string) : ''\n const docModule = typeof schema['module'] === 'string' ? (schema['module'] as string) : ''\n\n // (a) scrub(name) ↔ doctype directory name\n if (scrub(docName) !== dt.name) {\n diagnostics.push({\n file: jsonRel,\n line: 1,\n col: 1,\n severity: 'error',\n message: `DocType name \"${docName}\" does not match its directory: expected the directory to be named \"${scrub(docName)}\", found \"${dt.name}\"`,\n })\n }\n\n // (b) module registered in modules.txt\n if (!modulesByApp.has(dt.app)) modulesByApp.set(dt.app, readModules(root, dt.app))\n const modules = modulesByApp.get(dt.app)!\n if (!modules.includes(docModule)) {\n diagnostics.push({\n file: jsonRel,\n line: 1,\n col: 1,\n severity: 'error',\n message: `DocType \"${docName}\" declares module \"${docModule}\", which is not listed in apps/${dt.app}/${dt.app}/modules.txt — unregistered modules break \\`bench migrate\\``,\n })\n }\n\n // (c) scrub(module) ↔ module directory name\n if (scrub(docModule) !== dt.module) {\n diagnostics.push({\n file: jsonRel,\n line: 1,\n col: 1,\n severity: 'error',\n message: `DocType \"${docName}\" declares module \"${docModule}\" but lives under the \"${dt.module}\" module directory — expected \"${scrub(docModule)}/doctype/${dt.name}/\"`,\n })\n }\n }\n\n return diagnostics\n}\n"],"mappings":";AAAA,SAAS,YAAY,aAAa,oBAAoB;AACtD,OAAO,UAAU;AAIjB,SAAS,MAAM,MAAsB;AACnC,SAAO,KAAK,YAAY,EAAE,QAAQ,MAAM,GAAG;AAC7C;AAGA,SAAS,SAAS,MAAwB;AACxC,QAAM,UAAU,KAAK,KAAK,MAAM,MAAM;AACtC,MAAI;AACF,WAAO,YAAY,SAAS,EAAE,eAAe,KAAK,CAAC,EAChD,OAAO,CAAC,MAAM,EAAE,YAAY,KAAK,WAAW,KAAK,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC,CAAC,EACzF,IAAI,CAAC,MAAM,EAAE,IAAI;AAAA,EACtB,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAUA,SAAS,gBAAgB,MAA4B;AACnD,QAAM,MAAoB,CAAC;AAC3B,aAAW,OAAO,SAAS,IAAI,GAAG;AAChC,UAAM,MAAM,KAAK,KAAK,MAAM,QAAQ,KAAK,GAAG;AAC5C,QAAI,aAAuB,CA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+ /**
4
+ * DT004 — Field hygiene.
5
+ *
6
+ * Every entry of fields[] must carry a snake_case fieldname
7
+ * (^[a-z][a-z0-9_]*$) — layout breaks (Section/Column/Tab Break) included —
8
+ * and fieldnames must be unique within the DocType.
9
+ */
10
+ declare function check(root: string): RawDiagnostic[];
11
+
12
+ export { check as default };
@@ -0,0 +1,101 @@
1
+ // src/commands/lint/checks/DT/004.ts
2
+ import { existsSync, readdirSync, readFileSync } from "fs";
3
+ import path from "pathe";
4
+ var FIELDNAME_RE = /^[a-z][a-z0-9_]*$/;
5
+ function listApps(root) {
6
+ const appsDir = path.join(root, "apps");
7
+ try {
8
+ return readdirSync(appsDir, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, "pyproject.toml"))).map((e) => e.name);
9
+ } catch {
10
+ return [];
11
+ }
12
+ }
13
+ function listDoctypeDirs(root) {
14
+ const out = [];
15
+ for (const app of listApps(root)) {
16
+ const pkg = path.join(root, "apps", app, app);
17
+ let moduleDirs = [];
18
+ try {
19
+ moduleDirs = readdirSync(pkg, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(path.join(pkg, e.name, "doctype"))).map((e) => e.name);
20
+ } catch {
21
+ continue;
22
+ }
23
+ for (const mod of moduleDirs) {
24
+ let names = [];
25
+ try {
26
+ names = readdirSync(path.join(pkg, mod, "doctype"), { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "__pycache__").map((e) => e.name);
27
+ } catch {
28
+ continue;
29
+ }
30
+ for (const name of names) {
31
+ out.push({ app, module: mod, name, rel: `apps/${app}/${app}/${mod}/doctype/${name}` });
32
+ }
33
+ }
34
+ }
35
+ return out;
36
+ }
37
+ function lineOfFieldname(raw, fieldname) {
38
+ const lines = raw.split("\n");
39
+ const re = new RegExp(`"fieldname"\\s*:\\s*"${fieldname}"`);
40
+ const idx = lines.findIndex((l) => re.test(l));
41
+ return idx === -1 ? 1 : idx + 1;
42
+ }
43
+ function check(root) {
44
+ const diagnostics = [];
45
+ for (const dt of listDoctypeDirs(root)) {
46
+ const jsonRel = `${dt.rel}/${dt.name}.json`;
47
+ const jsonAbs = path.join(root, jsonRel);
48
+ if (!existsSync(jsonAbs)) continue;
49
+ let raw;
50
+ let schema;
51
+ try {
52
+ raw = readFileSync(jsonAbs, "utf8");
53
+ schema = JSON.parse(raw);
54
+ } catch {
55
+ continue;
56
+ }
57
+ const fields = Array.isArray(schema["fields"]) ? schema["fields"] : [];
58
+ const seen = /* @__PURE__ */ new Map();
59
+ for (const entry of fields) {
60
+ const field = entry ?? {};
61
+ const fieldname = typeof field["fieldname"] === "string" ? field["fieldname"] : "";
62
+ const label = typeof field["label"] === "string" ? field["label"] : "";
63
+ if (!fieldname) {
64
+ diagnostics.push({
65
+ file: jsonRel,
66
+ line: 1,
67
+ col: 1,
68
+ severity: "error",
69
+ message: `DocType "${dt.name}" has a field${label ? ` (label "${label}")` : ""} without a "fieldname" \u2014 every fields[] entry needs one, layout breaks included`
70
+ });
71
+ continue;
72
+ }
73
+ const line = lineOfFieldname(raw, fieldname);
74
+ if (!FIELDNAME_RE.test(fieldname)) {
75
+ diagnostics.push({
76
+ file: jsonRel,
77
+ line,
78
+ col: 1,
79
+ severity: "error",
80
+ message: `Fieldname "${fieldname}" is not snake_case \u2014 fieldnames become DB columns and API keys and must match ^[a-z][a-z0-9_]*$`
81
+ });
82
+ }
83
+ if (seen.has(fieldname)) {
84
+ diagnostics.push({
85
+ file: jsonRel,
86
+ line,
87
+ col: 1,
88
+ severity: "error",
89
+ message: `Duplicate fieldname "${fieldname}" in DocType "${dt.name}" (first declared on line ${seen.get(fieldname)}) \u2014 fieldnames must be unique within a DocType`
90
+ });
91
+ } else {
92
+ seen.set(fieldname, line);
93
+ }
94
+ }
95
+ }
96
+ return diagnostics;
97
+ }
98
+ export {
99
+ check as default
100
+ };
101
+ //# sourceMappingURL=004.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/commands/lint/checks/DT/004.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\n\nconst FIELDNAME_RE = /^[a-z][a-z0-9_]*$/\n\n/** Apps under apps/ that have a pyproject.toml (valid bench apps). */\nfunction listApps(root: string): string[] {\n const appsDir = path.join(root, 'apps')\n try {\n return readdirSync(appsDir, { withFileTypes: true })\n .filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, 'pyproject.toml')))\n .map((e) => e.name)\n } catch {\n return []\n }\n}\n\ninterface DoctypeDir {\n app: string\n module: string\n name: string\n rel: string // repo-relative doctype directory\n}\n\n/** Every apps/<app>/<app>/<module>/doctype/<d>/ directory. */\nfunction listDoctypeDirs(root: string): DoctypeDir[] {\n const out: DoctypeDir[] = []\n for (const app of listApps(root)) {\n const pkg = path.join(root, 'apps', app, app)\n let moduleDirs: string[] = []\n try {\n moduleDirs = readdirSync(pkg, { withFileTypes: true })\n .filter((e) => e.isDirectory() && existsSync(path.join(pkg, e.name, 'doctype')))\n .map((e) => e.name)\n } catch {\n continue\n }\n for (const mod of moduleDirs) {\n let names: string[] = []\n try {\n names = readdirSync(path.join(pkg, mod, 'doctype'), { withFileTypes: true })\n .filter((e) => e.isDirectory() && !e.name.startsWith('.') && e.name !== '__pycache__')\n .map((e) => e.name)\n } catch {\n continue\n }\n for (const name of names) {\n out.push({ app, module: mod, name, rel: `apps/${app}/${app}/${mod}/doctype/${name}` })\n }\n }\n }\n return out\n}\n\n/** 1-based line of the first `\"fieldname\": \"<value>\"` occurrence, or 1. */\nfunction lineOfFieldname(raw: string, fieldname: string): number {\n const lines = raw.split('\\n')\n const re = new RegExp(`\"fieldname\"\\\\s*:\\\\s*\"${fieldname}\"`)\n const idx = lines.findIndex((l) => re.test(l))\n return idx === -1 ? 1 : idx + 1\n}\n\n/**\n * DT004 — Field hygiene.\n *\n * Every entry of fields[] must carry a snake_case fieldname\n * (^[a-z][a-z0-9_]*$) — layout breaks (Section/Column/Tab Break) included —\n * and fieldnames must be unique within the DocType.\n */\nexport default function check(root: string): RawDiagnostic[] {\n const diagnostics: RawDiagnostic[] = []\n\n for (const dt of listDoctypeDirs(root)) {\n const jsonRel = `${dt.rel}/${dt.name}.json`\n const jsonAbs = path.join(root, jsonRel)\n if (!existsSync(jsonAbs)) continue // DT001 reports the missing schema\n\n let raw: string\n let schema: Record<string, unknown>\n try {\n raw = readFileSync(jsonAbs, 'utf8')\n schema = JSON.parse(raw) as Record<string, unknown>\n } catch {\n continue // DT002 reports the unparseable schema\n }\n\n const fields = Array.isArray(schema['fields']) ? (schema['fields'] as unknown[]) : []\n const seen = new Map<string, number>() // fieldname → first line\n\n for (const entry of fields) {\n const field = (entry ?? {}) as Record<string, unknown>\n const fieldname = typeof field['fieldname'] === 'string' ? (field['fieldname'] as string) : ''\n const label = typeof field['label'] === 'string' ? (field['label'] as string) : ''\n\n if (!fieldname) {\n diagnostics.push({\n file: jsonRel,\n line: 1,\n col: 1,\n severity: 'error',\n message: `DocType \"${dt.name}\" has a field${label ? ` (label \"${label}\")` : ''} without a \"fieldname\" — every fields[] entry needs one, layout breaks included`,\n })\n continue\n }\n\n const line = lineOfFieldname(raw, fieldname)\n\n if (!FIELDNAME_RE.test(fieldname)) {\n diagnostics.push({\n file: jsonRel,\n line,\n col: 1,\n severity: 'error',\n message: `Fieldname \"${fieldname}\" is not snake_case — fieldnames become DB columns and API keys and must match ^[a-z][a-z0-9_]*$`,\n })\n }\n\n if (seen.has(fieldname)) {\n diagnostics.push({\n file: jsonRel,\n line,\n col: 1,\n severity: 'error',\n message: `Duplicate fieldname \"${fieldname}\" in DocType \"${dt.name}\" (first declared on line ${seen.get(fieldname)}) — fieldnames must be unique within a DocType`,\n })\n } else {\n seen.set(fieldname, line)\n }\n }\n }\n\n return diagnostics\n}\n"],"mappings":";AAAA,SAAS,YAAY,aAAa,oBAAoB;AACtD,OAAO,UAAU;AAGjB,IAAM,eAAe;AAGrB,SAAS,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AAAA,UACL,UAAU;AAAA,UACV,SAAS,cAAc,SAAS;AAAA,QAClC,CAAC;AAAA,MACH;AAEA,UAAI,KAAK,IAAI,SAAS,GAAG;AACvB,oBAAY,KAAK;AAAA,UACf,MAAM;AAAA,UACN;AAAA,UACA,KAAK;AAAA,UACL,UAAU;AAAA,UACV,SAAS,wBAAwB,SAAS,iBAAiB,GAAG,IAAI,6BAA6B,KAAK,IAAI,SAAS,CAAC;AAAA,QACpH,CAAC;AAAA,MACH,OAAO;AACL,aAAK,IAAI,WAAW,IAAI;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,12 @@
1
+ import { RawDiagnostic } from '@cubocicloide/dude';
2
+
3
+ /**
4
+ * PY001 — No unjustified guest APIs.
5
+ *
6
+ * `allow_guest=True` inside a @frappe.whitelist(...) decorator is an error
7
+ * unless justified with a `# guest-ok: <reason>` comment on the same line or
8
+ * the line directly above.
9
+ */
10
+ declare function check(root: string): RawDiagnostic[];
11
+
12
+ export { check as default };
@@ -0,0 +1,87 @@
1
+ // src/commands/lint/checks/PY/001.ts
2
+ import { existsSync, readdirSync, readFileSync } from "fs";
3
+ import path from "pathe";
4
+ var GUEST_RE = /allow_guest\s*=\s*True/;
5
+ var JUSTIFICATION_RE = /#\s*guest-ok:/;
6
+ function listApps(root) {
7
+ const appsDir = path.join(root, "apps");
8
+ try {
9
+ return readdirSync(appsDir, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, "pyproject.toml"))).map((e) => e.name);
10
+ } catch {
11
+ return [];
12
+ }
13
+ }
14
+ function walkPy(dir, out = []) {
15
+ let entries;
16
+ try {
17
+ entries = readdirSync(dir, { withFileTypes: true });
18
+ } catch {
19
+ return out;
20
+ }
21
+ for (const e of entries) {
22
+ if (e.isDirectory()) {
23
+ if (!e.name.startsWith(".")) walkPy(path.join(dir, e.name), out);
24
+ } else if (e.name.endsWith(".py")) {
25
+ out.push(path.join(dir, e.name));
26
+ }
27
+ }
28
+ return out;
29
+ }
30
+ function check(root) {
31
+ const diagnostics = [];
32
+ for (const app of listApps(root)) {
33
+ const pkg = path.join(root, "apps", app, app);
34
+ for (const file of walkPy(pkg)) {
35
+ const rel = `apps/${app}/${app}/${path.relative(pkg, file)}`;
36
+ let src;
37
+ try {
38
+ src = readFileSync(file, "utf8");
39
+ } catch {
40
+ continue;
41
+ }
42
+ const lines = src.split("\n");
43
+ let inDecorator = false;
44
+ let parenDepth = 0;
45
+ const flag = (i) => {
46
+ const line = lines[i];
47
+ const m = line.match(GUEST_RE);
48
+ if (!m) return;
49
+ const justified = JUSTIFICATION_RE.test(line) || i > 0 && JUSTIFICATION_RE.test(lines[i - 1]);
50
+ if (justified) return;
51
+ diagnostics.push({
52
+ file: rel,
53
+ line: i + 1,
54
+ col: (m.index ?? 0) + 1,
55
+ severity: "error",
56
+ message: 'allow_guest=True exposes this whitelisted method to unauthenticated callers (it bypasses login entirely). Remove it, or justify it with a "# guest-ok: <reason>" comment on the same line or the line above.'
57
+ });
58
+ };
59
+ for (let i = 0; i < lines.length; i++) {
60
+ const line = lines[i];
61
+ if (!inDecorator) {
62
+ const m = line.match(/@frappe\.whitelist\s*\(/);
63
+ if (!m) continue;
64
+ inDecorator = true;
65
+ parenDepth = 0;
66
+ for (const ch of line.slice(m.index)) {
67
+ if (ch === "(") parenDepth++;
68
+ else if (ch === ")") parenDepth--;
69
+ }
70
+ flag(i);
71
+ } else {
72
+ for (const ch of line) {
73
+ if (ch === "(") parenDepth++;
74
+ else if (ch === ")") parenDepth--;
75
+ }
76
+ flag(i);
77
+ }
78
+ if (parenDepth <= 0) inDecorator = false;
79
+ }
80
+ }
81
+ }
82
+ return diagnostics;
83
+ }
84
+ export {
85
+ check as default
86
+ };
87
+ //# sourceMappingURL=001.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/commands/lint/checks/PY/001.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\n\nconst GUEST_RE = /allow_guest\\s*=\\s*True/\nconst JUSTIFICATION_RE = /#\\s*guest-ok:/\n\n/** Apps under apps/ that have a pyproject.toml (valid bench apps). */\nfunction listApps(root: string): string[] {\n const appsDir = path.join(root, 'apps')\n try {\n return readdirSync(appsDir, { withFileTypes: true })\n .filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, 'pyproject.toml')))\n .map((e) => e.name)\n } catch {\n return []\n }\n}\n\n/** All .py files under a directory, recursively. */\nfunction walkPy(dir: string, out: string[] = []): string[] {\n let entries\n try {\n entries = readdirSync(dir, { withFileTypes: true })\n } catch {\n return out\n }\n for (const e of entries) {\n if (e.isDirectory()) {\n if (!e.name.startsWith('.')) walkPy(path.join(dir, e.name), out)\n } else if (e.name.endsWith('.py')) {\n out.push(path.join(dir, e.name))\n }\n }\n return out\n}\n\n/**\n * PY001 — No unjustified guest APIs.\n *\n * `allow_guest=True` inside a @frappe.whitelist(...) decorator is an error\n * unless justified with a `# guest-ok: <reason>` comment on the same line or\n * the line directly above.\n */\nexport default function check(root: string): RawDiagnostic[] {\n const diagnostics: RawDiagnostic[] = []\n\n for (const app of listApps(root)) {\n const pkg = path.join(root, 'apps', app, app)\n for (const file of walkPy(pkg)) {\n const rel = `apps/${app}/${app}/${path.relative(pkg, file)}`\n let src: string\n try {\n src = readFileSync(file, 'utf8')\n } catch {\n continue\n }\n\n const lines = src.split('\\n')\n let inDecorator = false\n let parenDepth = 0\n\n const flag = (i: number) => {\n const line = lines[i]!\n const m = line.match(GUEST_RE)\n if (!m) return\n const justified =\n JUSTIFICATION_RE.test(line) || (i > 0 && JUSTIFICATION_RE.test(lines[i - 1]!))\n if (justified) return\n diagnostics.push({\n file: rel,\n line: i + 1,\n col: (m.index ?? 0) + 1,\n severity: 'error',\n message:\n 'allow_guest=True exposes this whitelisted method to unauthenticated callers (it bypasses login entirely). Remove it, or justify it with a \"# guest-ok: <reason>\" comment on the same line or the line above.',\n })\n }\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!\n if (!inDecorator) {\n const m = line.match(/@frappe\\.whitelist\\s*\\(/)\n if (!m) continue\n inDecorator = true\n parenDepth = 0\n for (const ch of line.slice(m.index!)) {\n if (ch === '(') parenDepth++\n else if (ch === ')') parenDepth--\n }\n flag(i)\n } else {\n for (const ch of line) {\n if (ch === '(') parenDepth++\n else if (ch === ')') parenDepth--\n }\n flag(i)\n }\n if (parenDepth <= 0) inDecorator = false\n }\n }\n }\n\n return diagnostics\n}\n"],"mappings":";AAAA,SAAS,YAAY,aAAa,oBAAoB;AACtD,OAAO,UAAU;AAGjB,IAAM,WAAW;AACjB,IAAM,mBAAmB;AAGzB,SAAS,SAAS,MAAwB;AACxC,QAAM,UAAU,KAAK,KAAK,MAAM,MAAM;AACtC,MAAI;AACF,WAAO,YAAY,SAAS,EAAE,eAAe,KAAK,CAAC,EAChD,OAAO,CAAC,MAAM,EAAE,YAAY,KAAK,WAAW,KAAK,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC,CAAC,EACzF,IAAI,CAAC,MAAM,EAAE,IAAI;AAAA,EACtB,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAGA,SAAS,OAAO,KAAa,MAAgB,CAAC,GAAa;AACzD,MAAI;AACJ,MAAI;AACF,cAAU,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC;AAAA,EACpD,QAAQ;AACN,WAAO;AAAA,EACT;AACA,aAAW,KAAK,SAAS;AACvB,QAAI,EAAE,YAAY,GAAG;AACnB,UAAI,CAAC,EAAE,KAAK,WAAW,GAAG,EAAG,QAAO,KAAK,KAAK,KAAK,EAAE,IAAI,GAAG,GAAG;AAAA,IACjE,WAAW,EAAE,KAAK,SAAS,KAAK,GAAG;AACjC,UAAI,KAAK,KAAK,KAAK,KAAK,EAAE,IAAI,CAAC;AAAA,IACjC;AAAA,EACF;AACA,SAAO;AACT;AASe,SA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B;AACA,eAAK,CAAC;AAAA,QACR;AACA,YAAI,cAAc,EAAG,eAAc;AAAA,MACrC;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,12 @@
1
+ import { RawDiagnostic } from '@cubocicloide/dude';
2
+
3
+ /**
4
+ * PY002 — SQL safety.
5
+ *
6
+ * frappe.db.sql() with a dynamically-built query (f-string, %, .format, +) is
7
+ * an error (SQL injection). Any other raw frappe.db.sql() call is a warning:
8
+ * prefer frappe.get_all / frappe.qb.
9
+ */
10
+ declare function check(root: string): RawDiagnostic[];
11
+
12
+ export { check as default };
@@ -0,0 +1,80 @@
1
+ // src/commands/lint/checks/PY/002.ts
2
+ import { existsSync, readdirSync, readFileSync } from "fs";
3
+ import path from "pathe";
4
+ var SQL_CALL = "frappe.db.sql(";
5
+ function listApps(root) {
6
+ const appsDir = path.join(root, "apps");
7
+ try {
8
+ return readdirSync(appsDir, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, "pyproject.toml"))).map((e) => e.name);
9
+ } catch {
10
+ return [];
11
+ }
12
+ }
13
+ function walkPy(dir, out = []) {
14
+ let entries;
15
+ try {
16
+ entries = readdirSync(dir, { withFileTypes: true });
17
+ } catch {
18
+ return out;
19
+ }
20
+ for (const e of entries) {
21
+ if (e.isDirectory()) {
22
+ if (!e.name.startsWith(".")) walkPy(path.join(dir, e.name), out);
23
+ } else if (e.name.endsWith(".py")) {
24
+ out.push(path.join(dir, e.name));
25
+ }
26
+ }
27
+ return out;
28
+ }
29
+ function stripStringsAndComment(fragment) {
30
+ const noStrings = fragment.replace(/(['"])(?:\\.|(?!\1).)*?\1/g, "''");
31
+ const hash = noStrings.indexOf("#");
32
+ return hash === -1 ? noStrings : noStrings.slice(0, hash);
33
+ }
34
+ function check(root) {
35
+ const diagnostics = [];
36
+ for (const app of listApps(root)) {
37
+ const pkg = path.join(root, "apps", app, app);
38
+ for (const file of walkPy(pkg)) {
39
+ const rel = `apps/${app}/${app}/${path.relative(pkg, file)}`;
40
+ let src;
41
+ try {
42
+ src = readFileSync(file, "utf8");
43
+ } catch {
44
+ continue;
45
+ }
46
+ const lines = src.split("\n");
47
+ for (let i = 0; i < lines.length; i++) {
48
+ const line = lines[i];
49
+ const idx = line.indexOf(SQL_CALL);
50
+ if (idx === -1) continue;
51
+ const call = line.slice(idx + SQL_CALL.length);
52
+ const firstArgIsFString = /^\s*(?:rf|fr|f)["']/i.test(call);
53
+ const stripped = stripStringsAndComment(call);
54
+ const concatenates = stripped.includes("%") || stripped.includes(".format(") || stripped.includes("+");
55
+ if (firstArgIsFString || concatenates) {
56
+ diagnostics.push({
57
+ file: rel,
58
+ line: i + 1,
59
+ col: idx + 1,
60
+ severity: "error",
61
+ message: "frappe.db.sql() with a dynamically-built query (f-string / % / .format / +) is a SQL injection risk \u2014 use parameterized queries: frappe.db.sql(query, values) with %(name)s placeholders."
62
+ });
63
+ } else {
64
+ diagnostics.push({
65
+ file: rel,
66
+ line: i + 1,
67
+ col: idx + 1,
68
+ severity: "warning",
69
+ message: "Raw frappe.db.sql() \u2014 prefer frappe.get_all / frappe.get_list or frappe.qb (the query builder), which respect permissions and stay portable. Keep raw SQL for what the ORM genuinely cannot express."
70
+ });
71
+ }
72
+ }
73
+ }
74
+ }
75
+ return diagnostics;
76
+ }
77
+ export {
78
+ check as default
79
+ };
80
+ //# sourceMappingURL=002.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/commands/lint/checks/PY/002.ts"],"sourcesContent":["import { existsSync, readdirSync, readFileSync } from 'node:fs'\nimport path from 'pathe'\nimport type { RawDiagnostic } from '@cubocicloide/dude'\n\nconst SQL_CALL = 'frappe.db.sql('\n\n/** Apps under apps/ that have a pyproject.toml (valid bench apps). */\nfunction listApps(root: string): string[] {\n const appsDir = path.join(root, 'apps')\n try {\n return readdirSync(appsDir, { withFileTypes: true })\n .filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, 'pyproject.toml')))\n .map((e) => e.name)\n } catch {\n return []\n }\n}\n\n/** All .py files under a directory, recursively. */\nfunction walkPy(dir: string, out: string[] = []): string[] {\n let entries\n try {\n entries = readdirSync(dir, { withFileTypes: true })\n } catch {\n return out\n }\n for (const e of entries) {\n if (e.isDirectory()) {\n if (!e.name.startsWith('.')) walkPy(path.join(dir, e.name), out)\n } else if (e.name.endsWith('.py')) {\n out.push(path.join(dir, e.name))\n }\n }\n return out\n}\n\n/** Remove string-literal contents and trailing comment from a code fragment. */\nfunction stripStringsAndComment(fragment: string): string {\n const noStrings = fragment.replace(/(['\"])(?:\\\\.|(?!\\1).)*?\\1/g, \"''\")\n const hash = noStrings.indexOf('#')\n return hash === -1 ? noStrings : noStrings.slice(0, hash)\n}\n\n/**\n * PY002 — SQL safety.\n *\n * frappe.db.sql() with a dynamically-built query (f-string, %, .format, +) is\n * an error (SQL injection). Any other raw frappe.db.sql() call is a warning:\n * prefer frappe.get_all / frappe.qb.\n */\nexport default function check(root: string): RawDiagnostic[] {\n const diagnostics: RawDiagnostic[] = []\n\n for (const app of listApps(root)) {\n const pkg = path.join(root, 'apps', app, app)\n for (const file of walkPy(pkg)) {\n const rel = `apps/${app}/${app}/${path.relative(pkg, file)}`\n let src: string\n try {\n src = readFileSync(file, 'utf8')\n } catch {\n continue\n }\n\n const lines = src.split('\\n')\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!\n const idx = line.indexOf(SQL_CALL)\n if (idx === -1) continue\n\n const call = line.slice(idx + SQL_CALL.length)\n const firstArgIsFString = /^\\s*(?:rf|fr|f)[\"']/i.test(call)\n const stripped = stripStringsAndComment(call)\n const concatenates =\n stripped.includes('%') || stripped.includes('.format(') || stripped.includes('+')\n\n if (firstArgIsFString || concatenates) {\n diagnostics.push({\n file: rel,\n line: i + 1,\n col: idx + 1,\n severity: 'error',\n message:\n 'frappe.db.sql() with a dynamically-built query (f-string / % / .format / +) is a SQL injection risk — use parameterized queries: frappe.db.sql(query, values) with %(name)s placeholders.',\n })\n } else {\n diagnostics.push({\n file: rel,\n line: i + 1,\n col: idx + 1,\n severity: 'warning',\n message:\n 'Raw frappe.db.sql() — prefer frappe.get_all / frappe.get_list or frappe.qb (the query builder), which respect permissions and stay portable. Keep raw SQL for what the ORM genuinely cannot express.',\n })\n }\n }\n }\n }\n\n return diagnostics\n}\n"],"mappings":";AAAA,SAAS,YAAY,aAAa,oBAAoB;AACtD,OAAO,UAAU;AAGjB,IAAM,WAAW;AAGjB,SAAS,SAAS,MAAwB;AACxC,QAAM,UAAU,KAAK,KAAK,MAAM,MAAM;AACtC,MAAI;AACF,WAAO,YAAY,SAAS,EAAE,eAAe,KAAK,CAAC,EAChD,OAAO,CAAC,MAAM,EAAE,YAAY,KAAK,WAAW,KAAK,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC,CAAC,EACzF,IAAI,CAAC,MAAM,EAAE,IAAI;AAAA,EACtB,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAGA,SAAS,OAAO,KAAa,MAAgB,CAAC,GAAa;AACzD,MAAI;AACJ,MAAI;AACF,cAAU,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC;AAAA,EACpD,QAAQ;AACN,WAAO;AAAA,EACT;AACA,aAAW,KAAK,SAAS;AACvB,QAAI,EAAE,YAAY,GAAG;AACnB,UAAI,CAAC,EAAE,KAAK,WAAW,GAAG,EAAG,QAAO,KAAK,KAAK,KAAK,EAAE,IAAI,GAAG,GAAG;AAAA,IACjE,WAAW,EAAE,KAAK,SAAS,KAAK,GAAG;AACjC,UAAI,KAAK,KAAK,KAAK,KAAK,EAAE,IAAI,CAAC;AAAA,IACjC;AAAA,EACF;AACA,SAAO;AACT;AAGA,SAAS,uBAAuB,UAA0B;AACxD,QAAM,YAAY,SAAS,QAAQ,8BAA8B,IAAI;AACrE,QAAM,OAAO,UAAU,QAAQ,GAAG;AAClC,SAAO,SAAS,KAAK,YAAY,UAAU,MAAM,GAAG,IAAI;AAC1D;AASe,SAAR,MAAuB,MAA+B;AAC3D,QAAM,cAA+B,CAAC;AAEtC,aAAW,OAAO,SAAS,IAAI,GAAG;AAChC,UAAM,MAAM,KAAK,KAAK,MAAM,QAAQ,KAAK,GAAG;AAC5C,eAAW,QAAQ,OAAO,GAAG,GAAG;AAC9B,YAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,KAAK,SAAS,KAAK,IAAI,CAAC;AAC1D,UAAI;AACJ,UAAI;AACF,cAAM,aAAa,MAAM,MAAM;AAAA,MACjC,QAAQ;AACN;AAAA,MACF;AAEA,YAAM,QAAQ,IAAI,MAAM,IAAI;AAC5B,eAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAM,OAAO,MAAM,CAAC;AACpB,cAAM,MAAM,KAAK,QAAQ,QAAQ;AACjC,YAAI,QAAQ,GAAI;AAEhB,cAAM,OAAO,KAAK,MAAM,MAAM,SAAS,MAAM;AAC7C,cAAM,oBAAoB,uBAAuB,KAAK,IAAI;AAC1D,cAAM,WAAW,uBAAuB,IAAI;AAC5C,cAAM,eACJ,SAAS,SAAS,GAAG,KAAK,SAAS,SAAS,UAAU,KAAK,SAAS,SAAS,GAAG;AAElF,YAAI,qBAAqB,cAAc;AACrC,sBAAY,KAAK;AAAA,YACf,MAAM;AAAA,YACN,MAAM,IAAI;AAAA,YACV,KAAK,MAAM;AAAA,YACX,UAAU;AAAA,YACV,SACE;AAAA,UACJ,CAAC;AAAA,QACH,OAAO;AACL,sBAAY,KAAK;AAAA,YACf,MAAM;AAAA,YACN,MAAM,IAAI;AAAA,YACV,KAAK,MAAM;AAAA,YACX,UAAU;AAAA,YACV,SACE;AAAA,UACJ,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,11 @@
1
+ import { RawDiagnostic } from '@cubocicloide/dude';
2
+
3
+ /**
4
+ * PY003 — DocType tests exist (warning).
5
+ *
6
+ * Every doctype directory should ship a test_<d>.py next to the controller —
7
+ * `bench run-tests` discovers it automatically.
8
+ */
9
+ declare function check(root: string): RawDiagnostic[];
10
+
11
+ export { check as default };
@@ -0,0 +1,56 @@
1
+ // src/commands/lint/checks/PY/003.ts
2
+ import { existsSync, readdirSync } from "fs";
3
+ import path from "pathe";
4
+ function listApps(root) {
5
+ const appsDir = path.join(root, "apps");
6
+ try {
7
+ return readdirSync(appsDir, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(path.join(appsDir, e.name, "pyproject.toml"))).map((e) => e.name);
8
+ } catch {
9
+ return [];
10
+ }
11
+ }
12
+ function listDoctypeDirs(root) {
13
+ const out = [];
14
+ for (const app of listApps(root)) {
15
+ const pkg = path.join(root, "apps", app, app);
16
+ let moduleDirs = [];
17
+ try {
18
+ moduleDirs = readdirSync(pkg, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync(path.join(pkg, e.name, "doctype"))).map((e) => e.name);
19
+ } catch {
20
+ continue;
21
+ }
22
+ for (const mod of moduleDirs) {
23
+ let names = [];
24
+ try {
25
+ names = readdirSync(path.join(pkg, mod, "doctype"), { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "__pycache__").map((e) => e.name);
26
+ } catch {
27
+ continue;
28
+ }
29
+ for (const name of names) {
30
+ out.push({ app, module: mod, name, rel: `apps/${app}/${app}/${mod}/doctype/${name}` });
31
+ }
32
+ }
33
+ }
34
+ return out;
35
+ }
36
+ function check(root) {
37
+ const diagnostics = [];
38
+ for (const dt of listDoctypeDirs(root)) {
39
+ const testFile = `test_${dt.name}.py`;
40
+ if (existsSync(path.join(root, dt.rel, testFile))) continue;
41
+ const controllerRel = `${dt.rel}/${dt.name}.py`;
42
+ const reportRel = existsSync(path.join(root, controllerRel)) ? controllerRel : dt.rel;
43
+ diagnostics.push({
44
+ file: reportRel,
45
+ line: 1,
46
+ col: 1,
47
+ severity: "warning",
48
+ message: `DocType "${dt.name}" has no ${testFile} \u2014 add one next to the controller so \`bench run-tests\` (and \`dude test\`) exercises it`
49
+ });
50
+ }
51
+ return diagnostics;
52
+ }
53
+ export {
54
+ check as default
55
+ };
56
+ //# sourceMappingURL=003.js.map