Skip to content

Commit bfaf8ab

Browse files
committed
✅ test: add tests
1 parent 1789aca commit bfaf8ab

File tree

16 files changed

+183
-38
lines changed

16 files changed

+183
-38
lines changed

lib/rules/no-missing-keys.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'use strict'
55

66
const {
7+
UNEXPETECD_ERROR_LOCATION,
78
defineTemplateBodyVisitor,
89
loadLocaleMessages,
910
findMissingsFromLocaleMessages
@@ -13,6 +14,14 @@ let localeMessages = null // cache
1314

1415
function create (context) {
1516
const { settings } = context
17+
if (!settings['vue-i18n'] || !settings['vue-i18n'].localeDir) {
18+
context.report({
19+
loc: UNEXPETECD_ERROR_LOCATION,
20+
message: `You need to 'localeDir' at 'settings. See the 'eslint-plugin-vue-i18n documentation`
21+
})
22+
return {}
23+
}
24+
1625
const localeDir = settings['vue-i18n'].localeDir
1726
localeMessages = localeMessages || loadLocaleMessages(localeDir)
1827

lib/utils/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
const glob = require('glob')
88
const { resolve } = require('path')
99

10+
const UNEXPETECD_ERROR_LOCATION = { line: 1, column: 0 }
11+
1012
/**
1113
* Register the given visitor to parser services.
1214
* Borrow from GitHub `vuejs/eslint-plugin-vue` repo
@@ -15,7 +17,7 @@ const { resolve } = require('path')
1517
function defineTemplateBodyVisitor (context, templateBodyVisitor, scriptVisitor) {
1618
if (context.parserServices.defineTemplateBodyVisitor === null) {
1719
context.report({
18-
loc: { line: 1, column: 0 },
20+
loc: UNEXPETECD_ERROR_LOCATION,
1921
message: 'Use the latest vue-eslint-parser. See also https://github.com/vuejs/eslint-plugin-vue#what-is-the-use-the-latest-vue-eslint-parser-error'
2022
})
2123
return {}
@@ -55,6 +57,7 @@ function findMissingsFromLocaleMessages (localeMessages, key) {
5557
}
5658

5759
module.exports = {
60+
UNEXPETECD_ERROR_LOCATION,
5861
defineTemplateBodyVisitor,
5962
loadLocaleMessages,
6063
findMissingsFromLocaleMessages
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"hello": "hello world",
3+
"messages": {
4+
"hello": "hi DIO!",
5+
"link": "@:message.hello",
6+
"nested": {
7+
"hello": "hi jojo!"
8+
}
9+
},
10+
"hello_dio": "hello underscore DIO!",
11+
"hello {name}": "hello {name}!",
12+
"hello-dio": "hello hyphen DIO!"
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"hello": "ハローワールド",
3+
"messages": {
4+
"hello": "こんにちは、DIO!",
5+
"link": "@:message.hello",
6+
"nested": {
7+
"hello": "こんにちは、ジョジョ!"
8+
}
9+
},
10+
"hello_dio": "こんにちは、アンダースコア DIO!",
11+
"hello {name}": "こんにちは、{name}!",
12+
"hello-dio": "こんにちは、ハイフン DIO!"
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div id="app">
3+
<p v-t="'hello_dio'">{{ $t('messages.hello') }}</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'App',
10+
created () {
11+
this.$i18n.t('hello {name}', { name: 'DIO' })
12+
}
13+
}
14+
</script>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const $t = () => {}
2+
$t('hello')

0 commit comments

Comments
 (0)