Passed
Push — master ( 0a8095...60f354 )
by hung
01:03
created

src/helper/output.js   A

Complexity

Total Complexity 8
Complexity/F 2.67

Size

Lines of Code 29
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 8
c 1
b 0
f 0
nc 1
mnd 3
bc 9
fnc 3
dl 0
loc 29
rs 10
bpm 3
cpm 2.6666
noi 5

1 Function

Rating   Name   Duplication   Size   Complexity  
B output.js ➔ ??? 0 25 5
1
const fs = require('fs')
2
const { join } = require('path')
3
const { Writable } = require('stream')
4
5
module.exports = (output, data) => {
6
  if (!data) {
7
    return null
8
  }
9
  if (!output) {
10
    console.log(data)
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
11
  } else if (typeof output === 'string') {
12
    const path = join(__dirname, '../', output)
13
    fs.open(path, fs.W_OK, err => {
14
      if (err) {
15
        console.error(`Cannot write file to ${path}`)
16
        return
17
      }
18
      // TODO: maybe use appendFile for readStream
19
      fs.writeFileSync(path, data)
20
    })
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
21
  } else if (output instanceof Writable) {
22
    output.write(data + '\r\n')
23
    output.on('error', err => {
24
      console.error(err)
25
    })
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
26
  } else {
27
    console.error('Invalid Output')
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
28
  }
29
}
30