diff --git a/docs/rules/no-raw-text.md b/docs/rules/no-raw-text.md index 51883955..65f8dd68 100644 --- a/docs/rules/no-raw-text.md +++ b/docs/rules/no-raw-text.md @@ -29,11 +29,11 @@ This rule encourage i18n in about the application needs to be localized. ```js /* eslint @intlify/vue-i18n/no-raw-text: 'error' */ -export default { +export default Vue.extend({ // ✗ BAD template: '

hello

' // ... -} +}) ``` @@ -83,11 +83,11 @@ export default { ```js /* eslint @intlify/vue-i18n/no-raw-text: 'error' */ -export default { +export default Vue.extend({ // ✓ GOOD template: `

{{ \$t('hello') }}

` // ... -} +}) ``` diff --git a/lib/rules/no-raw-text.ts b/lib/rules/no-raw-text.ts index 4bdc4c47..b7624aba 100644 --- a/lib/rules/no-raw-text.ts +++ b/lib/rules/no-raw-text.ts @@ -2,68 +2,84 @@ * @author kazuya kawaguchi (a.k.a. kazupon) */ import { parse, AST as VAST } from 'vue-eslint-parser' -import { defineTemplateBodyVisitor, getVueObjectType } from '../utils/index' +import type { AST as JSONAST } from 'jsonc-eslint-parser' +import { parseJSON, getStaticJSONValue } from 'jsonc-eslint-parser' +import { + defineTemplateBodyVisitor, + getLocaleMessages, + getStaticAttributes, + getVueObjectType, + isI18nBlock, + isVElement +} from '../utils/index' import type { JSXText, RuleContext, + RuleFixer, Variable, RuleListener, - SourceLocation + SuggestionReportDescriptor, + Fix, + I18nLocaleMessageDictionary } from '../types' -type AnyValue = - | VAST.ESLintLiteral['value'] - | VAST.ESLintTemplateElement['value'] +type LiteralValue = VAST.ESLintLiteral['value'] +type StaticTemplateLiteral = VAST.ESLintTemplateLiteral & { + quasis: [VAST.ESLintTemplateElement] + expressions: [/* empty */] +} +type TemplateOptionValueNode = VAST.ESLintLiteral | StaticTemplateLiteral +type NodeScope = 'template' | 'template-option' | 'jsx' const config: { ignorePattern: RegExp ignoreNodes: string[] ignoreText: string[] } = { ignorePattern: /^[^\S\s]$/, ignoreNodes: [], ignoreText: [] } const hasOnlyWhitespace = (value: string) => /^[\r\n\s\t\f\v]+$/.test(value) -const hasTemplateElementValue = ( - value: AnyValue -): value is { raw: string; cooked: string } => - value != null && - typeof value === 'object' && - 'raw' in value && - typeof value.raw === 'string' && - 'cooked' in value && - typeof value.cooked === 'string' const INNER_START_OFFSET = '