Skip to content

Commit

Permalink
Fix: remove side effect that caused race condition in comment lines #90
Browse files Browse the repository at this point in the history
  • Loading branch information
mylinhdao authored Feb 8, 2024
2 parents 28a83c5 + 88fc2c7 commit fa4795c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/parser/metrics/CommentLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export class CommentLines implements Metric {
}

async calculate(parseFile: ParseFile, tree: Parser.Tree): Promise<MetricResult> {
const additionalStatements: QueryStatementInterface[] = [];
switch (parseFile.language) {
case Languages.Python:
this.statementsSuperSet.push(
additionalStatements.push(
new SimpleQueryStatement(
"(expression_statement (string)) @python_multiline_comment"
)
Expand All @@ -41,7 +42,13 @@ export class CommentLines implements Metric {
}

const queryBuilder = new QueryBuilder(parseFile, tree);
queryBuilder.setStatements(this.statementsSuperSet);

if (additionalStatements.length === 0) {
queryBuilder.setStatements(this.statementsSuperSet);
} else {
// Important to use concat() here, because we do not want to change this.statementSuperSet:
queryBuilder.setStatements(this.statementsSuperSet.concat(additionalStatements));
}

const query = queryBuilder.build();
let matches: QueryMatch[] = [];
Expand Down

0 comments on commit fa4795c

Please sign in to comment.