Chore: Fix typescript strict null errors from 674 -> 565 (#26057)

* Chore: Fix typescript strict null errors

* Added new limit

* Fixed ts issue

* fixed tests

* trying to fix type inference

* Fixing more ts errors

* Revert tsconfig option

* Fix

* Fixed code

* More fixes

* fix tests

* Updated snapshot
This commit is contained in:
Torkel Ödegaard
2020-07-06 21:16:27 +02:00
committed by GitHub
parent 4fc984f771
commit 7e8bd0c1b7
39 changed files with 198 additions and 182 deletions

View File

@@ -119,19 +119,20 @@ export function expandRecordingRules(query: string, mapping: { [name: string]: s
// Regex that matches occurences of ){ or }{ or ]{ which is a sign of incorrecly added labels.
const invalidLabelsRegex = /(\)\{|\}\{|\]\{)/;
const correctlyExpandedQueryArray = queryArray.map(query => {
let expression = query;
if (expression.match(invalidLabelsRegex)) {
expression = addLabelsToExpression(expression, invalidLabelsRegex);
}
return expression;
return addLabelsToExpression(query, invalidLabelsRegex);
});
return correctlyExpandedQueryArray.join('');
}
function addLabelsToExpression(expr: string, invalidLabelsRegexp: RegExp) {
const match = expr.match(invalidLabelsRegexp);
if (!match) {
return expr;
}
// Split query into 2 parts - before the invalidLabelsRegex match and after.
const indexOfRegexMatch = expr.match(invalidLabelsRegexp).index;
const indexOfRegexMatch = match.index ?? 0;
const exprBeforeRegexMatch = expr.substr(0, indexOfRegexMatch + 1);
const exprAfterRegexMatch = expr.substr(indexOfRegexMatch + 1);