From 777010b20b52a2a95e9bf47f2ef472ebfbc6e49f Mon Sep 17 00:00:00 2001 From: Patrick O'Carroll Date: Wed, 5 Sep 2018 10:53:58 +0200 Subject: [PATCH] added no-conditional-assignment rule and changed files to follow new rule --- public/app/containers/Explore/utils/dom.ts | 3 ++- public/app/core/components/search/search.ts | 3 ++- public/app/core/directives/rebuild_on_change.ts | 4 +++- public/app/features/dashboard/upload.ts | 5 ++++- public/app/plugins/datasource/graphite/datasource.ts | 10 ++++++---- public/app/plugins/datasource/graphite/lexer.ts | 5 +++-- .../plugins/datasource/logging/result_transformer.ts | 5 +++-- public/app/plugins/datasource/prometheus/datasource.ts | 6 ++++-- tslint.json | 1 + 9 files changed, 28 insertions(+), 14 deletions(-) diff --git a/public/app/containers/Explore/utils/dom.ts b/public/app/containers/Explore/utils/dom.ts index 6ab3de39923..381c150e3f4 100644 --- a/public/app/containers/Explore/utils/dom.ts +++ b/public/app/containers/Explore/utils/dom.ts @@ -9,7 +9,8 @@ if ('Element' in window && !Element.prototype.closest) { i = matches.length; // eslint-disable-next-line while (--i >= 0 && matches.item(i) !== el) {} - } while (i < 0 && (el = el.parentElement)); + el = el.parentElement; + } while (i < 0 && el); return el; }; } diff --git a/public/app/core/components/search/search.ts b/public/app/core/components/search/search.ts index b8e3ea5d3e2..d459c497521 100644 --- a/public/app/core/components/search/search.ts +++ b/public/app/core/components/search/search.ts @@ -131,7 +131,8 @@ export class SearchCtrl { const max = flattenedResult.length; let newIndex = this.selectedIndex + direction; - this.selectedIndex = (newIndex %= max) < 0 ? newIndex + max : newIndex; + const something = (newIndex %= max); + this.selectedIndex = something < 0 ? newIndex + max : newIndex; const selectedItem = flattenedResult[this.selectedIndex]; if (selectedItem.dashboardIndex === undefined && this.results[selectedItem.folderIndex].id === 0) { diff --git a/public/app/core/directives/rebuild_on_change.ts b/public/app/core/directives/rebuild_on_change.ts index 72b9c05064a..12034874bf9 100644 --- a/public/app/core/directives/rebuild_on_change.ts +++ b/public/app/core/directives/rebuild_on_change.ts @@ -5,14 +5,16 @@ function getBlockNodes(nodes) { let node = nodes[0]; const endNode = nodes[nodes.length - 1]; let blockNodes; + node = node.nextSibling; - for (let i = 1; node !== endNode && (node = node.nextSibling); i++) { + for (let i = 1; node !== endNode && node; i++) { if (blockNodes || nodes[i] !== node) { if (!blockNodes) { blockNodes = $([].slice.call(nodes, 0, i)); } blockNodes.push(node); } + node = node.nextSibling; } return blockNodes || nodes; diff --git a/public/app/features/dashboard/upload.ts b/public/app/features/dashboard/upload.ts index 10d35d1f300..ee77c6e5394 100644 --- a/public/app/features/dashboard/upload.ts +++ b/public/app/features/dashboard/upload.ts @@ -36,10 +36,13 @@ function uploadDashboardDirective(timer, alertSrv, $location) { }; }; - for (let i = 0, f; (f = files[i]); i++) { + let i = 0; + let f = files[i]; + for (i; f; i++) { const reader = new FileReader(); reader.onload = readerOnload(); reader.readAsText(f); + f = files[i]; } } diff --git a/public/app/plugins/datasource/graphite/datasource.ts b/public/app/plugins/datasource/graphite/datasource.ts index e07212491b0..78ce36f74a3 100644 --- a/public/app/plugins/datasource/graphite/datasource.ts +++ b/public/app/plugins/datasource/graphite/datasource.ts @@ -218,9 +218,10 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv, if (matches) { const expressions = []; const exprRegex = /, *([^,]+)/g; - let match; - while ((match = exprRegex.exec(matches[2])) !== null) { + let match = exprRegex.exec(matches[2]); + while (match !== null) { expressions.push(match[1]); + match = exprRegex.exec(matches[2]); } options.limit = 10000; return this.getTagValuesAutoComplete(expressions, matches[1], undefined, options); @@ -233,9 +234,10 @@ export function GraphiteDatasource(this: any, instanceSettings, $q, backendSrv, if (matches[1]) { expressions.push(matches[1]); const exprRegex = /, *([^,]+)/g; - let match; - while ((match = exprRegex.exec(matches[2])) !== null) { + let match = exprRegex.exec(matches[2]); + while (match !== null) { expressions.push(match[1]); + match = exprRegex.exec(matches[2]); } } options.limit = 10000; diff --git a/public/app/plugins/datasource/graphite/lexer.ts b/public/app/plugins/datasource/graphite/lexer.ts index 1f2da854991..8999751f08b 100644 --- a/public/app/plugins/datasource/graphite/lexer.ts +++ b/public/app/plugins/datasource/graphite/lexer.ts @@ -941,9 +941,10 @@ Lexer.prototype = { tokenize: function() { const list = []; - let token; - while ((token = this.next())) { + let token = this.next(); + while (token) { list.push(token); + token = this.next(); } return list; }, diff --git a/public/app/plugins/datasource/logging/result_transformer.ts b/public/app/plugins/datasource/logging/result_transformer.ts index e238778614c..891f9268068 100644 --- a/public/app/plugins/datasource/logging/result_transformer.ts +++ b/public/app/plugins/datasource/logging/result_transformer.ts @@ -26,13 +26,14 @@ export function getSearchMatches(line: string, search: string) { } const regexp = new RegExp(`(?:${search})`, 'g'); const matches = []; - let match; - while ((match = regexp.exec(line))) { + let match = regexp.exec(line); + while (match) { matches.push({ text: match[0], start: match.index, length: match[0].length, }); + match = regexp.exec(line); } return matches; } diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 356322cf369..e3158e64d18 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -55,11 +55,12 @@ export function addLabelToQuery(query: string, key: string, value: string): stri // Adding label to existing selectors const selectorRegexp = /{([^{]*)}/g; - let match = null; + let match = selectorRegexp.exec(query); const parts = []; let lastIndex = 0; let suffix = ''; - while ((match = selectorRegexp.exec(query))) { + + while (match) { const prefix = query.slice(lastIndex, match.index); const selectorParts = match[1].split(','); const labels = selectorParts.reduce((acc, label) => { @@ -77,6 +78,7 @@ export function addLabelToQuery(query: string, key: string, value: string): stri lastIndex = match.index + match[1].length + 2; suffix = query.slice(match.index + match[0].length); parts.push(prefix, '{', selector, '}'); + match = selectorRegexp.exec(query); } parts.push(suffix); return parts.join(''); diff --git a/tslint.json b/tslint.json index 0d525bea3f0..13323068ec1 100644 --- a/tslint.json +++ b/tslint.json @@ -33,6 +33,7 @@ "no-angle-bracket-type-assertion": true, "no-arg": true, "no-bitwise": false, + "no-conditional-assignment": true, "no-console": [true, "debug", "info", "time", "timeEnd", "trace"], "no-construct": true, "no-debugger": true,