@mrciphersmith/keryx 0.4.29 → 0.4.31
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/dist/cli.js +2446 -1391
- package/dist/core.js +90 -27
- package/dist/keryx-general-worker-entry.js +82 -25
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +2 -0
- package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
- package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
- package/src/gdskills/bundled/rules/core/clean-architecture.mdc +21 -3
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -49
- package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
- package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
- package/src/gdskills/bundled/rules/core/error-handling.mdc +7 -8
- package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
- package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
- package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
- package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
- package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
- package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
- package/src/gdskills/bundled/rules/core/solid-principles.mdc +31 -7
- package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
- package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
- package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
- package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +24 -60
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +13 -65
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +22 -35
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +16 -309
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +7 -21
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +83 -227
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +15 -37
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +7 -7
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +31 -66
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +21 -39
- package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
- package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
- package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
- package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
- package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
- package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
- package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -84
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
- package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
- package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
- package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
- package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
- package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
- package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
- package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
- package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
- package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
- package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
- package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
- package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
- package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
- package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
- package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
- package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +18 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
- package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
- package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
- package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
- package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
- package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
- package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
- package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
- package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
- package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
- package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
- package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
- package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
- package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
- package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
- package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
- package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
- package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
- package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
- package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
- package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
- package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
- package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
- package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
- package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
- package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +12 -45
- package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
- package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
- package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
- package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
- package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
- package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
- package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
- package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
- package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
- package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
- package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
- package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
- package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
- package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
- package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
- package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
- package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
- package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
- package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
|
@@ -7,71 +7,37 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Python testing
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
conventions. Applies only to `*.py`/`*.pyi` files; see
|
|
12
|
-
`skills/python-testing/SKILL.md` for the full test-authoring workflow this
|
|
13
|
-
rule file backs.
|
|
10
|
+
Narrows `core-common-rules`' testing guidance to `pytest`. Applies only to `*.py`/`*.pyi` files; see `skills/python-testing/SKILL.md` for the test-authoring workflow this rule file backs.
|
|
14
11
|
|
|
15
12
|
## Layout and discovery
|
|
16
13
|
|
|
17
|
-
- Match the project's
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- Name test files, classes, and functions so `pytest`'s default discovery
|
|
21
|
-
finds them (`test_*.py`/`*_test.py`, `Test*` classes with no `__init__`,
|
|
22
|
-
`test_*` functions) rather than relying on manual `testpaths` overrides.
|
|
23
|
-
- Keep a fixture in the narrowest `conftest.py` that covers every test
|
|
24
|
-
needing it; do not hoist a single-file fixture to the suite root.
|
|
14
|
+
- Match the project's layout: a `tests/` tree mirroring `src/`, or co-located `test_*.py`/`*_test.py`; do not introduce the other alongside it.
|
|
15
|
+
- Name tests so `pytest`'s default discovery finds them (`test_*.py`/`*_test.py`, `Test*` classes with no `__init__`, `test_*` functions), not via `testpaths` overrides.
|
|
16
|
+
- Keep a fixture in the narrowest `conftest.py` that covers every test needing it; do not hoist a single-file fixture to the suite root.
|
|
25
17
|
|
|
26
18
|
## Fixtures and parametrization
|
|
27
19
|
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- Use `@pytest.mark.parametrize` when only inputs vary; use a fixture (or
|
|
32
|
-
`pytest.fixture(params=[...])`) when setup/teardown logic itself varies
|
|
33
|
-
between cases.
|
|
34
|
-
- Give parametrized cases explicit `ids=` when the parameter values are not
|
|
35
|
-
self-describing in pytest's default test-ID output.
|
|
20
|
+
- Default to `function` scope; widen to `module`/`session` only for expensive, read-only setup, never for a fixture that mutates shared state.
|
|
21
|
+
- Use `@pytest.mark.parametrize` when only inputs vary; use a fixture (or `pytest.fixture(params=[...])`) when setup/teardown varies.
|
|
22
|
+
- Give parametrized cases explicit `ids=` when the values are not self-describing.
|
|
36
23
|
|
|
37
24
|
## Mocking
|
|
38
25
|
|
|
39
|
-
- Patch at the point of use (`mocker.patch("mypkg.module.dependency")`), not
|
|
40
|
-
|
|
41
|
-
- Mock only external dependencies (network, filesystem, other services,
|
|
42
|
-
wall-clock time); an internal collaborator mocked away stops the test
|
|
43
|
-
verifying real integration between your own modules.
|
|
44
|
-
- Prefer `unittest.mock.AsyncMock` (or `pytest-mock`'s `mocker.patch` with
|
|
45
|
-
`new=AsyncMock()`) for mocking an `async def` dependency, not a plain
|
|
46
|
-
`Mock` that returns a coroutine-shaped object nothing ever awaits.
|
|
26
|
+
- Patch at the point of use (`mocker.patch("mypkg.module.dependency")`), not at the definition site.
|
|
27
|
+
- Use `unittest.mock.AsyncMock` (or `mocker.patch` with `new=AsyncMock()`) for an `async def` dependency, not a plain `Mock`.
|
|
47
28
|
|
|
48
29
|
## Async tests
|
|
49
30
|
|
|
50
|
-
- Mark
|
|
51
|
-
|
|
52
|
-
without awaiting it silently never runs the coroutine's body.
|
|
53
|
-
- Use the project's configured event-loop fixture scope; do not create a new
|
|
54
|
-
event loop per test unless the project's async plugin requires it.
|
|
31
|
+
- Mark async tests with `pytest.mark.asyncio` (or the project's configured async plugin/mode).
|
|
32
|
+
- Use the project's configured event-loop fixture scope; do not create a new loop per test unless the plugin requires it.
|
|
55
33
|
|
|
56
34
|
## Determinism
|
|
57
35
|
|
|
58
|
-
- Never depend on real wall-clock time, network access
|
|
59
|
-
|
|
60
|
-
(`freezegun` or the project's equivalent) and mock the network.
|
|
61
|
-
- Never depend on dict/set iteration order for test correctness beyond
|
|
62
|
-
Python's own guaranteed dict insertion order; sort collections before
|
|
63
|
-
comparing when the underlying data structure does not guarantee order.
|
|
64
|
-
- A flaky test (passes/fails nondeterministically) gets fixed at its root
|
|
65
|
-
cause (a missing await, an unmocked clock, a race) — never retried into
|
|
66
|
-
passing or skipped to hide the flake.
|
|
36
|
+
- Never depend on real wall-clock time, network access or filesystem state outside `tmp_path`; freeze time (`freezegun` or equivalent) and mock the network.
|
|
37
|
+
- Do not depend on dict/set iteration order beyond the guaranteed dict insertion order; sort before comparing.
|
|
67
38
|
|
|
68
39
|
## Coverage expectations
|
|
69
40
|
|
|
70
|
-
- Every new or touched public function/class/endpoint gets at least one
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
- A test asserts one behavior; a test with several unrelated assertions
|
|
74
|
-
should split so a failure names the specific behavior that broke.
|
|
75
|
-
- Run the project's configured coverage tool (`pytest --cov` when
|
|
76
|
-
configured) and treat an uncovered branch in touched code as a gap to
|
|
77
|
-
close, not to suppress with a `# pragma: no cover` on real logic.
|
|
41
|
+
- Every new or touched public function/class/endpoint gets at least one test covering its happy path, documented edge cases and raised exception types.
|
|
42
|
+
- A test asserts one behavior; split a test with several unrelated assertions.
|
|
43
|
+
- Run the configured coverage tool (`pytest --cov`) and close uncovered branches in touched code; no `# pragma: no cover` on real logic.
|
|
@@ -7,52 +7,26 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# React coding style
|
|
9
9
|
|
|
10
|
-
Narrows `ts-js-node`'s coding style to React component files
|
|
11
|
-
|
|
12
|
-
comes from `ts-js-node`'s own coding-style rule, not this file.
|
|
10
|
+
Narrows `ts-js-node`'s coding style to React component files (`*.tsx`/`*.jsx`
|
|
11
|
+
only); non-component code stays with `ts-js-node`'s rule.
|
|
13
12
|
|
|
14
13
|
## Components
|
|
15
14
|
|
|
16
|
-
- Write function components; a class component is
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
- Name a component file after the component it exports (`UserCard.tsx`
|
|
22
|
-
exports `UserCard`), `PascalCase` for the component, `camelCase` for
|
|
23
|
-
hooks (`useUserCard`) and plain functions.
|
|
24
|
-
- Destructure props in the function signature; do not thread a whole
|
|
25
|
-
`props` object through the body when only a few fields are used.
|
|
26
|
-
- Type props with an explicit `interface`/`type`, not `React.FC` — `FC`'s
|
|
27
|
-
implicit `children` and weaker generic inference are a known footgun the
|
|
28
|
-
current React types intentionally do not paper over.
|
|
15
|
+
- Write function components; a class component only where none is possible (an error boundary).
|
|
16
|
+
- One component per file for anything exported and reused; a small private helper used only in its parent file can stay local.
|
|
17
|
+
- Name the file after the exported component (`UserCard.tsx`); `PascalCase` components, `camelCase` hooks (`useUserCard`) and functions.
|
|
18
|
+
- Destructure props in the signature.
|
|
19
|
+
- Type props with an explicit `interface`/`type`, not `React.FC`.
|
|
29
20
|
|
|
30
21
|
## Hooks and state
|
|
31
22
|
|
|
32
|
-
- Call hooks only at the top level of a component or
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
- Order hooks so the same hooks run in the same order on every render;
|
|
37
|
-
branch inside a hook's own logic (`if (x) return early` after the hook
|
|
38
|
-
call), not around the hook call itself.
|
|
39
|
-
- Prefer several focused `useState` calls over one large state object when
|
|
40
|
-
the fields update independently; group into one state (or `useReducer`)
|
|
41
|
-
only when fields change together.
|
|
42
|
-
- Name a custom hook's return values by what they mean in the caller
|
|
43
|
-
(`{ data, isLoading, error }`), not by the hook's internal variable
|
|
44
|
-
names.
|
|
23
|
+
- Call hooks only at the top level of a component or hook; do not add an eslint-disable to route around the react-hooks rule (see `rules/security.mdc` and `react-build-fix`'s guardrails).
|
|
24
|
+
- Branch inside a hook's own logic (early return after the hook call), not around the hook call.
|
|
25
|
+
- Prefer several focused `useState` calls over one state object when fields update independently; group (or `useReducer`) only when they change together.
|
|
26
|
+
- Name a custom hook's return values by caller meaning (`{ data, isLoading, error }`).
|
|
45
27
|
|
|
46
28
|
## Imports and structure
|
|
47
29
|
|
|
48
|
-
- Group imports
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
- Import hooks and utilities by name (`import { useState } from "react"`);
|
|
52
|
-
do not import the whole `React` namespace unless the project's JSX
|
|
53
|
-
transform requires it (check the project's `tsconfig`/bundler config —
|
|
54
|
-
the classic transform needs `import React from "react"` in scope, the
|
|
55
|
-
automatic transform introduced in React 17 does not).
|
|
56
|
-
- Co-locate a component's own styles, tests, and small subcomponents next
|
|
57
|
-
to it under one directory when the project already uses that layout;
|
|
58
|
-
match the existing convention rather than introducing a new one.
|
|
30
|
+
- Group imports React/framework, third-party, local, as in `ts-js-node`'s coding-style rule.
|
|
31
|
+
- Import hooks by name (`import { useState } from "react"`); import the `React` namespace only if the project's JSX transform requires it (classic transform yes, automatic transform from React 17 no).
|
|
32
|
+
- Co-locate a component's styles, tests, and small subcomponents under one directory when the project already does; match the existing convention.
|
|
@@ -7,73 +7,33 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# React patterns
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
Component design and anti-patterns for React 19-era code, narrowed to
|
|
11
|
+
`*.tsx`/`*.jsx`.
|
|
12
12
|
|
|
13
13
|
## Derive, don't sync
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
from a change in props/state is almost always replaceable by a plain
|
|
19
|
-
computed value (optionally memoized with `useMemo` when the computation
|
|
20
|
-
is expensive).
|
|
21
|
-
- Reset local state on a prop change by giving the component a `key` tied
|
|
22
|
-
to that prop (React unmounts and remounts a fresh component), not by
|
|
23
|
-
watching the prop in an effect and calling a setter.
|
|
24
|
-
- Effects are for synchronizing with something outside React: the DOM,
|
|
25
|
-
a subscription, a network request, browser storage, a third-party widget.
|
|
26
|
-
An effect with no external system on the other end is a sign the logic
|
|
27
|
-
belongs in an event handler or in render itself.
|
|
15
|
+
- Compute a value derivable from props/state during render (`useMemo` only when expensive); do not `useState` + `useEffect` to mirror one state into another.
|
|
16
|
+
- Reset local state on a prop change with a `key` tied to that prop, not an effect that calls a setter.
|
|
17
|
+
- Use effects only to synchronize with something outside React (DOM, subscription, network, browser storage, third-party widget); otherwise the logic belongs in an event handler or render.
|
|
28
18
|
|
|
29
19
|
## Lists and keys
|
|
30
20
|
|
|
31
|
-
-
|
|
32
|
-
|
|
33
|
-
provably static and never reordered/filtered/inserted into.
|
|
34
|
-
- Do not use `key` as a prop for anything other than list identity inside
|
|
35
|
-
the component receiving it — reading `props.key` returns `undefined`.
|
|
21
|
+
- Give every `.map` element a stable `key` from the data (an id), not the array index, unless the list is provably static and never reordered/filtered/inserted into.
|
|
22
|
+
- Do not use `key` as a prop for anything but list identity; `props.key` is `undefined`.
|
|
36
23
|
|
|
37
24
|
## Forms and events
|
|
38
25
|
|
|
39
|
-
- Prefer a controlled input (`value` + `onChange`) for
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
fire-and-forget fields where per-keystroke reactivity is not needed.
|
|
43
|
-
- For form submission with a pending/error/optimistic result, prefer an
|
|
44
|
-
Action (a function passed to a `<form action={...}>`,
|
|
45
|
-
`useActionState`, and `useOptimistic` for the optimistic update) over
|
|
46
|
-
hand-rolled `isSubmitting`/`error` state plus a submit handler that calls
|
|
47
|
-
`preventDefault` — the Actions API already tracks pending and error state
|
|
48
|
-
and integrates with Suspense.
|
|
49
|
-
- Reach for `useTransition` to mark a state update as non-urgent (keeps the
|
|
50
|
-
UI responsive during an expensive re-render) rather than debouncing or
|
|
51
|
-
deferring the update by hand.
|
|
26
|
+
- Prefer a controlled input (`value` + `onChange`) when the component validates, transforms, or reacts as the user types; uncontrolled (`defaultValue` + ref) only for simple fields without per-keystroke reactivity.
|
|
27
|
+
- For submission with pending/error/optimistic state, prefer an Action (`<form action={...}>`, `useActionState`, `useOptimistic`) over hand-rolled `isSubmitting`/`error` state plus `preventDefault`.
|
|
28
|
+
- Use `useTransition` for non-urgent updates rather than hand-rolled debouncing or deferral.
|
|
52
29
|
|
|
53
30
|
## Refs, Suspense, and composition
|
|
54
31
|
|
|
55
|
-
- In React 19, `ref` is an ordinary prop
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
-
|
|
59
|
-
or a context) instead of stuffing the result into state via an effect;
|
|
60
|
-
pair it with a `Suspense` boundary for the pending state and an error
|
|
61
|
-
boundary for the rejected state.
|
|
62
|
-
- Prefer composition (children, render props, or a small set of focused
|
|
63
|
-
components) over one component branching on a `type`/`variant` prop into
|
|
64
|
-
unrelated render trees.
|
|
65
|
-
- In a framework that supports server and client components, keep data
|
|
66
|
-
fetching and secrets in server components; a component needs
|
|
67
|
-
`"use client"` only once it uses state, effects, refs, or browser-only
|
|
68
|
-
APIs — do not mark a whole subtree client just because one leaf needs it.
|
|
32
|
+
- In React 19, `ref` is an ordinary prop: no `forwardRef` in new components; keep it only for code that must support pre-19 React.
|
|
33
|
+
- Read an async resource in render with `use` (promise or context) instead of an effect writing to state; pair with a `Suspense` boundary and an error boundary.
|
|
34
|
+
- Prefer composition (children, render props, focused components) over one component branching on a `type`/`variant` prop into unrelated trees.
|
|
35
|
+
- With server and client components, keep data fetching and secrets in server components; add `"use client"` only for a component that uses state, effects, refs, or browser-only APIs, not a whole subtree for one leaf.
|
|
69
36
|
|
|
70
37
|
## Compiler awareness
|
|
71
38
|
|
|
72
|
-
-
|
|
73
|
-
config or `babel-plugin-react-compiler`/`react-compiler` dependency),
|
|
74
|
-
do not hand-add `memo`, `useMemo`, or `useCallback` purely to prevent
|
|
75
|
-
re-renders — the compiler already memoizes automatically, and manual
|
|
76
|
-
memoization on compiled code is dead weight that can also mask a bug the
|
|
77
|
-
compiler would otherwise have caught. Without the compiler, manual
|
|
78
|
-
memoization is still a valid, deliberate optimization for a measured
|
|
79
|
-
re-render cost.
|
|
39
|
+
- With the React Compiler enabled (babel/swc config or `babel-plugin-react-compiler`/`react-compiler` dependency), do not hand-add `memo`, `useMemo`, or `useCallback` just to prevent re-renders. Without it, manual memoization is valid for a measured re-render cost.
|
|
@@ -7,64 +7,28 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# React security
|
|
9
9
|
|
|
10
|
-
Stack-specific risks for React component files (`*.tsx`/`*.jsx`),
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
Stack-specific risks for React component files (`*.tsx`/`*.jsx`), narrowing
|
|
11
|
+
`ts-js-node`'s generic security rule to the sinks React's rendering model
|
|
12
|
+
makes reachable.
|
|
13
13
|
|
|
14
14
|
## `dangerouslySetInnerHTML`
|
|
15
15
|
|
|
16
|
-
- Treat `dangerouslySetInnerHTML` as the default XSS sink
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
needs to render rich HTML (e.g. a CMS body).
|
|
20
|
-
- When it is unavoidable, sanitize the string through the project's own
|
|
21
|
-
sanitizer (e.g. DOMPurify) immediately before the prop is built, not
|
|
22
|
-
earlier in the pipeline where a later edit could drop the sanitize step;
|
|
23
|
-
never pass a raw string straight through.
|
|
24
|
-
- Never build the `__html` value by concatenating user input into a
|
|
25
|
-
template string of markup — that is the same sink with extra steps.
|
|
16
|
+
- Treat `dangerouslySetInnerHTML` as the default XSS sink for any user-, API-, or CMS-sourced string; render as text/JSX unless rich HTML is genuinely needed (e.g. a CMS body).
|
|
17
|
+
- When unavoidable, sanitize with the project's sanitizer (e.g. DOMPurify) immediately before the prop is built; never pass a raw string.
|
|
18
|
+
- Never build `__html` by concatenating user input into a markup template string.
|
|
26
19
|
|
|
27
20
|
## URLs from user data
|
|
28
21
|
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
`javascript:`, `data:`, and `vbscript:` schemes execute on click/load.
|
|
32
|
-
Validate against an allowlist (`http:`, `https:`, `mailto:`) before
|
|
33
|
-
binding it to the element.
|
|
34
|
-
- The same applies to a dynamic `src` on `<img>`, `<iframe>`, or `<script>`
|
|
35
|
-
built from anything not fully controlled by the app.
|
|
22
|
+
- Allowlist the scheme (`http:`, `https:`, `mailto:`) of a URL from user input, a query param, or an API response before binding it to `href`/`src`; `javascript:`, `data:`, and `vbscript:` execute.
|
|
23
|
+
- The same applies to a dynamic `src` on `<img>`, `<iframe>`, or `<script>` not fully controlled by the app.
|
|
36
24
|
|
|
37
25
|
## Secrets and client bundles
|
|
38
26
|
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
text — never put an API secret, private key, or unscoped token behind
|
|
43
|
-
one of these prefixes. A value that must stay server-only belongs in a
|
|
44
|
-
server component, a route handler/API route, or a server function/
|
|
45
|
-
action, never a client component or a plain (non-prefixed-and-still-
|
|
46
|
-
bundled) constant imported into client code.
|
|
47
|
-
- Grep a diff for the project's public-env prefix before approving a new
|
|
48
|
-
environment variable used inside a client component.
|
|
49
|
-
- A Server Function/Action is not merely a safe home for a server-only
|
|
50
|
-
value — calling it from the client turns it into a public, directly
|
|
51
|
-
reachable HTTP endpoint (its own route, invocable by anything that can
|
|
52
|
-
reach the app, not only through the form/button that references it in
|
|
53
|
-
the source). It gets none of the caller-identity or authorization
|
|
54
|
-
checks a UI-only flow implies; each Server Function/Action must
|
|
55
|
-
authenticate the caller, authorize the specific operation, and validate
|
|
56
|
-
every argument itself, exactly as a hand-written API route would,
|
|
57
|
-
before it touches data or a mutation.
|
|
27
|
+
- Never put an API secret, private key, or unscoped token behind a public-env prefix (`NEXT_PUBLIC_`/`VITE_`/`REACT_APP_`) or any value the bundler inlines into client output. Server-only values belong in a server component, route handler/API route, or server function/action.
|
|
28
|
+
- Grep a diff for the project's public-env prefix before approving a new environment variable used in a client component.
|
|
29
|
+
- A Server Function/Action called from the client is a public HTTP endpoint: each one must authenticate the caller, authorize the specific operation, and validate every argument itself, as a hand-written API route would, before touching data or a mutation.
|
|
58
30
|
|
|
59
31
|
## Third-party scripts and client-side auth
|
|
60
32
|
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
unvalidated `href`/`src` above; pin third-party script URLs to a fixed,
|
|
64
|
-
reviewed list.
|
|
65
|
-
- Do not gate a protected view purely on client-side state (a store flag,
|
|
66
|
-
a decoded-but-unverified JWT, a route guard component) — a client
|
|
67
|
-
component can always be bypassed by disabling JavaScript or calling the
|
|
68
|
-
underlying API directly. Client-side checks are UX only; the real
|
|
69
|
-
authorization check must happen server-side (server component, route
|
|
70
|
-
handler, or backend).
|
|
33
|
+
- Do not inject a `<script>` with a dynamic or user-influenced `src`; pin third-party script URLs to a fixed, reviewed list.
|
|
34
|
+
- Do not gate a protected view only on client-side state (store flag, unverified decoded JWT, route guard component); client checks are UX only, authorization happens server-side (server component, route handler, or backend).
|
|
@@ -12,49 +12,22 @@ Test layout, runner, and assertion conventions for React component files
|
|
|
12
12
|
|
|
13
13
|
## Layout and runner
|
|
14
14
|
|
|
15
|
-
- Use the project's
|
|
16
|
-
|
|
17
|
-
— do not introduce Enzyme or a shallow-render helper into a project that
|
|
18
|
-
does not already use one.
|
|
19
|
-
- Co-locate a component's test next to it (`UserCard.test.tsx`) when the
|
|
20
|
-
project already follows that layout, or under a mirrored `__tests__`
|
|
21
|
-
tree when that is the existing convention; match, do not introduce.
|
|
15
|
+
- Use the project's configured runner (Vitest or Jest) with React Testing Library (`@testing-library/react` + `@testing-library/user-event`); do not introduce Enzyme or a shallow-render helper.
|
|
16
|
+
- Co-locate a component's test (`UserCard.test.tsx`) or use a mirrored `__tests__` tree, whichever the project already follows.
|
|
22
17
|
|
|
23
18
|
## Queries and interaction
|
|
24
19
|
|
|
25
|
-
- Query by role/label/text
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
markup itself may be missing an accessible name.
|
|
29
|
-
- Never assert on a component's internal state, instance fields, or
|
|
30
|
-
implementation details (no reaching into a ref's internals, no snapshot
|
|
31
|
-
of a component's private props) — assert on rendered output and
|
|
32
|
-
behavior only.
|
|
33
|
-
- Drive interaction through `@testing-library/user-event`
|
|
34
|
-
(`userEvent.click`/`.type`/`.tab`), not `fireEvent`, unless the project
|
|
35
|
-
is pinned to an older `user-event` major that cannot express the
|
|
36
|
-
interaction — `user-event` fires the fuller sequence of browser events a
|
|
37
|
-
real interaction would.
|
|
20
|
+
- Query by role/label/text (`getByRole`, `getByLabelText`, `getByText`); use `data-testid` only when no accessible query exists, and treat that as a sign the markup lacks an accessible name.
|
|
21
|
+
- Assert on rendered output and behavior, never on internal state, instance fields, or private props (no snapshots of them).
|
|
22
|
+
- Drive interaction with `userEvent` (`click`/`type`/`tab`), not `fireEvent`, unless the project is pinned to an older `user-event` major that cannot express it.
|
|
38
23
|
|
|
39
24
|
## Async and network
|
|
40
25
|
|
|
41
|
-
- Wait for async UI with `findBy*`
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
- Mock network calls at the request boundary (an MSW handler, or the
|
|
45
|
-
project's existing equivalent) rather than mocking the component's own
|
|
46
|
-
data-fetching function — a boundary mock still exercises the real
|
|
47
|
-
fetch/parse/error-handling code path.
|
|
48
|
-
- Wrap a state update triggered outside React Testing Library's own query
|
|
49
|
-
helpers (e.g. a manually invoked callback) in `act` only when RTL's
|
|
50
|
-
built-in wrapping does not already cover it; an `act` warning is a
|
|
51
|
-
signal to await the right query, not to silence the console.
|
|
26
|
+
- Wait for async UI with `findBy*` or `waitFor`, never `setTimeout`/`sleep`.
|
|
27
|
+
- Mock network at the request boundary (an MSW handler or the project's equivalent), not the component's own data-fetching function.
|
|
28
|
+
- Use `act` only where RTL's built-in wrapping does not cover the update; an `act` warning means await the right query, not silence the console.
|
|
52
29
|
|
|
53
30
|
## Coverage expectations
|
|
54
31
|
|
|
55
|
-
- Cover
|
|
56
|
-
|
|
57
|
-
of state gates.
|
|
58
|
-
- For a custom hook with logic worth testing on its own, use
|
|
59
|
-
`renderHook` from `@testing-library/react` rather than mounting a
|
|
60
|
-
throwaway component to exercise it.
|
|
32
|
+
- Cover initial/loading, success, error, and empty states, plus any branch a prop or state gates.
|
|
33
|
+
- Test a custom hook with logic on its own via `renderHook` from `@testing-library/react`, not a throwaway component.
|
|
@@ -7,63 +7,30 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Ruby on Rails coding style
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
(3.x) idiom and Rails conventions in one pack (this pack has no separate
|
|
12
|
-
`lang:ruby` base to extend). Applies only to `*.rb` files.
|
|
10
|
+
Narrows `core-common-rules`' style rules to modern Ruby (3.x) and Rails conventions in one pack (no separate `lang:ruby` base). Applies only to `*.rb` files.
|
|
13
11
|
|
|
14
12
|
## Naming and structure
|
|
15
13
|
|
|
16
|
-
- `
|
|
17
|
-
columns/tables; `CamelCase` for classes and modules — never mix Ruby's
|
|
18
|
-
own convention with a borrowed one from another language.
|
|
19
|
-
- A predicate method (returns true/false) ends in `?` (`published?`, not
|
|
20
|
-
`is_published`); a destructive/bang method that mutates in place or
|
|
21
|
-
raises instead of returning nil ends in `!` and normally has a
|
|
22
|
-
non-bang counterpart (`save!` alongside `save`).
|
|
23
|
-
- Two-space indentation, no tabs.
|
|
14
|
+
- A predicate method ends in `?` (`published?`, not `is_published`); a bang method that mutates in place or raises ends in `!` and normally has a non-bang counterpart (`save!` alongside `save`).
|
|
24
15
|
- Overrides the `solid-principles.mdc` "Function body length" row for
|
|
25
16
|
Ruby: a method over 10 lines is the threshold. Extract a private
|
|
26
17
|
method, a concern, or (per `rules/patterns.mdc`) a service object.
|
|
27
|
-
- Follow the app's
|
|
28
|
-
`app/jobs`, `app/services` (if the app already has one) — do not
|
|
29
|
-
invent a new top-level directory for one class.
|
|
18
|
+
- Follow the app's file layout (`app/models`, `app/controllers`, `app/jobs`, `app/services` if the app has one); do not invent a top-level directory for one class.
|
|
30
19
|
|
|
31
20
|
## Modern Ruby (3.x) idiom
|
|
32
21
|
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- An endless method (`def full_name = "#{first_name} #{last_name}"`) is
|
|
39
|
-
fine for a genuine one-expression method; do not squeeze a
|
|
40
|
-
multi-statement method onto one line just to use the syntax.
|
|
41
|
-
- Keyword arguments (`def initialize(name:, email:)`) for a method with
|
|
42
|
-
more than one or two parameters, especially when some are optional —
|
|
43
|
-
clearer at the call site than positional args, and safer against
|
|
44
|
-
argument-order mistakes than a trailing options hash.
|
|
45
|
-
- Prefer `Data.define`/a plain `Struct` for a small immutable value
|
|
46
|
-
object over a full `ActiveRecord`-backed model when nothing needs
|
|
47
|
-
persisting.
|
|
48
|
-
- Safe navigation (`user&.profile&.bio`) only where `nil` is an expected,
|
|
49
|
-
legitimate state for the chain; do not use it to paper over a case
|
|
50
|
-
where a `nil` actually signals a bug that should raise or be handled
|
|
51
|
-
explicitly.
|
|
22
|
+
- Use `case/in` pattern matching to destructure hash/array-shaped values when it reads clearer than `if`/`elsif` or `dig`/`fetch` chains; not for a simple `nil?` check.
|
|
23
|
+
- Use an endless method (`def full_name = "..."`) only for a genuine one-expression method.
|
|
24
|
+
- Use keyword arguments for a method with more than one or two parameters, especially when some are optional.
|
|
25
|
+
- Prefer `Data.define`/a plain `Struct` for a small immutable value object over an `ActiveRecord` model when nothing is persisted.
|
|
26
|
+
- Use safe navigation (`user&.profile&.bio`) only where `nil` is a legitimate state for the chain.
|
|
52
27
|
|
|
53
28
|
## Frozen string literals and immutability
|
|
54
29
|
|
|
55
|
-
- New Ruby files start with `# frozen_string_literal: true` (match the
|
|
56
|
-
|
|
57
|
-
frozen by default, so any `String#<<`/`gsub!`/`concat` mutation must
|
|
58
|
-
target an explicit `.dup`/`String.new`, not a literal.
|
|
59
|
-
- Prefer returning a new value over mutating an argument in place, except
|
|
60
|
-
for methods whose name signals mutation (`!`-suffixed, or a
|
|
61
|
-
conventionally mutating method like `each`'s block).
|
|
30
|
+
- New Ruby files start with `# frozen_string_literal: true` (match the project's convention); mutate strings only via an explicit `.dup`/`String.new`.
|
|
31
|
+
- Prefer returning a new value over mutating an argument, except for `!`-suffixed or conventionally mutating methods.
|
|
62
32
|
|
|
63
33
|
## Formatting and linting
|
|
64
34
|
|
|
65
|
-
- Match
|
|
66
|
-
|
|
67
|
-
project's cops would flag.
|
|
68
|
-
- Run `bundle exec rubocop` (scoped to changed files is fine during
|
|
69
|
-
iteration) before considering a change formatted correctly.
|
|
35
|
+
- Match the project's `.rubocop.yml`; do not hand-format around it.
|
|
36
|
+
- Run `bundle exec rubocop` (scoped to changed files is fine) before treating a change as formatted.
|
|
@@ -7,87 +7,38 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Ruby on Rails patterns
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
Rails application design and its common anti-patterns. Applies to
|
|
12
|
-
`*.rb` and `*.erb` files.
|
|
10
|
+
Narrows `core-common-rules`' design guidance to idiomatic Rails design and its anti-patterns. Applies to `*.rb` and `*.erb` files.
|
|
13
11
|
|
|
14
12
|
## MVC boundaries
|
|
15
13
|
|
|
16
|
-
- A controller action
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
inline in the action body.
|
|
20
|
-
- A view renders presentation only; move any non-trivial conditional or
|
|
21
|
-
data-shaping logic in a view into a helper or a presenter/decorator
|
|
22
|
-
object instead of embedded Ruby blocks doing real work.
|
|
23
|
-
- `ApplicationRecord` models hold persistence concerns (validations,
|
|
24
|
-
associations, scopes) and behavior that genuinely belongs to the
|
|
25
|
-
record itself; a model accumulating callbacks that orchestrate
|
|
26
|
-
unrelated side effects (send an email, call a third-party API, update
|
|
27
|
-
a different model) is a "fat model" — extract that orchestration into
|
|
28
|
-
a service object or an `ActiveJob`.
|
|
14
|
+
- A controller action reads params, calls a model/service, and renders/redirects; no inline business logic (validation rules, multi-step workflows, external API calls).
|
|
15
|
+
- Move non-trivial conditional or data-shaping logic out of a view into a helper or presenter/decorator.
|
|
16
|
+
- A model keeps persistence concerns (validations, associations, scopes) and behavior of the record itself; extract callbacks that orchestrate unrelated side effects (email, third-party API, another model) into a service object or an `ActiveJob`.
|
|
29
17
|
|
|
30
18
|
## Concerns
|
|
31
19
|
|
|
32
|
-
- A `Concern` (`app/models/concerns`, `app/controllers/concerns`)
|
|
33
|
-
|
|
34
|
-
class — not become a dumping ground for one model's unrelated methods
|
|
35
|
-
split out just to shrink the file. If nothing else in the app is ever
|
|
36
|
-
going to `include` it, it is not a concern, it is the class's own
|
|
37
|
-
method.
|
|
38
|
-
- Name a concern for the *capability* it adds (`Archivable`,
|
|
39
|
-
`Sluggable`), not for the model it happens to have been extracted
|
|
40
|
-
from.
|
|
20
|
+
- A `Concern` (`app/models/concerns`, `app/controllers/concerns`) bundles cohesive behavior shared by more than one class; if nothing else will `include` it, it is the class's own method.
|
|
21
|
+
- Name a concern for the capability it adds (`Archivable`, `Sluggable`), not the model it was extracted from.
|
|
41
22
|
|
|
42
|
-
## Service objects
|
|
23
|
+
## Service objects
|
|
43
24
|
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
the controller, extract a plain Ruby service object (a
|
|
47
|
-
`SomethingVerb` class with one public entry point, e.g. `.call`) that
|
|
48
|
-
the controller/model delegates to — do not grow the controller action
|
|
49
|
-
or a model callback to hold it, and match the app's own existing
|
|
50
|
-
service-object convention (directory, base class, `.call` vs `#call`)
|
|
51
|
-
if one already exists rather than inventing a second style.
|
|
52
|
-
- A service object should be easy to unit test without spinning up a
|
|
53
|
-
full request — keep framework concerns (params, session, rendering)
|
|
54
|
-
out of it; pass it plain values or model instances instead.
|
|
25
|
+
- Extract a plain Ruby service object (`SomethingVerb`, one public entry point, e.g. `.call`) when logic spans multiple models, calls an external service, or needs its own tests; match the app's existing convention (directory, base class, `.call` vs `#call`).
|
|
26
|
+
- Keep framework concerns (params, session, rendering) out of a service object; pass plain values or model instances.
|
|
55
27
|
|
|
56
28
|
## ActiveRecord query patterns
|
|
57
29
|
|
|
58
|
-
- Eager-load
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
hand-choosing one of the lower-level methods unless you have a
|
|
62
|
-
specific reason to force one.
|
|
63
|
-
- Push filtering/aggregation into the database (`where`, `group`,
|
|
64
|
-
`count`, a named `scope`) rather than loading full ActiveRecord
|
|
65
|
-
objects into Ruby and filtering/reducing them in memory.
|
|
66
|
-
- A named `scope` (`scope :published, -> { where(published: true) }`)
|
|
67
|
-
for a query fragment reused in more than one place, instead of
|
|
68
|
-
copy-pasting the same `where` clause across controllers/models.
|
|
30
|
+
- Eager-load before iterating (`Book.includes(:author)`); prefer `includes` over hand-choosing `preload`/`eager_load` unless one is needed.
|
|
31
|
+
- Push filtering/aggregation into the database (`where`, `group`, `count`, a named `scope`), not Ruby-side.
|
|
32
|
+
- Use a named `scope` for a query fragment reused in more than one place.
|
|
69
33
|
|
|
70
34
|
## Background jobs
|
|
71
35
|
|
|
72
|
-
-
|
|
73
|
-
|
|
74
|
-
double-charge, double-send, or otherwise corrupt state; guard with a
|
|
75
|
-
uniqueness check, an idempotency key, or an upsert instead of assuming
|
|
76
|
-
`perform` runs exactly once.
|
|
77
|
-
- Pass simple identifiers (an id) into a job's `perform`, not a whole
|
|
78
|
-
ActiveRecord object — the record can change or be deleted between
|
|
79
|
-
enqueue and execution (GlobalID serializes it, but the job should
|
|
80
|
-
re-fetch and handle a missing record rather than trust a stale copy).
|
|
36
|
+
- Make an `ActiveJob` idempotent (queue adapters are at-least-once): guard with a uniqueness check, an idempotency key or an upsert.
|
|
37
|
+
- Pass an id into `perform`, not an ActiveRecord object; re-fetch and handle a missing record.
|
|
81
38
|
|
|
82
39
|
## Anti-patterns to flag
|
|
83
40
|
|
|
84
|
-
- A
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
- A
|
|
88
|
-
share real behavior.
|
|
89
|
-
- Raw SQL string interpolation instead of ActiveRecord's parameterized
|
|
90
|
-
query interface or `sanitize_sql` (see `rules/security.mdc`).
|
|
91
|
-
- A `default_scope` that silently changes every query against a model —
|
|
92
|
-
usually surprising at a call site far from the model definition;
|
|
93
|
-
prefer an explicit named scope callers opt into.
|
|
41
|
+
- A fat controller action with inline business logic, or a fat model whose callbacks orchestrate unrelated side effects.
|
|
42
|
+
- A concern used only to shrink one class's file.
|
|
43
|
+
- Raw SQL string interpolation instead of parameterized queries or `sanitize_sql` (see `rules/security.mdc`).
|
|
44
|
+
- A `default_scope`; prefer an explicit named scope callers opt into.
|