@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.
- package/README.md +42 -0
- package/bin/code-standards.mjs +507 -96
- package/eslint/test.mjs +1 -5
- package/package.json +1 -1
- package/prettier/index.cjs +1 -1
- package/profiles/default.profile.json +2 -0
- package/profiles/schema.json +7 -7
- package/resources/ai/templates/examples/demo/src/billing/billing-service.ts +18 -3
- package/resources/ai/templates/examples/demo/src/config.ts +3 -0
- package/resources/ai/templates/examples/demo/src/invoices/invoice-errors.ts +12 -0
- package/resources/ai/templates/examples/demo/src/invoices/invoice-service.ts +14 -1
- package/resources/ai/templates/examples/rules/async-bad.ts +12 -0
- package/resources/ai/templates/examples/rules/async-good.ts +12 -0
- package/resources/ai/templates/examples/rules/class-first-bad.ts +12 -0
- package/resources/ai/templates/examples/rules/class-first-good.ts +12 -0
- package/resources/ai/templates/examples/rules/constructor-bad.ts +12 -0
- package/resources/ai/templates/examples/rules/constructor-good.ts +12 -0
- package/resources/ai/templates/examples/rules/control-flow-bad.ts +12 -0
- package/resources/ai/templates/examples/rules/control-flow-good.ts +12 -0
- package/resources/ai/templates/examples/rules/errors-bad.ts +12 -0
- package/resources/ai/templates/examples/rules/errors-good.ts +12 -0
- package/resources/ai/templates/examples/rules/functions-bad.ts +12 -0
- package/resources/ai/templates/examples/rules/functions-good.ts +12 -0
- package/resources/ai/templates/examples/rules/returns-bad.ts +12 -0
- package/resources/ai/templates/examples/rules/returns-good.ts +12 -0
- package/resources/ai/templates/examples/rules/testing-bad.ts +12 -0
- package/resources/ai/templates/examples/rules/testing-good.ts +12 -0
- package/resources/ai/templates/rules/architecture.md +2 -0
- package/resources/ai/templates/rules/class-first.md +2 -0
- package/resources/ai/templates/rules/functions.md +2 -0
- package/standards/architecture.md +2 -1
- package/standards/manifest.json +1 -1
- package/standards/schema.json +2 -11
- package/standards/style.md +13 -9
- package/templates/node-lib/src/config.ts +1 -0
- package/templates/node-lib/src/index.ts +3 -1
- package/templates/node-service/src/config.ts +3 -0
- package/templates/node-service/src/index.ts +4 -3
- 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
|
|
25
|
+
- Keep hardcoded application configuration centralized in `src/config.ts`.
|
package/standards/manifest.json
CHANGED
package/standards/schema.json
CHANGED
|
@@ -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":
|
|
36
|
+
"lineLength": { "type": "integer", "minimum": 80, "maximum": 200 },
|
|
46
37
|
"semi": { "type": "boolean" },
|
|
47
38
|
"singleQuote": { "type": "boolean" }
|
|
48
39
|
}
|
package/standards/style.md
CHANGED
|
@@ -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
|
|
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. `
|
|
46
|
-
7. `
|
|
47
|
-
8. `
|
|
48
|
-
9. `
|
|
49
|
-
10. `
|
|
50
|
-
11. `
|
|
51
|
-
12. `
|
|
52
|
-
13. `
|
|
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,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",
|
|
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 ??
|
|
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) => {
|