Showing 10 of 10 total issues
Function exports
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function(app) {
app.post('/:user/:repo/objects/batch', wrap(function* (req, res, next) {
// validate request body according to JSON Schema
try {
var body = yield parse.json(req);
Similar blocks of code found in 2 locations. Consider refactoring. Open
getDownloadAction(user, repo, oid, size) {
return {
href: `${BASE_URL}${user}/${repo}/objects/${oid}`,
expires_at: Store._getJWTExpireTime(),
header: {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 84.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
getUploadAction(user, repo, oid, size) {
return {
href: `${BASE_URL}${user}/${repo}/objects/${oid}`,
expires_at: Store._getJWTExpireTime(),
header: {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 84.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function checkJWT
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
var checkJWT = function(action) {
return wrap(function*(req, res, next) {
let user = req.params.user;
let repo = req.params.repo;
let oid = req.params.oid;
- 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 exports
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function(app) {
app.post('/:user/:repo/objects/verify', checkJWT('verify'), wrap(function* (req, res, next) {
try {
var body = yield parse.json(req);
- 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
Avoid too many return
statements within this function. Open
return res.status(403).end();
This generator function does not have 'yield'. Open
var handleVerifyObject = function* (user, repo, object) {
- Read upRead up
- Exclude checks
Disallow generator functions that do not have yield
(require-yield)
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
Examples
Examples of incorrect code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don't want to notify generator functions that have no yield
expression, then it's safe to disable this rule.
Related Rules
- [require-await](require-await.md) Source: http://eslint.org/docs/rules/
This generator function does not have 'yield'. Open
return wrap(function*(req, res, next) {
- Read upRead up
- Exclude checks
Disallow generator functions that do not have yield
(require-yield)
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
Examples
Examples of incorrect code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don't want to notify generator functions that have no yield
expression, then it's safe to disable this rule.
Related Rules
- [require-await](require-await.md) Source: http://eslint.org/docs/rules/
Unexpected lexical declaration in case block. Open
case 'upload':
- Read upRead up
- Exclude checks
Disallow lexical declarations in case/default clauses (no-case-declarations)
This rule disallows lexical declarations (let
, const
, function
and class
)
in case
/default
clauses. The reason is that the lexical declaration is visible
in the entire switch block but it only gets initialized when it is assigned, which
will only happen if the case where it is defined is reached.
To ensure that the lexical declaration only applies to the current case clause wrap your clauses in blocks.
Rule Details
This rule aims to prevent access to uninitialized lexical bindings as well as accessing hoisted functions across case clauses.
Examples of incorrect code for this rule:
/*eslint no-case-declarations: "error"*/
/*eslint-env es6*/
switch (foo) {
case 1:
let x = 1;
break;
case 2:
const y = 2;
break;
case 3:
function f() {}
break;
default:
class C {}
}
Examples of correct code for this rule:
/*eslint no-case-declarations: "error"*/
/*eslint-env es6*/
// Declarations outside switch-statements are valid
const a = 0;
switch (foo) {
// The following case clauses are wrapped into blocks using brackets
case 1: {
let x = 1;
break;
}
case 2: {
const y = 2;
break;
}
case 3: {
function f() {}
break;
}
case 4:
// Declarations using var without brackets are valid due to function-scope hoisting
var z = 4;
break;
default: {
class C {}
}
}
When Not To Use It
If you depend on fall through behavior and want access to bindings introduced in the case block.
Related Rules
- [no-fallthrough](no-fallthrough.md) Source: http://eslint.org/docs/rules/
This generator function does not have 'yield'. Open
var handleUploadObject = function* (user, repo, object) {
- Read upRead up
- Exclude checks
Disallow generator functions that do not have yield
(require-yield)
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
Examples
Examples of incorrect code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don't want to notify generator functions that have no yield
expression, then it's safe to disable this rule.
Related Rules
- [require-await](require-await.md) Source: http://eslint.org/docs/rules/