Skip to content

Commit

Permalink
ESLint Plugin: Relax check for i18n-text-domain rule (#21928)
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 30, 2020
1 parent 3299a87 commit 5395479
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions packages/eslint-plugin/rules/__tests__/i18n-text-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const ruleTester = new RuleTester( {

ruleTester.run( 'i18n-text-domain', rule, {
valid: [
{
code: `_x( 'Hello World' )`,
},
{
code: `_x( 'Hello World', 'random' )`,
},
{
code: `__( 'Hello World' )`,
options: [ { allowedTextDomain: 'default' } ],
Expand Down
14 changes: 9 additions & 5 deletions packages/eslint-plugin/rules/i18n-text-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ module.exports = {
},
{
type: 'string',
default: 'default',
},
],
},
Expand All @@ -68,12 +67,14 @@ module.exports = {
},
create( context ) {
const options = context.options[ 0 ] || {};
const { allowedTextDomain = 'default' } = options;
const { allowedTextDomain } = options;
const allowedTextDomains = Array.isArray( allowedTextDomain )
? allowedTextDomain
: [ allowedTextDomain ];
: [ allowedTextDomain ].filter( ( value ) => value );
const canFixTextDomain = allowedTextDomains.length === 1;
const allowDefault = allowedTextDomains.includes( 'default' );
const allowDefault =
allowedTextDomains.length === 0 ||
allowedTextDomains.includes( 'default' );

return {
CallExpression( node ) {
Expand Down Expand Up @@ -134,7 +135,10 @@ module.exports = {
return;
}

if ( ! allowedTextDomains.includes( value ) ) {
if (
allowedTextDomains.length &&
! allowedTextDomains.includes( value )
) {
const replaceTextDomain = ( fixer ) => {
return fixer.replaceTextRange(
// account for quotes.
Expand Down

0 comments on commit 5395479

Please sign in to comment.