Total Complexity | 3 |
Complexity/F | 1.5 |
Lines of Code | 24 |
Function Count | 2 |
Duplicated Lines | 24 |
Ratio | 100 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | /* eslint-env es6, node */ |
||
2 | View Code Duplication | 'use strict'; |
|
|
|||
3 | |||
4 | // eslint-disable-next-line security-node/detect-non-literal-require-calls , security/detect-non-literal-require |
||
5 | const osPaths = require('../' + require('../package.json').main); |
||
6 | |||
7 | /* eslint-disable no-console , functional/immutable-data , security/detect-object-injection, security-node/detect-crlf */ |
||
8 | |||
9 | function objectEntries(obj) { |
||
10 | const map = {}; |
||
11 | Object.keys(obj).forEach((key) => { |
||
12 | const value = obj[key]; |
||
13 | const val = typeof value === 'function' ? value() : value; |
||
14 | map[key] = val; |
||
15 | }); |
||
16 | return map; |
||
17 | } |
||
18 | |||
19 | console.log({ osPaths }); |
||
20 | console.log(objectEntries(osPaths)); |
||
21 | console.log('home() =', osPaths.home()); |
||
22 | console.log('temp() =', osPaths.temp()); |
||
23 | |||
24 | process.env.TMPDIR = process.env.TEMP = process.env.TMP = 'temp'; |
||
25 | console.log(objectEntries(osPaths)); |
||
26 | |||
28 |