@cldmv/eslint-plugin-jsonv 1.0.10 → 1.0.12
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 +202 -210
- package/README.md +49 -0
- package/dist/index.d.mts +32 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +440 -115
- package/package.json +17 -5
package/LICENSE
CHANGED
|
@@ -1,210 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
205
|
-
|
|
206
|
-
Unless required by applicable law or agreed to in writing, software
|
|
207
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
208
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
209
|
-
See the License for the specific language governing permissions and
|
|
210
|
-
limitations under the License.
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -6,6 +6,22 @@
|
|
|
6
6
|
|
|
7
7
|
ESLint plugin for validating `.jsonv` files using the [@cldmv/jsonv](https://github.com/CLDMV/jsonv) parser.
|
|
8
8
|
|
|
9
|
+
## ✨ What's New
|
|
10
|
+
|
|
11
|
+
### Latest: v1.0.12 (September 2026)
|
|
12
|
+
|
|
13
|
+
- **A real ESLint AST for `.jsonv` files** — the `jsonv/jsonv` language now builds a positioned AST from `@cldmv/jsonv`'s `parseToAst()` instead of an empty `Program`. Rules can select objects, arrays, properties, literals, references and templates; reports land on the node they target instead of `1:0`; and inline `eslint-disable` / `eslint-enable` / `eslint-disable-next-line` comments now work. Requires `@cldmv/jsonv` 1.1.0 or later (#26).
|
|
14
|
+
- [View full v1.0.12 Changelog](https://github.com/CLDMV/jsonv-eslint-plugin-jsonv/blob/master/docs/changelog/v1/v1.0.12.md)
|
|
15
|
+
|
|
16
|
+
### Recent Releases
|
|
17
|
+
|
|
18
|
+
- **v1.0.11** (September 2026) — language options are validated, parse errors report at their real position, and the plugin gained a vitest suite with a CI coverage badge (#16, #17, #18, #23, #24) ([Changelog](https://github.com/CLDMV/jsonv-eslint-plugin-jsonv/blob/master/docs/changelog/v1/v1.0.11.md))
|
|
19
|
+
- **v1.0.10** (September 2026) — the README links back to the jsonv repo (#15) ([Changelog](https://github.com/CLDMV/jsonv-eslint-plugin-jsonv/blob/master/docs/changelog/v1/v1.0.10.md))
|
|
20
|
+
- **v1.0.9** (September 2026) — corrected package name, badge row and license badges (#12) ([Changelog](https://github.com/CLDMV/jsonv-eslint-plugin-jsonv/blob/master/docs/changelog/v1/v1.0.9.md))
|
|
21
|
+
- **v1.0.8** (September 2026) — Node CI matrix updated for vitest 5 (max Node 26, min Node 22.12.0) (#10) ([Changelog](https://github.com/CLDMV/jsonv-eslint-plugin-jsonv/blob/master/docs/changelog/v1/v1.0.8.md))
|
|
22
|
+
|
|
23
|
+
📚 **For complete version history, see [docs/changelog/](https://github.com/CLDMV/jsonv-eslint-plugin-jsonv/tree/master/docs/changelog/) and the [GitHub Releases](https://github.com/CLDMV/jsonv-eslint-plugin-jsonv/releases).**
|
|
24
|
+
|
|
9
25
|
## Features
|
|
10
26
|
|
|
11
27
|
- **Syntax Validation**: Validates jsonv syntax using the actual jsonv parser
|
|
@@ -75,6 +91,39 @@ The parser supports the following options:
|
|
|
75
91
|
}
|
|
76
92
|
```
|
|
77
93
|
|
|
94
|
+
### Inline Configuration
|
|
95
|
+
|
|
96
|
+
The usual ESLint comments work inside `.jsonv` files: `// eslint-disable`, `/* eslint-disable <rule> */`, `/* eslint-enable */`, `// eslint-disable-line`, `// eslint-disable-next-line`, and `/* eslint <rule>: "off" */` rule configuration.
|
|
97
|
+
|
|
98
|
+
### Writing Rules
|
|
99
|
+
|
|
100
|
+
The `jsonv/jsonv` language exposes the document as an AST built from `@cldmv/jsonv`'s `parseToAst()`. Every node has a `loc` (1-based lines and columns) and a `range`, so reports on a node land on that node, and rules can use node types and selectors:
|
|
101
|
+
|
|
102
|
+
| Node type | Children | Notes |
|
|
103
|
+
|---|---|---|
|
|
104
|
+
| `Program` | `body` | The document; `body` is the root value. `comments` and `tokens` hang off it. |
|
|
105
|
+
| `ObjectExpression` | `properties` | `{ ... }` |
|
|
106
|
+
| `Property` | `key`, `value` | `key` is a `Literal` (quoted or numeric key) or an `Identifier` (unquoted key). |
|
|
107
|
+
| `ArrayExpression` | `elements` | `[ ... ]` |
|
|
108
|
+
| `Literal` | — | Strings, numbers, BigInt (`bigint` holds the digits), booleans, `null`, `Infinity`, `NaN`; `raw` is the source text. |
|
|
109
|
+
| `Identifier` | — | An unquoted key, or an internal reference such as `backup: port`. |
|
|
110
|
+
| `MemberExpression` | `object`, `property` | A dotted internal reference such as `server.port`. |
|
|
111
|
+
| `TemplateLiteral` | `quasis`, `expressions` | A backtick string with `${...}` interpolation (a plain backtick string is a `Literal`). |
|
|
112
|
+
| `TemplateElement` | — | A literal segment of a template. |
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
// Report every string value containing "TODO", on the string itself
|
|
116
|
+
create(context) {
|
|
117
|
+
return {
|
|
118
|
+
"Property > Literal.value"(node) {
|
|
119
|
+
if (typeof node.value === "string" && node.value.includes("TODO")) {
|
|
120
|
+
context.report({ node, message: "Unexpected TODO." });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
78
127
|
## Supported Features
|
|
79
128
|
|
|
80
129
|
### ES2011 (JSON5 Base)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview ESLint plugin for @cldmv/jsonv files
|
|
3
|
+
* @module eslint-plugin-jsonv
|
|
4
|
+
* @public
|
|
5
|
+
*
|
|
6
|
+
* @description
|
|
7
|
+
* Custom ESLint plugin for validating .jsonv files using the @cldmv/jsonv parser.
|
|
8
|
+
* Provides language definition, parser, and recommended rules for jsonv files.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Validates jsonv syntax using the actual jsonv parser
|
|
12
|
+
* - Reports parse errors with accurate source locations
|
|
13
|
+
* - Supports all ES2011-2025 features (JSON5, binary/octal literals, BigInt, numeric separators, etc.)
|
|
14
|
+
* - Detects internal reference errors (circular refs, undefined refs)
|
|
15
|
+
* - Configurable year-based feature detection
|
|
16
|
+
* - Exposes a positioned AST (objects, arrays, properties, literals, references, templates),
|
|
17
|
+
* comments and tokens, so rules can select nodes and inline `eslint-disable` comments work
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // In eslint.config.mjs
|
|
21
|
+
* import jsonv from 'eslint-plugin-jsonv';
|
|
22
|
+
*
|
|
23
|
+
* export default [
|
|
24
|
+
* {
|
|
25
|
+
* files: ["**\/*.jsonv"],
|
|
26
|
+
* plugins: { jsonv },
|
|
27
|
+
* language: "jsonv/jsonv",
|
|
28
|
+
* extends: ["jsonv/recommended"]
|
|
29
|
+
* }
|
|
30
|
+
* ];
|
|
31
|
+
*/
|
|
2
32
|
/**
|
|
3
33
|
* ESLint plugin export
|
|
4
34
|
*
|
|
@@ -6,4 +36,5 @@ export default plugin;
|
|
|
6
36
|
* @type {Object}
|
|
7
37
|
*/
|
|
8
38
|
declare const plugin: Object;
|
|
39
|
+
export default plugin;
|
|
9
40
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../index.mjs"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../index.mjs"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAigBH;;;;;GAKG;AACH,QAAA,MAAM,MAAM,EAFF,MAkBT,CAAC;eAEa,MAAM"}
|
package/dist/index.mjs
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* - Supports all ES2011-2025 features (JSON5, binary/octal literals, BigInt, numeric separators, etc.)
|
|
14
14
|
* - Detects internal reference errors (circular refs, undefined refs)
|
|
15
15
|
* - Configurable year-based feature detection
|
|
16
|
+
* - Exposes a positioned AST (objects, arrays, properties, literals, references, templates),
|
|
17
|
+
* comments and tokens, so rules can select nodes and inline `eslint-disable` comments work
|
|
16
18
|
*
|
|
17
19
|
* @example
|
|
18
20
|
* // In eslint.config.mjs
|
|
@@ -28,8 +30,369 @@
|
|
|
28
30
|
* ];
|
|
29
31
|
*/
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
import {
|
|
33
|
+
import { JsonvReferenceError, JsonvSyntaxError, parseToAst, parseWithOptions } from "@cldmv/jsonv/parser";
|
|
34
|
+
import { ConfigCommentParser, Directive, TextSourceCodeBase, VisitNodeStep } from "@eslint/plugin-kit";
|
|
35
|
+
|
|
36
|
+
import { existsSync } from "node:fs";
|
|
37
|
+
import { createRequire } from "node:module";
|
|
38
|
+
import { dirname, join } from "node:path";
|
|
39
|
+
import { fileURLToPath } from "node:url";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Reads this package's own `name` and `version` from its `package.json`.
|
|
43
|
+
*
|
|
44
|
+
* `scripts/build.mjs` copies this file verbatim into `dist/index.mjs` — one directory
|
|
45
|
+
* deeper than the source file — so `package.json` sits alongside the source copy but
|
|
46
|
+
* one level up from the built copy. Check the co-located path first and fall back to
|
|
47
|
+
* the parent directory so this resolves correctly from either location.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
* @returns {{name: string, version: string}} The package's `name` and `version`.
|
|
51
|
+
* @example
|
|
52
|
+
* const { name, version } = readPackageMeta();
|
|
53
|
+
*/
|
|
54
|
+
function readPackageMeta() {
|
|
55
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
56
|
+
const localPath = join(here, "package.json");
|
|
57
|
+
const pkgPath = existsSync(localPath) ? localPath : join(here, "..", "package.json");
|
|
58
|
+
const require = createRequire(import.meta.url);
|
|
59
|
+
const { name, version } = require(pkgPath);
|
|
60
|
+
return { name, version };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Language options `jsonvLanguage#parse` reads from `context.languageOptions` and
|
|
65
|
+
* forwards to `@cldmv/jsonv`'s `parseWithOptions`. Any other key is rejected by
|
|
66
|
+
* `validateLanguageOptions` since it would silently do nothing.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
* @type {Set<string>}
|
|
70
|
+
*/
|
|
71
|
+
const SUPPORTED_LANGUAGE_OPTIONS = new Set(["year", "strictBigInt"]);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Valid `year` language option values, matching @cldmv/jsonv's `ParseOptions["year"]`
|
|
75
|
+
* union (see `@cldmv/jsonv/parser`'s `ParseOptions` type).
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
* @type {Set<number>}
|
|
79
|
+
*/
|
|
80
|
+
const VALID_YEARS = new Set([2011, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025]);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Child keys of every node type in the AST `jsonvLanguage#parse` produces, in source order
|
|
84
|
+
* where that is defined. The node types and their shapes come from @cldmv/jsonv's own AST
|
|
85
|
+
* (`@cldmv/jsonv/parser`'s `Program`/`Expression` types); the plugin only re-positions them.
|
|
86
|
+
*
|
|
87
|
+
* - `Program` — the document; `body` is the single root value.
|
|
88
|
+
* - `ObjectExpression` — `{ ... }`, with `properties` (`Property` nodes).
|
|
89
|
+
* - `Property` — `key: value`; `key` is a `Literal` (quoted or numeric key) or an `Identifier` (unquoted key).
|
|
90
|
+
* - `ArrayExpression` — `[ ... ]`, with `elements`.
|
|
91
|
+
* - `Literal` — string, number, BigInt, boolean, null, `Infinity`, `NaN` (`raw` holds the source text).
|
|
92
|
+
* - `Identifier` — an unquoted key, or an internal reference such as `backup: port`.
|
|
93
|
+
* - `MemberExpression` — a dotted internal reference such as `server.port`.
|
|
94
|
+
* - `TemplateLiteral` / `TemplateElement` — backtick strings and their `${...}` interpolations.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
* @type {Readonly<Record<string, ReadonlyArray<string>>>}
|
|
98
|
+
*/
|
|
99
|
+
const VISITOR_KEYS = Object.freeze({
|
|
100
|
+
Program: Object.freeze(["body"]),
|
|
101
|
+
ObjectExpression: Object.freeze(["properties"]),
|
|
102
|
+
Property: Object.freeze(["key", "value"]),
|
|
103
|
+
ArrayExpression: Object.freeze(["elements"]),
|
|
104
|
+
Literal: Object.freeze([]),
|
|
105
|
+
Identifier: Object.freeze([]),
|
|
106
|
+
MemberExpression: Object.freeze(["object", "property"]),
|
|
107
|
+
TemplateLiteral: Object.freeze(["quasis", "expressions"]),
|
|
108
|
+
TemplateElement: Object.freeze([])
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Line terminators, matching how @cldmv/jsonv advances its line counter (`\r\n` as one
|
|
113
|
+
* break, plus lone `\r`, `\n`, U+2028 and U+2029), so `sourceCode.lines` and
|
|
114
|
+
* `getLocFromIndex()` agree with the node positions.
|
|
115
|
+
*
|
|
116
|
+
* @public
|
|
117
|
+
* @type {RegExp}
|
|
118
|
+
*/
|
|
119
|
+
const LINE_ENDING_PATTERN = /\r\n|[\r\n\u2028\u2029]/u;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Matches the comment bodies ESLint treats as inline configuration (same pattern as @eslint/json).
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
* @type {RegExp}
|
|
126
|
+
*/
|
|
127
|
+
const INLINE_CONFIG = /^\s*eslint(?:-enable|-disable(?:(?:-next)?-line)?)?(?:\s|$)/u;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Shared parser for `eslint-*` directive comments.
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
* @type {ConfigCommentParser}
|
|
134
|
+
*/
|
|
135
|
+
const commentParser = new ConfigCommentParser();
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Tests whether a value is a positioned @cldmv/jsonv AST node.
|
|
139
|
+
* @public
|
|
140
|
+
* @param {unknown} value - Any property value of a node.
|
|
141
|
+
* @returns {boolean} `true` for an object with a string `type` and a `loc`.
|
|
142
|
+
* @example
|
|
143
|
+
* isJsonvNode({ type: "Literal", loc: { start: {}, end: {} } }); // true
|
|
144
|
+
*/
|
|
145
|
+
function isJsonvNode(value) {
|
|
146
|
+
return value !== null && typeof value === "object" && typeof value.type === "string" && typeof value.loc === "object";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Returns the child keys to visit for a node: its entry in {@link VISITOR_KEYS}, or — for a
|
|
151
|
+
* node type @cldmv/jsonv may add later — every key holding a node or an array of nodes.
|
|
152
|
+
* @public
|
|
153
|
+
* @param {Object} node - An AST node.
|
|
154
|
+
* @returns {ReadonlyArray<string>} Child property names.
|
|
155
|
+
* @example
|
|
156
|
+
* getChildKeys({ type: "Property", key, value }); // ["key", "value"]
|
|
157
|
+
*/
|
|
158
|
+
function getChildKeys(node) {
|
|
159
|
+
return (
|
|
160
|
+
VISITOR_KEYS[node.type] ??
|
|
161
|
+
Object.keys(node).filter((key) => {
|
|
162
|
+
const value = node[key];
|
|
163
|
+
return Array.isArray(value) ? value.some(isJsonvNode) : isJsonvNode(value);
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Converts a @cldmv/jsonv `loc` (1-based lines, 0-based columns, 0-based `offset`s) into the
|
|
170
|
+
* ESLint `loc`/`range` pair for this language. The language declares `lineStart: 1` and
|
|
171
|
+
* `columnStart: 1`, so columns are shifted to 1-based; `range` comes from the offsets.
|
|
172
|
+
* @public
|
|
173
|
+
* @param {{start: {line: number, column: number, offset: number}, end: {line: number, column: number, offset: number}}} loc - A jsonv location.
|
|
174
|
+
* @returns {{loc: {start: {line: number, column: number}, end: {line: number, column: number}}, range: [number, number]}} The ESLint location and range.
|
|
175
|
+
* @example
|
|
176
|
+
* toEslintPosition({ start: { line: 1, column: 0, offset: 0 }, end: { line: 1, column: 3, offset: 3 } });
|
|
177
|
+
* // { loc: { start: { line: 1, column: 1 }, end: { line: 1, column: 4 } }, range: [0, 3] }
|
|
178
|
+
*/
|
|
179
|
+
function toEslintPosition(loc) {
|
|
180
|
+
return {
|
|
181
|
+
loc: {
|
|
182
|
+
start: { line: loc.start.line, column: loc.start.column + 1 },
|
|
183
|
+
end: { line: loc.end.line, column: loc.end.column + 1 }
|
|
184
|
+
},
|
|
185
|
+
range: [loc.start.offset, loc.end.offset]
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Copies a jsonv comment or token with ESLint positions (a 1-based `loc` and a `range`).
|
|
191
|
+
* Tokens are never walked for children: some token types share a name with a node type
|
|
192
|
+
* (`Identifier`, `TemplateLiteral`) but carry no child nodes.
|
|
193
|
+
* @public
|
|
194
|
+
* @param {Object} element - A jsonv comment or token.
|
|
195
|
+
* @returns {Object} The converted copy.
|
|
196
|
+
* @example
|
|
197
|
+
* convertLeaf(parseToAst("// note\n1").comments[0]);
|
|
198
|
+
*/
|
|
199
|
+
function convertLeaf(element) {
|
|
200
|
+
return { ...element, ...toEslintPosition(element.loc) };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Deep-copies a jsonv AST node with ESLint positions: every node gets a 1-based `loc` and a
|
|
205
|
+
* `range`, and child nodes are converted recursively.
|
|
206
|
+
* @public
|
|
207
|
+
* @param {Object} node - A jsonv AST node.
|
|
208
|
+
* @returns {Object} The converted copy.
|
|
209
|
+
* @example
|
|
210
|
+
* convertNode(parseToAst("{ a: 1 }").program.body);
|
|
211
|
+
*/
|
|
212
|
+
function convertNode(node) {
|
|
213
|
+
const converted = convertLeaf(node);
|
|
214
|
+
for (const key of getChildKeys(node)) {
|
|
215
|
+
const child = node[key];
|
|
216
|
+
converted[key] = Array.isArray(child) ? child.map(convertNode) : convertNode(child);
|
|
217
|
+
}
|
|
218
|
+
return converted;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Builds the ESLint AST for a document from @cldmv/jsonv's `parseToAst()` result: the
|
|
223
|
+
* `Program` root (whose `body` is the root value) with positioned `comments` and `tokens`.
|
|
224
|
+
* @public
|
|
225
|
+
* @param {{program: Object, comments: Object[], tokens: Object[]}} astResult - The `parseToAst()` result.
|
|
226
|
+
* @returns {Object} The `Program` node.
|
|
227
|
+
* @example
|
|
228
|
+
* buildProgram(parseToAst("// note\n{ a: 1 }"));
|
|
229
|
+
*/
|
|
230
|
+
function buildProgram({ program, comments, tokens }) {
|
|
231
|
+
return {
|
|
232
|
+
...convertNode(program),
|
|
233
|
+
comments: comments.map(convertLeaf),
|
|
234
|
+
tokens: tokens.map(convertLeaf)
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* SourceCode for a parsed `.jsonv` file, modelled on @eslint/json's `JSONSourceCode`:
|
|
240
|
+
* positions, lines and text helpers come from `TextSourceCodeBase`; this class adds AST
|
|
241
|
+
* traversal, parent lookup and inline configuration (`eslint-disable*` / `eslint-enable`
|
|
242
|
+
* directives and `/* eslint rule: ... *\/` config comments).
|
|
243
|
+
*
|
|
244
|
+
* @public
|
|
245
|
+
*/
|
|
246
|
+
class JsonvSourceCode extends TextSourceCodeBase {
|
|
247
|
+
/**
|
|
248
|
+
* Cached traversal steps.
|
|
249
|
+
* @type {VisitNodeStep[]|undefined}
|
|
250
|
+
*/
|
|
251
|
+
#steps;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Parent of every non-root node.
|
|
255
|
+
* @type {WeakMap<Object, Object>}
|
|
256
|
+
*/
|
|
257
|
+
#parents = new WeakMap();
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Cached inline configuration comments.
|
|
261
|
+
* @type {Object[]|undefined}
|
|
262
|
+
*/
|
|
263
|
+
#inlineConfigComments;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Creates a SourceCode object.
|
|
267
|
+
* @param {Object} options - Options.
|
|
268
|
+
* @param {string} options.text - The source text.
|
|
269
|
+
* @param {Object} options.ast - The `Program` node built by `jsonvLanguage#parse`.
|
|
270
|
+
*/
|
|
271
|
+
constructor({ text, ast }) {
|
|
272
|
+
super({ text, ast, lineEndingPattern: LINE_ENDING_PATTERN });
|
|
273
|
+
/** @type {Object[]} Comments in source order. */
|
|
274
|
+
this.comments = ast.comments;
|
|
275
|
+
/** @type {Object[]} Tokens in source order, excluding comments. */
|
|
276
|
+
this.tokens = ast.tokens;
|
|
277
|
+
/** @type {boolean} Whether the text starts with a byte order mark. */
|
|
278
|
+
this.hasBOM = text.charCodeAt(0) === 0xfeff;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Returns the source text split into lines (a fresh copy of `lines`).
|
|
283
|
+
* @public
|
|
284
|
+
* @returns {string[]} The lines.
|
|
285
|
+
*/
|
|
286
|
+
getLines() {
|
|
287
|
+
return [...this.lines];
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Walks the AST once, recording enter/exit steps and each node's parent.
|
|
292
|
+
* @returns {VisitNodeStep[]} The traversal steps.
|
|
293
|
+
*/
|
|
294
|
+
#ensureTraversal() {
|
|
295
|
+
if (!this.#steps) {
|
|
296
|
+
const steps = [];
|
|
297
|
+
const visit = (node, parent) => {
|
|
298
|
+
if (parent) this.#parents.set(node, parent);
|
|
299
|
+
steps.push(new VisitNodeStep({ target: node, phase: 1, args: [node, parent] }));
|
|
300
|
+
for (const key of getChildKeys(node)) {
|
|
301
|
+
const child = node[key];
|
|
302
|
+
for (const item of Array.isArray(child) ? child : [child]) visit(item, node);
|
|
303
|
+
}
|
|
304
|
+
steps.push(new VisitNodeStep({ target: node, phase: 2, args: [node, parent] }));
|
|
305
|
+
};
|
|
306
|
+
visit(this.ast, undefined);
|
|
307
|
+
this.#steps = steps;
|
|
308
|
+
}
|
|
309
|
+
return this.#steps;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Returns the enter/exit visit steps for every node, depth first in source order.
|
|
314
|
+
* @public
|
|
315
|
+
* @returns {Iterator<VisitNodeStep>} The traversal steps.
|
|
316
|
+
*/
|
|
317
|
+
traverse() {
|
|
318
|
+
return this.#ensureTraversal().values();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Returns the parent of a node, or `undefined` for the `Program` root.
|
|
323
|
+
* @public
|
|
324
|
+
* @param {Object} node - An AST node.
|
|
325
|
+
* @returns {Object|undefined} The parent node.
|
|
326
|
+
*/
|
|
327
|
+
getParent(node) {
|
|
328
|
+
this.#ensureTraversal();
|
|
329
|
+
return this.#parents.get(node);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Returns the comments that hold inline configuration (`eslint`, `eslint-enable`,
|
|
334
|
+
* `eslint-disable`, `eslint-disable-line`, `eslint-disable-next-line`).
|
|
335
|
+
* @public
|
|
336
|
+
* @returns {Object[]} The inline configuration comments.
|
|
337
|
+
*/
|
|
338
|
+
getInlineConfigNodes() {
|
|
339
|
+
if (!this.#inlineConfigComments) {
|
|
340
|
+
this.#inlineConfigComments = this.comments.filter((comment) => INLINE_CONFIG.test(comment.value));
|
|
341
|
+
}
|
|
342
|
+
return this.#inlineConfigComments;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Returns the `eslint-disable*` / `eslint-enable` directives, plus problems for malformed
|
|
347
|
+
* ones (an `eslint-disable-line` spanning several lines).
|
|
348
|
+
* @public
|
|
349
|
+
* @returns {{problems: Object[], directives: Directive[]}} Directives and problems.
|
|
350
|
+
*/
|
|
351
|
+
getDisableDirectives() {
|
|
352
|
+
const problems = [];
|
|
353
|
+
const directives = [];
|
|
354
|
+
|
|
355
|
+
for (const comment of this.getInlineConfigNodes()) {
|
|
356
|
+
const { label, value, justification } = commentParser.parseDirective(comment.value);
|
|
357
|
+
|
|
358
|
+
if (label === "eslint-disable-line" && comment.loc.start.line !== comment.loc.end.line) {
|
|
359
|
+
problems.push({ ruleId: null, message: `${label} comment should not span multiple lines.`, loc: comment.loc });
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (label !== "eslint") {
|
|
364
|
+
directives.push(new Directive({ type: label.slice("eslint-".length), node: comment, value, justification }));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return { problems, directives };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Returns the rule configurations from `/* eslint rule: ... *\/` comments, plus problems for
|
|
373
|
+
* ones that fail to parse.
|
|
374
|
+
* @public
|
|
375
|
+
* @returns {{problems: Object[], configs: Array<{config: {rules: Object}, loc: Object}>}} Configs and problems.
|
|
376
|
+
*/
|
|
377
|
+
applyInlineConfig() {
|
|
378
|
+
const problems = [];
|
|
379
|
+
const configs = [];
|
|
380
|
+
|
|
381
|
+
for (const comment of this.getInlineConfigNodes()) {
|
|
382
|
+
const { label, value } = commentParser.parseDirective(comment.value);
|
|
383
|
+
if (label !== "eslint") continue;
|
|
384
|
+
|
|
385
|
+
const parseResult = commentParser.parseJSONLikeConfig(value);
|
|
386
|
+
if (parseResult.ok) {
|
|
387
|
+
configs.push({ config: { rules: parseResult.config }, loc: comment.loc });
|
|
388
|
+
} else {
|
|
389
|
+
problems.push({ ruleId: null, message: parseResult.error.message, loc: comment.loc });
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return { problems, configs };
|
|
394
|
+
}
|
|
395
|
+
}
|
|
33
396
|
|
|
34
397
|
/**
|
|
35
398
|
* Language definition for jsonv files
|
|
@@ -42,13 +405,21 @@ const jsonvLanguage = {
|
|
|
42
405
|
fileType: "text",
|
|
43
406
|
/** Line numbering starts at 1 */
|
|
44
407
|
lineStart: 1,
|
|
45
|
-
/** Column numbering starts at 1 */
|
|
408
|
+
/** Column numbering starts at 1 (node `loc` columns are 1-based) */
|
|
46
409
|
columnStart: 1,
|
|
47
410
|
/** Property name for node types */
|
|
48
411
|
nodeTypeKey: "type",
|
|
412
|
+
/** Child keys of each AST node type, used for selector matching */
|
|
413
|
+
visitorKeys: VISITOR_KEYS,
|
|
49
414
|
|
|
50
415
|
/**
|
|
51
|
-
* Parse jsonv source code - ESLint
|
|
416
|
+
* Parse jsonv source code - ESLint Language API.
|
|
417
|
+
*
|
|
418
|
+
* The file is first parsed and evaluated with `parseWithOptions` — that is what reports
|
|
419
|
+
* syntax errors, year-gated features, `strictBigInt` violations and unresolved/circular
|
|
420
|
+
* internal references, each with its source position. A file that passes is then parsed
|
|
421
|
+
* with `parseToAst` to build the positioned AST, comments and tokens ESLint traverses.
|
|
422
|
+
*
|
|
52
423
|
* @param {Object} file - File object with body property containing source text
|
|
53
424
|
* @param {Object} context - Context with languageOptions
|
|
54
425
|
* @returns {Object} Parse result {ok, ast, jsonvValue} or {ok: false, errors}
|
|
@@ -56,157 +427,114 @@ const jsonvLanguage = {
|
|
|
56
427
|
parse(file, context) {
|
|
57
428
|
const text = file.body;
|
|
58
429
|
const options = context.languageOptions || {};
|
|
430
|
+
const parseOptions = {
|
|
431
|
+
year: options.year || 2025,
|
|
432
|
+
strictBigInt: options.strictBigInt !== undefined ? options.strictBigInt : false,
|
|
433
|
+
mode: "jsonv"
|
|
434
|
+
};
|
|
59
435
|
|
|
60
436
|
try {
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
strictBigInt: options.strictBigInt !== undefined ? options.strictBigInt : false,
|
|
65
|
-
mode: "jsonv",
|
|
66
|
-
preserveComments: true,
|
|
67
|
-
tolerant: false
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// Return parse result with minimal ESTree-compatible AST
|
|
437
|
+
const jsonvValue = parseWithOptions(text, { ...parseOptions, tolerant: false });
|
|
438
|
+
const ast = buildProgram(parseToAst(text, parseOptions));
|
|
439
|
+
|
|
71
440
|
return {
|
|
72
441
|
ok: true,
|
|
73
|
-
ast
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
sourceType: "module",
|
|
77
|
-
comments: [],
|
|
78
|
-
tokens: []
|
|
79
|
-
},
|
|
80
|
-
// Store the parsed jsonv value for potential use by rules
|
|
81
|
-
jsonvValue: result
|
|
442
|
+
ast,
|
|
443
|
+
// The evaluated document (references resolved) for callers of parse()
|
|
444
|
+
jsonvValue
|
|
82
445
|
};
|
|
83
446
|
} catch (error) {
|
|
84
|
-
//
|
|
447
|
+
// @cldmv/jsonv (>=1.1.0) throws a `JsonvSyntaxError` (or its `LexerError` subclass) for
|
|
448
|
+
// every parser-level and lexer-level failure, and a `JsonvReferenceError` for an
|
|
449
|
+
// unresolved or circular internal reference; both carry the real `line`/`column`/`loc`.
|
|
450
|
+
// Their `column` is 0-based (matching the column embedded in jsonv's messages), while
|
|
451
|
+
// this language's `columnStart: 1` means ESLint expects 1-based columns, hence `+ 1`.
|
|
452
|
+
//
|
|
453
|
+
// Anything else (e.g. a RangeError from exhausting the call stack on pathologically deep
|
|
454
|
+
// nesting) has no position — fall back to line 1, column 1.
|
|
455
|
+
const hasPosition = error instanceof JsonvSyntaxError || error instanceof JsonvReferenceError;
|
|
456
|
+
|
|
457
|
+
const errorInfo = hasPosition
|
|
458
|
+
? { message: error.message, line: error.line, column: error.column + 1, endLine: error.loc.end.line, endColumn: error.loc.end.column + 1 }
|
|
459
|
+
: { message: error.message, line: 1, column: 1 };
|
|
460
|
+
|
|
85
461
|
return {
|
|
86
462
|
ok: false,
|
|
87
|
-
errors: [
|
|
88
|
-
{
|
|
89
|
-
message: error.message,
|
|
90
|
-
line: error.line || 1,
|
|
91
|
-
column: error.column || 1
|
|
92
|
-
}
|
|
93
|
-
]
|
|
463
|
+
errors: [errorInfo]
|
|
94
464
|
};
|
|
95
465
|
}
|
|
96
466
|
},
|
|
97
467
|
|
|
98
468
|
/**
|
|
99
|
-
* Create
|
|
100
|
-
* Required by ESLint 9 language API
|
|
469
|
+
* Create the SourceCode object ESLint hands to rules
|
|
101
470
|
*
|
|
102
471
|
* @public
|
|
103
472
|
* @param {Object} file - The file object
|
|
104
|
-
* @param {Object} parseResult - The result from parse()
|
|
105
|
-
* @
|
|
106
|
-
* @returns {Object} SourceCode object
|
|
473
|
+
* @param {Object} parseResult - The successful result from parse()
|
|
474
|
+
* @returns {JsonvSourceCode} SourceCode object
|
|
107
475
|
*/
|
|
108
|
-
createSourceCode(file, parseResult
|
|
476
|
+
createSourceCode(file, parseResult) {
|
|
109
477
|
const text = typeof file.body === "string" ? file.body : String(file.body || "");
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
text,
|
|
114
|
-
ast,
|
|
115
|
-
lines: text.split(/\r\n|[\r\n\u2028\u2029]/g),
|
|
116
|
-
hasBOM: text.charCodeAt(0) === 0xfeff,
|
|
117
|
-
|
|
118
|
-
// Required methods
|
|
119
|
-
getLoc(node) {
|
|
120
|
-
return node.loc || { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } };
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
getRange(node) {
|
|
124
|
-
return node.range || [0, 0];
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
traverse() {
|
|
128
|
-
// ESLint expects: { kind: 1 (VISIT), target: node, phase: 1|2, args: [] }
|
|
129
|
-
// kind: 1 = STEP_KIND_VISIT
|
|
130
|
-
// phase: 1 = enter, 2 = exit
|
|
131
|
-
return [
|
|
132
|
-
{
|
|
133
|
-
kind: 1,
|
|
134
|
-
target: ast,
|
|
135
|
-
phase: 1,
|
|
136
|
-
args: [ast]
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
kind: 1,
|
|
140
|
-
target: ast,
|
|
141
|
-
phase: 2,
|
|
142
|
-
args: [ast]
|
|
143
|
-
}
|
|
144
|
-
].values();
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
// Optional helper methods
|
|
148
|
-
getText(node, beforeCount, afterCount) {
|
|
149
|
-
if (node && node.range) {
|
|
150
|
-
const [start, end] = node.range;
|
|
151
|
-
return text.slice(Math.max(0, start - (beforeCount || 0)), Math.min(text.length, end + (afterCount || 0)));
|
|
152
|
-
}
|
|
153
|
-
return text;
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
getLines() {
|
|
157
|
-
return text.split(/\r\n|[\r\n\u2028\u2029]/g);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
478
|
+
return new JsonvSourceCode({ text, ast: parseResult.ast });
|
|
160
479
|
},
|
|
161
480
|
|
|
162
481
|
/**
|
|
163
482
|
* Validate language options
|
|
164
|
-
* Required by ESLint 9 language API
|
|
483
|
+
* Required by ESLint 9 language API. ESLint calls this with the languageOptions
|
|
484
|
+
* already merged with `defaultLanguageOptions` below, so `languageOptions` here
|
|
485
|
+
* reflects the effective options that will reach `parse()`.
|
|
165
486
|
*
|
|
166
487
|
* @public
|
|
167
|
-
* @param {Object} languageOptions - The language options to validate
|
|
488
|
+
* @param {Object} languageOptions - The (already-merged) language options to validate
|
|
168
489
|
* @returns {void}
|
|
490
|
+
* @throws {TypeError} When an unsupported key is present, or a supported key holds an invalid value
|
|
169
491
|
*/
|
|
170
|
-
validateLanguageOptions(
|
|
171
|
-
|
|
172
|
-
// year, strictBigInt, mode, preserveComments, tolerant
|
|
173
|
-
},
|
|
492
|
+
validateLanguageOptions(languageOptions) {
|
|
493
|
+
const options = languageOptions ?? {};
|
|
174
494
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
495
|
+
for (const key of Object.keys(options)) {
|
|
496
|
+
if (!SUPPORTED_LANGUAGE_OPTIONS.has(key)) {
|
|
497
|
+
throw new TypeError(`Unknown language option "${key}". Supported options are: ${[...SUPPORTED_LANGUAGE_OPTIONS].join(", ")}.`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (options.year !== undefined && !VALID_YEARS.has(options.year)) {
|
|
502
|
+
throw new TypeError(
|
|
503
|
+
`Invalid "year" language option: ${JSON.stringify(options.year)}. Supported years are: ${[...VALID_YEARS].join(", ")}.`
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (options.strictBigInt !== undefined && typeof options.strictBigInt !== "boolean") {
|
|
508
|
+
throw new TypeError(`Invalid "strictBigInt" language option: expected a boolean, got ${typeof options.strictBigInt}.`);
|
|
509
|
+
}
|
|
186
510
|
},
|
|
187
511
|
|
|
188
|
-
/**
|
|
512
|
+
/**
|
|
513
|
+
* Default language options
|
|
514
|
+
* Required by ESLint 9 language API to supply defaults when a config specifies
|
|
515
|
+
* none — ESLint deep-merges this with the config's `languageOptions` before
|
|
516
|
+
* calling `validateLanguageOptions` and `parse()`.
|
|
189
517
|
*
|
|
190
518
|
* @public
|
|
191
519
|
* @type {Object}
|
|
192
520
|
*/
|
|
193
|
-
|
|
521
|
+
defaultLanguageOptions: {
|
|
194
522
|
year: 2025,
|
|
195
|
-
strictBigInt: false
|
|
196
|
-
mode: "jsonv"
|
|
523
|
+
strictBigInt: false
|
|
197
524
|
}
|
|
198
525
|
};
|
|
199
526
|
|
|
200
527
|
/**
|
|
201
528
|
* Recommended configuration for jsonv files
|
|
202
529
|
*
|
|
530
|
+
* `languageOptions.parser` is intentionally omitted: that field is only read by
|
|
531
|
+
* ESLint's built-in "js" language (for its legacy custom-parser support) — a custom
|
|
532
|
+
* `language` such as `jsonv/jsonv` never consults it, so setting it here was inert.
|
|
533
|
+
*
|
|
203
534
|
* @public
|
|
204
535
|
* @type {Object}
|
|
205
536
|
*/
|
|
206
537
|
const recommendedConfig = {
|
|
207
|
-
languageOptions: {
|
|
208
|
-
parser: jsonvLanguage
|
|
209
|
-
},
|
|
210
538
|
rules: {
|
|
211
539
|
// Add custom jsonv rules here in the future
|
|
212
540
|
// For now, parsing validation is enough
|
|
@@ -220,10 +548,7 @@ const recommendedConfig = {
|
|
|
220
548
|
* @type {Object}
|
|
221
549
|
*/
|
|
222
550
|
const plugin = {
|
|
223
|
-
meta:
|
|
224
|
-
name: "eslint-plugin-jsonv",
|
|
225
|
-
version: "0.1.0"
|
|
226
|
-
},
|
|
551
|
+
meta: readPackageMeta(),
|
|
227
552
|
languages: {
|
|
228
553
|
jsonv: jsonvLanguage
|
|
229
554
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/eslint-plugin-jsonv",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "ESLint plugin for @cldmv/jsonv files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -13,8 +13,13 @@
|
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "npm run build:js && npm run build:types",
|
|
16
|
+
"build:ci": "npm run lint --if-present && npm run format:check --if-present && npm run build",
|
|
16
17
|
"build:js": "node scripts/build.mjs",
|
|
17
|
-
"build:types": "tsc -p .configs/tsconfig.types.json"
|
|
18
|
+
"build:types": "tsc -p .configs/tsconfig.types.json",
|
|
19
|
+
"test": "node tests/run-vitest.mjs",
|
|
20
|
+
"test:watch": "vitest --config .configs/vitest.config.mjs",
|
|
21
|
+
"coverage": "node tests/run-vitest.mjs --coverage-quiet",
|
|
22
|
+
"ci:coverage": "npm run coverage"
|
|
18
23
|
},
|
|
19
24
|
"publishConfig": {
|
|
20
25
|
"access": "public"
|
|
@@ -24,11 +29,15 @@
|
|
|
24
29
|
"README.md"
|
|
25
30
|
],
|
|
26
31
|
"peerDependencies": {
|
|
27
|
-
"@cldmv/jsonv": "^1.0
|
|
32
|
+
"@cldmv/jsonv": "^1.1.0"
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
30
|
-
"@cldmv/jsonv": "^1.0
|
|
31
|
-
"
|
|
35
|
+
"@cldmv/jsonv": "^1.1.0",
|
|
36
|
+
"@cldmv/vitest-runner": "^1.4.3",
|
|
37
|
+
"@vitest/coverage-v8": "^5.0.2",
|
|
38
|
+
"eslint": "^10.11.0",
|
|
39
|
+
"typescript": "^7.0.2",
|
|
40
|
+
"vitest": "^5.0.2"
|
|
32
41
|
},
|
|
33
42
|
"keywords": [
|
|
34
43
|
"eslint",
|
|
@@ -72,5 +81,8 @@
|
|
|
72
81
|
"homepage": "https://github.com/CLDMV/jsonv-eslint-plugin-jsonv/#readme",
|
|
73
82
|
"engines": {
|
|
74
83
|
"node": ">=18.0.0"
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"@eslint/plugin-kit": "^0.7.3"
|
|
75
87
|
}
|
|
76
88
|
}
|