diff --git a/packages/eslint-plugin/rules/__tests__/valid-sprintf.js b/packages/eslint-plugin/rules/__tests__/valid-sprintf.js index 9b2b7de255d47b..8f5b77458fbaeb 100644 --- a/packages/eslint-plugin/rules/__tests__/valid-sprintf.js +++ b/packages/eslint-plugin/rules/__tests__/valid-sprintf.js @@ -71,6 +71,18 @@ sprintf( { code: `sprintf( '%(greeting)s %(toWhom)s', 'Hello', 'World' )`, }, + { + code: `sprintf( 'Rotated at %d %% degrees', 90 )`, + }, + { + code: `sprintf( 'Rotated at %d%% degrees', 90 )`, + }, + { + code: `sprintf( __( 'Rotated at %d%% degrees' ), 90 )`, + }, + { + code: `sprintf( 'Rotated at %1$d %% degrees, %2$d %% angles', 90, 180 )`, + }, ], invalid: [ { diff --git a/packages/eslint-plugin/utils/constants.js b/packages/eslint-plugin/utils/constants.js index a19add74964c0e..44e881fb867c78 100644 --- a/packages/eslint-plugin/utils/constants.js +++ b/packages/eslint-plugin/utils/constants.js @@ -37,13 +37,13 @@ const TRANSLATION_FUNCTIONS = new Set( [ '__', '_x', '_n', '_nx' ] ); * @type {RegExp} */ const REGEXP_SPRINTF_PLACEHOLDER = - /%(((\d+)\$)|(\(([$_a-zA-Z][$_a-zA-Z0-9]*)\)))?[ +0#-]*\d*(\.(\d+|\*))?(ll|[lhqL])?([cduxXefgsp%])/g; -// ▲ ▲ ▲ ▲ ▲ ▲ ▲ type -// │ │ │ │ │ └ Length (unsupported) -// │ │ │ │ └ Precision / max width -// │ │ │ └ Min width (unsupported) -// │ │ └ Flags (unsupported) -// └ Index └ Name (for named arguments) + /(?