Example:
// correct
var hostid = 12345,
item_applications = [];
// wrong
var Hostid = 12345,
itemApplications = [];
Example:
// correct
var $widget_header = $('.widget_header', $widget),
host_count = 5;
// wrong
var widget = $('.widget_container'),
$hosts = [$('#host1'), $('#host2')];
Example:
// correct
var CTimeLine = Class.create({});
// wrong
var cTimeLine = Class.create({}),
ctimeline = Class.create({}),
c_time_line = Class.create({});
Example:
Example:
// correct
function create() {
// some logic here
}
function getName() {
// some logic here
}
// wrong
function Create() {
// some logic here
}
function get_name() {
// some logic here
}
Example:
// correct
document.addEventListener('click', (e) => {
// some logic here
});
document.addEventListener('click', () => {
// some logic here
});
// wrong ('event' not shortened)
document.addEventListener('click', (event) => {
// some logic here
});
// wrong (no enclosing brackets)
document.addEventListener('click', e => {
// some logic here
});
Example:
// correct
var itemids = [],
item_applications = [];
// wrong
var itemids = [];
var item_applications = [];
// wrong
var itemids = hostids = [];
// wrong
var left = null, top = null, right = null, bottom = null;
// wrong
var itemIds = [],
itemApplications = [];
Example:
// correct
var person = {firstname: 'Mario', lastname: 'Smith'};
person.firstname = 'Mr.';
// wrong
var person = {"firstname": 'Mario', "lastname": 'Smith'};
// correct
curr_lbl.style.background = background;
curr_lbl.style.color = background;
// wrong
curr_lbl.style.background = curr_lbl.style.color = background;
// correct
var disable = ($('#mass_border_type').val() === '-1' && $('#chkboxBorderType').is(":checked"));
// wrong
var disable = $('#mass_border_type').val() === '-1' && $('#chkboxBorderType').is(":checked");
Example:
// correct
if (list.length > 100) {
// some logic here
}
// wrong
if (list.length > 100)
{
// some logic here
}
Example:
// correct
if (list.length > 100) {
// some logic here
}
// correct
if (list.length > 100) {
// some logic here
}
else {
// some logic here
}
// correct
if (list.length > 100) {
// some logic here
}
else if (list.length == 1) {
// some logic here
}
else {
// some logic here
}
// wrong
if (list.length > 100) // some logic here
if (list.length > 100) {
// some logic here
} else {
// some logic here
}
Example:
// correct
if (a == b) {
d = e;
}
else if (a == c) {
d = f;
}
else {
d = g;
}
// wrong
if (a == b) {
d = e;
}
if (a == c) {
d = f;
}
if (a != b && a != c)
d = g;
}
Example:
switch (condition) {
case 1:
// some logic here
// falls through
case 2:
// some logic here
break;
case 3:
// some logic here
break;
default:
// some logic here
break;
}
Example:
try {
// some logic here
}
catch (exception if condition) {
// some logic here
}
finally {
// some logic here
}
Example:
Example:
Example:
Example:
// correct
const x = 'string';
$('#expressions_' + index + '_expression').val()
// wrong
const x = "string";
jQuery('[data-dialogueid='+dialogueid+']').remove();
// correct
function updateUserProfile(idx, value_int, idx2) {
// ...
}
// wrong
function updateUserProfile(idx,value_int,idx2) {
// ...
}
// correct
if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
// wrong
if(n!==0&&n!==(1/0)&&n!==-(1/0)){
n=(n>0||-1)*Math.floor(Math.abs(n));
}
// correct
init: function(time) {
this.delay = time;
this.delayLeft = this.delay;
this.start();
}
// wrong
init:function(time) {
this.delay = time;
this.delayLeft = this.delay;
this.start();
}
'return
'.// correct
var footerButton = jQuery(e.target),
form = footerButton.closest('form'),
confirmText = footerButton.attr('confirm');
if (confirmText && !confirm(confirmText)) {
Event.stop(e);
return false;
}
// wrong
var footerButton = jQuery(e.target),
form = footerButton.closest('form'),
confirmText = footerButton.attr('confirm');
if (confirmText && !confirm(confirmText)) {
Event.stop(e);
return false;
}
Example:
Example:
Example:
'@return
' is not needed. For more than two return types it's better to combine types using the pipe char instead of 'mixed
'.'{}
' and start with a lowercase letter.Example:
/**
* Performs a cool magic trick.
*
* @param {object} fairy_dust The FairyDust object to use in the trick.
* @param {array} magic_stones An array of magic stones.
* @param {number} stones_limit Limit of magic stones.
* @param {string} stones_owner The name of the stones owner.
* @param {boolean} is_destructible Are the magic stones destructible.
*
* @return {object}
*/
function performMagic(fairy_dust, magic_stones, stones_limit, stones_owner, is_destructible) {
// some magic here
}
Example:
// correct
$msg_box = jQuery('<output>')
.addClass(type)
.attr('role', 'contentinfo')
.attr('aria-label', aria_labels[index]);
// wrong
$msg_box = jQuery('<output>').addClass(type).attr('role', 'contentinfo').attr('aria-label', aria_labels[index]);
Example:
Example:
Example: