eslint-plugin-toml 0.1.0 → 0.3.1
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 +36 -3
- package/lib/configs/standard.d.ts +1 -1
- package/lib/configs/standard.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/rules/array-bracket-newline.js +5 -4
- package/lib/rules/array-bracket-spacing.js +5 -4
- package/lib/rules/array-element-newline.js +5 -4
- package/lib/rules/comma-style.js +5 -4
- package/lib/rules/indent.js +3 -3
- package/lib/rules/inline-table-curly-spacing.js +5 -4
- package/lib/rules/key-spacing.d.ts +2 -0
- package/lib/rules/key-spacing.js +385 -0
- package/lib/rules/keys-order.js +7 -7
- package/lib/rules/no-mixed-type-in-array.js +1 -1
- package/lib/rules/no-non-decimal-integer.js +3 -4
- package/lib/rules/no-space-dots.js +1 -1
- package/lib/rules/no-unreadable-number-separator.js +1 -1
- package/lib/rules/padding-line-between-pairs.js +2 -2
- package/lib/rules/padding-line-between-tables.js +1 -1
- package/lib/rules/precision-of-fractional-seconds.js +2 -2
- package/lib/rules/precision-of-integer.js +3 -7
- package/lib/rules/quoted-keys.js +1 -1
- package/lib/rules/space-eq-sign.js +3 -1
- package/lib/rules/spaced-comment.js +1 -1
- package/lib/rules/table-bracket-spacing.js +1 -1
- package/lib/rules/tables-order.js +14 -27
- package/lib/rules/vue-custom-block/no-parsing-error.js +1 -1
- package/lib/types.d.ts +4 -2
- package/lib/utils/casing.js +11 -11
- package/lib/utils/index.js +6 -2
- package/lib/utils/rules.js +2 -0
- package/package.json +36 -30
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../utils");
|
|
4
|
+
const ast_utils_1 = require("../utils/ast-utils");
|
|
5
|
+
function containsLineTerminator(str) {
|
|
6
|
+
return /[\n\r\u2028\u2029]/u.test(str);
|
|
7
|
+
}
|
|
8
|
+
function last(arr) {
|
|
9
|
+
return arr[arr.length - 1];
|
|
10
|
+
}
|
|
11
|
+
function isSingleLine(node) {
|
|
12
|
+
return node.loc.end.line === node.loc.start.line;
|
|
13
|
+
}
|
|
14
|
+
function isSingleLineProperties(properties) {
|
|
15
|
+
const [firstProp] = properties;
|
|
16
|
+
const lastProp = last(properties);
|
|
17
|
+
return firstProp.loc.start.line === lastProp.loc.end.line;
|
|
18
|
+
}
|
|
19
|
+
function initOptionProperty(fromOptions) {
|
|
20
|
+
const mode = fromOptions.mode || "strict";
|
|
21
|
+
let beforeEqual, afterEqual;
|
|
22
|
+
if (typeof fromOptions.beforeEqual !== "undefined") {
|
|
23
|
+
beforeEqual = fromOptions.beforeEqual;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
beforeEqual = true;
|
|
27
|
+
}
|
|
28
|
+
if (typeof fromOptions.afterEqual !== "undefined") {
|
|
29
|
+
afterEqual = fromOptions.afterEqual;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
afterEqual = true;
|
|
33
|
+
}
|
|
34
|
+
let align = undefined;
|
|
35
|
+
if (typeof fromOptions.align !== "undefined") {
|
|
36
|
+
if (typeof fromOptions.align === "object") {
|
|
37
|
+
align = fromOptions.align;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
align = {
|
|
41
|
+
on: fromOptions.align,
|
|
42
|
+
mode,
|
|
43
|
+
beforeEqual,
|
|
44
|
+
afterEqual,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
mode,
|
|
50
|
+
beforeEqual,
|
|
51
|
+
afterEqual,
|
|
52
|
+
align,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function initOptions(fromOptions) {
|
|
56
|
+
let align, multiLine, singleLine;
|
|
57
|
+
if (typeof fromOptions.align === "object") {
|
|
58
|
+
align = Object.assign(Object.assign({}, initOptionProperty(fromOptions.align)), { on: fromOptions.align.on || "equal", mode: fromOptions.align.mode || "strict" });
|
|
59
|
+
multiLine = initOptionProperty(fromOptions.multiLine || fromOptions);
|
|
60
|
+
singleLine = initOptionProperty(fromOptions.singleLine || fromOptions);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
multiLine = initOptionProperty(fromOptions.multiLine || fromOptions);
|
|
64
|
+
singleLine = initOptionProperty(fromOptions.singleLine || fromOptions);
|
|
65
|
+
if (multiLine.align) {
|
|
66
|
+
align = {
|
|
67
|
+
on: multiLine.align.on,
|
|
68
|
+
mode: multiLine.align.mode || multiLine.mode,
|
|
69
|
+
beforeEqual: multiLine.align.beforeEqual,
|
|
70
|
+
afterEqual: multiLine.align.afterEqual,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
align,
|
|
76
|
+
multiLine,
|
|
77
|
+
singleLine,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const ON_SCHEMA = {
|
|
81
|
+
enum: ["equal", "value"],
|
|
82
|
+
};
|
|
83
|
+
const OBJECT_WITHOUT_ON_SCHEMA = {
|
|
84
|
+
type: "object",
|
|
85
|
+
properties: {
|
|
86
|
+
mode: {
|
|
87
|
+
enum: ["strict", "minimum"],
|
|
88
|
+
},
|
|
89
|
+
beforeEqual: {
|
|
90
|
+
type: "boolean",
|
|
91
|
+
},
|
|
92
|
+
afterEqual: {
|
|
93
|
+
type: "boolean",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
additionalProperties: false,
|
|
97
|
+
};
|
|
98
|
+
const ALIGN_OBJECT_SCHEMA = {
|
|
99
|
+
type: "object",
|
|
100
|
+
properties: Object.assign({ on: ON_SCHEMA }, OBJECT_WITHOUT_ON_SCHEMA.properties),
|
|
101
|
+
additionalProperties: false,
|
|
102
|
+
};
|
|
103
|
+
exports.default = (0, utils_1.createRule)("key-spacing", {
|
|
104
|
+
meta: {
|
|
105
|
+
docs: {
|
|
106
|
+
description: "enforce consistent spacing between keys and values in key/value pairs",
|
|
107
|
+
categories: ["standard"],
|
|
108
|
+
extensionRule: "key-spacing",
|
|
109
|
+
},
|
|
110
|
+
fixable: "whitespace",
|
|
111
|
+
schema: [
|
|
112
|
+
{
|
|
113
|
+
anyOf: [
|
|
114
|
+
{
|
|
115
|
+
type: "object",
|
|
116
|
+
properties: Object.assign({ align: {
|
|
117
|
+
anyOf: [ON_SCHEMA, ALIGN_OBJECT_SCHEMA],
|
|
118
|
+
} }, OBJECT_WITHOUT_ON_SCHEMA.properties),
|
|
119
|
+
additionalProperties: false,
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: {
|
|
124
|
+
singleLine: OBJECT_WITHOUT_ON_SCHEMA,
|
|
125
|
+
multiLine: {
|
|
126
|
+
type: "object",
|
|
127
|
+
properties: Object.assign({ align: {
|
|
128
|
+
anyOf: [ON_SCHEMA, ALIGN_OBJECT_SCHEMA],
|
|
129
|
+
} }, OBJECT_WITHOUT_ON_SCHEMA.properties),
|
|
130
|
+
additionalProperties: false,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
additionalProperties: false,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: "object",
|
|
137
|
+
properties: {
|
|
138
|
+
singleLine: OBJECT_WITHOUT_ON_SCHEMA,
|
|
139
|
+
multiLine: OBJECT_WITHOUT_ON_SCHEMA,
|
|
140
|
+
align: ALIGN_OBJECT_SCHEMA,
|
|
141
|
+
},
|
|
142
|
+
additionalProperties: false,
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
messages: {
|
|
148
|
+
extraKey: "Extra space after key '{{key}}'.",
|
|
149
|
+
extraValue: "Extra space before value for key '{{key}}'.",
|
|
150
|
+
missingKey: "Missing space after key '{{key}}'.",
|
|
151
|
+
missingValue: "Missing space before value for key '{{key}}'.",
|
|
152
|
+
},
|
|
153
|
+
type: "layout",
|
|
154
|
+
},
|
|
155
|
+
create,
|
|
156
|
+
});
|
|
157
|
+
function create(context) {
|
|
158
|
+
if (!context.parserServices.isTOML) {
|
|
159
|
+
return {};
|
|
160
|
+
}
|
|
161
|
+
const options = context.options[0] || {};
|
|
162
|
+
const { multiLine: multiLineOptions, singleLine: singleLineOptions, align: alignmentOptions, } = initOptions(options);
|
|
163
|
+
const sourceCode = context.getSourceCode();
|
|
164
|
+
function isKeyValueProperty(property) {
|
|
165
|
+
return property.type === "TOMLKeyValue";
|
|
166
|
+
}
|
|
167
|
+
function getLastTokenBeforeEqual(node) {
|
|
168
|
+
const equalToken = sourceCode.getTokenAfter(node, ast_utils_1.isEqualSign);
|
|
169
|
+
return sourceCode.getTokenBefore(equalToken);
|
|
170
|
+
}
|
|
171
|
+
function getNextEqual(node) {
|
|
172
|
+
return sourceCode.getTokenAfter(node, ast_utils_1.isEqualSign);
|
|
173
|
+
}
|
|
174
|
+
function getKey(property) {
|
|
175
|
+
const keys = property.key.keys;
|
|
176
|
+
return keys
|
|
177
|
+
.map((key) => sourceCode.getText().slice(key.range[0], key.range[1]))
|
|
178
|
+
.join(".");
|
|
179
|
+
}
|
|
180
|
+
function report(property, side, whitespace, expected, mode) {
|
|
181
|
+
const diff = whitespace.length - expected;
|
|
182
|
+
const nextEqual = getNextEqual(property.key);
|
|
183
|
+
const tokenBeforeEqual = sourceCode.getTokenBefore(nextEqual, {
|
|
184
|
+
includeComments: true,
|
|
185
|
+
});
|
|
186
|
+
const tokenAfterEqual = sourceCode.getTokenAfter(nextEqual, {
|
|
187
|
+
includeComments: true,
|
|
188
|
+
});
|
|
189
|
+
const invalid = (mode === "strict"
|
|
190
|
+
? diff !== 0
|
|
191
|
+
:
|
|
192
|
+
diff < 0 || (diff > 0 && expected === 0)) &&
|
|
193
|
+
!(expected && containsLineTerminator(whitespace));
|
|
194
|
+
if (!invalid) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const { locStart, locEnd, missingLoc } = side === "key"
|
|
198
|
+
? {
|
|
199
|
+
locStart: tokenBeforeEqual.loc.end,
|
|
200
|
+
locEnd: nextEqual.loc.start,
|
|
201
|
+
missingLoc: tokenBeforeEqual.loc,
|
|
202
|
+
}
|
|
203
|
+
: {
|
|
204
|
+
locStart: nextEqual.loc.start,
|
|
205
|
+
locEnd: tokenAfterEqual.loc.start,
|
|
206
|
+
missingLoc: tokenAfterEqual.loc,
|
|
207
|
+
};
|
|
208
|
+
const { loc, messageId } = diff > 0
|
|
209
|
+
? {
|
|
210
|
+
loc: { start: locStart, end: locEnd },
|
|
211
|
+
messageId: side === "key" ? "extraKey" : "extraValue",
|
|
212
|
+
}
|
|
213
|
+
: {
|
|
214
|
+
loc: missingLoc,
|
|
215
|
+
messageId: side === "key" ? "missingKey" : "missingValue",
|
|
216
|
+
};
|
|
217
|
+
context.report({
|
|
218
|
+
node: property[side],
|
|
219
|
+
loc,
|
|
220
|
+
messageId,
|
|
221
|
+
data: {
|
|
222
|
+
key: getKey(property),
|
|
223
|
+
},
|
|
224
|
+
fix(fixer) {
|
|
225
|
+
if (diff > 0) {
|
|
226
|
+
if (side === "key") {
|
|
227
|
+
return fixer.removeRange([
|
|
228
|
+
tokenBeforeEqual.range[1],
|
|
229
|
+
tokenBeforeEqual.range[1] + diff,
|
|
230
|
+
]);
|
|
231
|
+
}
|
|
232
|
+
return fixer.removeRange([
|
|
233
|
+
tokenAfterEqual.range[0] - diff,
|
|
234
|
+
tokenAfterEqual.range[0],
|
|
235
|
+
]);
|
|
236
|
+
}
|
|
237
|
+
const spaces = " ".repeat(-diff);
|
|
238
|
+
if (side === "key") {
|
|
239
|
+
return fixer.insertTextAfter(tokenBeforeEqual, spaces);
|
|
240
|
+
}
|
|
241
|
+
return fixer.insertTextBefore(tokenAfterEqual, spaces);
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function getKeyWidth(pair) {
|
|
246
|
+
const startToken = sourceCode.getFirstToken(pair);
|
|
247
|
+
const endToken = getLastTokenBeforeEqual(pair.key);
|
|
248
|
+
return endToken.range[1] - startToken.range[0];
|
|
249
|
+
}
|
|
250
|
+
function getPropertyWhitespace(pair) {
|
|
251
|
+
const whitespace = /(\s*)=(\s*)/u.exec(sourceCode.getText().slice(pair.key.range[1], pair.value.range[0]));
|
|
252
|
+
if (whitespace) {
|
|
253
|
+
return {
|
|
254
|
+
beforeEqual: whitespace[1],
|
|
255
|
+
afterEqual: whitespace[2],
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
function verifySpacing(node, lineOptions) {
|
|
261
|
+
const actual = getPropertyWhitespace(node);
|
|
262
|
+
if (actual) {
|
|
263
|
+
report(node, "key", actual.beforeEqual, lineOptions.beforeEqual ? 1 : 0, lineOptions.mode);
|
|
264
|
+
report(node, "value", actual.afterEqual, lineOptions.afterEqual ? 1 : 0, lineOptions.mode);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function verifyListSpacing(properties, lineOptions) {
|
|
268
|
+
const length = properties.length;
|
|
269
|
+
for (let i = 0; i < length; i++) {
|
|
270
|
+
verifySpacing(properties[i], lineOptions);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (alignmentOptions) {
|
|
274
|
+
return defineAlignmentVisitor(alignmentOptions);
|
|
275
|
+
}
|
|
276
|
+
return defineSpacingVisitor();
|
|
277
|
+
function defineAlignmentVisitor(alignmentOptions) {
|
|
278
|
+
return {
|
|
279
|
+
"TOMLTopLevelTable, TOMLTable, TOMLInlineTable"(node) {
|
|
280
|
+
if (isSingleLine(node)) {
|
|
281
|
+
const body = node.body;
|
|
282
|
+
verifyListSpacing(body.filter(isKeyValueProperty), singleLineOptions);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
verifyAlignment(node);
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
function verifyGroupAlignment(properties) {
|
|
290
|
+
const length = properties.length;
|
|
291
|
+
const widths = properties.map(getKeyWidth);
|
|
292
|
+
const align = alignmentOptions.on;
|
|
293
|
+
let targetWidth = Math.max(...widths);
|
|
294
|
+
let beforeEqual, afterEqual, mode;
|
|
295
|
+
if (alignmentOptions && length > 1) {
|
|
296
|
+
beforeEqual = alignmentOptions.beforeEqual ? 1 : 0;
|
|
297
|
+
afterEqual = alignmentOptions.afterEqual ? 1 : 0;
|
|
298
|
+
mode = alignmentOptions.mode;
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
beforeEqual = multiLineOptions.beforeEqual ? 1 : 0;
|
|
302
|
+
afterEqual = multiLineOptions.afterEqual ? 1 : 0;
|
|
303
|
+
mode = alignmentOptions.mode;
|
|
304
|
+
}
|
|
305
|
+
targetWidth += align === "equal" ? beforeEqual : afterEqual;
|
|
306
|
+
for (let i = 0; i < length; i++) {
|
|
307
|
+
const property = properties[i];
|
|
308
|
+
const whitespace = getPropertyWhitespace(property);
|
|
309
|
+
if (whitespace) {
|
|
310
|
+
const width = widths[i];
|
|
311
|
+
if (align === "value") {
|
|
312
|
+
report(property, "key", whitespace.beforeEqual, beforeEqual, mode);
|
|
313
|
+
report(property, "value", whitespace.afterEqual, targetWidth - width, mode);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
report(property, "key", whitespace.beforeEqual, targetWidth - width, mode);
|
|
317
|
+
report(property, "value", whitespace.afterEqual, afterEqual, mode);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function continuesPropertyGroup(lastMember, candidate) {
|
|
323
|
+
const groupEndLine = lastMember.loc.start.line;
|
|
324
|
+
const candidateStartLine = candidate.loc.start.line;
|
|
325
|
+
if (candidateStartLine - groupEndLine <= 1) {
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
const leadingComments = sourceCode.getCommentsBefore(candidate);
|
|
329
|
+
if (leadingComments.length &&
|
|
330
|
+
leadingComments[0].loc.start.line - groupEndLine <= 1 &&
|
|
331
|
+
candidateStartLine - last(leadingComments).loc.end.line <= 1) {
|
|
332
|
+
for (let i = 1; i < leadingComments.length; i++) {
|
|
333
|
+
if (leadingComments[i].loc.start.line -
|
|
334
|
+
leadingComments[i - 1].loc.end.line >
|
|
335
|
+
1) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
function createGroups(node) {
|
|
344
|
+
const body = node.body;
|
|
345
|
+
const pairs = body.filter(isKeyValueProperty);
|
|
346
|
+
if (pairs.length === 1) {
|
|
347
|
+
return [pairs];
|
|
348
|
+
}
|
|
349
|
+
return pairs.reduce((groups, property) => {
|
|
350
|
+
const currentGroup = last(groups);
|
|
351
|
+
const prev = last(currentGroup);
|
|
352
|
+
if (!prev || continuesPropertyGroup(prev, property)) {
|
|
353
|
+
currentGroup.push(property);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
groups.push([property]);
|
|
357
|
+
}
|
|
358
|
+
return groups;
|
|
359
|
+
}, [[]]);
|
|
360
|
+
}
|
|
361
|
+
function verifyAlignment(node) {
|
|
362
|
+
createGroups(node).forEach((group) => {
|
|
363
|
+
const properties = group;
|
|
364
|
+
if (properties.length > 0 &&
|
|
365
|
+
isSingleLineProperties(properties)) {
|
|
366
|
+
verifyListSpacing(properties, multiLineOptions);
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
verifyGroupAlignment(properties);
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function defineSpacingVisitor() {
|
|
375
|
+
return {
|
|
376
|
+
TOMLKeyValue(node) {
|
|
377
|
+
if (!isKeyValueProperty(node))
|
|
378
|
+
return;
|
|
379
|
+
verifySpacing(node, isSingleLine(node.parent)
|
|
380
|
+
? singleLineOptions
|
|
381
|
+
: multiLineOptions);
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
}
|
package/lib/rules/keys-order.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const toml_eslint_parser_1 = require("toml-eslint-parser");
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
|
-
exports.default = utils_1.createRule("keys-order", {
|
|
9
|
+
exports.default = (0, utils_1.createRule)("keys-order", {
|
|
10
10
|
meta: {
|
|
11
11
|
docs: {
|
|
12
12
|
description: "disallow defining pair keys out-of-order",
|
|
@@ -27,7 +27,7 @@ exports.default = utils_1.createRule("keys-order", {
|
|
|
27
27
|
const sourceCode = context.getSourceCode();
|
|
28
28
|
function applyKey(tableKeys, node) {
|
|
29
29
|
var _a;
|
|
30
|
-
const keyNames = toml_eslint_parser_1.getStaticTOMLValue(node.key);
|
|
30
|
+
const keyNames = (0, toml_eslint_parser_1.getStaticTOMLValue)(node.key);
|
|
31
31
|
let before = null;
|
|
32
32
|
let keys = tableKeys;
|
|
33
33
|
while (keyNames.length) {
|
|
@@ -36,14 +36,14 @@ exports.default = utils_1.createRule("keys-order", {
|
|
|
36
36
|
if (!next) {
|
|
37
37
|
next = {
|
|
38
38
|
key,
|
|
39
|
-
|
|
39
|
+
node,
|
|
40
40
|
keys: [],
|
|
41
41
|
};
|
|
42
|
-
before = ((_a = lodash_1.default.last(keys)) === null || _a === void 0 ? void 0 : _a.
|
|
42
|
+
before = ((_a = lodash_1.default.last(keys)) === null || _a === void 0 ? void 0 : _a.node) || null;
|
|
43
43
|
keys.push(next);
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
|
-
next.
|
|
46
|
+
next.node = node;
|
|
47
47
|
}
|
|
48
48
|
keys = next.keys;
|
|
49
49
|
}
|
|
@@ -62,8 +62,8 @@ exports.default = utils_1.createRule("keys-order", {
|
|
|
62
62
|
node: body.key,
|
|
63
63
|
messageId: "outOfOrder",
|
|
64
64
|
data: {
|
|
65
|
-
target: toml_eslint_parser_1.getStaticTOMLValue(body.key).join("."),
|
|
66
|
-
before: toml_eslint_parser_1.getStaticTOMLValue(before.key).join("."),
|
|
65
|
+
target: (0, toml_eslint_parser_1.getStaticTOMLValue)(body.key).join("."),
|
|
66
|
+
before: (0, toml_eslint_parser_1.getStaticTOMLValue)(before.key).join("."),
|
|
67
67
|
},
|
|
68
68
|
fix(fixer) {
|
|
69
69
|
const startToken = sourceCode.getTokenBefore(body);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
exports.default = utils_1.createRule("no-mixed-type-in-array", {
|
|
4
|
+
exports.default = (0, utils_1.createRule)("no-mixed-type-in-array", {
|
|
5
5
|
meta: {
|
|
6
6
|
docs: {
|
|
7
7
|
description: "disallow mixed data types in array",
|
|
@@ -17,7 +17,7 @@ function toDecimalText(str, radix) {
|
|
|
17
17
|
}
|
|
18
18
|
return digits.reverse().join("");
|
|
19
19
|
}
|
|
20
|
-
exports.default = utils_1.createRule("no-non-decimal-integer", {
|
|
20
|
+
exports.default = (0, utils_1.createRule)("no-non-decimal-integer", {
|
|
21
21
|
meta: {
|
|
22
22
|
docs: {
|
|
23
23
|
description: "disallow hexadecimal, octal and binary integer",
|
|
@@ -57,20 +57,19 @@ exports.default = utils_1.createRule("no-non-decimal-integer", {
|
|
|
57
57
|
const allowHexadecimal = Boolean((_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.allowHexadecimal);
|
|
58
58
|
const allowOctal = Boolean((_b = context.options[0]) === null || _b === void 0 ? void 0 : _b.allowOctal);
|
|
59
59
|
const allowBinary = Boolean((_c = context.options[0]) === null || _c === void 0 ? void 0 : _c.allowBinary);
|
|
60
|
-
const sourceCode = context.getSourceCode();
|
|
61
60
|
function buildFixer(node, text, mark) {
|
|
62
61
|
if (allowHexadecimal || allowOctal || allowBinary) {
|
|
63
62
|
return undefined;
|
|
64
63
|
}
|
|
65
64
|
return (fixer) => {
|
|
66
65
|
const d = mark === "x" ? 16 : mark === "o" ? 8 : 2;
|
|
67
|
-
const code = text.slice(2)
|
|
66
|
+
const code = text.slice(2);
|
|
68
67
|
const decimalText = toDecimalText(code, d);
|
|
69
68
|
return fixer.replaceText(node, decimalText);
|
|
70
69
|
};
|
|
71
70
|
}
|
|
72
71
|
function verifyText(node) {
|
|
73
|
-
const text =
|
|
72
|
+
const text = node.number;
|
|
74
73
|
if (text.startsWith("0")) {
|
|
75
74
|
const maybeMark = text[1];
|
|
76
75
|
if (maybeMark === "x" && !allowHexadecimal) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
exports.default = utils_1.createRule("no-space-dots", {
|
|
4
|
+
exports.default = (0, utils_1.createRule)("no-space-dots", {
|
|
5
5
|
meta: {
|
|
6
6
|
docs: {
|
|
7
7
|
description: "disallow spacing around infix operators",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
exports.default = utils_1.createRule("no-unreadable-number-separator", {
|
|
4
|
+
exports.default = (0, utils_1.createRule)("no-unreadable-number-separator", {
|
|
5
5
|
meta: {
|
|
6
6
|
docs: {
|
|
7
7
|
description: "disallow number separators that to not enhance readability.",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const toml_eslint_parser_1 = require("toml-eslint-parser");
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
exports.default = utils_1.createRule("padding-line-between-pairs", {
|
|
5
|
+
exports.default = (0, utils_1.createRule)("padding-line-between-pairs", {
|
|
6
6
|
meta: {
|
|
7
7
|
docs: {
|
|
8
8
|
description: "require or disallow padding lines between pairs",
|
|
@@ -66,7 +66,7 @@ exports.default = utils_1.createRule("padding-line-between-pairs", {
|
|
|
66
66
|
if (body.type !== "TOMLKeyValue") {
|
|
67
67
|
continue;
|
|
68
68
|
}
|
|
69
|
-
const keys = toml_eslint_parser_1.getStaticTOMLValue(body.key);
|
|
69
|
+
const keys = (0, toml_eslint_parser_1.getStaticTOMLValue)(body.key);
|
|
70
70
|
if (prev) {
|
|
71
71
|
verifyPairs(prev.node, prev.keys, body, keys);
|
|
72
72
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
exports.default = utils_1.createRule("padding-line-between-tables", {
|
|
4
|
+
exports.default = (0, utils_1.createRule)("padding-line-between-tables", {
|
|
5
5
|
meta: {
|
|
6
6
|
docs: {
|
|
7
7
|
description: "require or disallow padding lines between tables",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
exports.default = utils_1.createRule("precision-of-fractional-seconds", {
|
|
4
|
+
exports.default = (0, utils_1.createRule)("precision-of-fractional-seconds", {
|
|
5
5
|
meta: {
|
|
6
6
|
docs: {
|
|
7
7
|
description: "disallow precision of fractional seconds greater than the specified value.",
|
|
@@ -34,7 +34,7 @@ exports.default = utils_1.createRule("precision-of-fractional-seconds", {
|
|
|
34
34
|
function verifyText(node) {
|
|
35
35
|
var _a, _b;
|
|
36
36
|
const text = node.datetime;
|
|
37
|
-
const fractional = ((_a = /^\d{4}-\d{2}-\d{2}[
|
|
37
|
+
const fractional = ((_a = /^\d{4}-\d{2}-\d{2}[ Tt]\d{2}:\d{2}:\d{2}.(\d+)/u.exec(text)) === null || _a === void 0 ? void 0 : _a[1]) || ((_b = /^\d{2}:\d{2}:\d{2}.(\d+)/u.exec(text)) === null || _b === void 0 ? void 0 : _b[1]);
|
|
38
38
|
if (!fractional) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
@@ -50,7 +50,7 @@ function getMaxValues(bit) {
|
|
|
50
50
|
}
|
|
51
51
|
return (cacheMaxValues[bit] = maxBitToMaxValues(bit));
|
|
52
52
|
}
|
|
53
|
-
exports.default = utils_1.createRule("precision-of-integer", {
|
|
53
|
+
exports.default = (0, utils_1.createRule)("precision-of-integer", {
|
|
54
54
|
meta: {
|
|
55
55
|
docs: {
|
|
56
56
|
description: "disallow precision of integer greater than the specified value.",
|
|
@@ -81,12 +81,8 @@ exports.default = utils_1.createRule("precision-of-integer", {
|
|
|
81
81
|
}
|
|
82
82
|
const maxBit = (_b = (_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.maxBit) !== null && _b !== void 0 ? _b : 64;
|
|
83
83
|
const maxValues = getMaxValues(maxBit);
|
|
84
|
-
const sourceCode = context.getSourceCode();
|
|
85
84
|
function verifyMaxValue(node, numText, max) {
|
|
86
|
-
const num = numText
|
|
87
|
-
.replace(/_/g, "")
|
|
88
|
-
.replace(/^0+/, "")
|
|
89
|
-
.toLowerCase();
|
|
85
|
+
const num = numText.replace(/^0+/, "").toLowerCase();
|
|
90
86
|
if (num.length < max.length) {
|
|
91
87
|
return;
|
|
92
88
|
}
|
|
@@ -102,7 +98,7 @@ exports.default = utils_1.createRule("precision-of-integer", {
|
|
|
102
98
|
});
|
|
103
99
|
}
|
|
104
100
|
function verifyText(node) {
|
|
105
|
-
const text =
|
|
101
|
+
const text = node.number;
|
|
106
102
|
if (text.startsWith("0")) {
|
|
107
103
|
const maybeMark = text[1];
|
|
108
104
|
if (maybeMark === "x") {
|
package/lib/rules/quoted-keys.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
exports.default = utils_1.createRule("quoted-keys", {
|
|
4
|
+
exports.default = (0, utils_1.createRule)("quoted-keys", {
|
|
5
5
|
meta: {
|
|
6
6
|
docs: {
|
|
7
7
|
description: "require or disallow quotes around keys",
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
exports.default = utils_1.createRule("space-eq-sign", {
|
|
4
|
+
exports.default = (0, utils_1.createRule)("space-eq-sign", {
|
|
5
5
|
meta: {
|
|
6
6
|
docs: {
|
|
7
7
|
description: "require spacing around equals sign",
|
|
8
8
|
categories: ["standard"],
|
|
9
9
|
extensionRule: false,
|
|
10
|
+
replacedBy: ["key-spacing"],
|
|
10
11
|
},
|
|
12
|
+
deprecated: true,
|
|
11
13
|
fixable: "whitespace",
|
|
12
14
|
schema: [],
|
|
13
15
|
messages: {
|
|
@@ -48,7 +48,7 @@ function createNeverStylePattern(markers) {
|
|
|
48
48
|
const pattern = `^(${markers.map(escapeText).join("|")})?[ \t]+`;
|
|
49
49
|
return new RegExp(pattern, "u");
|
|
50
50
|
}
|
|
51
|
-
exports.default = utils_1.createRule("spaced-comment", {
|
|
51
|
+
exports.default = (0, utils_1.createRule)("spaced-comment", {
|
|
52
52
|
meta: {
|
|
53
53
|
docs: {
|
|
54
54
|
description: "enforce consistent spacing after the `#` in a comment",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
exports.default = utils_1.createRule("table-bracket-spacing", {
|
|
4
|
+
exports.default = (0, utils_1.createRule)("table-bracket-spacing", {
|
|
5
5
|
meta: {
|
|
6
6
|
docs: {
|
|
7
7
|
description: "enforce consistent spacing inside table brackets",
|