Issues (11)

src/helper/output.js (3 issues)

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
10
  if (typeof output === 'string') {
11
    // Output as file
12
    const path = join(output)
13
    fs.open(path, fs.W_OK, err => {
14
      if (err) {
15
        console.error(`Cannot write file to ${path}`)
16
        return
17
      }
18
      fs.appendFileSync(path, data + '\r\n')
19
    })
0 ignored issues
show
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...
20
  } else if (output instanceof Writable) {
21
    // Output as stream
22
    output.write(data + '\r\n')
23
    output.on('error', err => {
24
      console.error(err)
25
    })
0 ignored issues
show
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
    // Output as console
28
    console.log(data)
29
    return
0 ignored issues
show
This return has no effect and can be removed.
Loading history...
30
  }
31
}
32