From 7daa45137323f82634e9fce94313f7e63244597e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sajn=C3=B3g?= Date: Thu, 2 Aug 2018 16:24:01 +0200 Subject: [PATCH] Ignore indent rules on files other than .vue --- lib/utils/indent-common.js | 2 + .../fixtures/script-indent/if-statement-04.js | 4 - .../script-indent/if-statement-04.vue | 7 + .../fixtures/script-indent/if-statement-05.js | 6 - .../script-indent/opts-baseindent1.js | 16 -- tests/lib/rules/html-indent.js | 242 +++++++++++------- tests/lib/rules/script-indent.js | 92 ++++--- 7 files changed, 215 insertions(+), 154 deletions(-) delete mode 100644 tests/fixtures/script-indent/if-statement-04.js create mode 100644 tests/fixtures/script-indent/if-statement-04.vue delete mode 100644 tests/fixtures/script-indent/if-statement-05.js delete mode 100644 tests/fixtures/script-indent/opts-baseindent1.js diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js index afef755f5..a4dee6f21 100644 --- a/lib/utils/indent-common.js +++ b/lib/utils/indent-common.js @@ -269,6 +269,8 @@ function isTrivialToken (token) { * @returns {object} AST event handlers. */ module.exports.defineVisitor = function create (context, tokenStore, defaultOptions) { + if (!context.getFilename().endsWith('.vue')) return {} + const options = parseOptions(context.options[0], context.options[1] || {}, defaultOptions) const sourceCode = context.getSourceCode() const offsets = new Map() diff --git a/tests/fixtures/script-indent/if-statement-04.js b/tests/fixtures/script-indent/if-statement-04.js deleted file mode 100644 index 41831505e..000000000 --- a/tests/fixtures/script-indent/if-statement-04.js +++ /dev/null @@ -1,4 +0,0 @@ -/*{}*/ -if (a) - b; -c diff --git a/tests/fixtures/script-indent/if-statement-04.vue b/tests/fixtures/script-indent/if-statement-04.vue new file mode 100644 index 000000000..e6ba11eb4 --- /dev/null +++ b/tests/fixtures/script-indent/if-statement-04.vue @@ -0,0 +1,7 @@ + + + diff --git a/tests/fixtures/script-indent/if-statement-05.js b/tests/fixtures/script-indent/if-statement-05.js deleted file mode 100644 index 4e9af67f4..000000000 --- a/tests/fixtures/script-indent/if-statement-05.js +++ /dev/null @@ -1,6 +0,0 @@ -/*{}*/ -function wrap() { - if (x) - this.doSomething(); - foo -} diff --git a/tests/fixtures/script-indent/opts-baseindent1.js b/tests/fixtures/script-indent/opts-baseindent1.js deleted file mode 100644 index e5456c834..000000000 --- a/tests/fixtures/script-indent/opts-baseindent1.js +++ /dev/null @@ -1,16 +0,0 @@ -/*{"options":[2,{"baseIndent":1}]}*/ -var aaa = { - test: 1 -} -var bbb = { - test: 1 - }, - ccc = { - test: 1 - } -const ddd = { - test: 1 - }, - eee = (a) => { - foo(a) - } diff --git a/tests/lib/rules/html-indent.js b/tests/lib/rules/html-indent.js index b2f7ebe0b..a0613009a 100644 --- a/tests/lib/rules/html-indent.js +++ b/tests/lib/rules/html-indent.js @@ -108,114 +108,151 @@ tester.run('html-indent', rule, loadPatterns( // Valid [ // TemplateLiteral - unIndent` - - `, + test + \` + " + > + + ` + }, // VAttribute - unIndent` - - `, + { + filename: 'test.vue', + code: unIndent` + + ` + }, // Comments - unIndent` - - `, - unIndent` - - `, - unIndent` -