Skip to content

Commit

Permalink
Fix false negatives when using parsers other than vue-eslint-parser i…
Browse files Browse the repository at this point in the history
…n no-missing-keys (#312)
  • Loading branch information
ota-meshi authored Apr 7, 2022
1 parent 69925e0 commit b43bb16
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/rules/no-missing-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import {
defineTemplateBodyVisitor,
getLocaleMessages,
getStaticLiteralValue,
isStaticLiteral
isStaticLiteral,
compositingVisitors
} from '../utils/index'
import type { AST as VAST } from 'vue-eslint-parser'
import type { RuleContext, RuleListener } from '../types'
import { createRule } from '../utils/rule'

function create(context: RuleContext): RuleListener {
return defineTemplateBodyVisitor(
context,
{
return compositingVisitors(
defineTemplateBodyVisitor(context, {
"VAttribute[directive=true][key.name='t']"(node: VAST.VDirective) {
checkDirective(context, node)
},
Expand All @@ -33,7 +33,7 @@ function create(context: RuleContext): RuleListener {
CallExpression(node: VAST.ESLintCallExpression) {
checkCallExpression(context, node)
}
},
}),
{
CallExpression(node: VAST.ESLintCallExpression) {
checkCallExpression(context, node)
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export function skipTSAsExpression<T extends VAST.Node>(node: T): T {
return node
}

function compositingVisitors(
export function compositingVisitors(
visitor: RuleListener,
...visitors: RuleListener[]
) {
Expand Down
9 changes: 8 additions & 1 deletion tests/lib/rules/no-missing-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ tester.run('no-missing-keys', rule as never, {
]
),

invalid: buildTestsForLocales(
invalid: buildTestsForLocales<RuleTester.InvalidTestCase>(
[
{
// basic
Expand Down Expand Up @@ -275,6 +275,13 @@ tester.run('no-missing-keys', rule as never, {
errors: [
`'messages.missing' does not exist in localization message resources`
]
},
{
parser: require.resolve('espree'),
code: `$t('messages.missing')`,
errors: [
`'messages.missing' does not exist in localization message resources`
]
}
],
[
Expand Down

0 comments on commit b43bb16

Please sign in to comment.