eslint-plugin-yml 3.5.0 → 3.6.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/lib/index.mjs +57 -21
- package/package.json +5 -5
package/lib/index.mjs
CHANGED
|
@@ -4426,7 +4426,10 @@ var sort_keys_default = createRule("sort-keys", {
|
|
|
4426
4426
|
yield fixer.removeRange(removeRange);
|
|
4427
4427
|
yield fixer.insertTextAfterRange(moveTargetRange, `${isAtFileStart ? "\n" : ""}${insertCode}`);
|
|
4428
4428
|
} else {
|
|
4429
|
-
const nextToken = sourceCode.getTokenAfter(data.node, {
|
|
4429
|
+
const nextToken = sourceCode.getTokenAfter(data.node, {
|
|
4430
|
+
includeComments: true,
|
|
4431
|
+
filter: (t) => !isCommentToken(t) || data.node.loc.end.line < t.loc.start.line
|
|
4432
|
+
});
|
|
4430
4433
|
const removeRange = [data.node.range[0], nextToken.range[0]];
|
|
4431
4434
|
yield fixer.removeRange(removeRange);
|
|
4432
4435
|
const insertCode = `\n${sourceCode.text.slice(sourceCode.getIndexFromLoc({
|
|
@@ -4495,7 +4498,10 @@ var sort_keys_default = createRule("sort-keys", {
|
|
|
4495
4498
|
};
|
|
4496
4499
|
const beforeToken = sourceCode.getTokenBefore(node);
|
|
4497
4500
|
if (beforeToken) {
|
|
4498
|
-
const next = sourceCode.getTokenAfter(beforeToken, {
|
|
4501
|
+
const next = sourceCode.getTokenAfter(beforeToken, {
|
|
4502
|
+
includeComments: true,
|
|
4503
|
+
filter: (t) => !isCommentToken(t) || beforeToken.loc.end.line < t.loc.start.line
|
|
4504
|
+
});
|
|
4499
4505
|
if (beforeToken.loc.end.line < next.loc.start.line || beforeToken.loc.end.line < node.loc.start.line) {
|
|
4500
4506
|
const start = {
|
|
4501
4507
|
line: beforeToken.loc.end.line < next.loc.start.line ? next.loc.start.line : node.loc.start.line,
|
|
@@ -4599,6 +4605,10 @@ var YAMLEntryData = class {
|
|
|
4599
4605
|
get value() {
|
|
4600
4606
|
return (this.cached ?? (this.cached = { value: this.node == null ? null : getStaticYAMLValue(this.node) })).value;
|
|
4601
4607
|
}
|
|
4608
|
+
getValueForKey(key) {
|
|
4609
|
+
const val = this.value;
|
|
4610
|
+
if (val !== null && typeof val === "object" && !Array.isArray(val)) return val[key];
|
|
4611
|
+
}
|
|
4602
4612
|
};
|
|
4603
4613
|
var YAMLSequenceData = class {
|
|
4604
4614
|
node;
|
|
@@ -4617,7 +4627,7 @@ var YAMLSequenceData = class {
|
|
|
4617
4627
|
/**
|
|
4618
4628
|
* Build function which check that the given 2 names are in specific order.
|
|
4619
4629
|
*/
|
|
4620
|
-
function buildValidatorFromType(order, insensitive, natural) {
|
|
4630
|
+
function buildValidatorFromType(order, insensitive, natural, key) {
|
|
4621
4631
|
let compareValue = ([a, b]) => a <= b;
|
|
4622
4632
|
let compareText = compareValue;
|
|
4623
4633
|
if (natural) compareText = ([a, b]) => naturalCompare(a, b) <= 0;
|
|
@@ -4631,11 +4641,23 @@ function buildValidatorFromType(order, insensitive, natural) {
|
|
|
4631
4641
|
const baseCompareValue = compareValue;
|
|
4632
4642
|
compareValue = (args) => baseCompareValue(args.reverse());
|
|
4633
4643
|
}
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4644
|
+
/**
|
|
4645
|
+
* Compare resolved sequence entry values.
|
|
4646
|
+
*/
|
|
4647
|
+
function compare(aVal, bVal) {
|
|
4648
|
+
if (typeof aVal === "string" && typeof bVal === "string") return compareText([aVal, bVal]);
|
|
4649
|
+
const type = getYAMLPrimitiveType(aVal);
|
|
4650
|
+
if (type && type === getYAMLPrimitiveType(bVal)) return compareValue([aVal, bVal]);
|
|
4638
4651
|
return true;
|
|
4652
|
+
}
|
|
4653
|
+
return (a, b) => {
|
|
4654
|
+
if (key) {
|
|
4655
|
+
const aVal = a.getValueForKey(key);
|
|
4656
|
+
const bVal = b.getValueForKey(key);
|
|
4657
|
+
if (aVal === void 0 || bVal === void 0) return true;
|
|
4658
|
+
return compare(aVal, bVal);
|
|
4659
|
+
}
|
|
4660
|
+
return compare(a.value, b.value);
|
|
4639
4661
|
};
|
|
4640
4662
|
}
|
|
4641
4663
|
/**
|
|
@@ -4650,14 +4672,16 @@ function parseOptions(options, sourceCode) {
|
|
|
4650
4672
|
const type = order.type ?? "asc";
|
|
4651
4673
|
const insensitive = order.caseSensitive === false;
|
|
4652
4674
|
const natural = Boolean(order.natural);
|
|
4675
|
+
const key = order.key;
|
|
4653
4676
|
return {
|
|
4654
4677
|
isTargetArray,
|
|
4655
|
-
ignore: () => false,
|
|
4656
|
-
isValidOrder: buildValidatorFromType(type, insensitive, natural),
|
|
4678
|
+
ignore: key ? (v) => v.getValueForKey(key) === void 0 : () => false,
|
|
4679
|
+
isValidOrder: buildValidatorFromType(type, insensitive, natural, key),
|
|
4657
4680
|
orderText(data) {
|
|
4658
|
-
|
|
4659
|
-
return `${
|
|
4660
|
-
}
|
|
4681
|
+
const base = typeof data.value === "string" || key ? `${natural ? "natural " : ""}${insensitive ? "insensitive " : ""}${type}ending` : `${type}ending`;
|
|
4682
|
+
return key ? `${base} by '${key}'` : base;
|
|
4683
|
+
},
|
|
4684
|
+
key
|
|
4661
4685
|
};
|
|
4662
4686
|
}
|
|
4663
4687
|
const parsedOrder = [];
|
|
@@ -4671,9 +4695,16 @@ function parseOptions(options, sourceCode) {
|
|
|
4671
4695
|
const type = nestOrder.type ?? "asc";
|
|
4672
4696
|
const insensitive = nestOrder.caseSensitive === false;
|
|
4673
4697
|
const natural = Boolean(nestOrder.natural);
|
|
4698
|
+
const itemKey = nestOrder.key;
|
|
4674
4699
|
parsedOrder.push({
|
|
4675
|
-
test: (v) =>
|
|
4676
|
-
|
|
4700
|
+
test: (v) => {
|
|
4701
|
+
if (itemKey) {
|
|
4702
|
+
const keyVal = v.getValueForKey(itemKey);
|
|
4703
|
+
return valuePattern ? keyVal !== void 0 && valuePattern.test(String(keyVal)) : keyVal !== void 0;
|
|
4704
|
+
}
|
|
4705
|
+
return valuePattern ? Boolean(getYAMLPrimitiveType(v.value)) && valuePattern.test(String(v.value)) : true;
|
|
4706
|
+
},
|
|
4707
|
+
isValidNestOrder: buildValidatorFromType(type, insensitive, natural, itemKey)
|
|
4677
4708
|
});
|
|
4678
4709
|
}
|
|
4679
4710
|
return {
|
|
@@ -4743,7 +4774,8 @@ const ORDER_OBJECT_SCHEMA = {
|
|
|
4743
4774
|
properties: {
|
|
4744
4775
|
type: { enum: ["asc", "desc"] },
|
|
4745
4776
|
caseSensitive: { type: "boolean" },
|
|
4746
|
-
natural: { type: "boolean" }
|
|
4777
|
+
natural: { type: "boolean" },
|
|
4778
|
+
key: { type: "string" }
|
|
4747
4779
|
},
|
|
4748
4780
|
additionalProperties: false
|
|
4749
4781
|
};
|
|
@@ -4838,8 +4870,8 @@ var sort_sequence_values_default = createRule("sort-sequence-values", {
|
|
|
4838
4870
|
loc: edit.a.reportLoc,
|
|
4839
4871
|
messageId: "shouldBeAfter",
|
|
4840
4872
|
data: {
|
|
4841
|
-
thisValue: toText(edit.a),
|
|
4842
|
-
targetValue: toText(target),
|
|
4873
|
+
thisValue: toText(edit.a, option.key),
|
|
4874
|
+
targetValue: toText(target, option.key),
|
|
4843
4875
|
orderText: option.orderText(edit.a)
|
|
4844
4876
|
},
|
|
4845
4877
|
*fix(fixer) {
|
|
@@ -4854,8 +4886,8 @@ var sort_sequence_values_default = createRule("sort-sequence-values", {
|
|
|
4854
4886
|
loc: edit.a.reportLoc,
|
|
4855
4887
|
messageId: "shouldBeBefore",
|
|
4856
4888
|
data: {
|
|
4857
|
-
thisValue: toText(edit.a),
|
|
4858
|
-
targetValue: toText(target),
|
|
4889
|
+
thisValue: toText(edit.a, option.key),
|
|
4890
|
+
targetValue: toText(target, option.key),
|
|
4859
4891
|
orderText: option.orderText(edit.a)
|
|
4860
4892
|
},
|
|
4861
4893
|
*fix(fixer) {
|
|
@@ -4927,7 +4959,11 @@ var sort_sequence_values_default = createRule("sort-sequence-values", {
|
|
|
4927
4959
|
/**
|
|
4928
4960
|
* Convert to display text.
|
|
4929
4961
|
*/
|
|
4930
|
-
function toText(data) {
|
|
4962
|
+
function toText(data, key) {
|
|
4963
|
+
if (key) {
|
|
4964
|
+
const keyVal = data.getValueForKey(key);
|
|
4965
|
+
if (keyVal !== void 0) return String(keyVal);
|
|
4966
|
+
}
|
|
4931
4967
|
if (getYAMLPrimitiveType(data.value)) return String(data.value);
|
|
4932
4968
|
return sourceCode.getText(data.node);
|
|
4933
4969
|
}
|
|
@@ -5390,7 +5426,7 @@ var prettier_default = [...base_default, { rules: {
|
|
|
5390
5426
|
//#endregion
|
|
5391
5427
|
//#region package.json
|
|
5392
5428
|
var name$1 = "eslint-plugin-yml";
|
|
5393
|
-
var version$1 = "3.
|
|
5429
|
+
var version$1 = "3.6.1";
|
|
5394
5430
|
//#endregion
|
|
5395
5431
|
//#region src/meta.ts
|
|
5396
5432
|
var meta_exports = /* @__PURE__ */ __exportAll({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-yml",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"description": "This ESLint plugin provides linting rules for YAML.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.mjs",
|
|
@@ -89,8 +89,8 @@
|
|
|
89
89
|
"@types/natural-compare": "^1.4.0",
|
|
90
90
|
"@types/node": "^24.0.0",
|
|
91
91
|
"@types/semver": "^7.3.1",
|
|
92
|
-
"@typescript-eslint/eslint-plugin": "~8.
|
|
93
|
-
"@typescript-eslint/parser": "~8.
|
|
92
|
+
"@typescript-eslint/eslint-plugin": "~8.65.0",
|
|
93
|
+
"@typescript-eslint/parser": "~8.65.0",
|
|
94
94
|
"cross-env": "^10.0.0",
|
|
95
95
|
"env-cmd": "^11.0.0",
|
|
96
96
|
"eslint": "^10.0.0",
|
|
@@ -109,9 +109,9 @@
|
|
|
109
109
|
"eslint-plugin-yml": "^3.0.0",
|
|
110
110
|
"events": "^3.3.0",
|
|
111
111
|
"mocha": "^11.0.0",
|
|
112
|
-
"monaco-editor": "^0.
|
|
112
|
+
"monaco-editor": "^0.56.0",
|
|
113
113
|
"nyc": "^18.0.0",
|
|
114
|
-
"pako": "^
|
|
114
|
+
"pako": "^3.0.0",
|
|
115
115
|
"prettier": "^3.0.3",
|
|
116
116
|
"semver": "^7.3.2",
|
|
117
117
|
"stylelint": "^17.0.0",
|