eslint-plugin-yml 1.2.0 → 1.3.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/lib/rules/indent.js +55 -31
- package/lib/rules/sort-keys.js +4 -4
- package/lib/rules/sort-sequence-values.js +9 -9
- package/lib/types.d.ts +11 -11
- package/lib/utils/casing.d.ts +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/package.json +7 -7
package/lib/rules/indent.js
CHANGED
|
@@ -6,6 +6,20 @@ const ast_utils_1 = require("../utils/ast-utils");
|
|
|
6
6
|
const ITERATION_OPTS = Object.freeze({
|
|
7
7
|
includeComments: true,
|
|
8
8
|
});
|
|
9
|
+
function parseOptions(context) {
|
|
10
|
+
const [indentOption, objectOptions] = context.options;
|
|
11
|
+
const numOfIndent = (0, yaml_1.getNumOfIndent)(context, indentOption);
|
|
12
|
+
let indentBlockSequences = true;
|
|
13
|
+
if (objectOptions) {
|
|
14
|
+
if (objectOptions.indentBlockSequences === false) {
|
|
15
|
+
indentBlockSequences = false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
numOfIndent,
|
|
20
|
+
indentBlockSequences,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
9
23
|
exports.default = (0, utils_1.createRule)("indent", {
|
|
10
24
|
meta: {
|
|
11
25
|
docs: {
|
|
@@ -20,6 +34,13 @@ exports.default = (0, utils_1.createRule)("indent", {
|
|
|
20
34
|
type: "integer",
|
|
21
35
|
minimum: 2,
|
|
22
36
|
},
|
|
37
|
+
{
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: {
|
|
40
|
+
indentBlockSequences: { type: "boolean" },
|
|
41
|
+
},
|
|
42
|
+
additionalProperties: false,
|
|
43
|
+
},
|
|
23
44
|
],
|
|
24
45
|
messages: {
|
|
25
46
|
wrongIndentation: "Expected indentation of {{expected}} spaces but found {{actual}} spaces.",
|
|
@@ -33,7 +54,7 @@ exports.default = (0, utils_1.createRule)("indent", {
|
|
|
33
54
|
if ((0, yaml_1.hasTabIndent)(context)) {
|
|
34
55
|
return {};
|
|
35
56
|
}
|
|
36
|
-
const numOfIndent = (
|
|
57
|
+
const { numOfIndent, indentBlockSequences } = parseOptions(context);
|
|
37
58
|
const sourceCode = context.getSourceCode();
|
|
38
59
|
const offsets = new Map();
|
|
39
60
|
const marks = new Set();
|
|
@@ -89,6 +110,15 @@ exports.default = (0, utils_1.createRule)("indent", {
|
|
|
89
110
|
setOffset(right, 0, left);
|
|
90
111
|
}
|
|
91
112
|
}
|
|
113
|
+
function calcMappingPairValueIndentOffset(node) {
|
|
114
|
+
if (indentBlockSequences || !node) {
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
if (node.type === "YAMLSequence" && node.style === "block") {
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
return 1;
|
|
121
|
+
}
|
|
92
122
|
const documents = [];
|
|
93
123
|
return {
|
|
94
124
|
YAMLDocument(node) {
|
|
@@ -138,36 +168,14 @@ exports.default = (0, utils_1.createRule)("indent", {
|
|
|
138
168
|
},
|
|
139
169
|
YAMLPair(node) {
|
|
140
170
|
const pairFirst = sourceCode.getFirstToken(node);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
questionToken = pairFirst;
|
|
171
|
+
const keyToken = node.key && sourceCode.getFirstToken(node.key);
|
|
172
|
+
const colonToken = findColonToken();
|
|
173
|
+
const valueToken = node.value && sourceCode.getFirstToken(node.value);
|
|
174
|
+
const questionToken = (0, ast_utils_1.isQuestion)(pairFirst) ? pairFirst : null;
|
|
175
|
+
if (questionToken) {
|
|
147
176
|
marks.add(questionToken);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
valueToken = sourceCode.getFirstToken(node.value);
|
|
151
|
-
colonToken = sourceCode.getTokenBefore(node.value, ast_utils_1.isColon);
|
|
152
|
-
}
|
|
153
|
-
if (node.key) {
|
|
154
|
-
keyToken = sourceCode.getFirstToken(node.key);
|
|
155
|
-
if (!colonToken) {
|
|
156
|
-
const token = sourceCode.getTokenAfter(node.key, ast_utils_1.isColon);
|
|
157
|
-
if (token && token.range[0] < node.range[1]) {
|
|
158
|
-
colonToken = token;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (!colonToken) {
|
|
163
|
-
const tokens = sourceCode.getTokens(node, ast_utils_1.isColon);
|
|
164
|
-
if (tokens.length) {
|
|
165
|
-
colonToken = tokens[0];
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (keyToken) {
|
|
169
|
-
if (questionToken) {
|
|
170
|
-
setOffset(keyToken, 1, questionToken);
|
|
177
|
+
if (keyToken) {
|
|
178
|
+
setOffset(keyToken, calcMappingPairValueIndentOffset(node.key), questionToken);
|
|
171
179
|
}
|
|
172
180
|
}
|
|
173
181
|
if (colonToken) {
|
|
@@ -183,12 +191,28 @@ exports.default = (0, utils_1.createRule)("indent", {
|
|
|
183
191
|
}
|
|
184
192
|
if (valueToken) {
|
|
185
193
|
if (colonToken) {
|
|
186
|
-
setOffset(valueToken,
|
|
194
|
+
setOffset(valueToken, calcMappingPairValueIndentOffset(node.value), colonToken);
|
|
187
195
|
}
|
|
188
196
|
else if (keyToken) {
|
|
189
197
|
setOffset(valueToken, 1, keyToken);
|
|
190
198
|
}
|
|
191
199
|
}
|
|
200
|
+
function findColonToken() {
|
|
201
|
+
if (node.value) {
|
|
202
|
+
return sourceCode.getTokenBefore(node.value, ast_utils_1.isColon);
|
|
203
|
+
}
|
|
204
|
+
if (node.key) {
|
|
205
|
+
const token = sourceCode.getTokenAfter(node.key, ast_utils_1.isColon);
|
|
206
|
+
if (token && token.range[0] < node.range[1]) {
|
|
207
|
+
return token;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const tokens = sourceCode.getTokens(node, ast_utils_1.isColon);
|
|
211
|
+
if (tokens.length) {
|
|
212
|
+
return tokens[0];
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
192
216
|
},
|
|
193
217
|
YAMLWithMeta(node) {
|
|
194
218
|
const anchorToken = node.anchor && sourceCode.getFirstToken(node.anchor);
|
package/lib/rules/sort-keys.js
CHANGED
|
@@ -24,6 +24,10 @@ function getPropertyName(node, sourceCode) {
|
|
|
24
24
|
return sourceCode.text.slice(...target.range);
|
|
25
25
|
}
|
|
26
26
|
class YAMLPairData {
|
|
27
|
+
get reportLoc() {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
return (_b = (_a = this.node.key) === null || _a === void 0 ? void 0 : _a.loc) !== null && _b !== void 0 ? _b : this.node.loc;
|
|
30
|
+
}
|
|
27
31
|
constructor(mapping, node, index, anchorAlias) {
|
|
28
32
|
this.cachedName = null;
|
|
29
33
|
this.mapping = mapping;
|
|
@@ -31,10 +35,6 @@ class YAMLPairData {
|
|
|
31
35
|
this.index = index;
|
|
32
36
|
this.anchorAlias = anchorAlias;
|
|
33
37
|
}
|
|
34
|
-
get reportLoc() {
|
|
35
|
-
var _a, _b;
|
|
36
|
-
return (_b = (_a = this.node.key) === null || _a === void 0 ? void 0 : _a.loc) !== null && _b !== void 0 ? _b : this.node.loc;
|
|
37
|
-
}
|
|
38
38
|
get name() {
|
|
39
39
|
var _a;
|
|
40
40
|
return ((_a = this.cachedName) !== null && _a !== void 0 ? _a : (this.cachedName = getPropertyName(this.node, this.mapping.sourceCode)));
|
|
@@ -8,15 +8,6 @@ const utils_1 = require("../utils");
|
|
|
8
8
|
const ast_utils_1 = require("../utils/ast-utils");
|
|
9
9
|
const yaml_eslint_parser_1 = require("yaml-eslint-parser");
|
|
10
10
|
class YAMLEntryData {
|
|
11
|
-
constructor(sequence, node, index, anchorAlias) {
|
|
12
|
-
this.cached = null;
|
|
13
|
-
this.cachedRange = null;
|
|
14
|
-
this.cachedAroundTokens = null;
|
|
15
|
-
this.sequence = sequence;
|
|
16
|
-
this.node = node;
|
|
17
|
-
this.index = index;
|
|
18
|
-
this.anchorAlias = anchorAlias;
|
|
19
|
-
}
|
|
20
11
|
get reportLoc() {
|
|
21
12
|
if (this.node) {
|
|
22
13
|
return this.node.loc;
|
|
@@ -57,6 +48,15 @@ class YAMLEntryData {
|
|
|
57
48
|
const after = sourceCode.getTokenAfter(before);
|
|
58
49
|
return (this.cachedAroundTokens = { before, after });
|
|
59
50
|
}
|
|
51
|
+
constructor(sequence, node, index, anchorAlias) {
|
|
52
|
+
this.cached = null;
|
|
53
|
+
this.cachedRange = null;
|
|
54
|
+
this.cachedAroundTokens = null;
|
|
55
|
+
this.sequence = sequence;
|
|
56
|
+
this.node = node;
|
|
57
|
+
this.index = index;
|
|
58
|
+
this.anchorAlias = anchorAlias;
|
|
59
|
+
}
|
|
60
60
|
get value() {
|
|
61
61
|
var _a;
|
|
62
62
|
return ((_a = this.cached) !== null && _a !== void 0 ? _a : (this.cached = {
|
package/lib/types.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export interface PartialRuleMetaData {
|
|
|
75
75
|
deprecated?: boolean;
|
|
76
76
|
type: "problem" | "suggestion" | "layout";
|
|
77
77
|
}
|
|
78
|
-
export
|
|
78
|
+
export type YMLSettings = {
|
|
79
79
|
indent?: number;
|
|
80
80
|
};
|
|
81
81
|
export interface RuleContext {
|
|
@@ -98,8 +98,8 @@ export interface RuleContext {
|
|
|
98
98
|
export declare namespace SourceCode {
|
|
99
99
|
function splitLines(text: string): string[];
|
|
100
100
|
}
|
|
101
|
-
export
|
|
102
|
-
export
|
|
101
|
+
export type YAMLToken = AST.Token | AST.Comment;
|
|
102
|
+
export type YAMLNodeOrToken = AST.YAMLNode | YAMLToken;
|
|
103
103
|
export interface SourceCode {
|
|
104
104
|
text: string;
|
|
105
105
|
ast: AST.YAMLProgram;
|
|
@@ -149,13 +149,13 @@ export interface SourceCode {
|
|
|
149
149
|
getCommentsAfter(nodeOrToken: YAMLNodeOrToken): AST.Comment[];
|
|
150
150
|
getCommentsInside(node: AST.YAMLNode): AST.Comment[];
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
type FilterPredicate = (tokenOrComment: YAMLToken) => boolean;
|
|
153
|
+
type CursorWithSkipOptions = number | FilterPredicate | {
|
|
154
154
|
includeComments?: boolean;
|
|
155
155
|
filter?: FilterPredicate;
|
|
156
156
|
skip?: number;
|
|
157
157
|
};
|
|
158
|
-
|
|
158
|
+
type CursorWithCountOptions = number | FilterPredicate | {
|
|
159
159
|
includeComments?: boolean;
|
|
160
160
|
filter?: FilterPredicate;
|
|
161
161
|
count?: number;
|
|
@@ -166,22 +166,22 @@ interface ReportDescriptorOptionsBase {
|
|
|
166
166
|
};
|
|
167
167
|
fix?: null | ((fixer: RuleFixer) => null | Fix | IterableIterator<Fix> | Fix[]);
|
|
168
168
|
}
|
|
169
|
-
|
|
169
|
+
type SuggestionDescriptorMessage = {
|
|
170
170
|
desc: string;
|
|
171
171
|
} | {
|
|
172
172
|
messageId: string;
|
|
173
173
|
};
|
|
174
|
-
|
|
174
|
+
type SuggestionReportDescriptor = SuggestionDescriptorMessage & ReportDescriptorOptionsBase;
|
|
175
175
|
interface ReportDescriptorOptions extends ReportDescriptorOptionsBase {
|
|
176
176
|
suggest?: SuggestionReportDescriptor[] | null;
|
|
177
177
|
}
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
type ReportDescriptor = ReportDescriptorMessage & ReportDescriptorLocation & ReportDescriptorOptions;
|
|
179
|
+
type ReportDescriptorMessage = {
|
|
180
180
|
message: string;
|
|
181
181
|
} | {
|
|
182
182
|
messageId: string;
|
|
183
183
|
};
|
|
184
|
-
|
|
184
|
+
type ReportDescriptorLocation = {
|
|
185
185
|
node: YAMLNodeOrToken;
|
|
186
186
|
} | {
|
|
187
187
|
loc: SourceLocation | {
|
package/lib/utils/casing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type CasingKind = "camelCase" | "kebab-case" | "PascalCase" | "snake_case" | "SCREAMING_SNAKE_CASE";
|
|
2
2
|
export declare const allowedCaseOptions: CasingKind[];
|
|
3
3
|
export declare function kebabCase(str: string): string;
|
|
4
4
|
export declare function isKebabCase(str: string): boolean;
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { RuleListener, RuleModule, PartialRuleModule, RuleContext } from ".
|
|
|
2
2
|
import type { Rule } from "eslint";
|
|
3
3
|
import type { AST } from "yaml-eslint-parser";
|
|
4
4
|
export declare function createRule(ruleName: string, rule: PartialRuleModule): RuleModule;
|
|
5
|
-
|
|
5
|
+
type CoreRuleListener = {
|
|
6
6
|
[key: string]: (node: any) => void;
|
|
7
7
|
};
|
|
8
8
|
export declare function defineWrapperListener(coreRule: Rule.RuleModule, context: RuleContext, proxyOptions: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-yml",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "This ESLint plugin provides linting rules for YAML.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -65,16 +65,16 @@
|
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@changesets/changelog-github": "^0.4.6",
|
|
67
67
|
"@changesets/cli": "^2.24.2",
|
|
68
|
-
"@ota-meshi/eslint-plugin": "^0.
|
|
68
|
+
"@ota-meshi/eslint-plugin": "^0.13.0",
|
|
69
69
|
"@types/debug": "^4.1.5",
|
|
70
70
|
"@types/eslint": "^8.0.0",
|
|
71
71
|
"@types/eslint-scope": "^3.7.0",
|
|
72
72
|
"@types/eslint-visitor-keys": "^1.0.0",
|
|
73
73
|
"@types/estree": "^1.0.0",
|
|
74
74
|
"@types/lodash": "^4.14.158",
|
|
75
|
-
"@types/mocha": "^
|
|
75
|
+
"@types/mocha": "^10.0.0",
|
|
76
76
|
"@types/natural-compare": "^1.4.0",
|
|
77
|
-
"@types/node": "^
|
|
77
|
+
"@types/node": "^18.0.0",
|
|
78
78
|
"@types/semver": "^7.3.1",
|
|
79
79
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
80
80
|
"@typescript-eslint/parser": "^5.0.0",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"eslint-plugin-jsonc": "^2.0.0",
|
|
91
91
|
"eslint-plugin-markdown": "^3.0.0",
|
|
92
92
|
"eslint-plugin-node": "^11.1.0",
|
|
93
|
-
"eslint-plugin-node-dependencies": "^0.
|
|
93
|
+
"eslint-plugin-node-dependencies": "^0.10.0",
|
|
94
94
|
"eslint-plugin-prettier": "^4.0.0",
|
|
95
95
|
"eslint-plugin-regexp": "^1.0.0",
|
|
96
96
|
"eslint-plugin-vue": "^9.0.0",
|
|
@@ -105,9 +105,9 @@
|
|
|
105
105
|
"semver": "^7.3.2",
|
|
106
106
|
"stylelint": "^14.9.1",
|
|
107
107
|
"stylelint-config-recommended-vue": "^1.0.0",
|
|
108
|
-
"stylelint-config-standard": "^
|
|
108
|
+
"stylelint-config-standard": "^29.0.0",
|
|
109
109
|
"stylelint-stylus": "^0.17.0",
|
|
110
|
-
"typescript": "~4.
|
|
110
|
+
"typescript": "~4.9.0",
|
|
111
111
|
"vue-eslint-editor": "^1.1.0",
|
|
112
112
|
"vue-eslint-parser": "^9.0.0",
|
|
113
113
|
"vuepress": "^1.5.2",
|