Skip to content

Commit b82c54c

Browse files
authored
Fix new SonarQube issues (#1641)
* fix new sonarqube issues
1 parent 979e8b6 commit b82c54c

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src-electron/generator/helper-endpointconfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,10 +1392,10 @@ function endpoint_config(options) {
13921392
let sessionId = this.global.sessionId
13931393
let collectAttributesOptions = {
13941394
allowUnknownStorageOption:
1395-
options.hash.allowUnknownStorageOption === 'false' ? false : true,
1395+
options.hash.allowUnknownStorageOption !== 'false',
13961396
spaceForDefaultValue: options.hash.spaceForDefaultValue,
13971397
isReadableMaskGenerationEnabled:
1398-
options.hash.isReadableMaskGenerationEnabled === 'true' ? true : false
1398+
options.hash.isReadableMaskGenerationEnabled === 'true'
13991399
}
14001400
let promise = templateUtil
14011401
.ensureZclPackageIds(newContext)

src-electron/generator/matter/app/zap-templates/common/ClusterTestGeneration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ function attachGlobal(global, value, errorContext) {
987987
value = new String(value);
988988
break;
989989
case 'boolean':
990-
value = new Boolean(value);
990+
value = Boolean(value);
991991
break;
992992
default:
993993
throw new Error('Unsupported value: ' + JSON.stringify(value));

src-electron/util/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ function executeExternalProgram(
726726

727727
if (options.rejectOnFail) {
728728
// We return a rejected promise to allow the caller to handle it.
729-
return Promise.reject(error)
729+
return Promise.reject(toErrorObject(error))
730730
} else {
731731
// If we're not rejecting on fail, we just log the error and continue.
732732
console.error(error.message)

src-electron/validation/conformance-expression-evaluator.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
const dbEnum = require('../../src-shared/db-enum')
2525

26-
const OPERAND_REGEX = /[A-Za-z][A-Za-z0-9_]*/g
26+
const OPERAND_REGEX = /[A-Za-z]\w*/g
2727

2828
/**
2929
* Evaluate the value of a boolean conformance expression that includes operands and operators.
@@ -75,7 +75,7 @@ function evaluateConformanceExpression(expression, elementMap) {
7575
// if any operand is desc, the conformance is too complex to parse
7676
for (let part of parts) {
7777
let operands = getOperandsFromExpression(part)
78-
if (operands && operands.includes(dbEnum.conformanceTag.described)) {
78+
if (operands.includes(dbEnum.conformanceTag.described)) {
7979
return dbEnum.conformanceTag.described
8080
}
8181
}
@@ -141,7 +141,7 @@ function checkMissingOperands(expression, elementMap) {
141141
*/
142142
function checkIfExpressionHasOperand(expression, operand) {
143143
let operands = getOperandsFromExpression(expression)
144-
return operands && operands.includes(operand)
144+
return operands.includes(operand)
145145
}
146146

147147
/**
@@ -152,8 +152,8 @@ function checkIfExpressionHasOperand(expression, operand) {
152152
*/
153153
function getOperandsFromExpression(expression) {
154154
if (!expression) return []
155-
let operands = expression.match(OPERAND_REGEX)
156-
return operands ? operands : []
155+
let operands = expression.match(OPERAND_REGEX) || []
156+
return operands
157157
}
158158

159159
/**
@@ -262,12 +262,11 @@ function translateConformanceTag(expression) {
262262
*/
263263
function translateBooleanExpr(expr) {
264264
// match operands and operators
265-
let tokens = expr.match(/[A-Za-z0-9_]+|[!&|()]/g) || []
265+
let tokens = expr.match(/\w+|[!&|()]/g) || []
266266
let output = []
267-
268-
for (let i = 0; i < tokens.length; i++) {
267+
let i = 0
268+
while (i < tokens.length) {
269269
let token = tokens[i]
270-
271270
if (token === '&') {
272271
output.push(dbEnum.logicalOperators.and)
273272
} else if (token === '|') {
@@ -288,8 +287,8 @@ function translateBooleanExpr(expr) {
288287
// if none of the above is matched, it is an element operand
289288
output.push(`${token} is enabled`)
290289
}
290+
i++
291291
}
292-
293292
return output.join(' ')
294293
}
295294

@@ -321,7 +320,7 @@ function translateConformanceExpression(expression) {
321320
if (conformanceTag) return conformanceTag
322321

323322
// handle optional expressions surrounded by '[]'
324-
let optionalMatch = part.match(/^\[(.*)\]$/)
323+
let optionalMatch = /^\[(.*)\]$/.exec(part)
325324
if (optionalMatch) {
326325
// optionalMatch[1] is the expression inside '[]'
327326
let optionalText = translateBooleanExpr(optionalMatch[1])

0 commit comments

Comments
 (0)