Skip to content

Commit

Permalink
tools: add docs for prefer-util-format-errors rule
Browse files Browse the repository at this point in the history
I had a little trouble understanding what the rule was trying to say, so
am documenting what would pass/fail.

PR-URL: nodejs#17376
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
maclover7 committed Nov 30, 2017
1 parent 701dc9a commit 85e34b0
Showing 1 changed file with 5 additions and 0 deletions.
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

0 comments on commit 85e34b0

Please sign in to comment.