Completed
Push — master ( bdfcbe...91ed9c )
by
unknown
02:02
created

src/cli/cms/data/sql.js   F

Complexity

Total Complexity 122
Complexity/F 4.88

Size

Lines of Code 449
Function Count 25

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 122
c 1
b 0
f 0
nc 1
mnd 6
bc 88
fnc 25
dl 0
loc 449
rs 3.12
bpm 3.52
cpm 4.88
noi 33

14 Functions

Rating   Name   Duplication   Size   Complexity  
C sql.js ➔ recurseWhere 0 70 17
A sql.js ➔ sanitizeFromStatement 0 11 3
B sql.js ➔ getFromDirectory 0 18 10
A sql.js ➔ executeQuerySync 0 3 1
C sql.js ➔ executeWhereClause 0 35 11
C sql.js ➔ getWhereValuesToCompare 0 55 13
C sql.js ➔ cleanRequest 0 46 12
B sql.js ➔ getSourceType 0 22 5
B sql.js ➔ executeOrderByClause 0 15 7
C sql.js ➔ handleSqlRequest 0 71 15
A sql.js ➔ execQuery 0 11 1
A sql.js ➔ executeQuery 0 10 1
A sql.js ➔ getDataSource 0 15 3
A sql.js ➔ executeFromClause 0 21 2

How to fix   Complexity   

Complexity

Complex classes like src/cli/cms/data/sql.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import {parse} from 'node-sqlparser'
2
import {Promise} from 'es6-promise'
3
import path from 'path'
4
import {
5
  coreUtils,
6
  config,
7
  Manager,
8
  FileParser,
0 ignored issues
show
Unused Code introduced by
The variable FileParser seems to be never used. Consider removing it.
Loading history...
9
  getAttr
10
} from '../../'
11
12
export function cleanRequest(str, jsonPage) {
0 ignored issues
show
Unused Code introduced by
The parameter jsonPage is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
13
  var matchFrom = /from .(.*?) /
14
  var matchVariable = /{{([a-zA-Z]*)}}/
15
16
  var matchFromExec = matchFrom.exec(str)
17
  if(typeof matchFromExec !== 'undefined' && matchFromExec !== null
18
    && typeof matchFromExec[1] !== 'undefined' && matchFromExec[1] !== null) {
19
20
    var fromMatch
21
    var toReplace = matchFromExec[1]
22
    while (fromMatch = matchVariable.exec(toReplace)) {
23
      try {
24
        var value = eval('jsonPage.' + fromMatch[1])
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
25
        if(typeof value !== 'undefined' && value !== null) {
26
          toReplace = toReplace.replace('{{' + fromMatch[1] + '}}', value)
27
        }else {
28
          toReplace = toReplace.replace('{{' + fromMatch[1] + '}}', '')
29
        }
30
      }catch(e) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
31
      }
32
    }
33
34
    str = str.replace(matchFromExec[1], toReplace)
35
  }
36
37
  var from = /from ([\S\s]+)/.exec(str)
38
39
  var matches = from
40
  if(matches[1]) {
41
    var res = matches[1]
42
    var splitAttr = [' where ', ' order by ', ' limit ', ' WHERE ', ' ORDER BY ', ' LIMIT ']
43
    for(var i = 0; i < splitAttr.length; i++) {
44
      if(res.indexOf(splitAttr[i]) > -1) {
45
        res = res.substring(0, res.indexOf(splitAttr[i]))
46
      }
47
    }
48
    var escapedFrom = res.replace(/\//g, '___abe___')
49
    escapedFrom = escapedFrom.replace(/\./g, '___abe_dot___')
50
    escapedFrom = escapedFrom.replace(/-/g, '___abe_dash___')
51
    str = str.replace(res, escapedFrom)
52
  }
53
54
  str = str.replace(/``/g, '\'\'')
55
56
  return str
57
}
58
59
export function handleSqlRequest(str, jsonPage) {
60
  var req = cleanRequest(str, jsonPage)
61
  var request = parse(req)
62
  var reconstructSql = ''
63
64
  // SQL TYPE
65
  var type = ''
66
  if(typeof request.type !== 'undefined' && request.type !== null) {
67
    type = request.type
68
  }
69
  reconstructSql += `${type} `
70
71
  // SQL COLUMNS
72
  var columns = []
73
  if(typeof request.columns !== 'undefined' && request.columns !== null) {
74
    if(request.columns === '*') {
75
      columns.push('*')
76
    }else {
77
      Array.prototype.forEach.call(request.columns, (item) => {
78
        columns.push(item.expr.column)
79
      })
80
    }
81
  }
82
  reconstructSql += `${JSON.stringify(columns)} `
83
84
  // SQL FROM
85
  var from = []
86
  if(typeof request.from !== 'undefined' && request.from !== null) {
87
88
    Array.prototype.forEach.call(request.from, (item) => {
89
      from.push(item.table)
90
    })
91
  }else {
92
    from.push('*')
93
  }
94
  reconstructSql += `from ${JSON.stringify(from)} `
95
96
  var where
97
  if(typeof request.where !== 'undefined' && request.where !== null) {
98
    where = request.where
99
    // where = recurseWhere(request.where)
100
    // reconstructSql += 'where '
101
    // Array.prototype.forEach.call(where, (w) => {
102
    //   reconstructSql += `${w.operator} ${w.left} ${w.compare} ${w.right} `
103
    // })
104
  }
105
106
  var limit = -1
107
  if(typeof request.limit !== 'undefined' && request.limit !== null) {
108
    limit = request.limit[request.limit.length - 1].value
109
  }
110
111
  var orderby
112
  if(typeof request.orderby !== 'undefined' && request.orderby !== null && request.orderby.length > 0) {
113
    orderby = {
114
      column: request.orderby[0].expr.column,
115
      type: request.orderby[0].type
116
    }
117
    reconstructSql += `ORDER BY ${orderby.column} ${orderby.type} `
118
  }
119
120
  return {
121
    type: type,
122
    columns: columns,
123
    from: from,
124
    where: where,
0 ignored issues
show
Bug introduced by
The variable where does not seem to be initialized in case typeof request.where !=... request.where !== null on line 97 is false. Are you sure this can never be the case?
Loading history...
125
    string: reconstructSql,
126
    limit: limit,
127
    orderby: orderby
0 ignored issues
show
Bug introduced by
The variable orderby does not seem to be initialized in case typeof request.orderby ...uest.orderby.length > 0 on line 112 is false. Are you sure this can never be the case?
Loading history...
128
  }
129
}
130
131
export function getDataSource(str) {
132
  var res = str.substring(str.indexOf('source=') + 8, str.length)
133
134
  var reg = /([^'"]*=[\s\S]*?}})/g
135
  var matches = res.match(reg)
136
  if(typeof matches !== 'undefined' && matches !== null) {
137
    Array.prototype.forEach.call(matches, (match) => {
138
      res = res.replace(match, '')
139
    })
140
  }else {
141
    res = res.replace('}}', '')
142
  }
143
144
  return res.substring(0, res.length-1)
145
}
146
147
/**
148
 * replaces escaped characters with the right ones
149
 * @param  {String} statement the from clause
150
 * @return {String}           the from sanitized
151
 */
152
export function sanitizeFromStatement(statement){
153
  var from = ''
154
155
  if(typeof statement !== 'undefined' && statement !== null) {
156
    from = statement[0].replace(/___abe_dot___/g, '.')
157
    from = from.replace(/___abe___/g, '/')
158
    from = from.replace(/___abe_dash___/g, '-')
159
  }
160
161
  return from
162
}
163
164
/**
165
 * calculate the directory to analyze from the from clause
166
 * @param  {String} statement the from clause
167
 * @param  {String} tplPath   the path from the template originator
168
 * @return {string}           the directory to analyze
169
 */
170
export function getFromDirectory(statement, tplPath){
171
  var pathFromDir = ''
172
  if(typeof tplPath === 'undefined' || tplPath === null || tplPath === ''){
173
    tplPath = '/'
174
  }
175
176
  if(statement === '' || statement === '*' || statement === '/') {
177
    pathFromDir = path.join(config.root, config.data.url)
178
  }else if(statement === './') {
179
    pathFromDir = path.join(config.root, config.data.url, tplPath)
180
  }else if(statement.indexOf('/') === 0) {
181
    pathFromDir = path.join(config.root, config.data.url, statement)
182
  }else if(statement.indexOf('/') !== 0) {
183
    pathFromDir = path.join(config.root, config.data.url, tplPath, statement)
184
  }
185
186
  return pathFromDir
187
}
188
189
export function executeOrderByClause(files, orderby){
190
  if(typeof orderby !== 'undefined' && orderby !== null) {
191
    if(orderby.column.toLowerCase() === 'random') {
192
      files = coreUtils.sort.shuffle(files)
193
    }else if(orderby.column.toLowerCase() === 'date') {
194
      if(orderby.type === 'ASC') {
195
        files.sort(coreUtils.sort.byDateAsc)
196
      }else if(orderby.type === 'DESC') {
197
        files.sort(coreUtils.sort.byDateDesc)
198
      }
199
    }
200
  }
201
202
  return files
203
}
204
205
export function executeFromClause(statement, pathFromClause){
206
  var from = sanitizeFromStatement(statement)
207
208
  // if the from clause ends with a dot, we won't recurse the directory analyze
209
  if(from.slice(-1) === '.'){
210
    from = from.slice(0, -1)
211
  }
212
  
213
  var fromDirectory = getFromDirectory(from, pathFromClause)
214
215
  var list = Manager.instance.getList()
216
  var files_array = list.filter((element, index) => {
0 ignored issues
show
Unused Code introduced by
The parameter index is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
217
    if(element.publish) {
218
      if (element.path.indexOf(fromDirectory) > -1) {
219
        return true
220
      }
221
    }
222
    return false
223
  })
224
  return files_array
225
}
226
227
export function execQuery(pathQuery, match, jsonPage) {
228
  var res
229
  var files
230
  var request = handleSqlRequest(getAttr(match, 'source'), jsonPage)
231
232
  files = executeFromClause(request.from, pathQuery)
233
  files = executeOrderByClause(files, request.orderby)
234
  res = executeWhereClause(files, request.where, request.limit, request.columns, jsonPage)
235
236
  return res
237
}
238
239
export function executeQuerySync(pathQuerySync, match, jsonPage) {
240
  return execQuery(pathQuerySync, match, jsonPage)
241
}
242
243
export function executeQuery(pathexecuteQuery, match, jsonPage) {
244
  var p = new Promise((resolve) => {
245
    var res = execQuery(pathexecuteQuery, match, jsonPage)
246
    resolve(res)
247
  }).catch(function(e) {
248
    console.error(e)
249
  })
250
251
  return p
252
}
253
254
/**
255
 * check if a given string an url, string json, file url, abe sql request
256
 * 
257
 * get('http://google.com')
258
 * get('{"test":"test"}')
259
 * get('select * from ../')
260
 * get('test')
261
 * 
262
 * @param  {String} str 
263
 * @return {String} url | request | value | file | other
264
 */
265
export function getSourceType(str) {
266
  if(/http:\/\/|https:\/\//.test(str)) {
267
    return 'url'
268
  }
269
270
  if(/select[\S\s]*?from/.test(str)) {
271
    return 'request'
272
  }
273
274
  try {
275
    JSON.parse(str)
276
    return 'value'
277
  }catch(e) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
278
279
  }
280
281
  if(/\.json/.test(str)) {
282
    return 'file'
283
  }
284
285
  return 'other'
286
}
287
288
export function executeWhereClause(files, wheres, maxLimit, columns, jsonPage){
289
  var res = []
290
  var limit = 0
291
292
  for(let file of files) {
293
    if(limit < maxLimit || maxLimit === -1) {
294
      if(typeof wheres !== 'undefined' && wheres !== null) {
295
296
        if(!recurseWhere(wheres, file.publish, jsonPage)) {
297
          var json = JSON.parse(JSON.stringify(file.publish))
298
          var jsonValues = {}
299
300
          if(typeof columns !== 'undefined' && columns !== null && columns.length > 0 && columns[0] !== '*') {
301
            
302
            Array.prototype.forEach.call(columns, (column) => {
303
              if(typeof json[column] !== 'undefined' && json[column] !== null) {
0 ignored issues
show
Bug introduced by
The variable json is changed as part of the for-each loop for example by JSON.parse(JSON.stringify(file.publish)) on line 297. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
304
                jsonValues[column] = json[column]
0 ignored issues
show
Bug introduced by
The variable jsonValues is changed as part of the for-each loop for example by {} on line 298. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
305
              }
306
            })
307
            jsonValues['abe_meta'] = json['abe_meta']
308
          }else {
309
            jsonValues = json
310
          }
311
312
          res.push(jsonValues)
313
          limit++
314
        }
315
      }
316
    } else {
317
      break
318
    }
319
  }
320
321
  return res
322
}
323
324
export function getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc) {
0 ignored issues
show
Unused Code introduced by
The parameter jsonOriginalDoc is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter jsonDoc is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
325
  var regexIsVariable = /^{{(.*)}}$/
326
  var value
327
  var compare
328
329
  try {
330
    var variableLeft = where.left.column
331
    var checkIfLeftIsAVariable = regexIsVariable.exec(variableLeft)
332
    if(typeof checkIfLeftIsAVariable !== 'undefined' && checkIfLeftIsAVariable !== null && checkIfLeftIsAVariable.length > 0) {
333
      variableLeft = checkIfLeftIsAVariable[1]
334
    }
335
    value = eval('jsonDoc.' + variableLeft)
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
336
  }catch(e) {
337
    // console.log('e', e)
338
  }
339
  
340
  if(where.operator === 'IN' || where.operator === 'NOT IN') {
341
    compare = []
342
    Array.prototype.forEach.call(where.right.value, (right) => {
343
      var matchRightVariable = regexIsVariable.exec(right.column)
344
      if(typeof matchRightVariable !== 'undefined' && matchRightVariable !== null && matchRightVariable.length > 0) {
345
        try {
346
          var jsonOriginalValues = eval('jsonOriginalDoc.' + matchRightVariable[1])
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
347
          Array.prototype.forEach.call(jsonOriginalValues, (jsonOriginalValue) => {
0 ignored issues
show
Unused Code introduced by
The parameter jsonOriginalValue is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
348
            compare.push(eval('jsonOriginalValue.' + where.left.column))
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
349
          })
350
        }catch(e) {}
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
351
      }
352
      else{
353
        compare.push(right.column)
354
      }
355
    })
356
  }else {
357
    compare = where.right.column
358
    var matchRightVariable = regexIsVariable.exec(compare)
359
360
    if(typeof matchRightVariable !== 'undefined' && matchRightVariable !== null && matchRightVariable.length > 0) {
361
      try {
362
        var shouldCompare = eval('jsonOriginalDoc.' + matchRightVariable[1])
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
363
        if(typeof shouldCompare !== 'undefined' && shouldCompare !== null) {
364
          compare = shouldCompare
365
        }else {
366
          compare = null
367
        }
368
      }catch(e) {
369
        compare = null
370
      }
371
    }
372
  }
373
374
  return {
375
    left: value,
0 ignored issues
show
Bug introduced by
The variable value does not seem to be initialized in case var variableLeft = where.left.column on line 330 throws an error. Are you sure this can never be the case?
Loading history...
376
    right: compare
377
  }
378
}
379
380
export function recurseWhere(where, jsonDoc, jsonOriginalDoc) {
381
  var shouldAdd = true
0 ignored issues
show
Unused Code introduced by
The variable shouldAdd seems to be never used. Consider removing it.
Loading history...
382
  var isNotLeftCorrect = false
0 ignored issues
show
Unused Code introduced by
The assignment to variable isNotLeftCorrect seems to be never used. Consider removing it.
Loading history...
383
  var isNotRightCorrect = false
0 ignored issues
show
Unused Code introduced by
The assignment to variable isNotRightCorrect seems to be never used. Consider removing it.
Loading history...
384
  var isNotCorrect = false
0 ignored issues
show
Unused Code introduced by
The assignment to variable isNotCorrect seems to be never used. Consider removing it.
Loading history...
385
386
  switch(where.operator) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
387
  case '=':
388
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
389
    isNotCorrect = !(values.left === values.right)
390
    break
391
  case '!=':
392
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 388. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
393
    isNotCorrect = !(values.left !== values.right)
394
    break
395
  case '>':
396
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 388. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
397
    isNotCorrect = !(values.left > values.right)
398
    break
399
  case '>=':
400
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 388. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
401
    isNotCorrect = !(values.left >= values.right)
402
    break
403
  case '<':
404
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 388. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
405
    isNotCorrect = !(values.left < values.right)
406
    break
407
  case '<=':
408
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 388. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
409
    isNotCorrect = !(values.left <= values.right)
410
    break
411
  case 'LIKE':
412
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 388. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
413
    isNotCorrect = !(values.left && values.left.indexOf(values.right) > -1)
414
    break
415
  case 'NOT LIKE':
416
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 388. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
417
    isNotCorrect = !(values.left && values.left.indexOf(values.right) === -1)
418
    break
419
  case 'AND':
420
    isNotLeftCorrect = recurseWhere(where.left, jsonDoc, jsonOriginalDoc)
421
    isNotRightCorrect = recurseWhere(where.right, jsonDoc, jsonOriginalDoc)
422
    isNotCorrect = (isNotLeftCorrect || isNotRightCorrect) ? true : false
423
    break
424
  case 'OR':
425
    isNotLeftCorrect = recurseWhere(where.left, jsonDoc, jsonOriginalDoc)
426
    isNotRightCorrect = recurseWhere(where.right, jsonDoc, jsonOriginalDoc)
427
    isNotCorrect = (isNotLeftCorrect && isNotRightCorrect) ? true : false
428
    break
429
  case 'IN':
430
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 388. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
431
    isNotCorrect = true
432
    Array.prototype.forEach.call(values.right, (right) => {
433
      if(values.left === right) {
434
        isNotCorrect = false
435
      }
436
    })
437
    break
438
  case 'NOT IN':
439
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 388. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
440
    isNotCorrect = false
441
    Array.prototype.forEach.call(values.right, (right) => {
442
      if(values.left === right) {
443
        isNotCorrect = true
444
      }
445
    })
446
    break
447
  }
448
  return isNotCorrect
449
}