Showing 12 of 12 total issues
Function loadFlash
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
var loadFlash = function() {
var animationEnd = whichAnimationEvent();
var mainFlashNode = document.getElementById('main-flash');
var flashBackDrop = document.createElement("div");
- Create a ticketCreate a ticket
Function initDropdowns
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
var initDropdowns = function() {
function whichTransitionEvent(){
var t;
var el = document.createElement('fakeelement');
- Create a ticketCreate a ticket
Function initChangeImageColor
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
var initChangeImageColor = function() {
var elements = document.querySelectorAll('.pk-js-changed-color-images');
for(var i = 0; i < elements.length; i++) {
var elem = elements[i];
- Create a ticketCreate a ticket
Method attend_event_link
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def attend_event_link(event, visit_request)
return unless current_user
return if visit_request&.pending?
return if visit_request&.approved?
- Read upRead up
- Create a ticketCreate a ticket
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return if event.visitors.include?(current_user)
- Create a ticketCreate a ticket
Method expect_an_error
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def expect_an_error(hash_pair = {}, nope = false) # rubocop:disable Metrics/AbcSize
field = hash_pair.keys.first
value = hash_pair.values.first
error_div = "div.#{field}.field_with_errors"
- Read upRead up
- Create a ticketCreate a ticket
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method expect_an_error
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def expect_an_error(hash_pair = {}, nope = false) # rubocop:disable Metrics/AbcSize
field = hash_pair.keys.first
value = hash_pair.values.first
error_div = "div.#{field}.error"
- Read upRead up
- Create a ticketCreate a ticket
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method visit_request_confirm_message
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def visit_request_confirm_message(visit_request)
return unless visit_request && current_user
if visit_request.confirmed?
t('visit_requests.messages.see_you')
- Read upRead up
- Create a ticketCreate a ticket
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method call
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def call # rubocop:disable Metrics/AbcSize
return VisitRequest::Approve.call(visit_request) if user.verified? && policy.free_slot_for?(user)
VisitRequestMailer.needs_confirmation(visit_request).deliver_later unless user.verified?
visit_request.pending!
- Read upRead up
- Create a ticketCreate a ticket
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Don't make functions within a loop. Open
flashNodes[i].addEventListener("click", function(e){
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Disallow Functions in Loops (no-loop-func)
Writing functions within loops tends to result in errors due to the way the function creates a closure around the loop. For example:
for (var i = 0; i < 10; i++) {
funcs[i] = function() {
return i;
};
}
In this case, you would expect each function created within the loop to return a different number. In reality, each function returns 10, because that was the last value of i
in the scope.
let
or const
mitigate this problem.
/*eslint-env es6*/
for (let i = 0; i < 10; i++) {
funcs[i] = function() {
return i;
};
}
In this case, each function created within the loop returns a different number as expected.
Rule Details
This error is raised to highlight a piece of code that may not work as you expect it to and could also indicate a misunderstanding of how the language works. Your code may run without any problems if you do not fix this error, but in some situations it could behave unexpectedly.
Examples of incorrect code for this rule:
/*eslint no-loop-func: "error"*/
/*eslint-env es6*/
for (var i=10; i; i--) {
(function() { return i; })();
}
while(i) {
var a = function() { return i; };
a();
}
do {
function a() { return i; };
a();
} while (i);
let foo = 0;
for (let i=10; i; i--) {
// Bad, function is referencing block scoped variable in the outer scope.
var a = function() { return foo; };
a();
}
Examples of correct code for this rule:
/*eslint no-loop-func: "error"*/
/*eslint-env es6*/
var a = function() {};
for (var i=10; i; i--) {
a();
}
for (var i=10; i; i--) {
var a = function() {}; // OK, no references to variables in the outer scopes.
a();
}
for (let i=10; i; i--) {
var a = function() { return i; }; // OK, all references are referring to block scoped variables in the loop.
a();
}
var foo = 100;
for (let i=10; i; i--) {
var a = function() { return foo; }; // OK, all references are referring to never modified variables.
a();
}
//... no modifications of foo after this loop ...
Source: http://eslint.org/docs/rules/
Move function declaration to function body root. Open
function transitionEndAction(e) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
disallow variable or function
declarations in nested blocks (no-inner-declarations)
In JavaScript, prior to ES6, a function declaration is only allowed in the first level of a program or the body of another function, though parsers sometimes erroneously accept them elsewhere. This only applies to function declarations; named or anonymous function expressions can occur anywhere an expression is permitted.
// Good
function doSomething() { }
// Bad
if (test) {
function doSomethingElse () { }
}
function anotherThing() {
var fn;
if (test) {
// Good
fn = function expression() { };
// Bad
function declaration() { }
}
}
A variable declaration is permitted anywhere a statement can go, even nested deeply inside other blocks. This is often undesirable due to variable hoisting, and moving declarations to the root of the program or function body can increase clarity. Note that block bindings (let
, const
) are not hoisted and therefore they are not affected by this rule.
/*eslint-env es6*/
// Good
var foo = 42;
// Good
if (foo) {
let bar1;
}
// Bad
while (test) {
var bar2;
}
function doSomething() {
// Good
var baz = true;
// Bad
if (baz) {
var quux;
}
}
Rule Details
This rule requires that function declarations and, optionally, variable declarations be in the root of a program or the body of a function.
Options
This rule has a string option:
-
"functions"
(default) disallowsfunction
declarations in nested blocks -
"both"
disallowsfunction
andvar
declarations in nested blocks
functions
Examples of incorrect code for this rule with the default "functions"
option:
/*eslint no-inner-declarations: "error"*/
if (test) {
function doSomething() { }
}
function doSomethingElse() {
if (test) {
function doAnotherThing() { }
}
}
Examples of correct code for this rule with the default "functions"
option:
/*eslint no-inner-declarations: "error"*/
function doSomething() { }
function doSomethingElse() {
function doAnotherThing() { }
}
if (test) {
asyncCall(id, function (err, data) { });
}
var fn;
if (test) {
fn = function fnExpression() { };
}
both
Examples of incorrect code for this rule with the "both"
option:
/*eslint no-inner-declarations: ["error", "both"]*/
if (test) {
var foo = 42;
}
function doAnotherThing() {
if (test) {
var bar = 81;
}
}
Examples of correct code for this rule with the "both"
option:
/*eslint no-inner-declarations: "error"*/
/*eslint-env es6*/
var bar = 42;
if (test) {
let baz = 43;
}
function doAnotherThing() {
var baz = 81;
}
When Not To Use It
The function declaration portion rule will be rendered obsolete when block-scoped functions land in ES6, but until then, it should be left on to enforce valid constructions. Disable checking variable declarations when using [block-scoped-var](block-scoped-var.md) or if declaring variables in nested blocks is acceptable despite hoisting. Source: http://eslint.org/docs/rules/
Don't make functions within a loop. Open
function transitionEndAction(e) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Disallow Functions in Loops (no-loop-func)
Writing functions within loops tends to result in errors due to the way the function creates a closure around the loop. For example:
for (var i = 0; i < 10; i++) {
funcs[i] = function() {
return i;
};
}
In this case, you would expect each function created within the loop to return a different number. In reality, each function returns 10, because that was the last value of i
in the scope.
let
or const
mitigate this problem.
/*eslint-env es6*/
for (let i = 0; i < 10; i++) {
funcs[i] = function() {
return i;
};
}
In this case, each function created within the loop returns a different number as expected.
Rule Details
This error is raised to highlight a piece of code that may not work as you expect it to and could also indicate a misunderstanding of how the language works. Your code may run without any problems if you do not fix this error, but in some situations it could behave unexpectedly.
Examples of incorrect code for this rule:
/*eslint no-loop-func: "error"*/
/*eslint-env es6*/
for (var i=10; i; i--) {
(function() { return i; })();
}
while(i) {
var a = function() { return i; };
a();
}
do {
function a() { return i; };
a();
} while (i);
let foo = 0;
for (let i=10; i; i--) {
// Bad, function is referencing block scoped variable in the outer scope.
var a = function() { return foo; };
a();
}
Examples of correct code for this rule:
/*eslint no-loop-func: "error"*/
/*eslint-env es6*/
var a = function() {};
for (var i=10; i; i--) {
a();
}
for (var i=10; i; i--) {
var a = function() {}; // OK, no references to variables in the outer scopes.
a();
}
for (let i=10; i; i--) {
var a = function() { return i; }; // OK, all references are referring to block scoped variables in the loop.
a();
}
var foo = 100;
for (let i=10; i; i--) {
var a = function() { return foo; }; // OK, all references are referring to never modified variables.
a();
}
//... no modifications of foo after this loop ...
Source: http://eslint.org/docs/rules/