eslint-plugin-yml 0.11.0 → 0.12.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
@@ -188,6 +188,7 @@ The rules with the following star :star: are included in the config.
188
188
  | [yml/flow-sequence-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-yml/rules/flow-sequence-bracket-spacing.html) | enforce consistent spacing inside flow sequence brackets | :wrench: | | :star: |
189
189
  | [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: |
190
190
  | [yml/no-irregular-whitespace](https://ota-meshi.github.io/eslint-plugin-yml/rules/no-irregular-whitespace.html) | disallow irregular whitespace | | :star: | :star: |
191
+ | [yml/no-multiple-empty-lines](https://ota-meshi.github.io/eslint-plugin-yml/rules/no-multiple-empty-lines.html) | disallow multiple empty lines | :wrench: | | |
191
192
  | [yml/sort-keys](https://ota-meshi.github.io/eslint-plugin-yml/rules/sort-keys.html) | require mapping keys to be sorted | :wrench: | | |
192
193
  | [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: |
193
194
 
@@ -9,6 +9,7 @@ declare const _default: {
9
9
  "yml/flow-sequence-bracket-spacing": string;
10
10
  "yml/indent": string;
11
11
  "yml/key-spacing": string;
12
+ "yml/no-multiple-empty-lines": string;
12
13
  "yml/quotes": string;
13
14
  };
14
15
  };
@@ -16,6 +16,7 @@ module.exports = {
16
16
  "yml/flow-sequence-bracket-spacing": "off",
17
17
  "yml/indent": "off",
18
18
  "yml/key-spacing": "off",
19
+ "yml/no-multiple-empty-lines": "off",
19
20
  "yml/quotes": "off",
20
21
  },
21
22
  };
package/lib/index.d.ts CHANGED
@@ -60,6 +60,7 @@ declare const _default: {
60
60
  "yml/flow-sequence-bracket-spacing": string;
61
61
  "yml/indent": string;
62
62
  "yml/key-spacing": string;
63
+ "yml/no-multiple-empty-lines": string;
63
64
  "yml/quotes": string;
64
65
  };
65
66
  };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").RuleModule;
2
+ export default _default;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../utils");
4
+ exports.default = (0, utils_1.createRule)("no-multiple-empty-lines", {
5
+ meta: {
6
+ docs: {
7
+ description: "disallow multiple empty lines",
8
+ categories: null,
9
+ extensionRule: "no-multiple-empty-lines",
10
+ layout: true,
11
+ },
12
+ fixable: "whitespace",
13
+ schema: [
14
+ {
15
+ type: "object",
16
+ properties: {
17
+ max: {
18
+ type: "integer",
19
+ minimum: 0,
20
+ },
21
+ maxEOF: {
22
+ type: "integer",
23
+ minimum: 0,
24
+ },
25
+ maxBOF: {
26
+ type: "integer",
27
+ minimum: 0,
28
+ },
29
+ },
30
+ required: ["max"],
31
+ additionalProperties: false,
32
+ },
33
+ ],
34
+ messages: {
35
+ blankBeginningOfFile: "Too many blank lines at the beginning of file. Max of {{max}} allowed.",
36
+ blankEndOfFile: "Too many blank lines at the end of file. Max of {{max}} allowed.",
37
+ consecutiveBlank: "More than {{max}} blank {{pluralizedLines}} not allowed.",
38
+ },
39
+ type: "layout",
40
+ },
41
+ create(context) {
42
+ var _a, _b, _c, _d, _e, _f;
43
+ if (!context.parserServices.isYAML) {
44
+ return {};
45
+ }
46
+ const maxOption = (_b = (_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.max) !== null && _b !== void 0 ? _b : 2;
47
+ const options = {
48
+ max: maxOption,
49
+ maxEOF: (_d = (_c = context.options[0]) === null || _c === void 0 ? void 0 : _c.maxEOF) !== null && _d !== void 0 ? _d : maxOption,
50
+ maxBOF: (_f = (_e = context.options[0]) === null || _e === void 0 ? void 0 : _e.maxBOF) !== null && _f !== void 0 ? _f : maxOption,
51
+ };
52
+ const sourceCode = context.getSourceCode();
53
+ const allLines = [...sourceCode.lines];
54
+ if (allLines[allLines.length - 1] === "") {
55
+ allLines.pop();
56
+ }
57
+ const ignoreLineIndexes = new Set();
58
+ function verifyEmptyLines(startLineIndex, endLineIndex) {
59
+ const emptyLineCount = endLineIndex - startLineIndex;
60
+ let messageId, max;
61
+ if (startLineIndex === 0) {
62
+ messageId = "blankBeginningOfFile";
63
+ max = options.maxBOF;
64
+ }
65
+ else if (endLineIndex === allLines.length) {
66
+ messageId = "blankEndOfFile";
67
+ max = options.maxEOF;
68
+ }
69
+ else {
70
+ messageId = "consecutiveBlank";
71
+ max = options.max;
72
+ }
73
+ if (emptyLineCount > max) {
74
+ context.report({
75
+ loc: {
76
+ start: {
77
+ line: startLineIndex + max + 1,
78
+ column: 0,
79
+ },
80
+ end: { line: endLineIndex + 1, column: 0 },
81
+ },
82
+ messageId,
83
+ data: {
84
+ max: String(max),
85
+ pluralizedLines: max === 1 ? "line" : "lines",
86
+ },
87
+ fix(fixer) {
88
+ const rangeStart = sourceCode.getIndexFromLoc({
89
+ line: startLineIndex + max + 1,
90
+ column: 0,
91
+ });
92
+ const rangeEnd = endLineIndex < allLines.length
93
+ ? sourceCode.getIndexFromLoc({
94
+ line: endLineIndex + 1,
95
+ column: 0,
96
+ })
97
+ : sourceCode.text.length;
98
+ return fixer.removeRange([rangeStart, rangeEnd]);
99
+ },
100
+ });
101
+ }
102
+ }
103
+ return {
104
+ YAMLScalar(node) {
105
+ for (let lineIndex = node.loc.start.line - 1; lineIndex < node.loc.end.line; lineIndex++) {
106
+ ignoreLineIndexes.add(lineIndex);
107
+ }
108
+ },
109
+ "Program:exit"() {
110
+ let startEmptyLineIndex = null;
111
+ for (let lineIndex = 0; lineIndex < allLines.length; lineIndex++) {
112
+ const line = allLines[lineIndex];
113
+ const isEmptyLine = !line.trim() && !ignoreLineIndexes.has(lineIndex);
114
+ if (isEmptyLine) {
115
+ startEmptyLineIndex !== null && startEmptyLineIndex !== void 0 ? startEmptyLineIndex : (startEmptyLineIndex = lineIndex);
116
+ }
117
+ else {
118
+ if (startEmptyLineIndex != null) {
119
+ verifyEmptyLines(startEmptyLineIndex, lineIndex);
120
+ }
121
+ startEmptyLineIndex = null;
122
+ }
123
+ }
124
+ if (startEmptyLineIndex != null) {
125
+ verifyEmptyLines(startEmptyLineIndex, allLines.length);
126
+ }
127
+ },
128
+ };
129
+ },
130
+ });
@@ -20,6 +20,7 @@ const no_empty_key_1 = __importDefault(require("../rules/no-empty-key"));
20
20
  const no_empty_mapping_value_1 = __importDefault(require("../rules/no-empty-mapping-value"));
21
21
  const no_empty_sequence_entry_1 = __importDefault(require("../rules/no-empty-sequence-entry"));
22
22
  const no_irregular_whitespace_1 = __importDefault(require("../rules/no-irregular-whitespace"));
23
+ const no_multiple_empty_lines_1 = __importDefault(require("../rules/no-multiple-empty-lines"));
23
24
  const no_tab_indent_1 = __importDefault(require("../rules/no-tab-indent"));
24
25
  const plain_scalar_1 = __importDefault(require("../rules/plain-scalar"));
25
26
  const quotes_1 = __importDefault(require("../rules/quotes"));
@@ -44,6 +45,7 @@ exports.rules = [
44
45
  no_empty_mapping_value_1.default,
45
46
  no_empty_sequence_entry_1.default,
46
47
  no_irregular_whitespace_1.default,
48
+ no_multiple_empty_lines_1.default,
47
49
  no_tab_indent_1.default,
48
50
  plain_scalar_1.default,
49
51
  quotes_1.default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-yml",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "This ESLint plugin provides linting rules for YAML.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -59,7 +59,7 @@
59
59
  "devDependencies": {
60
60
  "@ota-meshi/eslint-plugin": "^0.10.0",
61
61
  "@types/debug": "^4.1.5",
62
- "@types/eslint": "^7.2.0",
62
+ "@types/eslint": "^8.0.0",
63
63
  "@types/eslint-scope": "^3.7.0",
64
64
  "@types/eslint-visitor-keys": "^1.0.0",
65
65
  "@types/estree": "^0.0.50",
@@ -84,7 +84,7 @@
84
84
  "eslint-plugin-prettier": "^4.0.0",
85
85
  "eslint-plugin-regexp": "^1.0.0",
86
86
  "eslint-plugin-vue": "^8.0.0",
87
- "eslint-plugin-yml": "^0.10.0",
87
+ "eslint-plugin-yml": "^0.11.0",
88
88
  "eslint4b": "^7.3.1",
89
89
  "espree": "^9.0.0",
90
90
  "mocha": "^9.0.0",
@@ -95,10 +95,10 @@
95
95
  "semver": "^7.3.2",
96
96
  "stylelint": "^14.0.0",
97
97
  "stylelint-config-recommended-vue": "^1.0.0",
98
- "stylelint-config-standard": "^23.0.0",
98
+ "stylelint-config-standard": "^24.0.0",
99
99
  "stylelint-plugin-stylus": "^0.13.0",
100
100
  "ts-node": "^10.0.0",
101
- "typescript": "~4.4.3",
101
+ "typescript": "~4.5.0",
102
102
  "vue-eslint-editor": "^1.1.0",
103
103
  "vue-eslint-parser": "^8.0.0",
104
104
  "vuepress": "^1.5.2"