@cldmv/eslint-plugin-jsonv 1.0.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 +210 -0
- package/README.md +131 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +243 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License.
|
|
67
|
+
|
|
68
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
69
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
70
|
+
royalty-free, irrevocable copyright license to reproduce, prepare
|
|
71
|
+
Derivative Works of, publicly display, publicly perform, sublicense,
|
|
72
|
+
and distribute the Work and such Derivative Works in Source or Object
|
|
73
|
+
form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License.
|
|
76
|
+
|
|
77
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
78
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
79
|
+
royalty-free, irrevocable (except as stated in this section) patent
|
|
80
|
+
license to make, have made, use, offer to sell, sell, import, and
|
|
81
|
+
otherwise transfer the Work, where such license applies only to those
|
|
82
|
+
patent claims licensable by such Contributor that are necessarily
|
|
83
|
+
infringed by their Contribution(s) alone or by combination of their
|
|
84
|
+
Contribution(s) with the Work to which such Contribution(s) was
|
|
85
|
+
submitted. If You institute patent litigation against any entity
|
|
86
|
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
87
|
+
the Work or a Contribution incorporated within the Work constitutes
|
|
88
|
+
direct or contributory patent infringement, then any patent licenses
|
|
89
|
+
granted to You under this License for that Work shall terminate as of
|
|
90
|
+
the date such litigation is filed.
|
|
91
|
+
|
|
92
|
+
4. Redistribution.
|
|
93
|
+
|
|
94
|
+
You may reproduce and distribute copies of the Work or Derivative
|
|
95
|
+
Works thereof in any medium, with or without modifications, and in
|
|
96
|
+
Source or Object form, provided that You meet the following conditions:
|
|
97
|
+
|
|
98
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
99
|
+
a copy of this License; and
|
|
100
|
+
|
|
101
|
+
(b) You must cause any modified files to carry prominent notices
|
|
102
|
+
stating that You changed the files; and
|
|
103
|
+
|
|
104
|
+
(c) You must retain, in the Source form of any Derivative Works that
|
|
105
|
+
You distribute, all copyright, patent, trademark, and attribution
|
|
106
|
+
notices from the Source form of the Work, excluding those notices
|
|
107
|
+
that do not pertain to any part of the Derivative Works; and
|
|
108
|
+
|
|
109
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
110
|
+
distribution, then any Derivative Works that You distribute must
|
|
111
|
+
include a readable copy of the attribution notices contained
|
|
112
|
+
within such NOTICE file, excluding those notices that do not
|
|
113
|
+
pertain to any part of the Derivative Works, in at least one
|
|
114
|
+
of the following places: within a NOTICE text file distributed
|
|
115
|
+
as part of the Derivative Works; within the Source form or
|
|
116
|
+
documentation, if provided along with the Derivative Works; or,
|
|
117
|
+
within a display generated by the Derivative Works, if and
|
|
118
|
+
wherever such third-party notices normally appear. The contents
|
|
119
|
+
of the NOTICE file are for informational purposes only and
|
|
120
|
+
do not modify the License. You may add Your own attribution
|
|
121
|
+
notices within Derivative Works that You distribute, alongside
|
|
122
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
123
|
+
that such additional attribution notices cannot be construed
|
|
124
|
+
as modifying the License.
|
|
125
|
+
|
|
126
|
+
You may add Your own copyright statement to Your modifications and
|
|
127
|
+
may provide additional or different license terms and conditions
|
|
128
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
129
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
130
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
131
|
+
the conditions stated in this License.
|
|
132
|
+
|
|
133
|
+
5. Submission of Contributions.
|
|
134
|
+
|
|
135
|
+
Unless You explicitly state otherwise, any Contribution intentionally
|
|
136
|
+
submitted for inclusion in the Work by You to the Licensor shall be
|
|
137
|
+
under the terms and conditions of this License, without any additional
|
|
138
|
+
terms or conditions. Notwithstanding the above, nothing herein shall
|
|
139
|
+
supersede or modify the terms of any separate license agreement you
|
|
140
|
+
may have executed with Licensor regarding such Contributions.
|
|
141
|
+
|
|
142
|
+
6. Trademarks.
|
|
143
|
+
|
|
144
|
+
This License does not grant permission to use the trade names,
|
|
145
|
+
trademarks, service marks, or product names of the Licensor, except
|
|
146
|
+
as required for describing the origin of the Work and reproducing
|
|
147
|
+
the content of the NOTICE file.
|
|
148
|
+
|
|
149
|
+
7. Disclaimer of Warranty.
|
|
150
|
+
|
|
151
|
+
Unless required by applicable law or agreed to in writing, Licensor
|
|
152
|
+
provides the Work (and each Contributor provides its Contributions)
|
|
153
|
+
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
154
|
+
either express or implied, including, without limitation, any
|
|
155
|
+
warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY,
|
|
156
|
+
or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for
|
|
157
|
+
determining the appropriateness of using or redistributing the Work
|
|
158
|
+
and assume any risks associated with Your exercise of permissions
|
|
159
|
+
under this License.
|
|
160
|
+
|
|
161
|
+
8. Limitation of Liability.
|
|
162
|
+
|
|
163
|
+
In no event and under no legal theory, whether in tort (including
|
|
164
|
+
negligence), contract, or otherwise, unless required by applicable
|
|
165
|
+
law (such as deliberate and grossly negligent acts) or agreed to in
|
|
166
|
+
writing, shall any Contributor be liable to You for damages, including
|
|
167
|
+
any direct, indirect, special, incidental, or consequential damages
|
|
168
|
+
of any character arising as a result of this License or out of the
|
|
169
|
+
use or inability to use the Work (including but not limited to damages
|
|
170
|
+
for loss of goodwill, work stoppage, computer failure or malfunction,
|
|
171
|
+
or any and all other commercial damages or losses), even if such
|
|
172
|
+
Contributor has been advised of the possibility of such damages.
|
|
173
|
+
|
|
174
|
+
9. Accepting Warranty or Additional Liability.
|
|
175
|
+
|
|
176
|
+
While redistributing the Work or Derivative Works thereof, You may choose
|
|
177
|
+
to offer, and charge a fee for, acceptance of support, warranty, indemnity,
|
|
178
|
+
or other liability obligations and/or rights consistent with this License.
|
|
179
|
+
However, in accepting such obligations, You may act only on Your own behalf
|
|
180
|
+
and on Your sole responsibility, not on behalf of any other Contributor,
|
|
181
|
+
and only if You agree to indemnify, defend, and hold each Contributor
|
|
182
|
+
harmless for any liability incurred by, or claims asserted against, such
|
|
183
|
+
Contributor by reason of your accepting any such warranty or additional
|
|
184
|
+
liability.
|
|
185
|
+
|
|
186
|
+
END OF TERMS AND CONDITIONS
|
|
187
|
+
|
|
188
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
189
|
+
|
|
190
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
191
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
|
192
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
193
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
194
|
+
recommend that a file or class name and description of purpose be included
|
|
195
|
+
on the same "printed page" as the copyright notice for easier
|
|
196
|
+
identification within third-party archives.
|
|
197
|
+
|
|
198
|
+
Copyright [yyyy] [name of copyright owner]
|
|
199
|
+
|
|
200
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
201
|
+
you may not use this file except in compliance with the License.
|
|
202
|
+
You may obtain a copy of the License at
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# eslint-plugin-jsonv
|
|
2
|
+
|
|
3
|
+
ESLint plugin for validating `.jsonv` files using the @cldmv/jsonv parser.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Syntax Validation**: Validates jsonv syntax using the actual jsonv parser
|
|
8
|
+
- **ES2011-2025 Support**: All JSON5, ES2015, ES2020, ES2021 features supported
|
|
9
|
+
- **Internal References**: Validates bare identifiers, template interpolation, nested property access
|
|
10
|
+
- **BigInt Support**: Validates BigInt literals and numeric separators
|
|
11
|
+
- **Accurate Error Reporting**: Parse errors include line/column information
|
|
12
|
+
- **Year-Based Features**: Configurable target ES year for feature detection
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install --save-dev eslint-plugin-jsonv
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Note:** This plugin requires `@cldmv/jsonv` as a peer dependency.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @cldmv/jsonv
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Building the Plugin
|
|
27
|
+
|
|
28
|
+
If you're developing the plugin:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install
|
|
32
|
+
npm run build
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This will:
|
|
36
|
+
1. Copy `index.mjs` into `dist/index.mjs`
|
|
37
|
+
2. Generate type definitions into `dist/index.d.mts`
|
|
38
|
+
3. Prepare the plugin for use
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### ESLint Flat Config (eslint.config.mjs)
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
import jsonv from 'eslint-plugin-jsonv';
|
|
46
|
+
|
|
47
|
+
export default [
|
|
48
|
+
{
|
|
49
|
+
files: ["**/*.jsonv"],
|
|
50
|
+
plugins: { jsonv },
|
|
51
|
+
language: "jsonv/jsonv",
|
|
52
|
+
extends: ["jsonv/recommended"]
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Configuration Options
|
|
58
|
+
|
|
59
|
+
The parser supports the following options:
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
{
|
|
63
|
+
files: ["**/*.jsonv"],
|
|
64
|
+
plugins: { jsonv },
|
|
65
|
+
language: "jsonv/jsonv",
|
|
66
|
+
languageOptions: {
|
|
67
|
+
year: 2025, // Target ES year (2011, 2015, 2020, 2021, 2022-2025)
|
|
68
|
+
strictBigInt: false, // Require 'n' suffix for large integers
|
|
69
|
+
mode: "jsonv" // Parse mode: "jsonv", "json5", "json"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Supported Features
|
|
75
|
+
|
|
76
|
+
### ES2011 (JSON5 Base)
|
|
77
|
+
- Single-line (`//`) and multi-line (`/* */`) comments
|
|
78
|
+
- Trailing commas in objects and arrays
|
|
79
|
+
- Unquoted object keys
|
|
80
|
+
- Single-quoted strings
|
|
81
|
+
- Hexadecimal number literals (`0xFF`)
|
|
82
|
+
- Leading/trailing decimal points (`.5`, `5.`)
|
|
83
|
+
- Explicit positive sign (`+5`)
|
|
84
|
+
- `Infinity`, `-Infinity`, `NaN`
|
|
85
|
+
- Multi-line strings with backslash continuation
|
|
86
|
+
- **Internal references via bare identifiers**: `{ port: 8080, backup: port }`
|
|
87
|
+
|
|
88
|
+
### ES2015 (ES6)
|
|
89
|
+
- Binary literals (`0b1010`)
|
|
90
|
+
- Octal literals (`0o755`, also legacy `0755`)
|
|
91
|
+
- Template literals (backtick strings)
|
|
92
|
+
- **Template interpolation for internal refs**: `` url: `http://${host}:${port}` ``
|
|
93
|
+
|
|
94
|
+
### ES2020
|
|
95
|
+
- BigInt literals (`9007199254740992n`)
|
|
96
|
+
- BigInt in hex/binary/octal formats
|
|
97
|
+
|
|
98
|
+
### ES2021
|
|
99
|
+
- Numeric separators (`1_000_000`, `0xFF_AA`, `0b1111_0000`)
|
|
100
|
+
|
|
101
|
+
## Example
|
|
102
|
+
|
|
103
|
+
**config.jsonv:**
|
|
104
|
+
```jsonv
|
|
105
|
+
{
|
|
106
|
+
// Server configuration with internal references
|
|
107
|
+
host: "localhost",
|
|
108
|
+
port: 8080,
|
|
109
|
+
|
|
110
|
+
// Template interpolation
|
|
111
|
+
url: `http://${host}:${port}`,
|
|
112
|
+
|
|
113
|
+
// ES2021 numeric separators
|
|
114
|
+
maxConnections: 1_000_000,
|
|
115
|
+
|
|
116
|
+
// ES2020 BigInt
|
|
117
|
+
userId: 9007199254740993n,
|
|
118
|
+
|
|
119
|
+
// ES2015 binary flags
|
|
120
|
+
permissions: 0b1111_0000,
|
|
121
|
+
|
|
122
|
+
// Nested reference
|
|
123
|
+
monitoring: {
|
|
124
|
+
healthCheck: url
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../index.mjs"],"names":[],"mappings":";AAuNA;;;;;GAKG;AACH,sBAFU,MAAM,CAqBd"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
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
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // In eslint.config.mjs
|
|
19
|
+
* import jsonv from 'eslint-plugin-jsonv';
|
|
20
|
+
*
|
|
21
|
+
* export default [
|
|
22
|
+
* {
|
|
23
|
+
* files: ["**\/*.jsonv"],
|
|
24
|
+
* plugins: { jsonv },
|
|
25
|
+
* language: "jsonv/jsonv",
|
|
26
|
+
* extends: ["jsonv/recommended"]
|
|
27
|
+
* }
|
|
28
|
+
* ];
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
// Use proper package import - package is copied to node_modules during build
|
|
32
|
+
import { parseWithOptions } from "@cldmv/jsonv/parser";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Language definition for jsonv files
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
* @type {Object}
|
|
39
|
+
*/
|
|
40
|
+
const jsonvLanguage = {
|
|
41
|
+
/** File type - must be "text" for text-based languages */
|
|
42
|
+
fileType: "text",
|
|
43
|
+
/** Line numbering starts at 1 */
|
|
44
|
+
lineStart: 1,
|
|
45
|
+
/** Column numbering starts at 1 */
|
|
46
|
+
columnStart: 1,
|
|
47
|
+
/** Property name for node types */
|
|
48
|
+
nodeTypeKey: "type",
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Parse jsonv source code - ESLint 9 Language API
|
|
52
|
+
* @param {Object} file - File object with body property containing source text
|
|
53
|
+
* @param {Object} context - Context with languageOptions
|
|
54
|
+
* @returns {Object} Parse result {ok, ast, jsonvValue} or {ok: false, errors}
|
|
55
|
+
*/
|
|
56
|
+
parse(file, context) {
|
|
57
|
+
const text = file.body;
|
|
58
|
+
const options = context.languageOptions || {};
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
// Parse with all features enabled (ES2025) and strict mode off by default
|
|
62
|
+
const result = parseWithOptions(text, {
|
|
63
|
+
year: options.year || 2025,
|
|
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
|
|
71
|
+
return {
|
|
72
|
+
ok: true,
|
|
73
|
+
ast: {
|
|
74
|
+
type: "Program",
|
|
75
|
+
body: [],
|
|
76
|
+
sourceType: "module",
|
|
77
|
+
comments: [],
|
|
78
|
+
tokens: []
|
|
79
|
+
},
|
|
80
|
+
// Store the parsed jsonv value for potential use by rules
|
|
81
|
+
jsonvValue: result
|
|
82
|
+
};
|
|
83
|
+
} catch (error) {
|
|
84
|
+
// Return error result
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
errors: [
|
|
88
|
+
{
|
|
89
|
+
message: error.message,
|
|
90
|
+
line: error.line || 1,
|
|
91
|
+
column: error.column || 1
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create source code object
|
|
100
|
+
* Required by ESLint 9 language API
|
|
101
|
+
*
|
|
102
|
+
* @public
|
|
103
|
+
* @param {Object} file - The file object
|
|
104
|
+
* @param {Object} parseResult - The result from parse()
|
|
105
|
+
* @param {Object} context - Context object
|
|
106
|
+
* @returns {Object} SourceCode object
|
|
107
|
+
*/
|
|
108
|
+
createSourceCode(file, parseResult, context) {
|
|
109
|
+
const text = typeof file.body === "string" ? file.body : String(file.body || "");
|
|
110
|
+
const ast = parseResult.ast;
|
|
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
|
+
};
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Validate language options
|
|
164
|
+
* Required by ESLint 9 language API
|
|
165
|
+
*
|
|
166
|
+
* @public
|
|
167
|
+
* @param {Object} languageOptions - The language options to validate
|
|
168
|
+
* @returns {void}
|
|
169
|
+
*/
|
|
170
|
+
validateLanguageOptions(___languageOptions) {
|
|
171
|
+
// No validation needed - all options are optional
|
|
172
|
+
// year, strictBigInt, mode, preserveComments, tolerant
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Validate language options
|
|
177
|
+
* Required by ESLint 9 language API
|
|
178
|
+
*
|
|
179
|
+
* @public
|
|
180
|
+
* @param {Object} languageOptions - The language options to validate
|
|
181
|
+
* @returns {void}
|
|
182
|
+
*/
|
|
183
|
+
validateLanguageOptions(___languageOptions) {
|
|
184
|
+
// No validation needed - all options are optional
|
|
185
|
+
// year, strictBigInt, mode, preserveComments, tolerant
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
/** * Default parser options
|
|
189
|
+
*
|
|
190
|
+
* @public
|
|
191
|
+
* @type {Object}
|
|
192
|
+
*/
|
|
193
|
+
defaultParserOptions: {
|
|
194
|
+
year: 2025,
|
|
195
|
+
strictBigInt: false,
|
|
196
|
+
mode: "jsonv"
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Recommended configuration for jsonv files
|
|
202
|
+
*
|
|
203
|
+
* @public
|
|
204
|
+
* @type {Object}
|
|
205
|
+
*/
|
|
206
|
+
const recommendedConfig = {
|
|
207
|
+
languageOptions: {
|
|
208
|
+
parser: jsonvLanguage
|
|
209
|
+
},
|
|
210
|
+
rules: {
|
|
211
|
+
// Add custom jsonv rules here in the future
|
|
212
|
+
// For now, parsing validation is enough
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* ESLint plugin export
|
|
218
|
+
*
|
|
219
|
+
* @public
|
|
220
|
+
* @type {Object}
|
|
221
|
+
*/
|
|
222
|
+
const plugin = {
|
|
223
|
+
meta: {
|
|
224
|
+
name: "eslint-plugin-jsonv",
|
|
225
|
+
version: "0.1.0"
|
|
226
|
+
},
|
|
227
|
+
languages: {
|
|
228
|
+
jsonv: jsonvLanguage
|
|
229
|
+
},
|
|
230
|
+
configs: {
|
|
231
|
+
recommended: recommendedConfig
|
|
232
|
+
},
|
|
233
|
+
rules: {
|
|
234
|
+
// Future: Add custom rules for jsonv-specific validations
|
|
235
|
+
// Examples:
|
|
236
|
+
// - "no-circular-references": enforce no circular internal refs
|
|
237
|
+
// - "require-bigint-suffix": enforce 'n' suffix for large integers
|
|
238
|
+
// - "prefer-template-interpolation": prefer ${} over string concat
|
|
239
|
+
// - "no-duplicate-keys": enforce unique object keys
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
export default plugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cldmv/eslint-plugin-jsonv",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "ESLint plugin for @cldmv/jsonv files",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.mts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"import": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "npm run build:js && npm run build:types",
|
|
16
|
+
"build:js": "node scripts/build.mjs",
|
|
17
|
+
"build:types": "tsc -p .configs/tsconfig.types.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist/**",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@cldmv/jsonv": "^1.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@cldmv/jsonv": "^1.0.0",
|
|
28
|
+
"typescript": "^5.9.3"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"eslint",
|
|
32
|
+
"eslintplugin",
|
|
33
|
+
"jsonv",
|
|
34
|
+
"json5",
|
|
35
|
+
"linter",
|
|
36
|
+
"validation",
|
|
37
|
+
"parser",
|
|
38
|
+
"config",
|
|
39
|
+
"es2015",
|
|
40
|
+
"es2020",
|
|
41
|
+
"es2021",
|
|
42
|
+
"bigint",
|
|
43
|
+
"numeric-separators"
|
|
44
|
+
],
|
|
45
|
+
"author": {
|
|
46
|
+
"name": "Shinrai",
|
|
47
|
+
"company": "CLDMV",
|
|
48
|
+
"email": "git+npm@cldmv.net",
|
|
49
|
+
"url": "https://cldmv.net"
|
|
50
|
+
},
|
|
51
|
+
"contributors": [
|
|
52
|
+
{
|
|
53
|
+
"name": "CLDMV",
|
|
54
|
+
"url": "https://github.com/CLDMV"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"license": "Apache-2.0",
|
|
58
|
+
"funding": {
|
|
59
|
+
"type": "github",
|
|
60
|
+
"url": "https://github.com/sponsors/shinrai"
|
|
61
|
+
},
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "https://github.com/CLDMV/jsonv-eslint-plugin-jsonv.git"
|
|
65
|
+
},
|
|
66
|
+
"bugs": {
|
|
67
|
+
"url": "https://github.com/CLDMV/jsonv-eslint-plugin-jsonv/issues"
|
|
68
|
+
},
|
|
69
|
+
"homepage": "https://github.com/CLDMV/jsonv-eslint-plugin-jsonv/#readme",
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=18.0.0"
|
|
72
|
+
}
|
|
73
|
+
}
|