@html-eslint/eslint-plugin 0.13.1 → 0.13.2

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.
@@ -12,7 +12,6 @@
12
12
  * @typedef {Object} MessageId
13
13
  * @property {"wrongIndent"} WRONG_INDENT
14
14
  */
15
-
16
15
  const { RULE_CATEGORY, NODE_TYPES } = require("../constants");
17
16
  const { NodeUtils } = require("./utils");
18
17
 
@@ -68,18 +67,33 @@ module.exports = {
68
67
  },
69
68
  create(context) {
70
69
  const sourceCode = context.getSourceCode();
70
+
71
71
  const indentLevel = new IndentLevel();
72
72
  const { indentType, indentSize } = getIndentTypeAndSize(context.options);
73
73
  const indentUnit =
74
74
  indentType === INDENT_TYPES.SPACE ? " ".repeat(indentSize) : "\t";
75
75
 
76
+ /**
77
+ * @param {string} str
78
+ */
79
+ function countIndentSize(str) {
80
+ return str.length - str.replace(/^[\s\t]+/, "").length;
81
+ }
82
+
76
83
  /**
77
84
  * @param {BaseNode} node
78
85
  */
79
86
  function getLineCodeBefore(node) {
80
- return sourceCode.text
81
- .slice(node.range[0] - node.loc.start.column, node.range[0])
82
- .replace("\n", "");
87
+ const lines = sourceCode.getLines();
88
+ const line = lines[node.loc.start.line - 1];
89
+ let end = node.loc.start.column;
90
+ // @ts-ignore
91
+ if (typeof node.textLine === "string") {
92
+ // @ts-ignore
93
+ end += countIndentSize(node.textLine);
94
+ }
95
+
96
+ return line.slice(0, end);
83
97
  }
84
98
 
85
99
  /**
@@ -120,10 +134,13 @@ module.exports = {
120
134
  actual,
121
135
  },
122
136
  fix(fixer) {
123
- return fixer.replaceTextRange(
124
- [node.range[0] - (node.loc.start.column - 1), node.range[0]],
125
- expectedIndent
126
- );
137
+ const start = node.range[0] - node.loc.start.column;
138
+ let end = node.range[0];
139
+ // @ts-ignore
140
+ if (node.textLine) {
141
+ end += codeBefore.length;
142
+ }
143
+ return fixer.replaceTextRange([start, end], expectedIndent);
127
144
  },
128
145
  });
129
146
  }
@@ -143,7 +160,7 @@ module.exports = {
143
160
  }
144
161
 
145
162
  /**
146
- * @param {AnyNode} startTag
163
+ * @param {BaseNode} startTag
147
164
  */
148
165
  function checkEndOfStartTag(startTag) {
149
166
  const start = startTag.range[1] - 1;
@@ -207,7 +224,7 @@ module.exports = {
207
224
  }
208
225
  node.lineNodes.forEach((lineNode) => {
209
226
  if (lineNode.textLine.trim().length) {
210
- checkIndent(lineNode, node);
227
+ checkIndent(lineNode);
211
228
  }
212
229
  });
213
230
  if (!node.startTag) {
@@ -96,6 +96,10 @@ module.exports = {
96
96
  * @param {AttrNode} attr
97
97
  */
98
98
  function checkQuotes(attr) {
99
+ if (attr.value.includes(expectedQuote)) {
100
+ return;
101
+ }
102
+
99
103
  const [opening, closing] = getQuotes(attr);
100
104
  if (QUOTES_CODES.includes(opening)) {
101
105
  if (opening === closing && opening !== expectedQuote) {
@@ -16,7 +16,7 @@ module.exports = {
16
16
  type: "code",
17
17
 
18
18
  docs: {
19
- description: 'Enforce to use `<meta name="chartset">` in `<head>`',
19
+ description: 'Enforce to use `<meta charset="...">` in `<head>`',
20
20
  category: RULE_CATEGORY.BEST_PRACTICE,
21
21
  recommended: false,
22
22
  },
@@ -24,7 +24,7 @@ module.exports = {
24
24
  fixable: null,
25
25
  schema: [],
26
26
  messages: {
27
- [MESSAGE_IDS.MISSING]: 'Missing `<meta name="description">`.',
27
+ [MESSAGE_IDS.MISSING]: 'Missing `<meta charset="...">`.',
28
28
  [MESSAGE_IDS.EMPTY]: "Unexpected empty charset.",
29
29
  },
30
30
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@html-eslint/eslint-plugin",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "ESLint plugin for html",
5
5
  "author": "yeonjuan",
6
6
  "homepage": "https://github.com/yeonjuan/html-eslint#readme",
@@ -40,10 +40,10 @@
40
40
  "accessibility"
41
41
  ],
42
42
  "devDependencies": {
43
- "@html-eslint/parser": "^0.13.1",
43
+ "@html-eslint/parser": "^0.13.2",
44
44
  "@types/eslint": "^7.2.10",
45
45
  "@types/estree": "^0.0.47",
46
46
  "typescript": "^4.4.4"
47
47
  },
48
- "gitHead": "1df1923b655563738947e88da159f8f772f94265"
48
+ "gitHead": "3f1599284d5725db38e0984ecdcd283a76a530fa"
49
49
  }