@html-eslint/eslint-plugin 0.15.0 → 0.16.0-alpha.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
@@ -2,9 +2,17 @@
2
2
 
3
3
  An ESLint plugin which provides lint rules for HTML.
4
4
 
5
- - [Getting Started](https://github.com/yeonjuan/html-eslint#Getting-Started)
6
- - [Installation](https://github.com/yeonjuan/html-eslint#Installation)
7
- - [Configuration](https://github.com/yeonjuan/html-eslint#Configuration)
8
- - [Recommended Configs](https://github.com/yeonjuan/html-eslint#Recommended-Configs)
9
- - [Rules](https://github.com/yeonjuan/html-eslint#Rules)
10
- - [License](https://github.com/yeonjuan/html-eslint#License)
5
+ 1. [Getting Started](https://yeonjuan.github.io/html-eslint/docs/getting-started)
6
+ - [Installation](https://yeonjuan.github.io/html-eslint/docs/getting-started#installation)
7
+ - [Configuration](https://yeonjuan.github.io/html-eslint/docs/getting-started#configuration)
8
+ - [Editor Configuration](https://yeonjuan.github.io/html-eslint/docs/getting-started#editor-configuration)
9
+ - [VSCode](https://yeonjuan.github.io/html-eslint/docs/getting-started#vscode)
10
+ 1. [Recommended Configs](https://yeonjuan.github.io/html-eslint/docs/getting-started#recommended-configs)
11
+ 1. [Rules](https://yeonjuan.github.io/html-eslint/docs/rules)
12
+ 1. [CLI](https://yeonjuan.github.io/html-eslint/docs/cli)
13
+ 1. [Playground](https://yeonjuan.github.io/html-eslint/playground)
14
+ 1. [License](#License)
15
+
16
+ ## License
17
+
18
+ Distributed under the MIT License.
@@ -8,6 +8,7 @@ const MESSAGE_IDS = {
8
8
  EXTRA_BETWEEN: "unexpectedBetween",
9
9
  EXTRA_AFTER: "unexpectedAfter",
10
10
  EXTRA_BEFORE: "unexpectedBefore",
11
+ MISSING_BEFORE: "missingBefore",
11
12
  MISSING_BEFORE_SELF_CLOSE: "missingBeforeSelfClose",
12
13
  EXTRA_BEFORE_SELF_CLOSE: "unexpectedBeforeSelfClose",
13
14
  };
@@ -30,6 +31,9 @@ module.exports = {
30
31
  {
31
32
  type: "object",
32
33
  properties: {
34
+ disallowMissing: {
35
+ type: "boolean",
36
+ },
33
37
  enforceBeforeSelfClose: {
34
38
  type: "boolean",
35
39
  },
@@ -44,11 +48,13 @@ module.exports = {
44
48
  "Missing space before self closing",
45
49
  [MESSAGE_IDS.EXTRA_BEFORE_SELF_CLOSE]:
46
50
  "Unexpected extra spaces before self closing",
51
+ [MESSAGE_IDS.MISSING_BEFORE]: "Missing space before attribute",
47
52
  },
48
53
  },
49
54
  create(context) {
50
55
  const enforceBeforeSelfClose = !!(context.options[0] || {})
51
56
  .enforceBeforeSelfClose;
57
+ const disallowMissing = !!(context.options[0] || {}).disallowMissing;
52
58
 
53
59
  function checkExtraSpacesBetweenAttrs(attrs) {
54
60
  attrs.forEach((current, index, attrs) => {
@@ -69,6 +75,14 @@ module.exports = {
69
75
  return fixer.removeRange([current.range[1] + 1, after.range[0]]);
70
76
  },
71
77
  });
78
+ } else if (disallowMissing && spacesBetween < 1) {
79
+ context.report({
80
+ loc: after.loc,
81
+ messageId: MESSAGE_IDS.MISSING_BEFORE,
82
+ fix(fixer) {
83
+ return fixer.insertTextAfter(current, " ");
84
+ },
85
+ });
72
86
  }
73
87
  });
74
88
  }
@@ -167,24 +181,25 @@ module.exports = {
167
181
  if (node.attributes.length) {
168
182
  checkExtraSpaceBefore(node.openStart, node.attributes[0]);
169
183
  }
170
-
171
- const isSelfClosing = node.openEnd.value === "/>";
172
-
173
- if (node.openEnd && node.attributes && node.attributes.length > 0) {
174
- checkExtraSpaceAfter(
175
- node.openEnd,
176
- node.attributes[node.attributes.length - 1],
177
- isSelfClosing
178
- );
179
- }
180
-
181
- checkExtraSpacesBetweenAttrs(node.attributes);
182
- if (
183
- node.attributes.length === 0 &&
184
- isSelfClosing &&
185
- enforceBeforeSelfClose
186
- ) {
187
- checkSpaceBeforeSelfClosing(node.openStart, node.openEnd);
184
+ if (node.openEnd) {
185
+ const isSelfClosing = node.openEnd.value === "/>";
186
+
187
+ if (node.attributes && node.attributes.length > 0) {
188
+ checkExtraSpaceAfter(
189
+ node.openEnd,
190
+ node.attributes[node.attributes.length - 1],
191
+ isSelfClosing
192
+ );
193
+ }
194
+
195
+ checkExtraSpacesBetweenAttrs(node.attributes);
196
+ if (
197
+ node.attributes.length === 0 &&
198
+ isSelfClosing &&
199
+ enforceBeforeSelfClose
200
+ ) {
201
+ checkSpaceBeforeSelfClosing(node.openStart, node.openEnd);
202
+ }
188
203
  }
189
204
  },
190
205
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@html-eslint/eslint-plugin",
3
- "version": "0.15.0",
3
+ "version": "0.16.0-alpha.0",
4
4
  "description": "ESLint plugin for html",
5
5
  "author": "yeonjuan",
6
6
  "homepage": "https://github.com/yeonjuan/html-eslint#readme",
@@ -40,11 +40,11 @@
40
40
  "accessibility"
41
41
  ],
42
42
  "devDependencies": {
43
- "@html-eslint/parser": "^0.15.0",
43
+ "@html-eslint/parser": "^0.16.0-alpha.0",
44
44
  "@types/eslint": "^7.2.10",
45
45
  "@types/estree": "^0.0.47",
46
46
  "es-html-parser": "^0.0.8",
47
47
  "typescript": "^4.4.4"
48
48
  },
49
- "gitHead": "9795f56dcf8662ba882555a35c9d3114927f2075"
49
+ "gitHead": "499a9a47682743426515af6ac26b8f4bab50e052"
50
50
  }