eslint-plugin-yml 1.9.0 → 1.11.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/README.md +6 -1
- package/lib/meta.d.ts +1 -1
- package/lib/meta.js +1 -1
- package/lib/rules/block-mapping-colon-indicator-newline.js +3 -2
- package/lib/rules/block-mapping-question-indicator-newline.js +3 -2
- package/lib/rules/block-mapping.js +4 -2
- package/lib/rules/block-sequence-hyphen-indicator-newline.js +3 -2
- package/lib/rules/block-sequence.js +6 -4
- package/lib/rules/file-extension.js +4 -2
- package/lib/rules/flow-mapping-curly-newline.js +3 -2
- package/lib/rules/flow-mapping-curly-spacing.js +173 -23
- package/lib/rules/flow-sequence-bracket-newline.js +3 -2
- package/lib/rules/flow-sequence-bracket-spacing.js +165 -23
- package/lib/rules/indent.js +3 -2
- package/lib/rules/key-name-casing.js +3 -1
- package/lib/rules/key-spacing.js +3 -2
- package/lib/rules/no-empty-document.js +3 -1
- package/lib/rules/no-empty-key.js +3 -1
- package/lib/rules/no-empty-mapping-value.js +3 -1
- package/lib/rules/no-empty-sequence-entry.js +3 -2
- package/lib/rules/no-irregular-whitespace.js +3 -2
- package/lib/rules/no-multiple-empty-lines.js +3 -2
- package/lib/rules/no-tab-indent.js +3 -2
- package/lib/rules/no-trailing-zeros.js +3 -1
- package/lib/rules/plain-scalar.js +4 -8
- package/lib/rules/quotes.js +3 -1
- package/lib/rules/require-string-key.js +3 -1
- package/lib/rules/sort-keys.js +4 -3
- package/lib/rules/sort-sequence-values.js +4 -3
- package/lib/rules/spaced-comment.js +3 -2
- package/lib/rules/vue-custom-block/no-parsing-error.js +5 -1
- package/lib/types.d.ts +1 -0
- package/lib/utils/ast-utils.d.ts +4 -0
- package/lib/utils/ast-utils.js +17 -1
- package/lib/utils/compat.d.ts +5 -0
- package/lib/utils/compat.js +12 -0
- package/lib/utils/index.d.ts +1 -14
- package/lib/utils/index.js +6 -62
- package/lib/utils/yaml.js +7 -6
- package/package.json +20 -17
package/README.md
CHANGED
|
@@ -161,7 +161,12 @@ Example **.vscode/settings.json**:
|
|
|
161
161
|
|
|
162
162
|
```json
|
|
163
163
|
{
|
|
164
|
-
"eslint.validate": [
|
|
164
|
+
"eslint.validate": [
|
|
165
|
+
"javascript",
|
|
166
|
+
"javascriptreact",
|
|
167
|
+
"yaml",
|
|
168
|
+
"github-actions-workflow" // for GitHub Actions workflow files
|
|
169
|
+
]
|
|
165
170
|
}
|
|
166
171
|
```
|
|
167
172
|
|
package/lib/meta.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name: "eslint-plugin-yml";
|
|
2
|
-
export declare const version: "1.
|
|
2
|
+
export declare const version: "1.11.0";
|
package/lib/meta.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
4
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
5
|
+
const compat_1 = require("../utils/compat");
|
|
5
6
|
exports.default = (0, utils_1.createRule)("block-mapping-colon-indicator-newline", {
|
|
6
7
|
meta: {
|
|
7
8
|
docs: {
|
|
@@ -23,8 +24,8 @@ exports.default = (0, utils_1.createRule)("block-mapping-colon-indicator-newline
|
|
|
23
24
|
type: "layout",
|
|
24
25
|
},
|
|
25
26
|
create(context) {
|
|
26
|
-
const sourceCode =
|
|
27
|
-
if (!
|
|
27
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
28
|
+
if (!sourceCode.parserServices.isYAML) {
|
|
28
29
|
return {};
|
|
29
30
|
}
|
|
30
31
|
const option = context.options[0] || "never";
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
4
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
5
|
+
const compat_1 = require("../utils/compat");
|
|
5
6
|
exports.default = (0, utils_1.createRule)("block-mapping-question-indicator-newline", {
|
|
6
7
|
meta: {
|
|
7
8
|
docs: {
|
|
@@ -23,8 +24,8 @@ exports.default = (0, utils_1.createRule)("block-mapping-question-indicator-newl
|
|
|
23
24
|
type: "layout",
|
|
24
25
|
},
|
|
25
26
|
create(context) {
|
|
26
|
-
const sourceCode =
|
|
27
|
-
if (!
|
|
27
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
28
|
+
if (!sourceCode.parserServices.isYAML) {
|
|
28
29
|
return {};
|
|
29
30
|
}
|
|
30
31
|
const option = context.options[0] || "never";
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
4
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
5
5
|
const yaml_1 = require("../utils/yaml");
|
|
6
|
+
const compat_1 = require("../utils/compat");
|
|
6
7
|
const OPTIONS_ENUM = ["always", "never", "ignore"];
|
|
7
8
|
function parseOptions(option) {
|
|
8
9
|
const opt = {
|
|
@@ -56,7 +57,8 @@ exports.default = (0, utils_1.createRule)("block-mapping", {
|
|
|
56
57
|
type: "layout",
|
|
57
58
|
},
|
|
58
59
|
create(context) {
|
|
59
|
-
|
|
60
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
61
|
+
if (!sourceCode.parserServices.isYAML) {
|
|
60
62
|
return {};
|
|
61
63
|
}
|
|
62
64
|
const options = parseOptions(context.options[0]);
|
|
@@ -201,7 +203,7 @@ function canFixToFlow(mappingInfo, node) {
|
|
|
201
203
|
}
|
|
202
204
|
function buildFixFlowToBlock(node, context) {
|
|
203
205
|
return function* (fixer) {
|
|
204
|
-
const sourceCode =
|
|
206
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
205
207
|
const open = sourceCode.getFirstToken(node);
|
|
206
208
|
const close = sourceCode.getLastToken(node);
|
|
207
209
|
if ((open === null || open === void 0 ? void 0 : open.value) !== "{" || (close === null || close === void 0 ? void 0 : close.value) !== "}") {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
4
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
5
|
+
const compat_1 = require("../utils/compat");
|
|
5
6
|
exports.default = (0, utils_1.createRule)("block-sequence-hyphen-indicator-newline", {
|
|
6
7
|
meta: {
|
|
7
8
|
docs: {
|
|
@@ -30,8 +31,8 @@ exports.default = (0, utils_1.createRule)("block-sequence-hyphen-indicator-newli
|
|
|
30
31
|
},
|
|
31
32
|
create(context) {
|
|
32
33
|
var _a, _b;
|
|
33
|
-
const sourceCode =
|
|
34
|
-
if (!
|
|
34
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
35
|
+
if (!sourceCode.parserServices.isYAML) {
|
|
35
36
|
return {};
|
|
36
37
|
}
|
|
37
38
|
const style = context.options[0] || "never";
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
4
|
const yaml_1 = require("../utils/yaml");
|
|
5
5
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
6
|
+
const compat_1 = require("../utils/compat");
|
|
6
7
|
const OPTIONS_ENUM = ["always", "never", "ignore"];
|
|
7
8
|
function parseOptions(option) {
|
|
8
9
|
const opt = {
|
|
@@ -56,7 +57,8 @@ exports.default = (0, utils_1.createRule)("block-sequence", {
|
|
|
56
57
|
type: "layout",
|
|
57
58
|
},
|
|
58
59
|
create(context) {
|
|
59
|
-
|
|
60
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
61
|
+
if (!sourceCode.parserServices.isYAML) {
|
|
60
62
|
return {};
|
|
61
63
|
}
|
|
62
64
|
const options = parseOptions(context.options[0]);
|
|
@@ -130,7 +132,7 @@ exports.default = (0, utils_1.createRule)("block-sequence", {
|
|
|
130
132
|
if ((0, yaml_1.isKeyNode)(node)) {
|
|
131
133
|
return;
|
|
132
134
|
}
|
|
133
|
-
const canFix = canFixToBlock(sequenceInfo, node,
|
|
135
|
+
const canFix = canFixToBlock(sequenceInfo, node, sourceCode) &&
|
|
134
136
|
!(0, yaml_1.hasTabIndent)(context);
|
|
135
137
|
context.report({
|
|
136
138
|
loc: node.loc,
|
|
@@ -213,7 +215,7 @@ function canFixToFlow(sequenceInfo, node, context) {
|
|
|
213
215
|
}
|
|
214
216
|
function buildFixFlowToBlock(node, context) {
|
|
215
217
|
return function* (fixer) {
|
|
216
|
-
const sourceCode =
|
|
218
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
217
219
|
const open = sourceCode.getFirstToken(node);
|
|
218
220
|
const close = sourceCode.getLastToken(node);
|
|
219
221
|
if ((open === null || open === void 0 ? void 0 : open.value) !== "[" || (close === null || close === void 0 ? void 0 : close.value) !== "]") {
|
|
@@ -295,7 +297,7 @@ function buildFixFlowToBlock(node, context) {
|
|
|
295
297
|
};
|
|
296
298
|
}
|
|
297
299
|
function buildFixBlockToFlow(node, context) {
|
|
298
|
-
const sourceCode =
|
|
300
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
299
301
|
return function* (fixer) {
|
|
300
302
|
const entries = node.entries.filter((e) => e != null);
|
|
301
303
|
if (entries.length !== node.entries.length) {
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
|
+
const compat_1 = require("../utils/compat");
|
|
8
9
|
exports.default = (0, utils_1.createRule)("file-extension", {
|
|
9
10
|
meta: {
|
|
10
11
|
docs: {
|
|
@@ -34,14 +35,15 @@ exports.default = (0, utils_1.createRule)("file-extension", {
|
|
|
34
35
|
},
|
|
35
36
|
create(context) {
|
|
36
37
|
var _a, _b, _c;
|
|
37
|
-
|
|
38
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
39
|
+
if (!sourceCode.parserServices.isYAML) {
|
|
38
40
|
return {};
|
|
39
41
|
}
|
|
40
42
|
const expected = ((_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.extension) || "yaml";
|
|
41
43
|
const caseSensitive = (_c = (_b = context.options[0]) === null || _b === void 0 ? void 0 : _b.caseSensitive) !== null && _c !== void 0 ? _c : true;
|
|
42
44
|
return {
|
|
43
45
|
Program(node) {
|
|
44
|
-
const filename =
|
|
46
|
+
const filename = (0, compat_1.getFilename)(context);
|
|
45
47
|
const actual = path_1.default.extname(filename);
|
|
46
48
|
if ((caseSensitive ? actual : actual.toLocaleLowerCase()) ===
|
|
47
49
|
`.${expected}`) {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
4
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
5
5
|
const yaml_1 = require("../utils/yaml");
|
|
6
|
+
const compat_1 = require("../utils/compat");
|
|
6
7
|
const OPTION_VALUE = {
|
|
7
8
|
oneOf: [
|
|
8
9
|
{
|
|
@@ -75,10 +76,10 @@ exports.default = (0, utils_1.createRule)("flow-mapping-curly-newline", {
|
|
|
75
76
|
type: "layout",
|
|
76
77
|
},
|
|
77
78
|
create(context) {
|
|
78
|
-
|
|
79
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
80
|
+
if (!sourceCode.parserServices.isYAML) {
|
|
79
81
|
return {};
|
|
80
82
|
}
|
|
81
|
-
const sourceCode = context.getSourceCode();
|
|
82
83
|
const options = normalizeOptionValue(context.options[0]);
|
|
83
84
|
function check(node) {
|
|
84
85
|
if ((0, yaml_1.isKeyNode)(node)) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
const
|
|
4
|
+
const compat_1 = require("../utils/compat");
|
|
5
|
+
const ast_utils_1 = require("../utils/ast-utils");
|
|
5
6
|
exports.default = (0, utils_1.createRule)("flow-mapping-curly-spacing", {
|
|
6
7
|
meta: {
|
|
7
8
|
docs: {
|
|
@@ -10,32 +11,181 @@ exports.default = (0, utils_1.createRule)("flow-mapping-curly-spacing", {
|
|
|
10
11
|
extensionRule: "object-curly-spacing",
|
|
11
12
|
layout: true,
|
|
12
13
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
schema:
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
type: "layout",
|
|
15
|
+
fixable: "whitespace",
|
|
16
|
+
schema: [
|
|
17
|
+
{
|
|
18
|
+
type: "string",
|
|
19
|
+
enum: ["always", "never"],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
arraysInObjects: {
|
|
25
|
+
type: "boolean",
|
|
26
|
+
},
|
|
27
|
+
objectsInObjects: {
|
|
28
|
+
type: "boolean",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
messages: {
|
|
35
|
+
requireSpaceBefore: "A space is required before '{{token}}'.",
|
|
36
|
+
requireSpaceAfter: "A space is required after '{{token}}'.",
|
|
37
|
+
unexpectedSpaceBefore: "There should be no space before '{{token}}'.",
|
|
38
|
+
unexpectedSpaceAfter: "There should be no space after '{{token}}'.",
|
|
39
|
+
},
|
|
18
40
|
},
|
|
19
41
|
create(context) {
|
|
20
|
-
|
|
42
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
43
|
+
if (!sourceCode.parserServices.isYAML) {
|
|
21
44
|
return {};
|
|
22
45
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
const spaced = context.options[0] === "always";
|
|
47
|
+
function isOptionSet(option) {
|
|
48
|
+
return context.options[1]
|
|
49
|
+
? context.options[1][option] === !spaced
|
|
50
|
+
: false;
|
|
51
|
+
}
|
|
52
|
+
const options = {
|
|
53
|
+
spaced,
|
|
54
|
+
arraysInObjectsException: isOptionSet("arraysInObjects"),
|
|
55
|
+
objectsInObjectsException: isOptionSet("objectsInObjects"),
|
|
56
|
+
isOpeningCurlyBraceMustBeSpaced(second) {
|
|
57
|
+
var _a;
|
|
58
|
+
const targetPenultimateType = options.arraysInObjectsException && (0, ast_utils_1.isOpeningBracketToken)(second)
|
|
59
|
+
? "YAMLSequence"
|
|
60
|
+
: options.objectsInObjectsException && (0, ast_utils_1.isOpeningBraceToken)(second)
|
|
61
|
+
? "YAMLMapping"
|
|
62
|
+
: null;
|
|
63
|
+
return targetPenultimateType &&
|
|
64
|
+
((_a = sourceCode.getNodeByRangeIndex(second.range[0])) === null || _a === void 0 ? void 0 : _a.type) ===
|
|
65
|
+
targetPenultimateType
|
|
66
|
+
? !options.spaced
|
|
67
|
+
: options.spaced;
|
|
68
|
+
},
|
|
69
|
+
isClosingCurlyBraceMustBeSpaced(penultimate) {
|
|
70
|
+
var _a;
|
|
71
|
+
const targetPenultimateType = options.arraysInObjectsException && (0, ast_utils_1.isClosingBracketToken)(penultimate)
|
|
72
|
+
? "YAMLSequence"
|
|
73
|
+
: options.objectsInObjectsException &&
|
|
74
|
+
(0, ast_utils_1.isClosingBraceToken)(penultimate)
|
|
75
|
+
? "YAMLMapping"
|
|
76
|
+
: null;
|
|
77
|
+
return targetPenultimateType &&
|
|
78
|
+
((_a = sourceCode.getNodeByRangeIndex(penultimate.range[0])) === null || _a === void 0 ? void 0 : _a.type) ===
|
|
79
|
+
targetPenultimateType
|
|
80
|
+
? !options.spaced
|
|
81
|
+
: options.spaced;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
function reportNoBeginningSpace(node, token) {
|
|
85
|
+
const nextToken = sourceCode.getTokenAfter(token, {
|
|
86
|
+
includeComments: true,
|
|
87
|
+
});
|
|
88
|
+
context.report({
|
|
89
|
+
node,
|
|
90
|
+
loc: { start: token.loc.end, end: nextToken.loc.start },
|
|
91
|
+
messageId: "unexpectedSpaceAfter",
|
|
92
|
+
data: {
|
|
93
|
+
token: token.value,
|
|
94
|
+
},
|
|
95
|
+
fix(fixer) {
|
|
96
|
+
return fixer.removeRange([token.range[1], nextToken.range[0]]);
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function reportNoEndingSpace(node, token) {
|
|
101
|
+
const previousToken = sourceCode.getTokenBefore(token, {
|
|
102
|
+
includeComments: true,
|
|
103
|
+
});
|
|
104
|
+
context.report({
|
|
105
|
+
node,
|
|
106
|
+
loc: { start: previousToken.loc.end, end: token.loc.start },
|
|
107
|
+
messageId: "unexpectedSpaceBefore",
|
|
108
|
+
data: {
|
|
109
|
+
token: token.value,
|
|
110
|
+
},
|
|
111
|
+
fix(fixer) {
|
|
112
|
+
return fixer.removeRange([previousToken.range[1], token.range[0]]);
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function reportRequiredBeginningSpace(node, token) {
|
|
117
|
+
context.report({
|
|
118
|
+
node,
|
|
119
|
+
loc: token.loc,
|
|
120
|
+
messageId: "requireSpaceAfter",
|
|
121
|
+
data: {
|
|
122
|
+
token: token.value,
|
|
123
|
+
},
|
|
124
|
+
fix(fixer) {
|
|
125
|
+
return fixer.insertTextAfter(token, " ");
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function reportRequiredEndingSpace(node, token) {
|
|
130
|
+
context.report({
|
|
131
|
+
node,
|
|
132
|
+
loc: token.loc,
|
|
133
|
+
messageId: "requireSpaceBefore",
|
|
134
|
+
data: {
|
|
135
|
+
token: token.value,
|
|
136
|
+
},
|
|
137
|
+
fix(fixer) {
|
|
138
|
+
return fixer.insertTextBefore(token, " ");
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function validateBraceSpacing(node, first, second, penultimate, last) {
|
|
143
|
+
if ((0, ast_utils_1.isTokenOnSameLine)(first, second)) {
|
|
144
|
+
const firstSpaced = sourceCode.isSpaceBetweenTokens(first, second);
|
|
145
|
+
if (options.isOpeningCurlyBraceMustBeSpaced(second)) {
|
|
146
|
+
if (!firstSpaced)
|
|
147
|
+
reportRequiredBeginningSpace(node, first);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
if (firstSpaced && second.type !== "Line")
|
|
151
|
+
reportNoBeginningSpace(node, first);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if ((0, ast_utils_1.isTokenOnSameLine)(penultimate, last)) {
|
|
155
|
+
const lastSpaced = sourceCode.isSpaceBetweenTokens(penultimate, last);
|
|
156
|
+
if (options.isClosingCurlyBraceMustBeSpaced(penultimate)) {
|
|
157
|
+
if (!lastSpaced)
|
|
158
|
+
reportRequiredEndingSpace(node, last);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
if (lastSpaced)
|
|
162
|
+
reportNoEndingSpace(node, last);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function getClosingBraceOfObject(node) {
|
|
167
|
+
const lastProperty = node.pairs[node.pairs.length - 1];
|
|
168
|
+
return sourceCode.getTokenAfter(lastProperty, ast_utils_1.isClosingBraceToken);
|
|
169
|
+
}
|
|
170
|
+
function checkForObject(node) {
|
|
171
|
+
if (node.pairs.length === 0)
|
|
172
|
+
return;
|
|
173
|
+
const first = sourceCode.getFirstToken(node);
|
|
174
|
+
const last = getClosingBraceOfObject(node);
|
|
175
|
+
const second = sourceCode.getTokenAfter(first, {
|
|
176
|
+
includeComments: true,
|
|
177
|
+
});
|
|
178
|
+
const penultimate = sourceCode.getTokenBefore(last, {
|
|
179
|
+
includeComments: true,
|
|
180
|
+
});
|
|
181
|
+
validateBraceSpacing(node, first, second, penultimate, last);
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
YAMLMapping(node) {
|
|
185
|
+
if (node.style === "flow") {
|
|
186
|
+
checkForObject(node);
|
|
187
|
+
}
|
|
38
188
|
},
|
|
39
|
-
}
|
|
189
|
+
};
|
|
40
190
|
},
|
|
41
191
|
});
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
4
|
const yaml_1 = require("../utils/yaml");
|
|
5
5
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
6
|
+
const compat_1 = require("../utils/compat");
|
|
6
7
|
exports.default = (0, utils_1.createRule)("flow-sequence-bracket-newline", {
|
|
7
8
|
meta: {
|
|
8
9
|
docs: {
|
|
@@ -43,10 +44,10 @@ exports.default = (0, utils_1.createRule)("flow-sequence-bracket-newline", {
|
|
|
43
44
|
type: "layout",
|
|
44
45
|
},
|
|
45
46
|
create(context) {
|
|
46
|
-
|
|
47
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
48
|
+
if (!sourceCode.parserServices.isYAML) {
|
|
47
49
|
return {};
|
|
48
50
|
}
|
|
49
|
-
const sourceCode = context.getSourceCode();
|
|
50
51
|
function normalizeOptionValue(option) {
|
|
51
52
|
let consistent = false;
|
|
52
53
|
let multiline = false;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("../utils");
|
|
4
|
-
const
|
|
4
|
+
const compat_1 = require("../utils/compat");
|
|
5
|
+
const ast_utils_1 = require("../utils/ast-utils");
|
|
5
6
|
exports.default = (0, utils_1.createRule)("flow-sequence-bracket-spacing", {
|
|
6
7
|
meta: {
|
|
7
8
|
docs: {
|
|
@@ -10,32 +11,173 @@ exports.default = (0, utils_1.createRule)("flow-sequence-bracket-spacing", {
|
|
|
10
11
|
extensionRule: "array-bracket-spacing",
|
|
11
12
|
layout: true,
|
|
12
13
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
schema:
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
type: "layout",
|
|
15
|
+
fixable: "whitespace",
|
|
16
|
+
schema: [
|
|
17
|
+
{
|
|
18
|
+
type: "string",
|
|
19
|
+
enum: ["always", "never"],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
singleValue: {
|
|
25
|
+
type: "boolean",
|
|
26
|
+
},
|
|
27
|
+
objectsInArrays: {
|
|
28
|
+
type: "boolean",
|
|
29
|
+
},
|
|
30
|
+
arraysInArrays: {
|
|
31
|
+
type: "boolean",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
messages: {
|
|
38
|
+
unexpectedSpaceAfter: "There should be no space after '{{tokenValue}}'.",
|
|
39
|
+
unexpectedSpaceBefore: "There should be no space before '{{tokenValue}}'.",
|
|
40
|
+
missingSpaceAfter: "A space is required after '{{tokenValue}}'.",
|
|
41
|
+
missingSpaceBefore: "A space is required before '{{tokenValue}}'.",
|
|
42
|
+
},
|
|
18
43
|
},
|
|
19
44
|
create(context) {
|
|
20
|
-
|
|
45
|
+
const sourceCode = (0, compat_1.getSourceCode)(context);
|
|
46
|
+
if (!sourceCode.parserServices.isYAML) {
|
|
21
47
|
return {};
|
|
22
48
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
49
|
+
const spaced = context.options[0] === "always";
|
|
50
|
+
function isOptionSet(option) {
|
|
51
|
+
return context.options[1]
|
|
52
|
+
? context.options[1][option] === !spaced
|
|
53
|
+
: false;
|
|
54
|
+
}
|
|
55
|
+
const options = {
|
|
56
|
+
spaced,
|
|
57
|
+
singleElementException: isOptionSet("singleValue"),
|
|
58
|
+
objectsInArraysException: isOptionSet("objectsInArrays"),
|
|
59
|
+
arraysInArraysException: isOptionSet("arraysInArrays"),
|
|
60
|
+
isOpeningBracketMustBeSpaced(node) {
|
|
61
|
+
if (options.singleElementException && node.entries.length === 1) {
|
|
62
|
+
return !options.spaced;
|
|
63
|
+
}
|
|
64
|
+
const firstElement = node.entries[0];
|
|
65
|
+
return firstElement &&
|
|
66
|
+
((options.objectsInArraysException && isObjectType(firstElement)) ||
|
|
67
|
+
(options.arraysInArraysException && isArrayType(firstElement)))
|
|
68
|
+
? !options.spaced
|
|
69
|
+
: options.spaced;
|
|
70
|
+
},
|
|
71
|
+
isClosingBracketMustBeSpaced(node) {
|
|
72
|
+
if (options.singleElementException && node.entries.length === 1) {
|
|
73
|
+
return !options.spaced;
|
|
74
|
+
}
|
|
75
|
+
const lastElement = node.entries[node.entries.length - 1];
|
|
76
|
+
return lastElement &&
|
|
77
|
+
((options.objectsInArraysException && isObjectType(lastElement)) ||
|
|
78
|
+
(options.arraysInArraysException && isArrayType(lastElement)))
|
|
79
|
+
? !options.spaced
|
|
80
|
+
: options.spaced;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
function reportNoBeginningSpace(node, token) {
|
|
84
|
+
const nextToken = sourceCode.getTokenAfter(token);
|
|
85
|
+
context.report({
|
|
86
|
+
node,
|
|
87
|
+
loc: { start: token.loc.end, end: nextToken.loc.start },
|
|
88
|
+
messageId: "unexpectedSpaceAfter",
|
|
89
|
+
data: {
|
|
90
|
+
tokenValue: token.value,
|
|
91
|
+
},
|
|
92
|
+
fix(fixer) {
|
|
93
|
+
return fixer.removeRange([token.range[1], nextToken.range[0]]);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function reportNoEndingSpace(node, token) {
|
|
98
|
+
const previousToken = sourceCode.getTokenBefore(token);
|
|
99
|
+
context.report({
|
|
100
|
+
node,
|
|
101
|
+
loc: { start: previousToken.loc.end, end: token.loc.start },
|
|
102
|
+
messageId: "unexpectedSpaceBefore",
|
|
103
|
+
data: {
|
|
104
|
+
tokenValue: token.value,
|
|
105
|
+
},
|
|
106
|
+
fix(fixer) {
|
|
107
|
+
return fixer.removeRange([previousToken.range[1], token.range[0]]);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function reportRequiredBeginningSpace(node, token) {
|
|
112
|
+
context.report({
|
|
113
|
+
node,
|
|
114
|
+
loc: token.loc,
|
|
115
|
+
messageId: "missingSpaceAfter",
|
|
116
|
+
data: {
|
|
117
|
+
tokenValue: token.value,
|
|
118
|
+
},
|
|
119
|
+
fix(fixer) {
|
|
120
|
+
return fixer.insertTextAfter(token, " ");
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function reportRequiredEndingSpace(node, token) {
|
|
125
|
+
context.report({
|
|
126
|
+
node,
|
|
127
|
+
loc: token.loc,
|
|
128
|
+
messageId: "missingSpaceBefore",
|
|
129
|
+
data: {
|
|
130
|
+
tokenValue: token.value,
|
|
131
|
+
},
|
|
132
|
+
fix(fixer) {
|
|
133
|
+
return fixer.insertTextBefore(token, " ");
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function isObjectType(node) {
|
|
138
|
+
return node && node.type === "YAMLMapping";
|
|
139
|
+
}
|
|
140
|
+
function isArrayType(node) {
|
|
141
|
+
return node && node.type === "YAMLSequence";
|
|
142
|
+
}
|
|
143
|
+
function validateArraySpacing(node) {
|
|
144
|
+
if (options.spaced && node.entries.length === 0)
|
|
145
|
+
return;
|
|
146
|
+
const first = sourceCode.getFirstToken(node);
|
|
147
|
+
const last = sourceCode.getLastToken(node);
|
|
148
|
+
const second = sourceCode.getTokenAfter(first, {
|
|
149
|
+
includeComments: true,
|
|
150
|
+
});
|
|
151
|
+
const penultimate = sourceCode.getTokenBefore(last, {
|
|
152
|
+
includeComments: true,
|
|
153
|
+
});
|
|
154
|
+
if ((0, ast_utils_1.isTokenOnSameLine)(first, second)) {
|
|
155
|
+
if (options.isOpeningBracketMustBeSpaced(node)) {
|
|
156
|
+
if (!sourceCode.isSpaceBetweenTokens(first, second))
|
|
157
|
+
reportRequiredBeginningSpace(node, first);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
if (sourceCode.isSpaceBetweenTokens(first, second))
|
|
161
|
+
reportNoBeginningSpace(node, first);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (first !== penultimate && (0, ast_utils_1.isTokenOnSameLine)(penultimate, last)) {
|
|
165
|
+
if (options.isClosingBracketMustBeSpaced(node)) {
|
|
166
|
+
if (!sourceCode.isSpaceBetweenTokens(penultimate, last))
|
|
167
|
+
reportRequiredEndingSpace(node, last);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
if (sourceCode.isSpaceBetweenTokens(penultimate, last))
|
|
171
|
+
reportNoEndingSpace(node, last);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
YAMLSequence(node) {
|
|
177
|
+
if (node.style === "flow") {
|
|
178
|
+
validateArraySpacing(node);
|
|
179
|
+
}
|
|
38
180
|
},
|
|
39
|
-
}
|
|
181
|
+
};
|
|
40
182
|
},
|
|
41
183
|
});
|