diff --git a/.eslintignore b/.eslintignore
index f8b4a50d08..e58be97cba 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -12,6 +12,7 @@ packages/lqip-loader/lib/
packages/docusaurus/lib/
packages/docusaurus-*/lib/*
packages/docusaurus-*/lib-next/
+packages/eslint-plugin/lib/
packages/stylelint-copyright/lib/
copyUntypedFiles.mjs
diff --git a/.eslintrc.js b/.eslintrc.js
index 110a6d6886..d8b7a4584e 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -316,7 +316,7 @@ module.exports = {
'@docusaurus/no-untranslated-text': [
WARNING,
{
- ignoreStrings: [
+ ignoredStrings: [
'·',
'-',
'—',
diff --git a/.gitignore b/.gitignore
index 29b717df7f..0e0bd14648 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,7 @@ packages/create-docusaurus/lib/
packages/lqip-loader/lib/
packages/docusaurus/lib/
packages/docusaurus-*/lib/*
+packages/eslint-plugin/lib/
packages/stylelint-copyright/lib/
packages/docusaurus-*/lib-next/
diff --git a/.prettierignore b/.prettierignore
index 98de3b0f4a..c7aec4e026 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -10,6 +10,7 @@ packages/docusaurus-*/lib/*
packages/docusaurus-*/lib-next/
packages/create-docusaurus/lib/*
packages/create-docusaurus/templates/*/docusaurus.config.js
+packages/eslint-plugin/lib/
packages/stylelint-copyright/lib/
__fixtures__
diff --git a/packages/docusaurus-theme-common/src/components/Details/index.tsx b/packages/docusaurus-theme-common/src/components/Details/index.tsx
index 5288622062..0936ccf9db 100644
--- a/packages/docusaurus-theme-common/src/components/Details/index.tsx
+++ b/packages/docusaurus-theme-common/src/components/Details/index.tsx
@@ -91,6 +91,7 @@ export function Details({
// setOpen(false);
}
}}>
+ {/* eslint-disable-next-line @docusaurus/no-untranslated-text */}
{summary || Details}
- !isParentFragment &&
- child.parent.openingElement.name.name === 'Translate';
-
- const isChildValid = ({child, isParentFragment}) => {
- if (!isTextLabelChild({child, ignoreWhitespace: true, stringsToIgnore})) {
- return true;
- }
- return isParentTranslate({child, isParentFragment});
- };
-
- const isNodeValid = ({node, isFragment = false} = {}) =>
- node.children.every((child) =>
- isChildValid({child, isParentFragment: isFragment}),
- );
-
- return {
- 'JSXElement[openingElement.selfClosing=false]': (node) => {
- if (!isNodeValid({node})) {
- report(context, node, 'translateChildren');
- }
- },
- 'JSXFragment[openingFragment]': (node) => {
- if (!isNodeValid({node, isFragment: true})) {
- report(context, node, 'translateChildren');
- }
- },
- };
- },
-};
diff --git a/packages/eslint-plugin/lib/rules/string-literal-i18n-messages.js b/packages/eslint-plugin/lib/rules/string-literal-i18n-messages.js
deleted file mode 100644
index 7b557026b3..0000000000
--- a/packages/eslint-plugin/lib/rules/string-literal-i18n-messages.js
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-const {
- isTextLabelChild,
- report,
- isStringWithoutExpressions,
-} = require('../util');
-
-/**
- * @type {import('eslint').Rule.RuleModule}
- */
-module.exports = {
- meta: {
- type: 'problem',
- docs: {
- description: 'enforce translate APIs to be called on plain text labels',
- category: 'Possible Problems',
- url: 'https://docusaurus.io/docs/api/misc/@docusaurus/eslint-plugin/string-literal-i18n-messages',
- },
- schema: [],
- messages: {
- translateChildren:
- ' children must be hardcoded strings. You can have in-string dynamic placeholders using the values prop.',
- translateArg:
- 'translation message must be a hardcoded string. You can have in-string dynamic placeholders using the values argument.',
- },
- },
-
- create(context) {
- const isNodeValid = (node) =>
- node.children.every((child) => isTextLabelChild({child}));
-
- return {
- "JSXElement[openingElement.name.name='Translate']": (node) => {
- if (!isNodeValid(node)) {
- report(context, node, 'translateChildren');
- }
- },
- "CallExpression > Identifier[name='translate']": (node) => {
- const messageProperty = node.parent.arguments[0].properties.find(
- (property) => property.key.name === 'message',
- );
- if (!messageProperty) {
- return;
- }
-
- if (
- !isStringWithoutExpressions({
- text: messageProperty.value,
- })
- ) {
- report(context, node, 'translateArg');
- }
- },
- };
- },
-};
diff --git a/packages/eslint-plugin/lib/util.js b/packages/eslint-plugin/lib/util.js
deleted file mode 100644
index 388cbb0819..0000000000
--- a/packages/eslint-plugin/lib/util.js
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-const isMadeOfIgnoredStrings = ({text, stringsToIgnore}) =>
- text
- .trim()
- .split(/\s+/)
- .every((string) => stringsToIgnore.includes(string));
-
-const isWhitespace = (text) => !text || !text.trim();
-
-const isTextValid = ({text, ignoreWhitespace, stringsToIgnore}) =>
- !!text &&
- !(ignoreWhitespace && isWhitespace(text)) &&
- !isMadeOfIgnoredStrings({
- text,
- stringsToIgnore,
- });
-
-const isStringWithoutExpressions = ({
- text,
- ignoreWhitespace = false,
- stringsToIgnore = [],
-} = {}) => {
- switch (text.type) {
- case 'Literal':
- return isTextValid({text: text.value, ignoreWhitespace, stringsToIgnore});
- case 'TemplateLiteral':
- return (
- !text.expressions.length &&
- isTextValid({
- text: text.quasis[0].value.raw,
- ignoreWhitespace,
- stringsToIgnore,
- })
- );
- default:
- return false;
- }
-};
-
-const isTextLabelChild = ({
- child,
- ignoreWhitespace = false,
- stringsToIgnore = [],
-} = {}) => {
- switch (child.type) {
- case 'JSXText':
- return isTextValid({
- text: child.value,
- ignoreWhitespace,
- stringsToIgnore,
- });
- case 'JSXExpressionContainer':
- return isStringWithoutExpressions({
- text: child.expression,
- ignoreWhitespace,
- stringsToIgnore,
- });
- default:
- return false;
- }
-};
-
-const report = (context, node, messageId) => {
- context.report({
- node,
- messageId,
- });
-};
-
-const getCommonValidTests = () => [
- {
- code: 'text',
- },
- {
- code: ' text ',
- },
- {
- code: '"text"',
- },
- {
- code: "'text'",
- },
- {
- code: '`text`',
- },
- {
- code: '{"text"}',
- },
- {
- code: "{'text'}",
- },
- {
- code: '{`text`}',
- },
- {
- code: '{text}',
- },
- {
- code: ' {text} ',
- },
- {
- code: 'translate({message: `My page meta title`})',
- },
- {
- code: `
- Welcome to my website
- `,
- },
- {
- code: `
- {'Welcome, {firstName}! How are you?'}
- `,
- },
- {
- code: `{'This'} is {\`valid\`}`,
- },
- {
- code: "translate({message: 'My page meta title'})",
- },
- {
- code: "translate({message: 'The logo of site {siteName}'}, {siteName: 'Docusaurus'})",
- },
- {
- code: 'translate({otherProp: metaTitle})',
- },
- {
- code: 'translate({otherProp: `My page meta title`})',
- },
-];
-
-module.exports = {
- isTextLabelChild,
- report,
- getCommonValidTests,
- isStringWithoutExpressions,
-};
diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json
index 3fb79ea135..f5567a993f 100644
--- a/packages/eslint-plugin/package.json
+++ b/packages/eslint-plugin/package.json
@@ -17,8 +17,12 @@
"access": "public"
},
"license": "MIT",
+ "scripts": {
+ "build": "tsc"
+ },
"dependencies": {
- "requireindex": "^1.2.0"
+ "@typescript-eslint/utils": "^5.21.0",
+ "tslib": "^2.4.0"
},
"devDependencies": {
"eslint-plugin-eslint-plugin": "^4.1.0"
diff --git a/packages/eslint-plugin/lib/index.js b/packages/eslint-plugin/src/index.ts
similarity index 81%
rename from packages/eslint-plugin/lib/index.js
rename to packages/eslint-plugin/src/index.ts
index 6ca7189608..1274bc31df 100644
--- a/packages/eslint-plugin/lib/index.js
+++ b/packages/eslint-plugin/src/index.ts
@@ -5,10 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/
-const requireIndex = require('requireindex');
+import rules from './rules';
-module.exports = {
- rules: requireIndex(`${__dirname}/rules`),
+export = {
+ rules,
configs: {
recommended: {
rules: {
diff --git a/packages/eslint-plugin/lib/rules/__tests__/no-untranslated-text.test.js b/packages/eslint-plugin/src/rules/__tests__/no-untranslated-text.test.ts
similarity index 66%
rename from packages/eslint-plugin/lib/rules/__tests__/no-untranslated-text.test.js
rename to packages/eslint-plugin/src/rules/__tests__/no-untranslated-text.test.ts
index 12e83856bc..869605a48c 100644
--- a/packages/eslint-plugin/lib/rules/__tests__/no-untranslated-text.test.js
+++ b/packages/eslint-plugin/src/rules/__tests__/no-untranslated-text.test.ts
@@ -5,69 +5,73 @@
* LICENSE file in the root directory of this source tree.
*/
-const rule = require('../no-untranslated-text');
-const {RuleTester} = require('eslint');
-const {getCommonValidTests} = require('../../util');
+import rule from '../no-untranslated-text';
+import {getCommonValidTests, RuleTester} from './testUtils';
-const errorsJSX = [{messageId: 'translateChildren', type: 'JSXElement'}];
+const errorsJSX = [
+ {messageId: 'translateChildren', type: 'JSXElement'},
+] as const;
const errorsJSXFragment = [
{messageId: 'translateChildren', type: 'JSXFragment'},
];
const ruleTester = new RuleTester({
+ parser: '@typescript-eslint/parser',
parserOptions: {
- ecmaVersion: 2022,
- ecmaFeatures: {jsx: true},
+ ecmaFeatures: {
+ jsx: true,
+ },
},
});
+
ruleTester.run('no-untranslated-text', rule, {
valid: [
...getCommonValidTests(),
{
code: '·',
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: '· ',
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: ' · ',
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: '· ·',
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: '· — ×',
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: '{"·"}',
- options: [{ignoreStrings: ['·']}],
+ options: [{ignoredStrings: ['·']}],
},
{
code: "{'·'}",
- options: [{ignoreStrings: ['·']}],
+ options: [{ignoredStrings: ['·']}],
},
{
code: '{`·`}',
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: 'Docusaurus',
- options: [{ignoreStrings: ['Docusaurus']}],
+ options: [{ignoredStrings: ['Docusaurus']}],
},
{
code: '',
- options: [{ignoreStrings: ['']}],
+ options: [{ignoredStrings: ['']}],
},
{
code: `<>
{' · '}
>`,
- options: [{ignoreStrings: ['·', "'"]}],
+ options: [{ignoredStrings: ['·']}],
},
],
@@ -111,37 +115,37 @@ ruleTester.run('no-untranslated-text', rule, {
{
code: '· — ×',
errors: errorsJSX,
- options: [{ignoreStrings: ['·', '—']}],
+ options: [{ignoredStrings: ['·', '—']}],
},
{
code: '··',
errors: errorsJSX,
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: ' ·· ',
errors: errorsJSX,
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: '"·"',
errors: errorsJSX,
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: "'·'",
errors: errorsJSX,
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: '`·`',
errors: errorsJSX,
- options: [{ignoreStrings: ['·', '—', '×']}],
+ options: [{ignoredStrings: ['·', '—', '×']}],
},
{
code: 'Docusaurus',
errors: errorsJSX,
- options: [{ignoreStrings: ['Docu', 'saurus']}],
+ options: [{ignoredStrings: ['Docu', 'saurus']}],
},
],
});
diff --git a/packages/eslint-plugin/lib/rules/__tests__/string-literal-i18n-messages.test.js b/packages/eslint-plugin/src/rules/__tests__/string-literal-i18n-messages.test.ts
similarity index 71%
rename from packages/eslint-plugin/lib/rules/__tests__/string-literal-i18n-messages.test.js
rename to packages/eslint-plugin/src/rules/__tests__/string-literal-i18n-messages.test.ts
index 8b381f4c1f..d836979acd 100644
--- a/packages/eslint-plugin/lib/rules/__tests__/string-literal-i18n-messages.test.js
+++ b/packages/eslint-plugin/src/rules/__tests__/string-literal-i18n-messages.test.ts
@@ -5,19 +5,25 @@
* LICENSE file in the root directory of this source tree.
*/
-const rule = require('../string-literal-i18n-messages');
-const {RuleTester} = require('eslint');
-const {getCommonValidTests} = require('../../util');
+import rule from '../string-literal-i18n-messages';
+import {getCommonValidTests, RuleTester} from './testUtils';
-const errorsJSX = [{messageId: 'translateChildren', type: 'JSXElement'}];
-const errorsFunc = [{messageId: 'translateArg', type: 'Identifier'}];
+const errorsJSX = [
+ {messageId: 'translateChildren', type: 'JSXElement'},
+] as const;
+const errorsFunc = [
+ {messageId: 'translateArg', type: 'CallExpression'},
+] as const;
const ruleTester = new RuleTester({
+ parser: '@typescript-eslint/parser',
parserOptions: {
- ecmaVersion: 2022,
- ecmaFeatures: {jsx: true},
+ ecmaFeatures: {
+ jsx: true,
+ },
},
});
+
ruleTester.run('string-literal-i18n-messages', rule, {
valid: [...getCommonValidTests()],
diff --git a/packages/eslint-plugin/src/rules/__tests__/testUtils.ts b/packages/eslint-plugin/src/rules/__tests__/testUtils.ts
new file mode 100644
index 0000000000..1c3f19854b
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/__tests__/testUtils.ts
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+import {ESLintUtils} from '@typescript-eslint/utils';
+
+const {RuleTester} = ESLintUtils;
+
+export {RuleTester};
+
+export const getCommonValidTests = (): {code: string}[] => [
+ {
+ code: 'text',
+ },
+ {
+ code: ' text ',
+ },
+ {
+ code: '"text"',
+ },
+ {
+ code: "'text'",
+ },
+ {
+ code: '`text`',
+ },
+ {
+ code: '{"text"}',
+ },
+ {
+ code: "{'text'}",
+ },
+ {
+ code: '{`text`}',
+ },
+ {
+ code: '{text}',
+ },
+ {
+ code: ' {text} ',
+ },
+ {
+ code: 'translate({message: `My page meta title`})',
+ },
+ {
+ code: `
+ Welcome to my website
+ `,
+ },
+ {
+ code: `
+ {'Welcome, {firstName}! How are you?'}
+ `,
+ },
+ {
+ code: `{'This'} is {\`valid\`}`,
+ },
+ {
+ code: "translate({message: 'My page meta title'})",
+ },
+ {
+ code: "translate({message: 'The logo of site {siteName}'}, {siteName: 'Docusaurus'})",
+ },
+ {
+ code: 'translate({otherProp: metaTitle})',
+ },
+ {
+ code: 'translate({otherProp: `My page meta title`})',
+ },
+];
diff --git a/packages/eslint-plugin/src/rules/index.ts b/packages/eslint-plugin/src/rules/index.ts
new file mode 100644
index 0000000000..70a83f55a7
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/index.ts
@@ -0,0 +1,14 @@
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+import noUntranslatedText from './no-untranslated-text';
+import stringLiteralI18nMessages from './string-literal-i18n-messages';
+
+export default {
+ 'no-untranslated-text': noUntranslatedText,
+ 'string-literal-i18n-messages': stringLiteralI18nMessages,
+};
diff --git a/packages/eslint-plugin/src/rules/no-untranslated-text.ts b/packages/eslint-plugin/src/rules/no-untranslated-text.ts
new file mode 100644
index 0000000000..cdf416069a
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/no-untranslated-text.ts
@@ -0,0 +1,79 @@
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+import {isTextLabelChild, createRule} from '../util';
+import type {TSESTree} from '@typescript-eslint/types/dist/ts-estree';
+
+type Options = [
+ {
+ ignoredStrings: string[];
+ },
+];
+type MessageIds = 'translateChildren';
+
+export default createRule({
+ name: 'no-untranslated-text',
+ meta: {
+ type: 'suggestion',
+ docs: {
+ description:
+ 'enforce text labels in JSX to be wrapped by translate calls',
+ recommended: false,
+ },
+ schema: [
+ {
+ type: 'object',
+ properties: {
+ ignoredStrings: {
+ type: 'array',
+ },
+ },
+ additionalProperties: false,
+ },
+ ],
+ messages: {
+ translateChildren:
+ 'All text labels in JSX should be wrapped by translate calls',
+ },
+ },
+ defaultOptions: [
+ {
+ ignoredStrings: [],
+ },
+ ],
+
+ create(context, [options]) {
+ const {ignoredStrings} = options;
+ return {
+ JSXElement(node) {
+ if (
+ node.openingElement.selfClosing ||
+ (node.openingElement.name as TSESTree.JSXIdentifier).name ===
+ 'Translate'
+ ) {
+ return;
+ }
+ if (
+ node.children.some((child) =>
+ isTextLabelChild(child, {ignoredStrings}),
+ )
+ ) {
+ context.report({node, messageId: 'translateChildren'});
+ }
+ },
+ JSXFragment(node) {
+ if (
+ node.children.some((child) =>
+ isTextLabelChild(child, {ignoredStrings}),
+ )
+ ) {
+ context.report({node, messageId: 'translateChildren'});
+ }
+ },
+ };
+ },
+});
diff --git a/packages/eslint-plugin/src/rules/string-literal-i18n-messages.ts b/packages/eslint-plugin/src/rules/string-literal-i18n-messages.ts
new file mode 100644
index 0000000000..1ac36ac9db
--- /dev/null
+++ b/packages/eslint-plugin/src/rules/string-literal-i18n-messages.ts
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+import {
+ isTextLabelChild,
+ isStringWithoutExpressions,
+ createRule,
+} from '../util';
+import type {TSESTree} from '@typescript-eslint/types/dist/ts-estree';
+
+type Options = [];
+type MessageIds = 'translateChildren' | 'translateArg';
+
+export default createRule({
+ name: 'string-literal-i18n-messages',
+ meta: {
+ type: 'problem',
+ docs: {
+ description: 'enforce translate APIs to be called on plain text labels',
+ recommended: 'error',
+ },
+ schema: [],
+ messages: {
+ translateChildren:
+ ' children must be hardcoded strings. You can have in-string dynamic placeholders using the values prop.',
+ translateArg:
+ 'translation message must be a hardcoded string. You can have in-string dynamic placeholders using the values argument.',
+ },
+ },
+ defaultOptions: [],
+
+ create(context) {
+ return {
+ JSXElement(node) {
+ if (
+ (node.openingElement.name as TSESTree.JSXIdentifier).name !==
+ 'Translate'
+ ) {
+ return;
+ }
+ if (node.children.some((child) => !isTextLabelChild(child))) {
+ context.report({node, messageId: 'translateChildren'});
+ }
+ },
+ CallExpression(node) {
+ if (
+ node.callee.type !== 'Identifier' ||
+ node.callee.name !== 'translate'
+ ) {
+ return;
+ }
+ const param = node.arguments[0];
+ if (!param || param.type !== 'ObjectExpression') {
+ context.report({node, messageId: 'translateArg'});
+ return;
+ }
+ const messageProperty = param.properties.find(
+ (property): property is TSESTree.Property =>
+ property.type === 'Property' &&
+ (property.key as TSESTree.Identifier).name === 'message',
+ );
+ if (!messageProperty) {
+ return;
+ }
+
+ if (!isStringWithoutExpressions(messageProperty.value)) {
+ context.report({node, messageId: 'translateArg'});
+ }
+ },
+ };
+ },
+});
diff --git a/packages/eslint-plugin/src/util.ts b/packages/eslint-plugin/src/util.ts
new file mode 100644
index 0000000000..439a068e65
--- /dev/null
+++ b/packages/eslint-plugin/src/util.ts
@@ -0,0 +1,67 @@
+/**
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+import {ESLintUtils} from '@typescript-eslint/utils';
+import type {TSESTree} from '@typescript-eslint/types/dist/ts-estree';
+
+type CheckTranslateChildOptions = {
+ ignoredStrings?: string[];
+};
+
+const isMadeOfIgnoredStrings = (text: string, ignoredStrings: string[]) =>
+ text
+ .trim()
+ .split(/\s+/)
+ .every((string) => !string || ignoredStrings.includes(string));
+
+const isValidTranslationLabel = (
+ text: unknown,
+ {ignoredStrings}: CheckTranslateChildOptions = {},
+) => {
+ if (!ignoredStrings) {
+ return typeof text === 'string';
+ }
+ return (
+ typeof text === 'string' && !isMadeOfIgnoredStrings(text, ignoredStrings)
+ );
+};
+
+export function isStringWithoutExpressions(
+ text: TSESTree.Node,
+ options?: CheckTranslateChildOptions,
+): boolean {
+ switch (text.type) {
+ case 'Literal':
+ return isValidTranslationLabel(text.value, options);
+ case 'TemplateLiteral':
+ return (
+ text.expressions.length === 0 &&
+ isValidTranslationLabel(text.quasis[0]!.value.raw, options)
+ );
+ default:
+ return false;
+ }
+}
+
+export function isTextLabelChild(
+ child: TSESTree.JSXChild,
+ options?: CheckTranslateChildOptions,
+): boolean {
+ switch (child.type) {
+ case 'JSXText':
+ return isValidTranslationLabel(child.value, options);
+ case 'JSXExpressionContainer':
+ return isStringWithoutExpressions(child.expression, options);
+ default:
+ return false;
+ }
+}
+
+export const createRule = ESLintUtils.RuleCreator(
+ (name) =>
+ `https://docusaurus.io/docs/api/misc/@docusaurus/eslint-plugin/${name}`,
+);
diff --git a/packages/eslint-plugin/tsconfig.json b/packages/eslint-plugin/tsconfig.json
new file mode 100644
index 0000000000..f5902ba108
--- /dev/null
+++ b/packages/eslint-plugin/tsconfig.json
@@ -0,0 +1,9 @@
+{
+ "extends": "../../tsconfig.json",
+ "compilerOptions": {
+ "incremental": true,
+ "tsBuildInfoFile": "./lib/.tsbuildinfo",
+ "rootDir": "src",
+ "outDir": "lib"
+ }
+}
diff --git a/project-words.txt b/project-words.txt
index 4309c77a0c..4bf268862f 100644
--- a/project-words.txt
+++ b/project-words.txt
@@ -84,6 +84,7 @@ errnametoolong
esbenp
esbuild
eslintcache
+estree
evaluable
externalwaiting
failfast
@@ -303,6 +304,7 @@ treeifies
treeify
treosh
triaging
+tses
typecheck
typechecks
typedoc
diff --git a/website/docs/api/misc/eslint-plugin/README.md b/website/docs/api/misc/eslint-plugin/README.md
index c42ba573e7..3354d63f80 100644
--- a/website/docs/api/misc/eslint-plugin/README.md
+++ b/website/docs/api/misc/eslint-plugin/README.md
@@ -67,7 +67,7 @@ module.exports = {
rules: {
'@docusaurus/no-untranslated-text': [
'warn',
- {ignoreStrings: ['·', '—', '×']},
+ {ignoredStrings: ['·', '—', '×']},
],
},
};
diff --git a/website/docs/api/misc/eslint-plugin/no-untranslated-text.md b/website/docs/api/misc/eslint-plugin/no-untranslated-text.md
index 66dbc2d764..346c021fe8 100644
--- a/website/docs/api/misc/eslint-plugin/no-untranslated-text.md
+++ b/website/docs/api/misc/eslint-plugin/no-untranslated-text.md
@@ -34,7 +34,7 @@ Accepted fields:
| Option | Type | Default | Description |
| --- | --- | --- | --- |
-| `ignoreStrings` | `string[]` | `[]` | Text labels that only contain strings in this list will not be reported. |
+| `ignoredStrings` | `string[]` | `[]` | Text labels that only contain strings in this list will not be reported. |
diff --git a/yarn.lock b/yarn.lock
index 6cfb20afba..90bdf2f6c6 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3902,9 +3902,9 @@
semver "^7.3.5"
tsutils "^3.21.0"
-"@typescript-eslint/utils@5.21.0", "@typescript-eslint/utils@^5.10.0":
+"@typescript-eslint/utils@5.21.0", "@typescript-eslint/utils@^5.10.0", "@typescript-eslint/utils@^5.21.0":
version "5.21.0"
- resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.21.0.tgz#51d7886a6f0575e23706e5548c7e87bce42d7c18"
+ resolved "https://registry.npmmirror.com/@typescript-eslint/utils/-/utils-5.21.0.tgz#51d7886a6f0575e23706e5548c7e87bce42d7c18"
integrity sha512-q/emogbND9wry7zxy7VYri+7ydawo2HDZhRZ5k6yggIvXa7PvBbAAZ4PFH/oZLem72ezC4Pr63rJvDK/sTlL8Q==
dependencies:
"@types/json-schema" "^7.0.9"
@@ -13177,11 +13177,6 @@ require-from-string@^2.0.2:
resolved "https://registry.yarnpkg.com/require-like/-/require-like-0.1.2.tgz#ad6f30c13becd797010c468afa775c0c0a6b47fa"
integrity sha512-oyrU88skkMtDdauHDuKVrgR+zuItqr6/c//FXzvmxRGMexSDc6hNvJInGW3LL46n+8b50RykrvwSUIIQH2LQ5A==
-requireindex@^1.2.0:
- version "1.2.0"
- resolved "https://registry.yarnpkg.com/requireindex/-/requireindex-1.2.0.tgz#3463cdb22ee151902635aa6c9535d4de9c2ef1ef"
- integrity sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==
-
requires-port@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"