nginx-lint-plugin 0.0.1 → 0.8.3
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/README.md +239 -28
- package/dist/config-builder.d.ts +10 -0
- package/dist/config-builder.js +109 -0
- package/dist/include-context.d.ts +16 -0
- package/dist/include-context.js +25 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +10 -0
- package/dist/plugin-test-runner.d.ts +66 -0
- package/dist/plugin-test-runner.js +92 -0
- package/package.json +29 -7
- package/wasm/parser/interfaces/nginx-lint-plugin-data-types.d.ts +60 -0
- package/wasm/parser/interfaces/nginx-lint-plugin-parser-types.d.ts +33 -0
- package/wasm/parser/parser.core.wasm +0 -0
- package/wasm/parser/parser.d.ts +5 -0
- package/wasm/parser/parser.js +2177 -0
- package/wit/nginx-lint-plugin.wit +281 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
package nginx-lint:plugin@3.0.0;
|
|
2
|
+
|
|
3
|
+
interface types {
|
|
4
|
+
enum severity {
|
|
5
|
+
error,
|
|
6
|
+
warning,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
record fix {
|
|
10
|
+
line: u32,
|
|
11
|
+
old-text: option<string>,
|
|
12
|
+
new-text: string,
|
|
13
|
+
delete-line: bool,
|
|
14
|
+
insert-after: bool,
|
|
15
|
+
start-offset: option<u32>,
|
|
16
|
+
end-offset: option<u32>,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
record lint-error {
|
|
20
|
+
rule: string,
|
|
21
|
+
category: string,
|
|
22
|
+
message: string,
|
|
23
|
+
severity: severity,
|
|
24
|
+
line: option<u32>,
|
|
25
|
+
column: option<u32>,
|
|
26
|
+
fixes: list<fix>,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
record plugin-spec {
|
|
30
|
+
name: string,
|
|
31
|
+
category: string,
|
|
32
|
+
description: string,
|
|
33
|
+
api-version: string,
|
|
34
|
+
severity: option<string>,
|
|
35
|
+
why: option<string>,
|
|
36
|
+
bad-example: option<string>,
|
|
37
|
+
good-example: option<string>,
|
|
38
|
+
references: option<list<string>>,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// Shared data types used by both the plugin config-api (resource-based)
|
|
43
|
+
/// and the parser output (record-based).
|
|
44
|
+
interface data-types {
|
|
45
|
+
/// Argument value type
|
|
46
|
+
enum argument-type {
|
|
47
|
+
literal,
|
|
48
|
+
quoted-string,
|
|
49
|
+
single-quoted-string,
|
|
50
|
+
variable,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// Argument data (returned as a record since it's small)
|
|
54
|
+
record argument-info {
|
|
55
|
+
value: string,
|
|
56
|
+
raw: string,
|
|
57
|
+
arg-type: argument-type,
|
|
58
|
+
line: u32,
|
|
59
|
+
column: u32,
|
|
60
|
+
start-offset: u32,
|
|
61
|
+
end-offset: u32,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// Comment data
|
|
65
|
+
record comment-info {
|
|
66
|
+
text: string,
|
|
67
|
+
line: u32,
|
|
68
|
+
column: u32,
|
|
69
|
+
leading-whitespace: string,
|
|
70
|
+
trailing-whitespace: string,
|
|
71
|
+
start-offset: u32,
|
|
72
|
+
end-offset: u32,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Blank line data
|
|
76
|
+
record blank-line-info {
|
|
77
|
+
line: u32,
|
|
78
|
+
content: string,
|
|
79
|
+
start-offset: u32,
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// All flat properties of a directive (for bulk retrieval)
|
|
83
|
+
record directive-data {
|
|
84
|
+
name: string,
|
|
85
|
+
args: list<argument-info>,
|
|
86
|
+
line: u32,
|
|
87
|
+
column: u32,
|
|
88
|
+
start-offset: u32,
|
|
89
|
+
end-offset: u32,
|
|
90
|
+
end-line: u32,
|
|
91
|
+
end-column: u32,
|
|
92
|
+
leading-whitespace: string,
|
|
93
|
+
trailing-whitespace: string,
|
|
94
|
+
space-before-terminator: string,
|
|
95
|
+
has-block: bool,
|
|
96
|
+
block-is-raw: bool,
|
|
97
|
+
/// Actual raw content for raw blocks (e.g., lua code); none if not a raw block
|
|
98
|
+
block-raw-content: option<string>,
|
|
99
|
+
/// Leading whitespace before the closing brace; none if no block
|
|
100
|
+
closing-brace-leading-whitespace: option<string>,
|
|
101
|
+
/// Trailing whitespace after the closing brace; none if no block
|
|
102
|
+
block-trailing-whitespace: option<string>,
|
|
103
|
+
/// Text of the trailing comment on the directive line; none if no comment
|
|
104
|
+
trailing-comment-text: option<string>,
|
|
105
|
+
/// End column of the name token (1-based)
|
|
106
|
+
name-end-column: u32,
|
|
107
|
+
/// End byte offset of the name token (0-based)
|
|
108
|
+
name-end-offset: u32,
|
|
109
|
+
/// Start line of the block's opening brace (1-based); none if no block
|
|
110
|
+
block-start-line: option<u32>,
|
|
111
|
+
/// Start column of the block's opening brace (1-based); none if no block
|
|
112
|
+
block-start-column: option<u32>,
|
|
113
|
+
/// Start byte offset of the block's opening brace (0-based); none if no block
|
|
114
|
+
block-start-offset: option<u32>,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface config-api {
|
|
119
|
+
use types.{fix};
|
|
120
|
+
use data-types.{argument-type, argument-info, comment-info, blank-line-info, directive-data};
|
|
121
|
+
|
|
122
|
+
/// A config item (directive, comment, or blank line)
|
|
123
|
+
variant config-item {
|
|
124
|
+
directive-item(directive),
|
|
125
|
+
comment-item(comment-info),
|
|
126
|
+
blank-line-item(blank-line-info),
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/// A directive paired with its parent block context
|
|
130
|
+
record directive-context {
|
|
131
|
+
directive: directive,
|
|
132
|
+
parent-stack: list<string>,
|
|
133
|
+
depth: u32,
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// An nginx directive (resource backed by host data)
|
|
137
|
+
resource directive {
|
|
138
|
+
/// Get all flat properties in a single call (optimized for reconstruction)
|
|
139
|
+
data: func() -> directive-data;
|
|
140
|
+
/// Get the directive name
|
|
141
|
+
name: func() -> string;
|
|
142
|
+
/// Check if the directive has the given name
|
|
143
|
+
is: func(name: string) -> bool;
|
|
144
|
+
|
|
145
|
+
/// Get the first argument value
|
|
146
|
+
first-arg: func() -> option<string>;
|
|
147
|
+
/// Check if the first argument equals the given value
|
|
148
|
+
first-arg-is: func(value: string) -> bool;
|
|
149
|
+
/// Get the argument at the given index
|
|
150
|
+
arg-at: func(index: u32) -> option<string>;
|
|
151
|
+
/// Get the last argument value
|
|
152
|
+
last-arg: func() -> option<string>;
|
|
153
|
+
/// Check if any argument equals the given value
|
|
154
|
+
has-arg: func(value: string) -> bool;
|
|
155
|
+
/// Return the number of arguments
|
|
156
|
+
arg-count: func() -> u32;
|
|
157
|
+
/// Get all arguments as records
|
|
158
|
+
args: func() -> list<argument-info>;
|
|
159
|
+
|
|
160
|
+
/// Get the start line number (1-based)
|
|
161
|
+
line: func() -> u32;
|
|
162
|
+
/// Get the start column number (1-based)
|
|
163
|
+
column: func() -> u32;
|
|
164
|
+
/// Get the start byte offset (0-based)
|
|
165
|
+
start-offset: func() -> u32;
|
|
166
|
+
/// Get the end byte offset (0-based)
|
|
167
|
+
end-offset: func() -> u32;
|
|
168
|
+
/// Get the leading whitespace before the directive
|
|
169
|
+
leading-whitespace: func() -> string;
|
|
170
|
+
/// Get the trailing whitespace after the directive
|
|
171
|
+
trailing-whitespace: func() -> string;
|
|
172
|
+
/// Get the space before the terminator (; or {)
|
|
173
|
+
space-before-terminator: func() -> string;
|
|
174
|
+
|
|
175
|
+
/// Check if the directive has a block
|
|
176
|
+
has-block: func() -> bool;
|
|
177
|
+
/// Get the items inside the directive's block
|
|
178
|
+
block-items: func() -> list<config-item>;
|
|
179
|
+
/// Check if the block contains raw content (e.g., lua blocks)
|
|
180
|
+
block-is-raw: func() -> bool;
|
|
181
|
+
|
|
182
|
+
/// Create a fix that replaces this directive with new text
|
|
183
|
+
replace-with: func(new-text: string) -> fix;
|
|
184
|
+
/// Create a fix that deletes this directive's line
|
|
185
|
+
delete-line-fix: func() -> fix;
|
|
186
|
+
/// Create a fix that inserts a new line after this directive
|
|
187
|
+
insert-after: func(new-text: string) -> fix;
|
|
188
|
+
/// Create a fix that inserts a new line before this directive
|
|
189
|
+
insert-before: func(new-text: string) -> fix;
|
|
190
|
+
/// Create a fix that inserts multiple lines after this directive
|
|
191
|
+
insert-after-many: func(lines: list<string>) -> fix;
|
|
192
|
+
/// Create a fix that inserts multiple lines before this directive
|
|
193
|
+
insert-before-many: func(lines: list<string>) -> fix;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/// The parsed nginx configuration (resource backed by host data)
|
|
197
|
+
resource config {
|
|
198
|
+
/// Iterate over all directives recursively with parent context
|
|
199
|
+
all-directives-with-context: func() -> list<directive-context>;
|
|
200
|
+
/// Iterate over all directives recursively
|
|
201
|
+
all-directives: func() -> list<directive>;
|
|
202
|
+
/// Get the top-level config items
|
|
203
|
+
items: func() -> list<config-item>;
|
|
204
|
+
|
|
205
|
+
/// Get the include context (parent block names from include directive)
|
|
206
|
+
include-context: func() -> list<string>;
|
|
207
|
+
/// Check if this config is included from within a specific context
|
|
208
|
+
is-included-from: func(context: string) -> bool;
|
|
209
|
+
/// Check if included from http context
|
|
210
|
+
is-included-from-http: func() -> bool;
|
|
211
|
+
/// Check if included from http > server context
|
|
212
|
+
is-included-from-http-server: func() -> bool;
|
|
213
|
+
/// Check if included from http > ... > location context
|
|
214
|
+
is-included-from-http-location: func() -> bool;
|
|
215
|
+
/// Check if included from stream context
|
|
216
|
+
is-included-from-stream: func() -> bool;
|
|
217
|
+
/// Get the immediate parent context
|
|
218
|
+
immediate-parent-context: func() -> option<string>;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// Record-based types for parser output (no resources, no recursion).
|
|
223
|
+
/// Uses index-based references to represent the tree structure:
|
|
224
|
+
/// all config items are stored in a flat array, with child-indices
|
|
225
|
+
/// pointing to children within that array.
|
|
226
|
+
interface parser-types {
|
|
227
|
+
use data-types.{comment-info, blank-line-info, directive-data};
|
|
228
|
+
|
|
229
|
+
/// The kind of a config item (non-recursive)
|
|
230
|
+
variant config-item-value {
|
|
231
|
+
directive-item(directive-data),
|
|
232
|
+
comment-item(comment-info),
|
|
233
|
+
blank-line-item(blank-line-info),
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/// A config item in the flat all-items array.
|
|
237
|
+
/// For directive items with blocks, child-indices contains the indices
|
|
238
|
+
/// of child items within the all-items array.
|
|
239
|
+
record config-item {
|
|
240
|
+
value: config-item-value,
|
|
241
|
+
child-indices: list<u32>,
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/// A directive paired with its parent block context
|
|
245
|
+
record directive-context {
|
|
246
|
+
data: directive-data,
|
|
247
|
+
/// Indices of block items in the all-items array
|
|
248
|
+
block-item-indices: list<u32>,
|
|
249
|
+
parent-stack: list<string>,
|
|
250
|
+
depth: u32,
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/// Complete parser output
|
|
254
|
+
record parse-output {
|
|
255
|
+
directives-with-context: list<directive-context>,
|
|
256
|
+
include-context: list<string>,
|
|
257
|
+
/// Flat array of all config items (DFS order)
|
|
258
|
+
all-items: list<config-item>,
|
|
259
|
+
/// Indices of top-level items in all-items
|
|
260
|
+
top-level-indices: list<u32>,
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
world plugin {
|
|
265
|
+
use types.{plugin-spec, lint-error};
|
|
266
|
+
use config-api.{config};
|
|
267
|
+
import config-api;
|
|
268
|
+
|
|
269
|
+
/// Return plugin metadata
|
|
270
|
+
export spec: func() -> plugin-spec;
|
|
271
|
+
|
|
272
|
+
/// Check config and return lint errors
|
|
273
|
+
export check: func(cfg: borrow<config>, path: string) -> list<lint-error>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
world parser {
|
|
277
|
+
use parser-types.{parse-output};
|
|
278
|
+
|
|
279
|
+
/// Parse nginx config source and return structured output
|
|
280
|
+
export parse-config: func(source: string, include-context: list<string>) -> result<parse-output, string>;
|
|
281
|
+
}
|