Showing 6 of 6 total issues
Function createGithubTicket
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
exports.createGithubTicket = rateLimit(1, 2000, function(github, repo, user, ticket, people, cb) {
//console.log(people); process.exit(1);
function getComments(ticket) {
return '### Comments\n\n' + ticket.comments.map(function(comment) {
var commenter = people[comment.personId] ? people[comment.personId].name : comment.personId;
- Read upRead up
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
Function createGithubTicket
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
exports.createGithubTicket = rateLimit(1, 2000, function(github, repo, user, ticket, people, cb) {
//console.log(people); process.exit(1);
function getComments(ticket) {
return '### Comments\n\n' + ticket.comments.map(function(comment) {
var commenter = people[comment.personId] ? people[comment.personId].name : comment.personId;
Function createGithubTickets
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
exports.createGithubTickets = function(token, repo, user, tickets, people, cb) {
if(!cb) cb = function() {};
var github = new GitHubApi({
version: '3.0.0',
Function createGithubTicket
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
exports.createGithubTicket = rateLimit(1, 2000, function(github, repo, user, ticket, people, cb) {
Function createGithubTickets
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
exports.createGithubTickets = function(token, repo, user, tickets, people, cb) {
Expected error to be handled. Open
}, function(err, stories) {
- Read upRead up
- Exclude checks
Enforce Callback Error Handling (handle-callback-err)
In Node.js, a common pattern for dealing with asynchronous behavior is called the callback pattern.
This pattern expects an Error
object or null
as the first argument of the callback.
Forgetting to handle these errors can lead to some really strange behavior in your application.
function loadData (err, data) {
doSomething(); // forgot to handle error
}
Rule Details
This rule expects that when you're using the callback pattern in Node.js you'll handle the error.
Options
The rule takes a single string option: the name of the error parameter. The default is "err"
.
Examples of incorrect code for this rule with the default "err"
parameter name:
/*eslint handle-callback-err: "error"*/
function loadData (err, data) {
doSomething();
}
Examples of correct code for this rule with the default "err"
parameter name:
/*eslint handle-callback-err: "error"*/
function loadData (err, data) {
if (err) {
console.log(err.stack);
}
doSomething();
}
function generateError (err) {
if (err) {}
}
Examples of correct code for this rule with a sample "error"
parameter name:
/*eslint handle-callback-err: ["error", "error"]*/
function loadData (error, data) {
if (error) {
console.log(error.stack);
}
doSomething();
}
regular expression
Sometimes (especially in big projects) the name of the error variable is not consistent across the project, so you need a more flexible configuration to ensure that the rule reports all unhandled errors.
If the configured name of the error variable begins with a ^
it is considered to be a regexp pattern.
- If the option is
"^(err|error|anySpecificError)$"
, the rule reports unhandled errors where the parameter name can beerr
,error
oranySpecificError
. - If the option is
"^.+Error$"
, the rule reports unhandled errors where the parameter name ends withError
(for example,connectionError
orvalidationError
will match). - If the option is
"^.*(e|E)rr"
, the rule reports unhandled errors where the parameter name matches any string that containserr
orErr
(for example,err
,error
,anyError
,some_err
will match).
When Not To Use It
There are cases where it may be safe for your application to ignore errors, however only ignore errors if you are confident that some other form of monitoring will help you catch the problem.