node_modules/strip-json-comments/strip-json-comments.js   A
last analyzed

Complexity

Total Complexity 20
Complexity/F 10

Size

Lines of Code 57
Function Count 2

Duplication

Duplicated Lines 1
Ratio 1.75 %

Importance

Changes 0
Metric Value
cc 0
eloc 40
nc 192
dl 1
loc 57
rs 10
c 0
b 0
f 0
wmc 20
mnd 6
bc 13
fnc 2
bpm 6.5
cpm 10
noi 4

1 Function

Rating   Name   Duplication   Size   Complexity  
F strip-json-comments.js ➔ stripJsonComments 1 47 17

How to fix   Duplicated Code   

Duplicated Code

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
/*!
2
	strip-json-comments
3
	Strip comments from JSON. Lets you use comments in your JSON files!
4
	https://github.com/sindresorhus/strip-json-comments
5
	by Sindre Sorhus
6
	MIT License
7
*/
8
(function () {
9
	'use strict';
10
11
	function stripJsonComments(str) {
12
		var currentChar;
13
		var nextChar;
14
		var insideString = false;
15
		var insideComment = false;
16
		var ret = '';
17
18
		for (var i = 0; i < str.length; i++) {
19
			currentChar = str[i];
20
			nextChar = str[i + 1];
21
22
			if (!insideComment && str[i - 1] !== '\\' && currentChar === '"') {
23
				insideString = !insideString;
24
			}
25
26
			if (insideString) {
27
				ret += currentChar;
28
				continue;
29
			}
30
31
			if (!insideComment && currentChar + nextChar === '//') {
32
				insideComment = 'single';
33
				i++;
0 ignored issues
show
Complexity Coding Style introduced by
You seem to be assigning a new value to the loop variable i here. Please check if this was indeed your intention. Even if it was, consider using another kind of loop instead.
Loading history...
34
			} else if (insideComment === 'single' && currentChar + nextChar === '\r\n') {
35
				insideComment = false;
36
				i++;
0 ignored issues
show
Complexity Coding Style introduced by
You seem to be assigning a new value to the loop variable i here. Please check if this was indeed your intention. Even if it was, consider using another kind of loop instead.
Loading history...
37 View Code Duplication
			} else if (insideComment === 'single' && currentChar === '\n') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
38
				insideComment = false;
39
			} else if (!insideComment && currentChar + nextChar === '/*') {
40
				insideComment = 'multi';
41
				i++;
0 ignored issues
show
Complexity Coding Style introduced by
You seem to be assigning a new value to the loop variable i here. Please check if this was indeed your intention. Even if it was, consider using another kind of loop instead.
Loading history...
42
				continue;
43
			} else if (insideComment === 'multi' && currentChar + nextChar === '*/') {
44
				insideComment = false;
45
				i++;
0 ignored issues
show
Complexity Coding Style introduced by
You seem to be assigning a new value to the loop variable i here. Please check if this was indeed your intention. Even if it was, consider using another kind of loop instead.
Loading history...
46
				continue;
47
			}
48
49
			if (insideComment) {
50
				continue;
51
			}
52
53
			ret += currentChar;
54
		}
55
56
		return ret;
57
	}
58
59
	if (typeof module !== 'undefined' && module.exports) {
60
		module.exports = stripJsonComments;
61
	} else {
62
		window.stripJsonComments = stripJsonComments;
63
	}
64
})();
65