eslint-plugin-yml 0.12.0 → 0.13.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 CHANGED
@@ -146,6 +146,18 @@ Example **.vscode/settings.json**:
146
146
  }
147
147
  ```
148
148
 
149
+ ### JetBrains WebStorm IDEs
150
+
151
+ In any of the JetBrains IDEs you can [configure the linting scope](https://www.jetbrains.com/help/webstorm/eslint.html#ws_eslint_configure_scope).
152
+ Following the steps in their help document, you can add YAML files to the scope like so:
153
+
154
+ 1. Open the **Settings/Preferences** dialog, go to **Languages and Frameworks** | **JavaScript** | **Code Quality Tools** | **ESLint**, and select **Automatic ESLint configuration** or **Manual ESLint configuration**.
155
+ 2. In the **Run for files** field, update the pattern that defines the set of files to be linted to include YAML files as well:
156
+ ```
157
+ {**/*,*}.{js,ts,jsx,tsx,html,vue,yaml,yml}
158
+ ^^^^ ^^^
159
+ ```
160
+
149
161
  <!--USAGE_GUIDE_END-->
150
162
  <!--USAGE_SECTION_END-->
151
163
 
@@ -65,7 +65,7 @@ function parseOptions(options, sourceCode) {
65
65
  ];
66
66
  }
67
67
  return options.map((opt) => {
68
- var _a, _b, _c;
68
+ var _a, _b, _c, _d, _e;
69
69
  const order = opt.order;
70
70
  const pathPattern = new RegExp(opt.pathPattern);
71
71
  const hasProperties = (_a = opt.hasProperties) !== null && _a !== void 0 ? _a : [];
@@ -82,13 +82,47 @@ function parseOptions(options, sourceCode) {
82
82
  orderText: `${natural ? "natural " : ""}${insensitive ? "insensitive " : ""}${type}ending`,
83
83
  };
84
84
  }
85
+ const parsedOrder = [];
86
+ for (const o of order) {
87
+ if (typeof o === "string") {
88
+ parsedOrder.push({
89
+ test: (s) => s === o,
90
+ isValidNestOrder: () => true,
91
+ });
92
+ }
93
+ else {
94
+ const keyPattern = o.keyPattern
95
+ ? new RegExp(o.keyPattern)
96
+ : null;
97
+ const nestOrder = (_d = o.order) !== null && _d !== void 0 ? _d : {};
98
+ const type = (_e = nestOrder.type) !== null && _e !== void 0 ? _e : "asc";
99
+ const insensitive = nestOrder.caseSensitive === false;
100
+ const natural = Boolean(nestOrder.natural);
101
+ parsedOrder.push({
102
+ test: (s) => (keyPattern ? keyPattern.test(s) : true),
103
+ isValidNestOrder: buildValidatorFromType(type, insensitive, natural),
104
+ });
105
+ }
106
+ }
85
107
  return {
86
108
  isTargetMapping,
87
- ignore: (s) => !order.includes(s),
109
+ ignore: (s) => parsedOrder.every((p) => !p.test(s)),
88
110
  isValidOrder(a, b) {
89
- const aIndex = order.indexOf(a);
90
- const bIndex = order.indexOf(b);
91
- return aIndex <= bIndex;
111
+ for (const p of parsedOrder) {
112
+ const matchA = p.test(a);
113
+ const matchB = p.test(b);
114
+ if (!matchA || !matchB) {
115
+ if (matchA) {
116
+ return true;
117
+ }
118
+ if (matchB) {
119
+ return false;
120
+ }
121
+ continue;
122
+ }
123
+ return p.isValidNestOrder(a, b);
124
+ }
125
+ return false;
92
126
  },
93
127
  minKeys,
94
128
  orderText: "specified",
@@ -127,7 +161,22 @@ function parseOptions(options, sourceCode) {
127
161
  }
128
162
  });
129
163
  }
130
- const allowOrderTypes = ["asc", "desc"];
164
+ const ALLOW_ORDER_TYPES = ["asc", "desc"];
165
+ const ORDER_OBJECT_SCHEMA = {
166
+ type: "object",
167
+ properties: {
168
+ type: {
169
+ enum: ALLOW_ORDER_TYPES,
170
+ },
171
+ caseSensitive: {
172
+ type: "boolean",
173
+ },
174
+ natural: {
175
+ type: "boolean",
176
+ },
177
+ },
178
+ additionalProperties: false,
179
+ };
131
180
  exports.default = (0, utils_1.createRule)("sort-keys", {
132
181
  meta: {
133
182
  docs: {
@@ -153,24 +202,24 @@ exports.default = (0, utils_1.createRule)("sort-keys", {
153
202
  oneOf: [
154
203
  {
155
204
  type: "array",
156
- items: { type: "string" },
157
- uniqueItems: true,
158
- },
159
- {
160
- type: "object",
161
- properties: {
162
- type: {
163
- enum: allowOrderTypes,
164
- },
165
- caseSensitive: {
166
- type: "boolean",
167
- },
168
- natural: {
169
- type: "boolean",
170
- },
205
+ items: {
206
+ anyOf: [
207
+ { type: "string" },
208
+ {
209
+ type: "object",
210
+ properties: {
211
+ keyPattern: {
212
+ type: "string",
213
+ },
214
+ order: ORDER_OBJECT_SCHEMA,
215
+ },
216
+ additionalProperties: false,
217
+ },
218
+ ],
171
219
  },
172
- additionalProperties: false,
220
+ uniqueItems: true,
173
221
  },
222
+ ORDER_OBJECT_SCHEMA,
174
223
  ],
175
224
  },
176
225
  minKeys: {
@@ -187,7 +236,7 @@ exports.default = (0, utils_1.createRule)("sort-keys", {
187
236
  type: "array",
188
237
  items: [
189
238
  {
190
- enum: allowOrderTypes,
239
+ enum: ALLOW_ORDER_TYPES,
191
240
  },
192
241
  {
193
242
  type: "object",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-yml",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "This ESLint plugin provides linting rules for YAML.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -42,6 +42,7 @@
42
42
  "yml"
43
43
  ],
44
44
  "author": "Yosuke Ota",
45
+ "funding": "https://github.com/sponsors/ota-meshi",
45
46
  "license": "MIT",
46
47
  "bugs": {
47
48
  "url": "https://github.com/ota-meshi/eslint-plugin-yml/issues"
@@ -84,11 +85,11 @@
84
85
  "eslint-plugin-prettier": "^4.0.0",
85
86
  "eslint-plugin-regexp": "^1.0.0",
86
87
  "eslint-plugin-vue": "^8.0.0",
87
- "eslint-plugin-yml": "^0.11.0",
88
+ "eslint-plugin-yml": "^0.12.0",
88
89
  "eslint4b": "^7.3.1",
89
90
  "espree": "^9.0.0",
90
91
  "mocha": "^9.0.0",
91
- "monaco-editor": "^0.30.0",
92
+ "monaco-editor": "^0.31.0",
92
93
  "nyc": "^15.1.0",
93
94
  "prettier": "^2.2.1",
94
95
  "raw-loader": "^4.0.1",