Repository: vuejs/eslint-plugin-vue (JavaScript)

Issue:
vue/html-indent errors while using <textarea>
<!--
  ❗Please don't ignore this template.❗

  If you ignore it, we're just going to respond asking you to fill it out, which wastes everyone's time.
  The more relevant information you can include, the faster we can find the issue and fix it without asking you for more info.
-->

<!--
  Before posting the issue, please confirm that the problem you're getting
  is not related with your code editor configuration.
  To make sure it's not, run: yarn eslint src/your-file.vue
-->

**Checklist**

- [x] I have tried restarting my IDE and the issue persists.
- [x] I have read the [FAQ](https://eslint.vuejs.org/user-guide/#faq) and my problem is not listed.
<!-- If you do not read the FAQ and open an issue that is listed in the FAQ, we may silently close the issue. -->

**Tell us about your environment**

- **ESLint version:** 8.6.0
- **eslint-plugin-vue version:** 8.2.0
- **Node version:** 16.13.1
- **Operating System:** Ubuntu 20.04.3 

**Please show your full configuration:**
<!-- Paste content of your .eslintrc file -->
```js
module.exports = {
	"env": {
		"commonjs": true,
	},
	"extends": [
		"eslint:recommended",
		"plugin:vue/vue3-strongly-recommended"
	],
	"parserOptions": {
		"ecmaVersion": 13,
		"sourceType": "module"
	},
	"plugins": [
		"vue"
	],
	"rules": {
		"vue/html-indent": ["error", "tab"]
	}
};
```

**What did you do?**	
<!-- Please include the actual source code causing the issue. -->
```vue
<template>
	<textarea class="red">
		abc
</template>
```

**What did you expect to happen?**
Linting errors about missing a closing textarea tag

**What actually happened?**
<!--
  Please include the actual, raw output from ESLint.
  If you are only looking at the results of your editor extension, also check the CLI results.
-->
```
Oops! Something went wrong! :(

ESLint: 8.6.0

TypeError: Cannot read properties of null (reading 'range')
Occurred while linting /home/cheeze/repos/test-app/App.vue:1
Rule: "vue/html-indent"
    at TokenStore.getTokensBetween (/home/cheeze/repos/test-app/node_modules/vue-eslint-parser/index.js:4240:107)
    at setPreformattedTokens (/home/cheeze/repos/test-app/node_modules/eslint-plugin-vue/lib/utils/indent-common.js:314:36)
    at EventEmitter.VElement (/home/cheeze/repos/test-app/node_modules/eslint-plugin-vue/lib/utils/indent-common.js:971:9)
    at EventEmitter.emit (node:events:402:35)
    at NodeEventGenerator.applySelector (/home/cheeze/repos/test-app/node_modules/vue-eslint-parser/index.js:3826:26)
    at NodeEventGenerator.applySelectors (/home/cheeze/repos/test-app/node_modules/vue-eslint-parser/index.js:3840:22)
    at NodeEventGenerator.enterNode (/home/cheeze/repos/test-app/node_modules/vue-eslint-parser/index.js:3848:14)
    at traverse (/home/cheeze/repos/test-app/node_modules/vue-eslint-parser/index.js:117:13)
    at traverse (/home/cheeze/repos/test-app/node_modules/vue-eslint-parser/index.js:124:21)
    at traverseNodes (/home/cheeze/repos/test-app/node_modules/vue-eslint-parser/index.js:135:5)
```

**Repository to reproduce this issue**
<!--
  ❗ Please share a repository that can reproduce your issue.
  ❗ If you don't share it, we just label it as requesting a repository that can reproduce your issue.
  ❗ If you don't share it for a few days, we silently close this issue.
-->
[https://github.com/cheeze2000/eslint-vue-error](https://github.com/cheeze2000/eslint-vue-error)
To reproduce the error, `npm install` and `npm run lint`.



Discussion:
A more minimal `App.vue`:
```vue
<template>
	<textarea>
</template>
```

However, changing the `<textarea>` to other tags like `<p>` does not throw any error.
Thank you for posting this issue and providing repository to reproduce the issue.



Patch:
diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js
index d208d5a08..6897ea4e7 100644
--- a/lib/utils/indent-common.js
+++ b/lib/utils/indent-common.js
@@ -301,7 +301,7 @@ module.exports.defineVisitor = function create(
       tokenStore.getTokenAfter(node)
 
     /** @type {SourceCode.CursorWithSkipOptions} */
-    const option = {
+    const cursorOptions = {
       includeComments: true,
       filter: (token) =>
         token != null &&
@@ -311,11 +311,11 @@ module.exports.defineVisitor = function create(
           token.type === 'HTMLEndTagOpen' ||
           token.type === 'HTMLComment')
     }
-    for (const token of tokenStore.getTokensBetween(
-      node.startTag,
-      endToken,
-      option
-    )) {
+    const contentTokens = endToken
+      ? tokenStore.getTokensBetween(node.startTag, endToken, cursorOptions)
+      : tokenStore.getTokensAfter(node.startTag, cursorOptions)
+
+    for (const token of contentTokens) {
       ignoreTokens.add(token)
     }
     ignoreTokens.add(endToken)


Test patch:
diff --git a/tests/lib/rules/html-indent.js b/tests/lib/rules/html-indent.js
index 316eb9257..8340f9423 100644
--- a/tests/lib/rules/html-indent.js
+++ b/tests/lib/rules/html-indent.js
@@ -403,6 +403,22 @@ tester.run(
         text <span /> <!-- comment --></pre>
         </template>
       `
+      },
+      {
+        filename: 'test.vue',
+        code: unIndent`
+        <template>
+          <textarea>
+        </template>
+        `
+      },
+      {
+        filename: 'test.vue',
+        code: unIndent`
+        <template>
+          <pre>
+        </template>
+        `
       }
     ],
 
@@ -929,6 +945,25 @@ tester.run(
             line: 2
           }
         ]
+      },
+      {
+        filename: 'test.vue',
+        code: unIndent`
+        <template>
+            <textarea>
+        </template>
+        `,
+        output: unIndent`
+        <template>
+          <textarea>
+        </template>
+        `,
+        errors: [
+          {
+            message: 'Expected indentation of 2 spaces but found 4 spaces.',
+            line: 2
+          }
+        ]
       }
     ]
   )