@html-eslint/eslint-plugin 0.40.0-alpha.0 → 0.40.1

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.
@@ -2,6 +2,7 @@
2
2
  * @typedef { import("../types").RuleModule<[]> } RuleModule
3
3
  */
4
4
 
5
+ const { NodeTypes } = require("es-html-parser");
5
6
  const { RULE_CATEGORY } = require("../constants");
6
7
  const { findAttr } = require("./utils/node");
7
8
  const { createVisitors } = require("./utils/visitors");
@@ -252,6 +253,17 @@ module.exports = {
252
253
  if (!role) {
253
254
  return;
254
255
  }
256
+ /**
257
+ * Allow template expression.
258
+ * ex: html`<div role=${role}></div>`
259
+ */
260
+ if (
261
+ role.value &&
262
+ role.value.parts.some((part) => part.type === NodeTypes.Template)
263
+ ) {
264
+ return;
265
+ }
266
+
255
267
  const roleValue = (
256
268
  (role.value && role.value.value) ||
257
269
  ""
@@ -44,29 +44,32 @@ module.exports = {
44
44
  /**
45
45
  * @param {string} source
46
46
  * @param {string[]} lines
47
- * @param {number} rangeOffset
47
+ * @param {Object} offset
48
+ * @param {number} offset.range
49
+ * @param {number} offset.line
50
+ * @param {number} offset.column
48
51
  * @param {((CommentContent | Text)['parts'][number])[]} tokens
49
52
  */
50
- function check(source, lines, rangeOffset, tokens) {
51
- let rangeIndex = rangeOffset;
53
+ function check(source, lines, offset, tokens) {
52
54
  const lineBreaks = source.match(/\r\n|[\r\n\u2028\u2029]/gu);
55
+
53
56
  lines.forEach((line, index) => {
54
- const lineNumber = index + 1;
57
+ const lineNumber = index + offset.line;
55
58
  const match = line.match(/[ \t\u00a0\u2000-\u200b\u3000]+$/);
56
59
  const lineBreakLength =
57
60
  lineBreaks && lineBreaks[index] ? lineBreaks[index].length : 1;
58
61
  const lineLength = line.length + lineBreakLength;
59
-
62
+ const columnOffset = index === 0 ? offset.column : 0;
60
63
  if (match) {
61
64
  if (typeof match.index === "number" && match.index > 0) {
62
65
  const loc = {
63
66
  start: {
64
67
  line: lineNumber,
65
- column: match.index,
68
+ column: match.index + columnOffset,
66
69
  },
67
70
  end: {
68
71
  line: lineNumber,
69
- column: lineLength - lineBreakLength,
72
+ column: lineLength - lineBreakLength + columnOffset,
70
73
  },
71
74
  };
72
75
  const start = sourceCode.getIndexFromLoc(loc.start);
@@ -80,21 +83,26 @@ module.exports = {
80
83
  messageId: MESSAGE_IDS.TRAILING_SPACE,
81
84
  loc,
82
85
  fix(fixer) {
83
- return fixer.removeRange([
84
- rangeIndex + loc.start.column,
85
- rangeIndex + loc.end.column,
86
- ]);
86
+ return fixer.removeRange([start, end]);
87
87
  },
88
88
  });
89
89
  }
90
90
  }
91
- rangeIndex += lineLength;
92
91
  });
93
92
  }
94
93
 
95
94
  return {
96
95
  Document() {
97
- check(sourceCode.getText(), sourceCode.getLines(), 0, []);
96
+ check(
97
+ sourceCode.getText(),
98
+ sourceCode.getLines(),
99
+ {
100
+ range: 0,
101
+ line: 1,
102
+ column: 0,
103
+ },
104
+ []
105
+ );
98
106
  },
99
107
  TaggedTemplateExpression(node) {
100
108
  if (shouldCheckTaggedTemplateExpression(node, context)) {
@@ -107,8 +115,11 @@ module.exports = {
107
115
  check(
108
116
  html,
109
117
  lines,
110
- // @ts-ignore
111
- node.quasi.range[0] + 1,
118
+ {
119
+ range: node.quasi.range[0] + 1,
120
+ line: node.quasi.loc.start.line,
121
+ column: node.quasi.loc.start.column + 1,
122
+ },
112
123
  getTemplateTokens(tokens)
113
124
  );
114
125
  }
@@ -120,8 +131,11 @@ module.exports = {
120
131
  check(
121
132
  html,
122
133
  lines,
123
- // @ts-ignore
124
- node.range[0] + 1,
134
+ {
135
+ range: node.range[0] + 1,
136
+ line: node.loc.start.line,
137
+ column: node.loc.start.column + 1,
138
+ },
125
139
  getTemplateTokens(tokens)
126
140
  );
127
141
  }
@@ -9,6 +9,7 @@
9
9
  * @typedef { import("../types").RuleModule<[Option]> } RuleModule
10
10
  */
11
11
 
12
+ const { NodeTypes } = require("es-html-parser");
12
13
  const { RULE_CATEGORY } = require("../constants");
13
14
  const { getSourceCode } = require("./utils/source-code");
14
15
  const { createVisitors } = require("./utils/visitors");
@@ -87,6 +88,13 @@ module.exports = {
87
88
  if (!attr.value || attr.value.value.includes(expectedQuote)) {
88
89
  return;
89
90
  }
91
+ /**
92
+ * Allow template expression.
93
+ * ex: html`<div foo=${foo}></div>`
94
+ */
95
+ if (attr.value.parts.some((part) => part.type === NodeTypes.Template)) {
96
+ return;
97
+ }
90
98
 
91
99
  if (attr.startWrapper && attr.endWrapper) {
92
100
  const [opening, closing] = getQuotes(attr);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@html-eslint/eslint-plugin",
3
- "version": "0.40.0-alpha.0",
3
+ "version": "0.40.1",
4
4
  "description": "ESLint plugin for html",
5
5
  "author": "yeonjuan",
6
6
  "homepage": "https://github.com/yeonjuan/html-eslint#readme",
@@ -39,13 +39,13 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "@eslint/plugin-kit": "0.2.8",
42
- "@html-eslint/template-parser": "^0.40.0-alpha.0",
43
- "@html-eslint/template-syntax-parser": "^0.40.0-alpha.0"
42
+ "@html-eslint/template-parser": "^0.40.0",
43
+ "@html-eslint/template-syntax-parser": "^0.40.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@eslint/core": "0.13.0",
47
- "@html-eslint/parser": "^0.40.0-alpha.0",
48
- "@html-eslint/types": "^0.40.0-alpha.0",
47
+ "@html-eslint/parser": "^0.40.0",
48
+ "@html-eslint/types": "^0.40.0",
49
49
  "@types/eslint": "^9.6.1",
50
50
  "@types/estree": "^0.0.47",
51
51
  "es-html-parser": "0.2.0",
@@ -53,5 +53,5 @@
53
53
  "espree": "^10.3.0",
54
54
  "typescript": "^5.7.2"
55
55
  },
56
- "gitHead": "f62545e1268c688f79026b078fcdc013aa4a462d"
56
+ "gitHead": "595b1231bd0876792b229170edaecd4a7239d7fb"
57
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"no-invalid-role.d.ts","sourceRoot":"","sources":["../../lib/rules/no-invalid-role.js"],"names":[],"mappings":";;;wBAkOU,UAAU;;kBAjON,OAAO,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC"}
1
+ {"version":3,"file":"no-invalid-role.d.ts","sourceRoot":"","sources":["../../lib/rules/no-invalid-role.js"],"names":[],"mappings":";;;wBAmOU,UAAU;;kBAlON,OAAO,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"quotes.d.ts","sourceRoot":"","sources":["../../lib/rules/quotes.js"],"names":[],"mappings":";;;wBA4BU,UAAU;;aA3BN,OAAO,QAAQ,EAAE,GAAG,CAAC,KAAK;iBAC1B,OAAO,oBAAoB,EAAE,SAAS;WACtC,OAAO,oBAAoB,EAAE,GAAG;iBAChC,OAAO,oBAAoB,EAAE,SAAS;gBACtC,OAAO,oBAAoB,EAAE,QAAQ;cAEtC,QAAQ,GAAG,QAAQ;kBAClB,OAAO,UAAU,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"quotes.d.ts","sourceRoot":"","sources":["../../lib/rules/quotes.js"],"names":[],"mappings":";;;wBA6BU,UAAU;;aA5BN,OAAO,QAAQ,EAAE,GAAG,CAAC,KAAK;iBAC1B,OAAO,oBAAoB,EAAE,SAAS;WACtC,OAAO,oBAAoB,EAAE,GAAG;iBAChC,OAAO,oBAAoB,EAAE,SAAS;gBACtC,OAAO,oBAAoB,EAAE,QAAQ;cAEtC,QAAQ,GAAG,QAAQ;kBAClB,OAAO,UAAU,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC"}