diff --git a/.eslintrc.js b/.eslintrc.js index 3c36e33f1f31b6..d0c22090b93e87 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -180,7 +180,6 @@ module.exports = { '@wordpress/react-no-unsafe-timeout': 'error', '@wordpress/i18n-hyphenated-range': 'error', '@wordpress/i18n-no-flanking-whitespace': 'error', - '@wordpress/i18n-no-toggle': 'error', '@wordpress/i18n-text-domain': [ 'error', { diff --git a/packages/eslint-plugin/configs/i18n.js b/packages/eslint-plugin/configs/i18n.js index 72dbda7f0ac92e..fb8cad233232d4 100644 --- a/packages/eslint-plugin/configs/i18n.js +++ b/packages/eslint-plugin/configs/i18n.js @@ -10,6 +10,5 @@ module.exports = { '@wordpress/i18n-ellipsis': 'error', '@wordpress/i18n-no-flanking-whitespace': 'error', '@wordpress/i18n-hyphenated-range': 'error', - '@wordpress/i18n-no-toggle': 'error', }, }; diff --git a/packages/eslint-plugin/rules/__tests__/i18n-no-toggle.js b/packages/eslint-plugin/rules/__tests__/i18n-no-toggle.js deleted file mode 100644 index aec308831a5109..00000000000000 --- a/packages/eslint-plugin/rules/__tests__/i18n-no-toggle.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * External dependencies - */ -import { RuleTester } from 'eslint'; - -/** - * Internal dependencies - */ -const rule = require( '../i18n-no-toggle' ); - -const ruleTester = new RuleTester( { - parserOptions: { - ecmaVersion: 6, - }, -} ); - -ruleTester.run( 'i18n-no-toggle', rule, { - valid: [ - `__('Click to switch something');`, - `__('Enable this feature.');`, - `_x('Activate the option', 'context', 'context');`, - `_n('There is one item', 'There are many items', 1, 'context');`, - `_nx('Add the item', 'Add the items', 1, 'context', 'context');`, - `i18n.__('Activate the setting.');`, - ], - - invalid: [ - { - code: `__('Click to toggle something');`, - errors: [ - { - message: - "Avoid using the verb 'toggle' in translatable strings.", - }, - ], - }, - { - code: `_x('Toggle the feature', 'context', 'context');`, - errors: [ - { - message: - "Avoid using the verb 'Toggle' in translatable strings.", - }, - ], - }, - { - code: `_n('There is one toggle', 'There are many toggles', 1, 'context');`, - errors: [ - { - message: - "Avoid using the verb 'toggle' in translatable strings.", - }, - ], - }, - { - code: `_nx('Enable the toggle', 'Enable the toggles', 1, 'context', 'context');`, - errors: [ - { - message: - "Avoid using the verb 'toggle' in translatable strings.", - }, - ], - }, - { - code: `i18n.__('Click to Toggle something');`, - errors: [ - { - message: - "Avoid using the verb 'Toggle' in translatable strings.", - }, - ], - }, - ], -} ); diff --git a/packages/eslint-plugin/rules/i18n-no-toggle.js b/packages/eslint-plugin/rules/i18n-no-toggle.js deleted file mode 100644 index 29be0b57e67041..00000000000000 --- a/packages/eslint-plugin/rules/i18n-no-toggle.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Internal dependencies - */ -const { - TRANSLATION_FUNCTIONS, - getTextContentFromNode, - getTranslateFunctionName, - getTranslateFunctionArgs, -} = require( '../utils' ); - -module.exports = { - meta: { - type: 'problem', - schema: [], - messages: { - noToggle: - "Avoid using the verb '{{ word }}' in translatable strings.", - }, - fixable: null, - }, - create( context ) { - return { - CallExpression( node ) { - const { callee, arguments: args } = node; - - const functionName = getTranslateFunctionName( callee ); - - if ( ! TRANSLATION_FUNCTIONS.has( functionName ) ) { - return; - } - - const candidates = getTranslateFunctionArgs( - functionName, - args - ); - - for ( const arg of candidates ) { - const argumentString = getTextContentFromNode( arg ); - if ( ! argumentString ) { - continue; - } - - const match = /\btoggle\b/i.exec( argumentString ); - - if ( match ) { - const matchedWord = match[ 0 ]; - - context.report( { - node, - messageId: 'noToggle', - data: { - word: matchedWord, - }, - } ); - } - } - }, - }; - }, -};