bluetemberg-rules-typescript 0.1.0

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.
@@ -0,0 +1,21 @@
1
+ ---
2
+ description: Keep functions and components small, readable, and easy to reason about.
3
+ scope: "**"
4
+ ---
5
+
6
+ # Coding standards
7
+
8
+ Keep functions and components small, readable, and easy to reason about.
9
+
10
+ ## Function complexity
11
+
12
+ - Prefer small, single-purpose functions.
13
+ - Keep control flow shallow; avoid deep nesting.
14
+ - Use early returns and guard clauses to reduce `else` blocks.
15
+ - Extract complex logic into well-named helpers.
16
+
17
+ ## Readability
18
+
19
+ - Favor descriptive names for functions, variables, and components.
20
+ - Avoid magic numbers/strings; use constants where appropriate.
21
+ - Keep conditionals straightforward; prefer `if (!condition) return` patterns.
@@ -0,0 +1,13 @@
1
+ ---
2
+ description: Reuse existing shared UI components and design tokens before creating new ones.
3
+ scope: "**/*.{tsx,jsx,svelte,vue}"
4
+ ---
5
+
6
+ # Design system usage
7
+
8
+ When building new features or screens:
9
+
10
+ - Reuse existing shared UI components before introducing new bespoke ones.
11
+ - Prefer design tokens and shared theme primitives over hardcoded values.
12
+ - Only introduce new UI components if no suitable shared component exists.
13
+ - Keep component APIs and naming consistent across the workspace.
@@ -0,0 +1,39 @@
1
+ ---
2
+ description: Prefer early returns and guard clauses over nested conditionals.
3
+ scope: "**"
4
+ ---
5
+
6
+ # Early returns
7
+
8
+ Use early returns and guard clauses to keep control flow flat and readable.
9
+
10
+ ## Patterns
11
+
12
+ - Return early for invalid input, missing data, or edge cases at the top of functions.
13
+ - Avoid `else` blocks when the `if` branch returns or throws.
14
+ - Flatten nested `if`/`else` chains by inverting conditions.
15
+
16
+ ## Examples
17
+
18
+ ```ts
19
+ // BAD — deeply nested
20
+ function process(user) {
21
+ if (user) {
22
+ if (user.isActive) {
23
+ if (user.hasPermission) {
24
+ return doWork(user);
25
+ }
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+
31
+ // GOOD — guard clauses
32
+ function process(user) {
33
+ if (!user) return null;
34
+ if (!user.isActive) return null;
35
+ if (!user.hasPermission) return null;
36
+
37
+ return doWork(user);
38
+ }
39
+ ```
@@ -0,0 +1,31 @@
1
+ ---
2
+ description: Forbid console.log in production code; use a logger instead.
3
+ scope: "src/**"
4
+ ---
5
+
6
+ # No console.log in production code
7
+
8
+ Never use `console.log` (or `console.warn`, `console.error`, `console.debug`) directly in source files under `src/`.
9
+
10
+ Use the project logger instead so that log output is structured, level-controlled, and safe to ship.
11
+
12
+ ## Examples
13
+
14
+ ```ts
15
+ // BAD
16
+ console.log("Fetching page", slug);
17
+ console.error("Something went wrong", err);
18
+
19
+ // GOOD
20
+ logger.info("Fetching page", { slug });
21
+ logger.error("Something went wrong", { error: err });
22
+ ```
23
+
24
+ ## Exceptions
25
+
26
+ CLI entry points and files whose sole purpose is user-facing terminal output may use `console.log` directly. All other `src/` code must use a structured logger.
27
+
28
+ ## Why
29
+
30
+ - `console.*` calls leak implementation details and unstructured output into production.
31
+ - A logger allows log-level filtering, structured metadata, and integration with observability tooling.
@@ -0,0 +1,30 @@
1
+ ---
2
+ description: Enforce strict type safety — no implicit any, no unguarded assertions.
3
+ scope: "**"
4
+ ---
5
+
6
+ # Type safety
7
+
8
+ Maintain strict type safety across the codebase.
9
+
10
+ ## Rules
11
+
12
+ - Never use `any`. Use `unknown` when the type is genuinely uncertain, then narrow.
13
+ - Avoid type assertions (`as`) unless you add a comment explaining why it's safe.
14
+ - Enable and respect `strict` mode in `tsconfig.json`.
15
+ - Prefer type guards (`typeof`, `instanceof`, discriminated unions) over assertions.
16
+ - Use `satisfies` for object literals when you want type checking without widening.
17
+
18
+ ## Examples
19
+
20
+ ```ts
21
+ // BAD
22
+ const data: any = fetchData();
23
+ const name = (response as User).name;
24
+
25
+ // GOOD
26
+ const data: unknown = fetchData();
27
+ if (isUser(data)) {
28
+ const name = data.name;
29
+ }
30
+ ```
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "bluetemberg-rules-typescript",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript code quality rules for Bluetemberg — type safety, coding standards, early returns, no console.log, design system reuse.",
5
+ "keywords": [
6
+ "bluetemberg-pack",
7
+ "rules",
8
+ "typescript",
9
+ "code-quality"
10
+ ],
11
+ "author": "Prototyp Digital",
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/prototypdigital/bluetemberg-packs.git"
16
+ },
17
+ "files": [
18
+ "llm/"
19
+ ]
20
+ }