diff --git a/public/app/features/alerting/.eslintrc b/public/app/features/alerting/.eslintrc index 276a60245e1..2d9d9cbfe7b 100644 --- a/public/app/features/alerting/.eslintrc +++ b/public/app/features/alerting/.eslintrc @@ -1,6 +1,7 @@ { "plugins": ["testing-library"], "rules": { + "prefer-const": "error", "react/no-unused-prop-types": "error", }, "overrides": [ diff --git a/public/app/features/alerting/unified/AlertsFolderView.tsx b/public/app/features/alerting/unified/AlertsFolderView.tsx index bfebca0c03a..6bfbf2cfd0a 100644 --- a/public/app/features/alerting/unified/AlertsFolderView.tsx +++ b/public/app/features/alerting/unified/AlertsFolderView.tsx @@ -170,7 +170,7 @@ function filterAndSortRules( sortOrder: SortOrder ) { const matchers = parsePromQLStyleMatcherLooseSafe(labelFilter); - let rules = originalRules.filter( + const rules = originalRules.filter( (rule) => rule.name.toLowerCase().includes(nameFilter.toLowerCase()) && labelsMatchMatchers(rule.labels, matchers) ); diff --git a/public/app/features/alerting/unified/NotificationPolicies.tsx b/public/app/features/alerting/unified/NotificationPolicies.tsx index e02becd7c77..d59f23bd3ae 100644 --- a/public/app/features/alerting/unified/NotificationPolicies.tsx +++ b/public/app/features/alerting/unified/NotificationPolicies.tsx @@ -322,7 +322,7 @@ export const findRoutesMatchingFilters = (rootRoute: RouteWithID, filters: Route // // [contactPointMatches, labelMatcherMatches] -> [[{ a: [], b: [] }], [{ a: [], c: [] }]] // later we'll use intersection to find results in all sets of filter matchers - let matchedRoutes: RouteWithID[][] = []; + const matchedRoutes: RouteWithID[][] = []; // compute fully inherited tree so all policies have their inherited receiver const fullRoute = computeInheritedTree(rootRoute); diff --git a/public/app/features/alerting/unified/RuleList.test.tsx b/public/app/features/alerting/unified/RuleList.test.tsx index 6d9673b1c7a..91a647f7f31 100644 --- a/public/app/features/alerting/unified/RuleList.test.tsx +++ b/public/app/features/alerting/unified/RuleList.test.tsx @@ -384,7 +384,7 @@ describe('RuleList', () => { const table = await ui.rulesTable.find(groups[1]); // check that rule rows are rendered properly - let ruleRows = ui.ruleRow.getAll(table); + const ruleRows = ui.ruleRow.getAll(table); expect(ruleRows).toHaveLength(4); expect(ruleRows[0]).toHaveTextContent('Recording rule'); diff --git a/public/app/features/alerting/unified/api/annotations.test.ts b/public/app/features/alerting/unified/api/annotations.test.ts index ae8cece3be5..01da8c9da97 100644 --- a/public/app/features/alerting/unified/api/annotations.test.ts +++ b/public/app/features/alerting/unified/api/annotations.test.ts @@ -29,7 +29,7 @@ describe(sortStateHistory, () => { describe('should stably sort', () => { describe('when timeEnd is different', () => { it('should not sort by rule id', () => { - let data: StateHistoryItem[] = [ + const data: StateHistoryItem[] = [ { timeEnd: 23, time: 22, id: 1 } as StateHistoryItem, { timeEnd: 22, time: 21, id: 3 } as StateHistoryItem, { timeEnd: 22, time: 22, id: 2 } as StateHistoryItem, @@ -46,7 +46,7 @@ describe(sortStateHistory, () => { describe('when only the rule id is different', () => { it('should sort by rule id', () => { - let data: StateHistoryItem[] = [ + const data: StateHistoryItem[] = [ { timeEnd: 23, time: 22, id: 1 } as StateHistoryItem, { timeEnd: 23, time: 22, id: 3 } as StateHistoryItem, { timeEnd: 23, time: 22, id: 2 } as StateHistoryItem, diff --git a/public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx b/public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx index df53213e004..d4a1b73113b 100644 --- a/public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx +++ b/public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx @@ -42,7 +42,7 @@ const ContactPointsTab = () => { const { selectedAlertmanager } = useAlertmanager(); const [queryParams] = useURLSearchParams(); - let { isLoading, error, contactPoints } = useContactPointsWithStatus(); + const { isLoading, error, contactPoints } = useContactPointsWithStatus(); const { deleteTrigger, updateAlertmanagerState } = useDeleteContactPoint(selectedAlertmanager!); const [addContactPointSupported, addContactPointAllowed] = useAlertmanagerAbility( AlertmanagerAction.CreateContactPoint @@ -160,7 +160,7 @@ const ContactPointsPageContents = () => { const { selectedAlertmanager } = useAlertmanager(); const [activeTab, setActiveTab] = useTabQueryParam(); - let { contactPoints } = useContactPointsWithStatus(); + const { contactPoints } = useContactPointsWithStatus(); const showingContactPoints = activeTab === ActiveTab.ContactPoints; const showNotificationTemplates = activeTab === ActiveTab.NotificationTemplates; diff --git a/public/app/features/alerting/unified/components/rule-editor/dag.ts b/public/app/features/alerting/unified/components/rule-editor/dag.ts index 407fe2f0912..2971dd66a1e 100644 --- a/public/app/features/alerting/unified/components/rule-editor/dag.ts +++ b/public/app/features/alerting/unified/components/rule-editor/dag.ts @@ -63,7 +63,7 @@ export const getOriginOfRefId = memoize(_getOriginsOfRefId, (refId, graph) => re export function _getOriginsOfRefId(refId: string, graph: Graph): string[] { const node = graph.getNode(refId); - let origins: Node[] = []; + const origins: Node[] = []; // recurse through "node > inputEdges > inputNode" function findChildNode(node: Node) { @@ -90,8 +90,8 @@ export function fingerprintGraph(graph: Graph) { return Object.keys(graph.nodes) .map((name) => { const n = graph.nodes[name]; - let outputEdges = n.outputEdges.map((e: Edge) => e.outputNode?.name).join(', '); - let inputEdges = n.inputEdges.map((e: Edge) => e.inputNode?.name).join(', '); + const outputEdges = n.outputEdges.map((e: Edge) => e.outputNode?.name).join(', '); + const inputEdges = n.inputEdges.map((e: Edge) => e.inputNode?.name).join(', '); return `${n.name}:${outputEdges}:${inputEdges}`; }) .join(' '); diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationRoute.tsx b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationRoute.tsx index 8c114ddcfb5..da14fb357c3 100644 --- a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationRoute.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/NotificationRoute.tsx @@ -133,7 +133,7 @@ export function NotificationRoute({
{instanceMatches.map((instanceMatch) => { const matchArray = Array.from(instanceMatch.labelsMatch); - let matchResult = matchArray.map(([label, matchResult]) => ({ + const matchResult = matchArray.map(([label, matchResult]) => ({ label: `${label[0]}=${label[1]}`, match: matchResult.match, colorIndex: matchResult.match ? getTagColorIndexFromName(label[0]) : GREY_COLOR_INDEX, diff --git a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/reducer.test.tsx b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/reducer.test.tsx index cad78a29314..8a4a72c2173 100644 --- a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/reducer.test.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/reducer.test.tsx @@ -123,11 +123,11 @@ describe('Query and expressions reducer', () => { queries: [alertQuery, expressionQuery], }; - let stateWithoutB = queriesAndExpressionsReducer(initialState, removeExpression('B')); + const stateWithoutB = queriesAndExpressionsReducer(initialState, removeExpression('B')); expect(stateWithoutB.queries).toHaveLength(1); expect(stateWithoutB).toMatchSnapshot(); - let stateWithoutAOrB = queriesAndExpressionsReducer(stateWithoutB, removeExpression('A')); + const stateWithoutAOrB = queriesAndExpressionsReducer(stateWithoutB, removeExpression('A')); expect(stateWithoutAOrB.queries).toHaveLength(0); }); diff --git a/public/app/features/alerting/unified/components/rules/RuleDetails.tsx b/public/app/features/alerting/unified/components/rules/RuleDetails.tsx index 16086353b99..6c8ddb552e1 100644 --- a/public/app/features/alerting/unified/components/rules/RuleDetails.tsx +++ b/public/app/features/alerting/unified/components/rules/RuleDetails.tsx @@ -65,9 +65,9 @@ interface EvaluationBehaviorSummaryProps { const EvaluationBehaviorSummary = ({ rule }: EvaluationBehaviorSummaryProps) => { let forDuration: string | undefined; - let every = rule.group.interval; - let lastEvaluation = rule.promRule?.lastEvaluation; - let lastEvaluationDuration = rule.promRule?.evaluationTime; + const every = rule.group.interval; + const lastEvaluation = rule.promRule?.lastEvaluation; + const lastEvaluationDuration = rule.promRule?.evaluationTime; const metric = isGrafanaRecordingRule(rule.rulerRule) ? rule.rulerRule?.grafana_alert.record?.metric : undefined; // recording rules don't have a for duration diff --git a/public/app/features/alerting/unified/components/rules/RuleStats.tsx b/public/app/features/alerting/unified/components/rules/RuleStats.tsx index d772d6843a7..b0e696f11b5 100644 --- a/public/app/features/alerting/unified/components/rules/RuleStats.tsx +++ b/public/app/features/alerting/unified/components/rules/RuleStats.tsx @@ -62,7 +62,7 @@ function statsFromNamespaces(namespaces: CombinedRuleNamespace[]): AlertGroupTot namespaces.forEach(({ groups }) => { groups.forEach((group) => { const groupTotals = omitBy(group.totals, isUndefined); - for (let key in groupTotals) { + for (const key in groupTotals) { // @ts-ignore stats[key] += groupTotals[key]; } diff --git a/public/app/features/alerting/unified/components/settings/SettingsContext.tsx b/public/app/features/alerting/unified/components/settings/SettingsContext.tsx index 03fc283a8f1..c5c51cca7f6 100644 --- a/public/app/features/alerting/unified/components/settings/SettingsContext.tsx +++ b/public/app/features/alerting/unified/components/settings/SettingsContext.tsx @@ -45,7 +45,7 @@ const isInternalAlertmanager = (uid: string) => uid === GRAFANA_RULES_SOURCE_NAM export const SettingsProvider = (props: PropsWithChildren) => { // this list will keep track of Alertmanager UIDs (including internal) that are interested in receiving alert instances // this will be used to infer the correct "delivery mode" and update the correct list of datasources with "wantsAlertsReceived" - let interestedAlertmanagers: string[] = []; + const interestedAlertmanagers: string[] = []; const forwardingDisabled = config.featureToggles.alertingDisableSendAlertsExternal === true; diff --git a/public/app/features/alerting/unified/mocks/server/events.ts b/public/app/features/alerting/unified/mocks/server/events.ts index 0da10ccf3fc..6cc27da9d8e 100644 --- a/public/app/features/alerting/unified/mocks/server/events.ts +++ b/public/app/features/alerting/unified/mocks/server/events.ts @@ -41,7 +41,7 @@ interface SerializedRequest { * @deprecated Try not to use this 🙏 instead aim to assert against UI side effects */ export async function captureRequests(): Promise { - let requests: Request[] = []; + const requests: Request[] = []; server.events.on('request:start', ({ request }) => { requests.push(request); diff --git a/public/app/features/alerting/unified/search/searchParser.ts b/public/app/features/alerting/unified/search/searchParser.ts index 0861ad9d067..8e621df2c5d 100644 --- a/public/app/features/alerting/unified/search/searchParser.ts +++ b/public/app/features/alerting/unified/search/searchParser.ts @@ -99,7 +99,7 @@ export function applyFiltersToQuery( } }); - let newQueryExpressions: string[] = []; + const newQueryExpressions: string[] = []; // Apply filters from filterState in the same order as they appear in the search query // This allows to remain the order of filters in the search input during changes @@ -136,7 +136,7 @@ export function applyFiltersToQuery( function traverseNodeTree(query: string, supportedTerms: FilterSupportedTerm[], visit: (node: SyntaxNode) => void) { const dialect = supportedTerms.join(' '); const parsed = parser.configure({ dialect }).parse(query); - let cursor = parsed.cursor(); + const cursor = parsed.cursor(); do { visit(cursor.node); } while (cursor.next()); diff --git a/public/app/features/alerting/unified/utils/notification-policies.ts b/public/app/features/alerting/unified/utils/notification-policies.ts index 8e60490d7f8..685172a7b7e 100644 --- a/public/app/features/alerting/unified/utils/notification-policies.ts +++ b/public/app/features/alerting/unified/utils/notification-policies.ts @@ -89,7 +89,7 @@ function findMatchingRoutes(route: T, labels: Label[]): Array = []; + const parts: Array<[number, string]> = []; function matchDuration(part: string) { const match = DURATION_REGEXP.exec(part); diff --git a/public/app/features/alerting/unified/utils/timeRange.ts b/public/app/features/alerting/unified/utils/timeRange.ts index 11edb6c9034..043fdc7c524 100644 --- a/public/app/features/alerting/unified/utils/timeRange.ts +++ b/public/app/features/alerting/unified/utils/timeRange.ts @@ -45,8 +45,8 @@ const getReferencedIdsForClassicCondition = (model: ExpressionQuery) => { }; const getTimeRanges = (referencedRefIds: string[], queries: AlertQuery[]) => { - let from: number[] = []; - let to = [FALL_BACK_TIME_RANGE.to]; + const from: number[] = []; + const to = [FALL_BACK_TIME_RANGE.to]; for (const referencedRefIdsKey of referencedRefIds) { const query = queries.find((query) => query.refId === referencedRefIdsKey);