-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Add rule valid-sprintf #13756
Conversation
@@ -38,8 +38,7 @@ const embedAttributes = { | |||
}; | |||
|
|||
export function getEmbedBlockSettings( { title, description, icon, category = 'embed', transforms, keywords = [], supports = {}, responsive = true } ) { | |||
// translators: %s: Name of service (e.g. VideoPress, YouTube) | |||
const blockDescription = description || sprintf( __( 'Add a block that displays content pulled from other sites, like Twitter, Instagram or YouTube.' ), title ); | |||
const blockDescription = description || __( 'Add a block that displays content pulled from other sites, like Twitter, Instagram or YouTube.' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, so an example of something that got picked up by the new rule ;) nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request started as a very roundabout way of addressing this specific issue 😆
7abe8bb
to
afe9838
Compare
* Blocks: Embed: Avoid unneccessary sprintf * ESLint Plugin: Add rule valid-sprintf * i18n: Disable valid-sprintf for intentional error test case
* Blocks: Embed: Avoid unneccessary sprintf * ESLint Plugin: Add rule valid-sprintf * i18n: Disable valid-sprintf for intentional error test case
@@ -51,6 +51,7 @@ Rule|Description | |||
---|--- | |||
[no-unused-vars-before-return](/packages/eslint-plugin/docs/rules/no-unused-vars-before-return.md)|Disallow assigning variable values if unused before a return | |||
[dependency-group](/packages/eslint-plugin/docs/rules/dependency-group.md)|Enforce dependencies docblocks formatting | |||
[valid-sprintf](/packages/eslint-plugin/docs/rules/valid-sprintf.md)|Disallow assigning variable values if unused before a return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description is not correct 😅 #14666
Related: #6624 (comment)
This pull request seeks to introduce a new ESLint rule to help protect against invalid use of
sprintf
.Specifically, it enforces:
_n
or_nx
) contain an identical number of placeholders (a common error is forming a string likesprintf( _n( 'One cat', '%d cats', num ) )
)It does not (yet) enforce:
sprintf( '%1$s %1$s', '1' )
is valid)Testing instructions:
Verify that the description for the Embed block shows as expected:
Ensure tests pass: