Issues (117)

lib/handlebars/ifEqual.js (1 issue)

1 1
var handlebars = require('handlebars');
2
/**
3
 * Handlebars block helper that checks if two values are equal.
4
 * @param {mixed} a - First value to compare.
5
 * @param {mixed} b - Second value to compare.
6
 * @param {object} options - Handlebars object.
7
 * @returns If the values are equal, content inside of the helper. If not, the content inside the `{{else}}` block.
8
 */
9
function ifEqual (a, b, options) {
10 2
  if (a === b) return options.fn(this);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
11 1
  else return options.inverse(this);
12
};
13
14 1
handlebars.registerHelper('ifEqual', ifEqual);
15
handlebars.registerHelper('ifequal', ifEqual);
16
module.exports = ifEqual;