Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint Plugin: Relax check for i18n-text-domain rule #21928

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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