vue-model-contract-checker 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.
- package/LICENSE.md +21 -0
- package/README.md +132 -0
- package/dist/index.cjs +71031 -0
- package/package.json +41 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Johan Rouve
|
|
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
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# vue-model-contract-checker
|
|
2
|
+
|
|
3
|
+
Statically analyze a Vue codebase to ensure **v-model contract** compliance: any component prop that is part of a v-model contract is used only via `v-model` / `v-model:prop`, and never passed as a regular prop.
|
|
4
|
+
|
|
5
|
+
Inspired by [vue-unused-components-checker](https://github.com/BerniWittmann/vue-unused-components-checker): whole-project analysis, framework-aware, simple CLI.
|
|
6
|
+
|
|
7
|
+
## Goal
|
|
8
|
+
|
|
9
|
+
- Components define a **two-way binding contract** via `defineModel()`, or `props + emits (update:*)`.
|
|
10
|
+
- Consumers must use `v-model` / `v-model:prop` for those props, not `:prop="value"`.
|
|
11
|
+
|
|
12
|
+
## Installation (monorepo)
|
|
13
|
+
|
|
14
|
+
From the monorepo root:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
yarn install # if the package was just added (may require lockfile update)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
No need to install the package separately; it’s part of the workspace.
|
|
21
|
+
|
|
22
|
+
## Usage (monorepo)
|
|
23
|
+
|
|
24
|
+
From the **monorepo root**:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Check the webapp package only (recommended)
|
|
28
|
+
yarn check-vmodel
|
|
29
|
+
|
|
30
|
+
# Check the whole repo (all packages with .vue files)
|
|
31
|
+
yarn check-vmodel:all
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
From the **checker package** (paths relative to that package):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
cd packages/vue-model-contract-checker
|
|
38
|
+
yarn build
|
|
39
|
+
yarn exec node dist/index.js ../webapp # webapp only
|
|
40
|
+
yarn exec node dist/index.js ../.. # whole repo
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
CLI options:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
yarn check-vmodel -- --output-json # JSON output
|
|
47
|
+
yarn check-vmodel -- --stats # component/violation counts
|
|
48
|
+
yarn check-vmodel -- --debug # print component graph
|
|
49
|
+
yarn check-vmodel -- --no-fail-on-error # don’t exit 1 on violations
|
|
50
|
+
yarn check-vmodel -- --show-unresolved # list each unresolved import (default: only the count)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
Optional config file at project root: `vue-model-contract-checker.config.json`
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"include": ["src/**/*.vue"],
|
|
60
|
+
"exclude": ["**/node_modules/**", "**/dist/**"],
|
|
61
|
+
"extensions": [".vue"],
|
|
62
|
+
"failOnError": true
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Alias resolution (TypeScript paths + Vite)
|
|
67
|
+
|
|
68
|
+
Import aliases are resolved so that component paths match your project:
|
|
69
|
+
|
|
70
|
+
1. **TypeScript / JavaScript** – The checker looks for `tsconfig.json` or `jsconfig.json` in the project root. If the root has no `compilerOptions.paths`, it tries each entry in `references` until one has `paths`. Path mappings and `baseUrl` are used to resolve non-relative `.vue` imports. JSONC comments are stripped before parsing.
|
|
71
|
+
|
|
72
|
+
2. **Vite** – The checker also reads `resolve.alias` from `vite.config.ts` / `vite.config.js` (or `.mjs` / `.cjs`). It parses the config file as text and supports:
|
|
73
|
+
- Object form: `alias: { '@': path.join(__dirname, 'src'), '@ds': '@dilitrust/design-system/src' }`
|
|
74
|
+
- Array form: `alias: [ { find: '@', replacement: '...' } ]`
|
|
75
|
+
- Replacement values: string literals, `path.resolve/join(__dirname, '...')`, `fileURLToPath(new URL('...', import.meta.url))`, and package-like strings (resolved from `node_modules`).
|
|
76
|
+
|
|
77
|
+
Resolution order: relative path → tsconfig paths → Vite alias. Non-relative `.vue` imports that cannot be resolved are reported as errors.
|
|
78
|
+
|
|
79
|
+
## Violation example
|
|
80
|
+
|
|
81
|
+
**Invalid** (prop is a v-model contract):
|
|
82
|
+
|
|
83
|
+
```vue
|
|
84
|
+
<MyComp :modelValue="foo" />
|
|
85
|
+
<MyComp :title="foo" />
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Valid**:
|
|
89
|
+
|
|
90
|
+
```vue
|
|
91
|
+
<MyComp v-model="foo" />
|
|
92
|
+
<MyComp v-model:title="foo" />
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
To suppress a violation for the next line, add a comment on the preceding line that contains `vue-model-contract-checker-disable-next-line` (e.g. `<!-- vue-model-contract-checker-disable-next-line -->` in templates).
|
|
96
|
+
|
|
97
|
+
## Output format
|
|
98
|
+
|
|
99
|
+
CLI:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
[vue-model-contract-checker]
|
|
103
|
+
|
|
104
|
+
src/components/Parent.vue:12:10
|
|
105
|
+
❌ MyComp → prop "title" is a v-model contract
|
|
106
|
+
Use "v-model:title" instead of ":title"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
JSON (`--output-json`): object with `violations` and `unresolvedImports` arrays. Unresolved alias imports (no tsconfig path mapping) appear in `unresolvedImports`.
|
|
110
|
+
|
|
111
|
+
## Architecture
|
|
112
|
+
|
|
113
|
+
- **File Scanner** – discovers `.vue` files (include/exclude globs).
|
|
114
|
+
- **SFC Parser** – `@vue/compiler-sfc` to extract template and script.
|
|
115
|
+
- **Model extraction** – from `defineModel()`, `defineModel('name')`, `defineEmits(['update:...'])`.
|
|
116
|
+
- **Component Registry** – path → ComponentInfo (imports, modelProps).
|
|
117
|
+
- **Template Analyzer** – `@vue/compiler-dom` to parse template; for each component usage, flag `:prop` when `prop` is in modelProps.
|
|
118
|
+
- **Reporter** – CLI and optional JSON output.
|
|
119
|
+
|
|
120
|
+
## Scope (MVP)
|
|
121
|
+
|
|
122
|
+
- **Component resolution** via relative imports and via **TypeScript paths** (tsconfig/jsconfig `paths` + `baseUrl`).
|
|
123
|
+
- Unknown components (e.g. from node_modules) are ignored.
|
|
124
|
+
|
|
125
|
+
## Optional features (future)
|
|
126
|
+
|
|
127
|
+
- `--fix`: rewrite `:prop="x"` to `v-model:prop="x"` where safe.
|
|
128
|
+
- More emit patterns (e.g. Options API `emits: ['update:modelValue']`).
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
MIT
|