@reqvire-org/ads-guard 0.0.0 → 0.5.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ilija Ljubicic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,133 @@
1
- # @reqvire-org/ads-guard
1
+ # ADS Guard
2
2
 
3
- Placeholder that reserves the package name. It contains no code.
3
+ `@reqvire-org/ads-guard` confirms that the source of an application does no
4
+ design of its own and uses its [ADS](https://github.com/reqvire-org/ads) design
5
+ system only.
4
6
 
5
- The first real release is 0.5.0, published together with `@reqvire-org/ads`.
6
- See https://github.com/reqvire-org/ads/tree/main/packages/ads-guard
7
+ In an ADS project the design system owns all markup and all styling. An
8
+ application implements behavior: it gets data, holds state, chooses which owner
9
+ to show and handles events. The guard checks that the application's source
10
+ stays on its side of that line. It is the same check that ADS runs on a design
11
+ system's mocks.
12
+
13
+ The guard is optional. Use it when you want that line held automatically, in
14
+ particular when agents edit the application: it reports the moment design
15
+ drifts out of the design system.
16
+
17
+ ## Use
18
+
19
+ ```sh
20
+ npm install --save-dev @reqvire-org/ads-guard # or: bun add --dev @reqvire-org/ads-guard
21
+ npx ads-guard # or: bunx ads-guard
22
+ ```
23
+
24
+ It runs on Node or Bun. It does not need ADS in the application.
25
+
26
+ Where to run it:
27
+
28
+ | Stage | How |
29
+ | --- | --- |
30
+ | Lint | `"lint": "eslint . && ads-guard"` in `package.json` |
31
+ | Test | `"pretest": "ads-guard"` |
32
+ | Build | `"prebuild": "ads-guard"` |
33
+ | CI | A step `npx ads-guard`; it exits 1 on findings |
34
+ | An agent's own loop | Tell the agent to run `npx ads-guard` after it edits application code |
35
+
36
+ `ads-guard [directory] [--json]` reads `ads-guard.config.json` in the directory
37
+ (the current folder by default).
38
+
39
+ | Exit code | Meaning |
40
+ | --- | --- |
41
+ | 0 | The source uses the design system only. |
42
+ | 1 | There are findings. |
43
+ | 2 | The configuration or the arguments are wrong. |
44
+
45
+ ## Configuration
46
+
47
+ `ads-guard.config.json`, in the application's root:
48
+
49
+ ```json
50
+ {
51
+ "designSystem": "@acme/design",
52
+ "include": ["src"],
53
+ "exclude": ["src/generated"],
54
+ "allow": {
55
+ "react": ["Suspense", "StrictMode"],
56
+ "react-router": ["Outlet", "RouterProvider"],
57
+ "@tanstack/react-query": ["QueryClientProvider"]
58
+ }
59
+ }
60
+ ```
61
+
62
+ | Field | Meaning |
63
+ | --- | --- |
64
+ | `designSystem` | The specifier the application imports the design system by. The guard reads its public entry to learn which exports are patterns. |
65
+ | `entry` | Optional. The path of the design system's public entry file, when the specifier is an alias of the bundler or of TypeScript that Node cannot resolve. |
66
+ | `include` | The folders with the application's sources. Every `.tsx` and `.jsx` file under them is checked. |
67
+ | `exclude` | Optional. Folders and files under `include` that are not checked: generated or vendored code, an area being migrated. No wildcards. Every run reports them, and an entry that does not exist is an error. |
68
+ | `allow` | Optional. Components of other packages that carry no design (a router's outlet, a provider, the framework's own markers), listed one by one. `"default"` names a default export. |
69
+
70
+ Test files (`*.test.*`, `*.spec.*`, `__tests__/`) and the design system's own
71
+ files are never checked. The report counts them.
72
+
73
+ ## What it checks
74
+
75
+ | Code | Meaning | What to do |
76
+ | --- | --- | --- |
77
+ | `design-usage/local-markup` | An element or a local component that is not imported from the design system. | Render a design-system owner. An arrangement the screen needs is a pattern of the design system. |
78
+ | `design-usage/component-outside-pattern` | A component of the design system rendered outside every pattern. | A pattern arranges the screen; a component fills a pattern, as its child or in a slot prop. |
79
+ | `design-usage/design-prop` | `style`, `className`, `css` or `dangerouslySetInnerHTML`. | Choose the treatment through the owner's own props. |
80
+ | `design-usage/spread-props` | A JSX spread. | Pass each prop explicitly. |
81
+ | `design-usage/imperative-design` | A style written or DOM created by hand. | Render design-system owners with props. |
82
+ | `design-usage/hidden-definition` | A recipe, profile or custom-property reference in a string. | Design belongs in the design system. |
83
+ | `design-usage/design-import` | An ADS authoring macro. | Declare design in the design system. |
84
+
85
+ Document metadata is not design and is accepted anywhere: `<title>`, `<meta>`,
86
+ `<script>` and a `<link>` that is not a stylesheet.
87
+
88
+ JSX inside a helper function or a `map` callback is not judged for
89
+ `component-outside-pattern`, because syntax alone does not show where its
90
+ caller places it.
91
+
92
+ ## Libraries
93
+
94
+ What a library contributes decides how an application uses it.
95
+
96
+ | The library gives | Examples | Use |
97
+ | --- | --- | --- |
98
+ | Functions and hooks | Image URL builders, a router's hooks, date utilities | Freely. They are behavior. |
99
+ | Components that render nothing | `Suspense`, `Outlet`, providers | List them in `allow`. |
100
+ | Components with their own design | A styled component library, a framework's image component | Do not render them. Take the library's function and let the design system own the element. |
101
+
102
+ ### Images
103
+
104
+ Do not render a framework's image component. Ask the library for the URLs and
105
+ pass them to the design system's image owner:
106
+
107
+ ```tsx
108
+ // Next.js
109
+ import { getImageProps } from "next/image";
110
+ const { props } = getImageProps({ src: "/team.jpg", alt: "", width: 1200, height: 800, sizes: "50vw" });
111
+ <Image source={{ src: props.src, width: 1200, height: 800 }} responsive={{ srcSet: props.srcSet, sizes: props.sizes }} alt="The team" />
112
+ ```
113
+
114
+ The same shape serves Cloudinary, imgix and any service that maps a source and
115
+ a width to a URL: build the `src` and the `srcSet` with the service's function.
116
+
117
+ ### Links
118
+
119
+ The design system's pattern renders `<a href>` and reports the click. The
120
+ application navigates in the handler with its router (`router.push(href)`).
121
+
122
+ ## Library
123
+
124
+ ```ts
125
+ import { runGuard, checkDesignUsage, designSystemEntry, closeDesignUsage } from "@reqvire-org/ads-guard";
126
+
127
+ const result = await runGuard("."); // the configured run, as the command does
128
+ if (result.kind === "ok") console.log(result.value.findings);
129
+ await closeDesignUsage(); // releases the parser
130
+ ```
131
+
132
+ `checkDesignUsage(sources, entry, allowance)` checks texts you supply;
133
+ `designSystemEntry(specifier, entryFile)` reads which exports are patterns.