@sha3/code-standards 0.1.3 → 0.1.5

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 (39) hide show
  1. package/README.md +42 -0
  2. package/bin/code-standards.mjs +507 -96
  3. package/eslint/test.mjs +1 -5
  4. package/package.json +1 -1
  5. package/prettier/index.cjs +1 -1
  6. package/profiles/default.profile.json +2 -0
  7. package/profiles/schema.json +7 -7
  8. package/resources/ai/templates/examples/demo/src/billing/billing-service.ts +18 -3
  9. package/resources/ai/templates/examples/demo/src/config.ts +3 -0
  10. package/resources/ai/templates/examples/demo/src/invoices/invoice-errors.ts +12 -0
  11. package/resources/ai/templates/examples/demo/src/invoices/invoice-service.ts +14 -1
  12. package/resources/ai/templates/examples/rules/async-bad.ts +12 -0
  13. package/resources/ai/templates/examples/rules/async-good.ts +12 -0
  14. package/resources/ai/templates/examples/rules/class-first-bad.ts +12 -0
  15. package/resources/ai/templates/examples/rules/class-first-good.ts +12 -0
  16. package/resources/ai/templates/examples/rules/constructor-bad.ts +12 -0
  17. package/resources/ai/templates/examples/rules/constructor-good.ts +12 -0
  18. package/resources/ai/templates/examples/rules/control-flow-bad.ts +12 -0
  19. package/resources/ai/templates/examples/rules/control-flow-good.ts +12 -0
  20. package/resources/ai/templates/examples/rules/errors-bad.ts +12 -0
  21. package/resources/ai/templates/examples/rules/errors-good.ts +12 -0
  22. package/resources/ai/templates/examples/rules/functions-bad.ts +12 -0
  23. package/resources/ai/templates/examples/rules/functions-good.ts +12 -0
  24. package/resources/ai/templates/examples/rules/returns-bad.ts +12 -0
  25. package/resources/ai/templates/examples/rules/returns-good.ts +12 -0
  26. package/resources/ai/templates/examples/rules/testing-bad.ts +12 -0
  27. package/resources/ai/templates/examples/rules/testing-good.ts +12 -0
  28. package/resources/ai/templates/rules/architecture.md +2 -0
  29. package/resources/ai/templates/rules/class-first.md +2 -0
  30. package/resources/ai/templates/rules/functions.md +2 -0
  31. package/standards/architecture.md +2 -1
  32. package/standards/manifest.json +1 -1
  33. package/standards/schema.json +2 -11
  34. package/standards/style.md +13 -9
  35. package/templates/node-lib/src/config.ts +1 -0
  36. package/templates/node-lib/src/index.ts +3 -1
  37. package/templates/node-service/src/config.ts +3 -0
  38. package/templates/node-service/src/index.ts +4 -3
  39. package/templates/node-service/test/smoke.test.ts +1 -1
@@ -14,6 +14,7 @@ Two templates are supported:
14
14
  Both templates SHOULD keep this baseline structure:
15
15
 
16
16
  - `src/` for implementation.
17
+ - `src/config.ts` for non-parameterized hardcoded configuration values.
17
18
  - `test/` for automated tests.
18
19
  - Root tooling config files (`eslint`, `prettier`, `tsconfig`) at project root.
19
20
 
@@ -21,4 +22,4 @@ Both templates SHOULD keep this baseline structure:
21
22
 
22
23
  - Keep feature modules cohesive.
23
24
  - Avoid cyclic dependencies.
24
- - Keep configuration centralized at project root.
25
+ - Keep hardcoded application configuration centralized in `src/config.ts`.
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "formatting": {
14
14
  "prettier": true,
15
- "lineLength": 100,
15
+ "lineLength": 160,
16
16
  "semi": true,
17
17
  "singleQuote": false
18
18
  },
@@ -4,16 +4,7 @@
4
4
  "title": "Code Standards Manifest",
5
5
  "type": "object",
6
6
  "additionalProperties": false,
7
- "required": [
8
- "meta",
9
- "language",
10
- "formatting",
11
- "naming",
12
- "architecture",
13
- "testing",
14
- "tooling",
15
- "ai"
16
- ],
7
+ "required": ["meta", "language", "formatting", "naming", "architecture", "testing", "tooling", "ai"],
17
8
  "properties": {
18
9
  "meta": {
19
10
  "type": "object",
@@ -42,7 +33,7 @@
42
33
  "required": ["prettier", "lineLength", "semi", "singleQuote"],
43
34
  "properties": {
44
35
  "prettier": { "type": "boolean" },
45
- "lineLength": { "type": "integer", "minimum": 80, "maximum": 140 },
36
+ "lineLength": { "type": "integer", "minimum": 80, "maximum": 200 },
46
37
  "semi": { "type": "boolean" },
47
38
  "singleQuote": { "type": "boolean" }
48
39
  }
@@ -5,7 +5,8 @@ All code MUST follow the canonical rules in `standards/manifest.json`.
5
5
  ## Formatting
6
6
 
7
7
  - Use Prettier for formatting.
8
- - Use a max line length of 100.
8
+ - Use a max line length of 160.
9
+ - Keep lines as compact as possible: if a declaration/expression fits in one line within 160 chars, keep it on one line.
9
10
  - Use semicolons.
10
11
  - Use double quotes for strings.
11
12
 
@@ -17,6 +18,7 @@ All code MUST follow the canonical rules in `standards/manifest.json`.
17
18
  - Avoid `any` unless there is no viable alternative.
18
19
  - Prefer explicit return types for exported functions.
19
20
  - Use type-only imports when possible.
21
+ - If a function/method needs many inputs, define a named `<FunctionName>Options` type and pass a single `options` parameter.
20
22
  - Always use braces in control flow (`if`, `else`, `for`, `while`, `do`).
21
23
 
22
24
  ## Naming
@@ -42,14 +44,16 @@ Required block names:
42
44
  3. `consts`
43
45
  4. `types`
44
46
  5. `private:attributes`
45
- 6. `private:properties`
46
- 7. `public:properties`
47
- 8. `constructor`
48
- 9. `static:properties`
49
- 10. `factory`
50
- 11. `private:methods`
51
- 12. `public:methods`
52
- 13. `static:methods`
47
+ 6. `protected:attributes`
48
+ 7. `private:properties`
49
+ 8. `public:properties`
50
+ 9. `constructor`
51
+ 10. `static:properties`
52
+ 11. `factory`
53
+ 12. `private:methods`
54
+ 13. `protected:methods`
55
+ 14. `public:methods`
56
+ 15. `static:methods`
53
57
 
54
58
  All section blocks MUST be present even when empty. Empty sections MUST include:
55
59
 
@@ -0,0 +1 @@
1
+ export const GREETING_PREFIX = "Hello";
@@ -1,3 +1,5 @@
1
+ import { GREETING_PREFIX } from "./config.js";
2
+
1
3
  export function greet(name: string): string {
2
- return `Hello, ${name}`;
4
+ return `${GREETING_PREFIX}, ${name}`;
3
5
  }
@@ -0,0 +1,3 @@
1
+ export const RESPONSE_CONTENT_TYPE = "application/json";
2
+ export const DEFAULT_PORT = 3000;
3
+ export const EXTERNAL_STATUS_URL = "https://status.example.com/health";
@@ -1,15 +1,16 @@
1
1
  import { createServer } from "node:http";
2
+ import { DEFAULT_PORT, EXTERNAL_STATUS_URL, RESPONSE_CONTENT_TYPE } from "./config.js";
2
3
 
3
4
  export function buildServer() {
4
5
  return createServer((_, response) => {
5
6
  response.statusCode = 200;
6
- response.setHeader("content-type", "application/json");
7
- response.end(JSON.stringify({ ok: true }));
7
+ response.setHeader("content-type", RESPONSE_CONTENT_TYPE);
8
+ response.end(JSON.stringify({ ok: true, statusSource: EXTERNAL_STATUS_URL }));
8
9
  });
9
10
  }
10
11
 
11
12
  if (process.env.NODE_ENV !== "test") {
12
- const port = Number(process.env.PORT ?? "3000");
13
+ const port = Number(process.env.PORT ?? String(DEFAULT_PORT));
13
14
  const server = buildServer();
14
15
  server.listen(port, () => {
15
16
  console.log(`service listening on http://localhost:${port}`);
@@ -22,7 +22,7 @@ test("service responds with ok payload", async () => {
22
22
  const json = await response.json();
23
23
 
24
24
  assert.equal(response.status, 200);
25
- assert.deepEqual(json, { ok: true });
25
+ assert.deepEqual(json, { ok: true, statusSource: "https://status.example.com/health" });
26
26
 
27
27
  await new Promise<void>((resolve, reject) => {
28
28
  server.close((error) => {