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

tools: add docs for prefer-util-format-errors rule #17376

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions tools/eslint-rules/prefer-util-format-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ module.exports = {
if (!isArrowFunctionWithTemplateLiteral(msg))
return;

// Checks to see if order of arguments to function is the same as the
// order of them being concatenated in the template string. The idea is
// that if both match, then you can use `util.format`-style args.
// Would pass rule: (a, b) => `${b}${a}`.
// Would fail rule: (a, b) => `${a}${b}`, and needs to be rewritten.
const { expressions } = msg.body;
const hasSequentialParams = msg.params.every((param, index) => {
const expr = expressions[index];
Expand Down