From 84f37b8dded6f9c85c5489cb98435b30af3f77f4 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 22 Jul 2019 18:29:53 +0900 Subject: [PATCH] :bug: bug(rule): fix cannot detect raw text of template syntax expression closes #23 --- lib/rules/no-raw-text.js | 48 ++++++++++++++++++++++++++ tests/lib/rules/no-raw-text.js | 62 ++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/lib/rules/no-raw-text.js b/lib/rules/no-raw-text.js index 378bdbf8..f34333c0 100644 --- a/lib/rules/no-raw-text.js +++ b/lib/rules/no-raw-text.js @@ -7,6 +7,48 @@ const { parse, AST } = require('vue-eslint-parser') const { defineTemplateBodyVisitor } = require('../utils/index') const hasOnlyLineBreak = value => /^[\r\n\t\f\v]+$/.test(value.replace(/ /g, '')) +const INNER_START_OFFSET = '` + }, { + code: ` + + ` }, { filename: 'test.vue', code: ` @@ -85,6 +91,38 @@ tester.run('no-raw-text', rule, { }, { message: `raw text '!' is used`, line: 5 }] + }, { + // directly specify string literal in mustache + code: ` + + `, + errors: [{ + message: `raw text 'hello' is used`, line: 3 + }] + }, { + // javascript expression specify string literal in mustache + code: ` + + `, + errors: [{ + message: `raw text 'hello' is used`, line: 3 + }, { + message: `raw text 'world' is used`, line: 3 + }] + }, { + // directly specify string literal in v-text + code: ` + + `, + errors: [{ + message: `raw text 'hello' is used`, line: 3 + }] }, { // directly specify string literal to `template` component option at export default object code: ` @@ -116,6 +154,30 @@ tester.run('no-raw-text', rule, { errors: [{ message: `raw text 'hello' is used`, line: 2 }] + }, { + // directly specify string literal to `template` variable + code: ` + const template = '

{{ "hello" }}

' + const Component = { + template + } + `, + errors: [{ + message: `raw text 'hello' is used`, line: 2, column: 30 + }] + }, { + // javascript expression specify string literal to `template` variable in mustache + code: ` + const template = '

{{ ok ? "hello" : "world" }}

' + const Component = { + template + } + `, + errors: [{ + message: `raw text 'hello' is used`, line: 2, column: 35 + }, { + message: `raw text 'world' is used`, line: 2, column: 45 + }] }, { // directly specify string literal to JSX with `render` code: `