Total Complexity | 3 |
Complexity/F | 1.5 |
Lines of Code | 23 |
Function Count | 2 |
Duplicated Lines | 23 |
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 | const osPaths = require('../dist/cjs/mod.cjs.js'); |
||
5 | |||
6 | /* eslint-disable no-console , functional/immutable-data , security/detect-object-injection, security-node/detect-crlf */ |
||
7 | |||
8 | function objectEntries(obj) { |
||
9 | const map = {}; |
||
10 | Object.keys(obj).forEach((key) => { |
||
11 | const value = obj[key]; |
||
12 | const val = typeof value === 'function' ? value() : value; |
||
13 | map[key] = val; |
||
14 | }); |
||
15 | return map; |
||
16 | } |
||
17 | |||
18 | console.log({ osPaths }); |
||
19 | console.log(objectEntries(osPaths)); |
||
20 | console.log('home() =', osPaths.home()); |
||
21 | console.log('temp() =', osPaths.temp()); |
||
22 | |||
23 | process.env.TMPDIR = process.env.TEMP = process.env.TMP = 'temp'; |
||
24 | console.log(objectEntries(osPaths)); |
||
25 | |||
27 |