eslint-plugin-yml 3.4.0 → 3.5.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
@@ -257,6 +257,7 @@ The rules with the following star :star: are included in the config.
257
257
  | [yml/key-spacing](https://ota-meshi.github.io/eslint-plugin-yml/rules/key-spacing.html) | enforce consistent spacing between keys and values in mapping pairs | :wrench: | | :star: |
258
258
  | [yml/no-irregular-whitespace](https://ota-meshi.github.io/eslint-plugin-yml/rules/no-irregular-whitespace.html) | disallow irregular whitespace | | :star: | :star: |
259
259
  | [yml/no-multiple-empty-lines](https://ota-meshi.github.io/eslint-plugin-yml/rules/no-multiple-empty-lines.html) | disallow multiple empty lines | :wrench: | | :star: |
260
+ | [yml/no-trailing-spaces](https://ota-meshi.github.io/eslint-plugin-yml/rules/no-trailing-spaces.html) | disallow trailing whitespace at the end of lines | :wrench: | | :star: |
260
261
  | [yml/spaced-comment](https://ota-meshi.github.io/eslint-plugin-yml/rules/spaced-comment.html) | enforce consistent spacing after the `#` in a comment | :wrench: | | :star: |
261
262
 
262
263
  <!--RULES_TABLE_END-->
package/lib/index.mjs CHANGED
@@ -3376,6 +3376,99 @@ var no_tab_indent_default = createRule("no-tab-indent", {
3376
3376
  }
3377
3377
  });
3378
3378
  //#endregion
3379
+ //#region src/rules/no-trailing-spaces.ts
3380
+ const BLANK_CLASS = "[\\t \\u00a0\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u200b\\u3000]";
3381
+ const TRAILING_SPACES = new RegExp(`${BLANK_CLASS}+$`, "u");
3382
+ const BLANK_LINE = new RegExp(`^${BLANK_CLASS}*$`, "u");
3383
+ /** Check whether a reported whitespace range is fully inside a known range. */
3384
+ function isInRange(rangeStart, rangeEnd, range) {
3385
+ return range[0] <= rangeStart && rangeEnd <= range[1];
3386
+ }
3387
+ var no_trailing_spaces_default = createRule("no-trailing-spaces", {
3388
+ meta: {
3389
+ docs: {
3390
+ description: "disallow trailing whitespace at the end of lines",
3391
+ categories: ["standard"],
3392
+ extensionRule: "no-trailing-spaces",
3393
+ layout: true
3394
+ },
3395
+ fixable: "whitespace",
3396
+ schema: [{
3397
+ type: "object",
3398
+ properties: {
3399
+ skipBlankLines: {
3400
+ type: "boolean",
3401
+ default: false
3402
+ },
3403
+ ignoreComments: {
3404
+ type: "boolean",
3405
+ default: false
3406
+ }
3407
+ },
3408
+ additionalProperties: false
3409
+ }],
3410
+ messages: { trailingSpace: "Trailing spaces not allowed." },
3411
+ type: "layout"
3412
+ },
3413
+ create(context) {
3414
+ const sourceCode = context.sourceCode;
3415
+ if (!sourceCode.parserServices?.isYAML) return {};
3416
+ const options = context.options[0] || {};
3417
+ const skipBlankLines = Boolean(options.skipBlankLines);
3418
+ const ignoreComments = Boolean(options.ignoreComments);
3419
+ const scalarRanges = [];
3420
+ /** Check ranges that should not be reported or fixed. */
3421
+ function isIgnoredRange(lineNumber, rangeStart, rangeEnd) {
3422
+ if (ignoreComments && sourceCode.getAllComments().some((comment) => isInRange(rangeStart, rangeEnd, comment.range))) return true;
3423
+ return scalarRanges.some((scalar) => lineNumber > scalar.startLine && isInRange(rangeStart, rangeEnd, scalar.range));
3424
+ }
3425
+ return {
3426
+ YAMLScalar(node) {
3427
+ if (node.loc.start.line < node.loc.end.line) scalarRanges.push({
3428
+ range: node.range,
3429
+ startLine: node.loc.start.line
3430
+ });
3431
+ },
3432
+ "Program:exit"() {
3433
+ for (let lineIndex = 0; lineIndex < sourceCode.lines.length; lineIndex++) {
3434
+ const line = sourceCode.lines[lineIndex];
3435
+ const match = TRAILING_SPACES.exec(line);
3436
+ if (!match) continue;
3437
+ if (skipBlankLines && BLANK_LINE.test(line)) continue;
3438
+ const lineNumber = lineIndex + 1;
3439
+ const startColumn = match.index;
3440
+ const endColumn = line.length;
3441
+ const rangeStart = sourceCode.getIndexFromLoc({
3442
+ line: lineNumber,
3443
+ column: startColumn
3444
+ });
3445
+ const rangeEnd = sourceCode.getIndexFromLoc({
3446
+ line: lineNumber,
3447
+ column: endColumn
3448
+ });
3449
+ if (isIgnoredRange(lineNumber, rangeStart, rangeEnd)) continue;
3450
+ context.report({
3451
+ loc: {
3452
+ start: {
3453
+ line: lineNumber,
3454
+ column: startColumn
3455
+ },
3456
+ end: {
3457
+ line: lineNumber,
3458
+ column: endColumn
3459
+ }
3460
+ },
3461
+ messageId: "trailingSpace",
3462
+ fix(fixer) {
3463
+ return fixer.removeRange([rangeStart, rangeEnd]);
3464
+ }
3465
+ });
3466
+ }
3467
+ }
3468
+ };
3469
+ }
3470
+ });
3471
+ //#endregion
3379
3472
  //#region src/rules/no-trailing-zeros.ts
3380
3473
  var no_trailing_zeros_default = createRule("no-trailing-zeros", {
3381
3474
  meta: {
@@ -5088,6 +5181,7 @@ const rules$1 = [
5088
5181
  no_irregular_whitespace_default,
5089
5182
  no_multiple_empty_lines_default,
5090
5183
  no_tab_indent_default,
5184
+ no_trailing_spaces_default,
5091
5185
  no_trailing_zeros_default,
5092
5186
  plain_scalar_default,
5093
5187
  quotes_default,
@@ -5269,6 +5363,7 @@ var standard_default = [...base_default, { rules: {
5269
5363
  "yml/no-irregular-whitespace": "error",
5270
5364
  "yml/no-multiple-empty-lines": "error",
5271
5365
  "yml/no-tab-indent": "error",
5366
+ "yml/no-trailing-spaces": "error",
5272
5367
  "yml/no-trailing-zeros": "error",
5273
5368
  "yml/plain-scalar": "error",
5274
5369
  "yml/quotes": "error",
@@ -5288,13 +5383,14 @@ var prettier_default = [...base_default, { rules: {
5288
5383
  "yml/indent": "off",
5289
5384
  "yml/key-spacing": "off",
5290
5385
  "yml/no-multiple-empty-lines": "off",
5386
+ "yml/no-trailing-spaces": "off",
5291
5387
  "yml/no-trailing-zeros": "off",
5292
5388
  "yml/quotes": "off"
5293
5389
  } }];
5294
5390
  //#endregion
5295
5391
  //#region package.json
5296
5392
  var name$1 = "eslint-plugin-yml";
5297
- var version$1 = "3.4.0";
5393
+ var version$1 = "3.5.0";
5298
5394
  //#endregion
5299
5395
  //#region src/meta.ts
5300
5396
  var meta_exports = /* @__PURE__ */ __exportAll({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-yml",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
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.60.0",
93
- "@typescript-eslint/parser": "~8.60.0",
92
+ "@typescript-eslint/eslint-plugin": "~8.62.0",
93
+ "@typescript-eslint/parser": "~8.62.0",
94
94
  "cross-env": "^10.0.0",
95
95
  "env-cmd": "^11.0.0",
96
96
  "eslint": "^10.0.0",