2024-10-23 03:24:19 +09:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: dakkar and other Sharkey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2024-10-16 22:01:54 +09:00
|
|
|
const {RuleTester} = require("eslint");
|
|
|
|
const localeRule = require("./locale");
|
|
|
|
|
|
|
|
const locale = { foo: { bar: 'ok', baz: 'good {x}' }, top: '123' };
|
|
|
|
|
2024-10-16 23:57:15 +09:00
|
|
|
const ruleTester = new RuleTester({
|
|
|
|
languageOptions: {
|
|
|
|
parser: require('vue-eslint-parser'),
|
|
|
|
ecmaVersion: 2015,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
function testCase(code,errors) {
|
|
|
|
return { code, errors, options: [ locale ], filename: 'test.ts' };
|
|
|
|
}
|
|
|
|
function testCaseVue(code,errors) {
|
|
|
|
return { code, errors, options: [ locale ], filename: 'test.vue' };
|
|
|
|
}
|
2024-10-16 22:01:54 +09:00
|
|
|
|
|
|
|
ruleTester.run(
|
|
|
|
'sharkey-locale',
|
|
|
|
localeRule,
|
|
|
|
{
|
|
|
|
valid: [
|
2024-10-16 23:57:15 +09:00
|
|
|
testCase('i18n.ts.foo.bar'),
|
|
|
|
testCase('i18n.ts.top'),
|
|
|
|
testCase('i18n.tsx.foo.baz({x:1})'),
|
|
|
|
testCase('whatever.i18n.ts.blah.blah'),
|
|
|
|
testCase('whatever.i18n.tsx.does.not.matter'),
|
|
|
|
testCase('whatever(i18n.ts.foo.bar)'),
|
|
|
|
testCaseVue('<template><p>{{ i18n.ts.foo.bar }}</p></template>'),
|
|
|
|
testCaseVue('<template><I18n :src="i18n.ts.foo.baz"/></template>'),
|
2024-10-17 18:35:14 +09:00
|
|
|
// we don't detect the problem here, but should still accept it
|
|
|
|
testCase('i18n.ts.foo["something"]'),
|
|
|
|
testCase('i18n.ts.foo[something]'),
|
2024-10-16 22:01:54 +09:00
|
|
|
],
|
|
|
|
invalid: [
|
2024-10-16 23:57:15 +09:00
|
|
|
testCase('i18n.ts.not', 1),
|
|
|
|
testCase('i18n.tsx.deep.not', 1),
|
|
|
|
testCase('i18n.tsx.deep.not({x:12})', 1),
|
|
|
|
testCase('i18n.tsx.top({x:1})', 1),
|
|
|
|
testCase('i18n.ts.foo.baz', 1),
|
|
|
|
testCase('i18n.tsx.foo.baz', 1),
|
|
|
|
testCase('i18n.tsx.foo.baz({y:2})', 2),
|
|
|
|
testCaseVue('<template><p>{{ i18n.ts.not }}</p></template>', 1),
|
|
|
|
testCaseVue('<template><I18n :src="i18n.ts.not"/></template>', 1),
|
2024-10-16 22:01:54 +09:00
|
|
|
],
|
|
|
|
},
|
|
|
|
);
|