eslint-plugin-yml 3.5.0 → 3.6.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.
Files changed (2) hide show
  1. package/lib/index.mjs +49 -19
  2. package/package.json +2 -2
package/lib/index.mjs CHANGED
@@ -4599,6 +4599,10 @@ var YAMLEntryData = class {
4599
4599
  get value() {
4600
4600
  return (this.cached ?? (this.cached = { value: this.node == null ? null : getStaticYAMLValue(this.node) })).value;
4601
4601
  }
4602
+ getValueForKey(key) {
4603
+ const val = this.value;
4604
+ if (val !== null && typeof val === "object" && !Array.isArray(val)) return val[key];
4605
+ }
4602
4606
  };
4603
4607
  var YAMLSequenceData = class {
4604
4608
  node;
@@ -4617,7 +4621,7 @@ var YAMLSequenceData = class {
4617
4621
  /**
4618
4622
  * Build function which check that the given 2 names are in specific order.
4619
4623
  */
4620
- function buildValidatorFromType(order, insensitive, natural) {
4624
+ function buildValidatorFromType(order, insensitive, natural, key) {
4621
4625
  let compareValue = ([a, b]) => a <= b;
4622
4626
  let compareText = compareValue;
4623
4627
  if (natural) compareText = ([a, b]) => naturalCompare(a, b) <= 0;
@@ -4631,11 +4635,23 @@ function buildValidatorFromType(order, insensitive, natural) {
4631
4635
  const baseCompareValue = compareValue;
4632
4636
  compareValue = (args) => baseCompareValue(args.reverse());
4633
4637
  }
4634
- return (a, b) => {
4635
- if (typeof a.value === "string" && typeof b.value === "string") return compareText([a.value, b.value]);
4636
- const type = getYAMLPrimitiveType(a.value);
4637
- if (type && type === getYAMLPrimitiveType(b.value)) return compareValue([a.value, b.value]);
4638
+ /**
4639
+ * Compare resolved sequence entry values.
4640
+ */
4641
+ function compare(aVal, bVal) {
4642
+ if (typeof aVal === "string" && typeof bVal === "string") return compareText([aVal, bVal]);
4643
+ const type = getYAMLPrimitiveType(aVal);
4644
+ if (type && type === getYAMLPrimitiveType(bVal)) return compareValue([aVal, bVal]);
4638
4645
  return true;
4646
+ }
4647
+ return (a, b) => {
4648
+ if (key) {
4649
+ const aVal = a.getValueForKey(key);
4650
+ const bVal = b.getValueForKey(key);
4651
+ if (aVal === void 0 || bVal === void 0) return true;
4652
+ return compare(aVal, bVal);
4653
+ }
4654
+ return compare(a.value, b.value);
4639
4655
  };
4640
4656
  }
4641
4657
  /**
@@ -4650,14 +4666,16 @@ function parseOptions(options, sourceCode) {
4650
4666
  const type = order.type ?? "asc";
4651
4667
  const insensitive = order.caseSensitive === false;
4652
4668
  const natural = Boolean(order.natural);
4669
+ const key = order.key;
4653
4670
  return {
4654
4671
  isTargetArray,
4655
- ignore: () => false,
4656
- isValidOrder: buildValidatorFromType(type, insensitive, natural),
4672
+ ignore: key ? (v) => v.getValueForKey(key) === void 0 : () => false,
4673
+ isValidOrder: buildValidatorFromType(type, insensitive, natural, key),
4657
4674
  orderText(data) {
4658
- if (typeof data.value === "string") return `${natural ? "natural " : ""}${insensitive ? "insensitive " : ""}${type}ending`;
4659
- return `${type}ending`;
4660
- }
4675
+ const base = typeof data.value === "string" || key ? `${natural ? "natural " : ""}${insensitive ? "insensitive " : ""}${type}ending` : `${type}ending`;
4676
+ return key ? `${base} by '${key}'` : base;
4677
+ },
4678
+ key
4661
4679
  };
4662
4680
  }
4663
4681
  const parsedOrder = [];
@@ -4671,9 +4689,16 @@ function parseOptions(options, sourceCode) {
4671
4689
  const type = nestOrder.type ?? "asc";
4672
4690
  const insensitive = nestOrder.caseSensitive === false;
4673
4691
  const natural = Boolean(nestOrder.natural);
4692
+ const itemKey = nestOrder.key;
4674
4693
  parsedOrder.push({
4675
- test: (v) => valuePattern ? Boolean(getYAMLPrimitiveType(v.value)) && valuePattern.test(String(v.value)) : true,
4676
- isValidNestOrder: buildValidatorFromType(type, insensitive, natural)
4694
+ test: (v) => {
4695
+ if (itemKey) {
4696
+ const keyVal = v.getValueForKey(itemKey);
4697
+ return valuePattern ? keyVal !== void 0 && valuePattern.test(String(keyVal)) : keyVal !== void 0;
4698
+ }
4699
+ return valuePattern ? Boolean(getYAMLPrimitiveType(v.value)) && valuePattern.test(String(v.value)) : true;
4700
+ },
4701
+ isValidNestOrder: buildValidatorFromType(type, insensitive, natural, itemKey)
4677
4702
  });
4678
4703
  }
4679
4704
  return {
@@ -4743,7 +4768,8 @@ const ORDER_OBJECT_SCHEMA = {
4743
4768
  properties: {
4744
4769
  type: { enum: ["asc", "desc"] },
4745
4770
  caseSensitive: { type: "boolean" },
4746
- natural: { type: "boolean" }
4771
+ natural: { type: "boolean" },
4772
+ key: { type: "string" }
4747
4773
  },
4748
4774
  additionalProperties: false
4749
4775
  };
@@ -4838,8 +4864,8 @@ var sort_sequence_values_default = createRule("sort-sequence-values", {
4838
4864
  loc: edit.a.reportLoc,
4839
4865
  messageId: "shouldBeAfter",
4840
4866
  data: {
4841
- thisValue: toText(edit.a),
4842
- targetValue: toText(target),
4867
+ thisValue: toText(edit.a, option.key),
4868
+ targetValue: toText(target, option.key),
4843
4869
  orderText: option.orderText(edit.a)
4844
4870
  },
4845
4871
  *fix(fixer) {
@@ -4854,8 +4880,8 @@ var sort_sequence_values_default = createRule("sort-sequence-values", {
4854
4880
  loc: edit.a.reportLoc,
4855
4881
  messageId: "shouldBeBefore",
4856
4882
  data: {
4857
- thisValue: toText(edit.a),
4858
- targetValue: toText(target),
4883
+ thisValue: toText(edit.a, option.key),
4884
+ targetValue: toText(target, option.key),
4859
4885
  orderText: option.orderText(edit.a)
4860
4886
  },
4861
4887
  *fix(fixer) {
@@ -4927,7 +4953,11 @@ var sort_sequence_values_default = createRule("sort-sequence-values", {
4927
4953
  /**
4928
4954
  * Convert to display text.
4929
4955
  */
4930
- function toText(data) {
4956
+ function toText(data, key) {
4957
+ if (key) {
4958
+ const keyVal = data.getValueForKey(key);
4959
+ if (keyVal !== void 0) return String(keyVal);
4960
+ }
4931
4961
  if (getYAMLPrimitiveType(data.value)) return String(data.value);
4932
4962
  return sourceCode.getText(data.node);
4933
4963
  }
@@ -5390,7 +5420,7 @@ var prettier_default = [...base_default, { rules: {
5390
5420
  //#endregion
5391
5421
  //#region package.json
5392
5422
  var name$1 = "eslint-plugin-yml";
5393
- var version$1 = "3.5.0";
5423
+ var version$1 = "3.6.0";
5394
5424
  //#endregion
5395
5425
  //#region src/meta.ts
5396
5426
  var meta_exports = /* @__PURE__ */ __exportAll({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-yml",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "This ESLint plugin provides linting rules for YAML.",
5
5
  "type": "module",
6
6
  "main": "lib/index.mjs",
@@ -111,7 +111,7 @@
111
111
  "mocha": "^11.0.0",
112
112
  "monaco-editor": "^0.55.0",
113
113
  "nyc": "^18.0.0",
114
- "pako": "^2.1.0",
114
+ "pako": "^3.0.0",
115
115
  "prettier": "^3.0.3",
116
116
  "semver": "^7.3.2",
117
117
  "stylelint": "^17.0.0",