From ca618066b2fcd0db668ba17b70823fb1675c2395 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sun, 28 Jan 2018 16:34:38 +0900 Subject: [PATCH] Fix: vue/html-indent ignores `
` (fixes #365)

---
 lib/utils/indent-common.js     |  6 +++--
 tests/lib/rules/html-indent.js | 45 ++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js
index 704e8726c..c8719a98a 100644
--- a/lib/utils/indent-common.js
+++ b/lib/utils/indent-common.js
@@ -798,10 +798,12 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
 
     VElement (node) {
       const startTagToken = tokenStore.getFirstToken(node)
-      const childTokens = node.children.map(n => tokenStore.getFirstToken(n))
       const endTagToken = node.endTag && tokenStore.getFirstToken(node.endTag)
 
-      setOffset(childTokens, 1, startTagToken)
+      if (node.name !== 'pre') {
+        const childTokens = node.children.map(n => tokenStore.getFirstToken(n))
+        setOffset(childTokens, 1, startTagToken)
+      }
       setOffset(endTagToken, 0, startTagToken)
     },
 
diff --git a/tests/lib/rules/html-indent.js b/tests/lib/rules/html-indent.js
index e97aae5f2..b2f7ebe0b 100644
--- a/tests/lib/rules/html-indent.js
+++ b/tests/lib/rules/html-indent.js
@@ -230,6 +230,19 @@ tester.run('html-indent', rule, loadPatterns(
         // Ignore all :D
         ignores: ['*']
       }]
+    },
+
+    // Pre
+    {
+      code: unIndent`
+        
+      `
     }
   ],
 
@@ -480,6 +493,38 @@ tester.run('html-indent', rule, loadPatterns(
         { message: 'Expected indentation of 12 spaces but found 8 spaces.', line: 4 },
         { message: 'Expected indentation of 12 spaces but found 8 spaces.', line: 6 }
       ]
+    },
+
+    // Pre
+    {
+      code: unIndent`
+        
+      `,
+      output: unIndent`
+        
+      `,
+      errors: [
+        { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 2 },
+        { message: 'Expected indentation of 4 spaces but found 0 spaces.', line: 3 },
+        { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 4 },
+        { message: 'Expected indentation of 2 spaces but found 0 spaces.', line: 8 }
+      ]
     }
   ]
 ))