Sharkey/eslint/locale.test.js

34 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-10-16 13:01:54 +00:00
const {RuleTester} = require("eslint");
const localeRule = require("./locale");
const locale = { foo: { bar: 'ok', baz: 'good {x}' }, top: '123' };
const ruleTester = new RuleTester();
ruleTester.run(
'sharkey-locale',
localeRule,
{
valid: [
{code: 'i18n.ts.foo.bar', options: [locale] },
2024-10-16 14:56:48 +00:00
// we don't detect the problem here, but should still accept it
{code: 'i18n.ts.foo["something"]', options: [locale] },
2024-10-16 13:01:54 +00:00
{code: 'i18n.ts.top', options: [locale] },
2024-10-16 13:58:59 +00:00
{code: 'i18n.tsx.foo.baz({x:1})', options: [locale] },
2024-10-16 13:01:54 +00:00
{code: 'whatever.i18n.ts.blah.blah', options: [locale] },
{code: 'whatever.i18n.tsx.does.not.matter', options: [locale] },
2024-10-16 13:13:05 +00:00
{code: 'whatever(i18n.ts.foo.bar)', options: [locale] },
2024-10-16 13:01:54 +00:00
],
invalid: [
{code: 'i18n.ts.not', options: [locale], errors: 1 },
{code: 'i18n.tsx.deep.not', options: [locale], errors: 1 },
2024-10-16 13:58:59 +00:00
{code: 'i18n.tsx.deep.not({x:12})', options: [locale], errors: 1 },
{code: 'i18n.tsx.top({x:1})', options: [locale], errors: 1 },
2024-10-16 13:01:54 +00:00
{code: 'i18n.ts.foo.baz', options: [locale], errors: 1 },
{code: 'i18n.tsx.foo.baz', options: [locale], errors: 1 },
2024-10-16 13:58:59 +00:00
{code: 'i18n.tsx.foo.baz({y:2})', options: [locale], errors: 2 },
2024-10-16 13:01:54 +00:00
],
},
);