eslint-plugin-yml 1.5.0 → 1.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.
package/README.md CHANGED
@@ -207,6 +207,7 @@ The rules with the following star :star: are included in the config.
207
207
  | [yml/no-empty-mapping-value](https://ota-meshi.github.io/eslint-plugin-yml/rules/no-empty-mapping-value.html) | disallow empty mapping values | | :star: | :star: |
208
208
  | [yml/no-empty-sequence-entry](https://ota-meshi.github.io/eslint-plugin-yml/rules/no-empty-sequence-entry.html) | disallow empty sequence entries | | :star: | :star: |
209
209
  | [yml/no-tab-indent](https://ota-meshi.github.io/eslint-plugin-yml/rules/no-tab-indent.html) | disallow tabs for indentation. | | :star: | :star: |
210
+ | [yml/no-trailing-zeros](https://ota-meshi.github.io/eslint-plugin-yml/rules/no-trailing-zeros.html) | disallow trailing zeros for floats | :wrench: | | |
210
211
  | [yml/plain-scalar](https://ota-meshi.github.io/eslint-plugin-yml/rules/plain-scalar.html) | require or disallow plain style scalar. | :wrench: | | :star: |
211
212
  | [yml/quotes](https://ota-meshi.github.io/eslint-plugin-yml/rules/quotes.html) | enforce the consistent use of either double, or single quotes | :wrench: | | :star: |
212
213
  | [yml/require-string-key](https://ota-meshi.github.io/eslint-plugin-yml/rules/require-string-key.html) | disallow mapping keys other than strings | | | |
@@ -11,6 +11,7 @@ declare const _default: {
11
11
  "yml/indent": string;
12
12
  "yml/key-spacing": string;
13
13
  "yml/no-multiple-empty-lines": string;
14
+ "yml/no-trailing-zeros": string;
14
15
  "yml/quotes": string;
15
16
  };
16
17
  };
@@ -18,6 +18,7 @@ module.exports = {
18
18
  "yml/indent": "off",
19
19
  "yml/key-spacing": "off",
20
20
  "yml/no-multiple-empty-lines": "off",
21
+ "yml/no-trailing-zeros": "off",
21
22
  "yml/quotes": "off",
22
23
  },
23
24
  };
package/lib/index.d.ts CHANGED
@@ -63,6 +63,7 @@ declare const _default: {
63
63
  "yml/indent": string;
64
64
  "yml/key-spacing": string;
65
65
  "yml/no-multiple-empty-lines": string;
66
+ "yml/no-trailing-zeros": string;
66
67
  "yml/quotes": string;
67
68
  };
68
69
  };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").RuleModule;
2
+ export default _default;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../utils");
4
+ exports.default = (0, utils_1.createRule)("no-trailing-zeros", {
5
+ meta: {
6
+ docs: {
7
+ description: "disallow trailing zeros for floats",
8
+ categories: null,
9
+ extensionRule: false,
10
+ layout: true,
11
+ },
12
+ fixable: "code",
13
+ schema: [],
14
+ messages: {
15
+ wrongZeros: "Trailing zeros are not allowed, fix to `{{fixed}}`.",
16
+ },
17
+ type: "layout",
18
+ },
19
+ create(context) {
20
+ if (!context.parserServices.isYAML) {
21
+ return {};
22
+ }
23
+ return {
24
+ YAMLScalar(node) {
25
+ if (node.style !== "plain") {
26
+ return;
27
+ }
28
+ else if (typeof node.value !== "number") {
29
+ return;
30
+ }
31
+ const floating = parseFloatingPoint(node.strValue);
32
+ if (!floating) {
33
+ return;
34
+ }
35
+ let { decimalPart } = floating;
36
+ while (decimalPart.endsWith("_")) {
37
+ decimalPart = decimalPart.slice(0, -1);
38
+ }
39
+ if (!decimalPart.endsWith("0")) {
40
+ return;
41
+ }
42
+ while (decimalPart.endsWith("0")) {
43
+ decimalPart = decimalPart.slice(0, -1);
44
+ while (decimalPart.endsWith("_")) {
45
+ decimalPart = decimalPart.slice(0, -1);
46
+ }
47
+ }
48
+ const fixed = decimalPart
49
+ ? `${floating.sign}${floating.intPart}.${decimalPart}${floating.expPart}`
50
+ : `${floating.sign}${floating.intPart || "0"}${floating.expPart}`;
51
+ context.report({
52
+ node,
53
+ messageId: "wrongZeros",
54
+ data: {
55
+ fixed,
56
+ },
57
+ fix(fixer) {
58
+ return fixer.replaceText(node, fixed);
59
+ },
60
+ });
61
+ },
62
+ };
63
+ },
64
+ });
65
+ function parseFloatingPoint(str) {
66
+ const parts = str.split(".");
67
+ if (parts.length !== 2) {
68
+ return null;
69
+ }
70
+ let decimalPart, expPart, intPart, sign;
71
+ const expIndex = parts[1].search(/e/iu);
72
+ if (expIndex >= 0) {
73
+ decimalPart = parts[1].slice(0, expIndex);
74
+ expPart = parts[1].slice(expIndex);
75
+ }
76
+ else {
77
+ decimalPart = parts[1];
78
+ expPart = "";
79
+ }
80
+ if (parts[0].startsWith("-") || parts[0].startsWith("+")) {
81
+ sign = parts[0][0];
82
+ intPart = parts[0].slice(1);
83
+ }
84
+ else {
85
+ sign = "";
86
+ intPart = parts[0];
87
+ }
88
+ return {
89
+ sign,
90
+ intPart,
91
+ decimalPart,
92
+ expPart,
93
+ };
94
+ }
@@ -24,6 +24,7 @@ const no_empty_sequence_entry_1 = __importDefault(require("../rules/no-empty-seq
24
24
  const no_irregular_whitespace_1 = __importDefault(require("../rules/no-irregular-whitespace"));
25
25
  const no_multiple_empty_lines_1 = __importDefault(require("../rules/no-multiple-empty-lines"));
26
26
  const no_tab_indent_1 = __importDefault(require("../rules/no-tab-indent"));
27
+ const no_trailing_zeros_1 = __importDefault(require("../rules/no-trailing-zeros"));
27
28
  const plain_scalar_1 = __importDefault(require("../rules/plain-scalar"));
28
29
  const quotes_1 = __importDefault(require("../rules/quotes"));
29
30
  const require_string_key_1 = __importDefault(require("../rules/require-string-key"));
@@ -52,6 +53,7 @@ exports.rules = [
52
53
  no_irregular_whitespace_1.default,
53
54
  no_multiple_empty_lines_1.default,
54
55
  no_tab_indent_1.default,
56
+ no_trailing_zeros_1.default,
55
57
  plain_scalar_1.default,
56
58
  quotes_1.default,
57
59
  require_string_key_1.default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-yml",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "This ESLint plugin provides linting rules for YAML.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -44,7 +44,8 @@
44
44
  "eslintplugin",
45
45
  "eslint-plugin",
46
46
  "yaml",
47
- "yml"
47
+ "yml",
48
+ "lint"
48
49
  ],
49
50
  "author": "Yosuke Ota",
50
51
  "funding": "https://github.com/sponsors/ota-meshi",
@@ -57,7 +58,7 @@
57
58
  "debug": "^4.3.2",
58
59
  "lodash": "^4.17.21",
59
60
  "natural-compare": "^1.4.0",
60
- "yaml-eslint-parser": "^1.1.0"
61
+ "yaml-eslint-parser": "^1.2.1"
61
62
  },
62
63
  "peerDependencies": {
63
64
  "eslint": ">=6.0.0"
@@ -98,16 +99,16 @@
98
99
  "eslint4b": "^7.3.1",
99
100
  "espree": "^9.0.0",
100
101
  "mocha": "^10.0.0",
101
- "monaco-editor": "^0.35.0",
102
+ "monaco-editor": "^0.38.0",
102
103
  "nyc": "^15.1.0",
103
104
  "prettier": "^2.2.1",
104
105
  "raw-loader": "^4.0.1",
105
106
  "semver": "^7.3.2",
106
107
  "stylelint": "^15.0.0",
107
108
  "stylelint-config-recommended-vue": "^1.0.0",
108
- "stylelint-config-standard": "^30.0.1",
109
+ "stylelint-config-standard": "^33.0.0",
109
110
  "stylelint-stylus": "^0.18.0",
110
- "typescript": "~4.9.0",
111
+ "typescript": "~5.0.0",
111
112
  "vue-eslint-editor": "^1.1.0",
112
113
  "vue-eslint-parser": "^9.0.0",
113
114
  "vuepress": "^1.5.2",