Completed
Pull Request — master (#21)
by
unknown
02:20
created

src/server/routes/write-json.js   A

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 21
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
nc 1
dl 0
loc 21
rs 10
noi 5
c 1
b 0
f 0
cc 0
wmc 5
mnd 1
bc 2
fnc 2
bpm 1
cpm 2.5

1 Function

Rating   Name   Duplication   Size   Complexity  
A write-json.js ➔ route 0 9 3
1
import path from 'path'
2
import fse from 'fs-extra'
3
import mkdirp from 'mkdirp'
4
5
import {
6
  config,
7
  abeExtend,
0 ignored issues
show
Unused Code introduced by
The variable abeExtend seems to be never used. Consider removing it.
Loading history...
8
  Manager
9
} from '../../cli'
10
11
var route = function(req, res, next){
0 ignored issues
show
Unused Code introduced by
The parameter next is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
12
  if(typeof res._header !== 'undefined' && res._header !== null) return
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...
13
  fse.writeJson(path.join(config.root, req.body.url), JSON.parse(req.body.json), function (err) {
14
    if(err) console.log("write-json reference error: ", err)
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...
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
15
    Manager.instance.updateReferences()
16
    res.set('Content-Type', 'application/json')
17
    res.send(JSON.stringify({success: 1}))
18
  })
19
}
20
21
export default route