eslint-plugin-yml 1.6.0 → 1.8.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/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { RuleModule } from "./types";
2
+ import * as meta from "./meta";
2
3
  declare const _default: {
4
+ meta: typeof meta;
3
5
  configs: {
4
6
  base: {
5
7
  plugins: string[];
package/lib/index.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -7,6 +30,7 @@ const base_1 = __importDefault(require("./configs/base"));
7
30
  const recommended_1 = __importDefault(require("./configs/recommended"));
8
31
  const standard_1 = __importDefault(require("./configs/standard"));
9
32
  const prettier_1 = __importDefault(require("./configs/prettier"));
33
+ const meta = __importStar(require("./meta"));
10
34
  const configs = {
11
35
  base: base_1.default,
12
36
  recommended: recommended_1.default,
@@ -18,6 +42,7 @@ const rules = rules_1.rules.reduce((obj, r) => {
18
42
  return obj;
19
43
  }, {});
20
44
  module.exports = {
45
+ meta,
21
46
  configs,
22
47
  rules,
23
48
  };
package/lib/meta.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const name: "eslint-plugin-yml";
2
+ export declare const version: "1.8.0";
package/lib/meta.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.version = exports.name = void 0;
4
+ exports.name = "eslint-plugin-yml";
5
+ exports.version = "1.8.0";
@@ -1,4 +1,8 @@
1
1
  "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  const yaml_eslint_parser_1 = require("yaml-eslint-parser");
4
8
  const utils_1 = require("../utils");
@@ -61,7 +65,7 @@ exports.default = (0, utils_1.createRule)("plain-scalar", {
61
65
  const option = context.options[0] || "always";
62
66
  const ignorePatterns = toRegExps((_b = (_a = context.options[1]) === null || _a === void 0 ? void 0 : _a.ignorePatterns) !== null && _b !== void 0 ? _b : (option === "always"
63
67
  ? [
64
- String.raw `[\v\f\u0085\u00a0\u1680\u180e\u2000-\u200b\u2028\u2029\u202f\u205f\u3000\ufeff]`,
68
+ String.raw(templateObject_1 || (templateObject_1 = __makeTemplateObject(["[\v\f\u0085\u00A0\u1680\u180E\u2000-\u200B\u2028\u2029\u202F\u205F\u3000\uFEFF]"], ["[\\v\\f\\u0085\\u00a0\\u1680\\u180e\\u2000-\\u200b\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]"]))),
65
69
  ]
66
70
  : []));
67
71
  const sourceCode = context.getSourceCode();
@@ -166,3 +170,4 @@ exports.default = (0, utils_1.createRule)("plain-scalar", {
166
170
  };
167
171
  },
168
172
  });
173
+ var templateObject_1;
@@ -39,6 +39,10 @@ class YAMLPairData {
39
39
  var _a;
40
40
  return ((_a = this.cachedName) !== null && _a !== void 0 ? _a : (this.cachedName = getPropertyName(this.node, this.mapping.sourceCode)));
41
41
  }
42
+ getPrev() {
43
+ const prevIndex = this.index - 1;
44
+ return prevIndex >= 0 ? this.mapping.pairs[prevIndex] : null;
45
+ }
42
46
  }
43
47
  class YAMLMappingData {
44
48
  constructor(node, sourceCode, anchorAliasMap) {
@@ -51,6 +55,32 @@ class YAMLMappingData {
51
55
  var _a;
52
56
  return ((_a = this.cachedProperties) !== null && _a !== void 0 ? _a : (this.cachedProperties = this.node.pairs.map((e, index) => new YAMLPairData(this, e, index, this.anchorAliasMap.get(e)))));
53
57
  }
58
+ getPath(sourceCode) {
59
+ let path = "";
60
+ let curr = this.node;
61
+ let p = curr.parent;
62
+ while (p) {
63
+ if (p.type === "YAMLPair") {
64
+ const name = getPropertyName(p, sourceCode);
65
+ if (/^[$_a-z][\w$]*$/iu.test(name)) {
66
+ path = `.${name}${path}`;
67
+ }
68
+ else {
69
+ path = `[${JSON.stringify(name)}]${path}`;
70
+ }
71
+ }
72
+ else if (p.type === "YAMLSequence") {
73
+ const index = p.entries.indexOf(curr);
74
+ path = `[${index}]${path}`;
75
+ }
76
+ curr = p;
77
+ p = curr.parent;
78
+ }
79
+ if (path.startsWith(".")) {
80
+ path = path.slice(1);
81
+ }
82
+ return path;
83
+ }
54
84
  }
55
85
  function isCompatibleWithESLintOptions(options) {
56
86
  if (options.length === 0) {
@@ -83,12 +113,14 @@ function parseOptions(options, sourceCode) {
83
113
  const insensitive = obj.caseSensitive === false;
84
114
  const natural = Boolean(obj.natural);
85
115
  const minKeys = (_c = obj.minKeys) !== null && _c !== void 0 ? _c : 2;
116
+ const allowLineSeparatedGroups = obj.allowLineSeparatedGroups || false;
86
117
  return [
87
118
  {
88
119
  isTargetMapping: (data) => data.node.pairs.length >= minKeys,
89
120
  ignore: () => false,
90
121
  isValidOrder: buildValidatorFromType(type, insensitive, natural),
91
122
  orderText: `${natural ? "natural " : ""}${insensitive ? "insensitive " : ""}${type}ending`,
123
+ allowLineSeparatedGroups,
92
124
  },
93
125
  ];
94
126
  }
@@ -98,6 +130,7 @@ function parseOptions(options, sourceCode) {
98
130
  const pathPattern = new RegExp(opt.pathPattern);
99
131
  const hasProperties = (_a = opt.hasProperties) !== null && _a !== void 0 ? _a : [];
100
132
  const minKeys = (_b = opt.minKeys) !== null && _b !== void 0 ? _b : 2;
133
+ const allowLineSeparatedGroups = opt.allowLineSeparatedGroups || false;
101
134
  if (!Array.isArray(order)) {
102
135
  const type = (_c = order.type) !== null && _c !== void 0 ? _c : "asc";
103
136
  const insensitive = order.caseSensitive === false;
@@ -107,6 +140,7 @@ function parseOptions(options, sourceCode) {
107
140
  ignore: () => false,
108
141
  isValidOrder: buildValidatorFromType(type, insensitive, natural),
109
142
  orderText: `${natural ? "natural " : ""}${insensitive ? "insensitive " : ""}${type}ending`,
143
+ allowLineSeparatedGroups,
110
144
  };
111
145
  }
112
146
  const parsedOrder = [];
@@ -150,6 +184,7 @@ function parseOptions(options, sourceCode) {
150
184
  return false;
151
185
  },
152
186
  orderText: "specified",
187
+ allowLineSeparatedGroups,
153
188
  };
154
189
  function isTargetMapping(data) {
155
190
  if (data.node.pairs.length < minKeys) {
@@ -161,30 +196,7 @@ function parseOptions(options, sourceCode) {
161
196
  return false;
162
197
  }
163
198
  }
164
- let path = "";
165
- let curr = data.node;
166
- let p = curr.parent;
167
- while (p) {
168
- if (p.type === "YAMLPair") {
169
- const name = getPropertyName(p, sourceCode);
170
- if (/^[$_a-z][\w$]*$/iu.test(name)) {
171
- path = `.${name}${path}`;
172
- }
173
- else {
174
- path = `[${JSON.stringify(name)}]${path}`;
175
- }
176
- }
177
- else if (p.type === "YAMLSequence") {
178
- const index = p.entries.indexOf(curr);
179
- path = `[${index}]${path}`;
180
- }
181
- curr = p;
182
- p = curr.parent;
183
- }
184
- if (path.startsWith(".")) {
185
- path = path.slice(1);
186
- }
187
- return pathPattern.test(path);
199
+ return pathPattern.test(data.getPath(sourceCode));
188
200
  }
189
201
  });
190
202
  }
@@ -253,6 +265,9 @@ exports.default = (0, utils_1.createRule)("sort-keys", {
253
265
  type: "integer",
254
266
  minimum: 2,
255
267
  },
268
+ allowLineSeparatedGroups: {
269
+ type: "boolean",
270
+ },
256
271
  },
257
272
  required: ["pathPattern", "order"],
258
273
  additionalProperties: false,
@@ -278,6 +293,9 @@ exports.default = (0, utils_1.createRule)("sort-keys", {
278
293
  type: "integer",
279
294
  minimum: 2,
280
295
  },
296
+ allowLineSeparatedGroups: {
297
+ type: "boolean",
298
+ },
281
299
  },
282
300
  additionalProperties: false,
283
301
  },
@@ -323,10 +341,20 @@ exports.default = (0, utils_1.createRule)("sort-keys", {
323
341
  if (ignore(data, option)) {
324
342
  return;
325
343
  }
326
- const prevList = data.mapping.pairs
327
- .slice(0, data.index)
328
- .reverse()
329
- .filter((d) => !ignore(d, option));
344
+ const prevList = [];
345
+ let currTarget = data;
346
+ let prevTarget;
347
+ while ((prevTarget = currTarget.getPrev())) {
348
+ if (option.allowLineSeparatedGroups) {
349
+ if (hasBlankLine(prevTarget, currTarget)) {
350
+ break;
351
+ }
352
+ }
353
+ if (!ignore(prevTarget, option)) {
354
+ prevList.push(prevTarget);
355
+ }
356
+ currTarget = prevTarget;
357
+ }
330
358
  if (prevList.length === 0) {
331
359
  return;
332
360
  }
@@ -360,6 +388,23 @@ exports.default = (0, utils_1.createRule)("sort-keys", {
360
388
  });
361
389
  }
362
390
  }
391
+ function hasBlankLine(prev, next) {
392
+ const tokenOrNodes = [
393
+ ...sourceCode.getTokensBetween(prev.node, next.node, {
394
+ includeComments: true,
395
+ }),
396
+ next.node,
397
+ ];
398
+ let prevLoc = prev.node.loc;
399
+ for (const t of tokenOrNodes) {
400
+ const loc = t.loc;
401
+ if (loc.start.line - prevLoc.end.line > 1) {
402
+ return true;
403
+ }
404
+ prevLoc = loc;
405
+ }
406
+ return false;
407
+ }
363
408
  let pairStack = {
364
409
  upper: null,
365
410
  anchors: new Set(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-yml",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "This ESLint plugin provides linting rules for YAML.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -11,7 +11,8 @@
11
11
  },
12
12
  "scripts": {
13
13
  "prebuild": "npm run -s clean",
14
- "build": "npm run build:ts",
14
+ "build": "npm run build:meta && npm run build:ts",
15
+ "build:meta": "npm run ts -- ./tools/update-meta.ts",
15
16
  "build:ts": "tsc --project ./tsconfig.build.json",
16
17
  "clean": "rimraf .nyc_output dist coverage",
17
18
  "lint": "eslint . --ext .js,.vue,.ts,.json,.md,.yml,.yaml",
@@ -81,7 +82,7 @@
81
82
  "@typescript-eslint/parser": "^5.0.0",
82
83
  "cross-env": "^7.0.2",
83
84
  "env-cmd": "^10.1.0",
84
- "esbuild": "^0.17.0",
85
+ "esbuild": "^0.18.0",
85
86
  "esbuild-register": "^3.2.0",
86
87
  "eslint": "^8.0.0",
87
88
  "eslint-config-prettier": "^8.0.0",
@@ -91,7 +92,7 @@
91
92
  "eslint-plugin-jsonc": "^2.0.0",
92
93
  "eslint-plugin-markdown": "^3.0.0",
93
94
  "eslint-plugin-node": "^11.1.0",
94
- "eslint-plugin-node-dependencies": "^0.10.0",
95
+ "eslint-plugin-node-dependencies": "^0.11.0",
95
96
  "eslint-plugin-prettier": "^4.0.0",
96
97
  "eslint-plugin-regexp": "^1.0.0",
97
98
  "eslint-plugin-vue": "^9.0.0",
@@ -99,7 +100,7 @@
99
100
  "eslint4b": "^7.3.1",
100
101
  "espree": "^9.0.0",
101
102
  "mocha": "^10.0.0",
102
- "monaco-editor": "^0.38.0",
103
+ "monaco-editor": "^0.39.0",
103
104
  "nyc": "^15.1.0",
104
105
  "prettier": "^2.2.1",
105
106
  "raw-loader": "^4.0.1",
@@ -108,7 +109,7 @@
108
109
  "stylelint-config-recommended-vue": "^1.0.0",
109
110
  "stylelint-config-standard": "^33.0.0",
110
111
  "stylelint-stylus": "^0.18.0",
111
- "typescript": "~5.0.0",
112
+ "typescript": "~5.1.0",
112
113
  "vue-eslint-editor": "^1.1.0",
113
114
  "vue-eslint-parser": "^9.0.0",
114
115
  "vuepress": "^1.5.2",