mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Enable "prefer-const" rule (#91495)
This commit is contained in:
parent
e771500487
commit
500ae2ff1e
@ -1,6 +1,7 @@
|
||||
{
|
||||
"plugins": ["testing-library"],
|
||||
"rules": {
|
||||
"prefer-const": "error",
|
||||
"react/no-unused-prop-types": "error",
|
||||
},
|
||||
"overrides": [
|
||||
|
@ -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)
|
||||
);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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(' ');
|
||||
|
@ -133,7 +133,7 @@ export function NotificationRoute({
|
||||
<div className={styles.routeInstances} data-testid="route-matching-instance">
|
||||
{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,
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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
|
||||
|
@ -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];
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<Request[]> {
|
||||
let requests: Request[] = [];
|
||||
const requests: Request[] = [];
|
||||
|
||||
server.events.on('request:start', ({ request }) => {
|
||||
requests.push(request);
|
||||
|
@ -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());
|
||||
|
@ -89,7 +89,7 @@ function findMatchingRoutes<T extends Route>(route: T, labels: Label[]): Array<R
|
||||
// If the current node matches, recurse through child nodes
|
||||
if (route.routes) {
|
||||
for (const child of route.routes) {
|
||||
let matchingChildren = findMatchingRoutes(child, labels);
|
||||
const matchingChildren = findMatchingRoutes(child, labels);
|
||||
// TODO how do I solve this typescript thingy? It looks correct to me /shrug
|
||||
// @ts-ignore
|
||||
childMatches = childMatches.concat(matchingChildren);
|
||||
@ -266,7 +266,7 @@ function isLabelMatchInSet(matcher: ObjectMatcher, labels: Label[]): boolean {
|
||||
// for route selection algorithm, always compare a single matcher to the entire label set
|
||||
// see "matchLabelsSet"
|
||||
function isLabelMatch(matcher: ObjectMatcher, label: Label): boolean {
|
||||
let [labelKey, labelValue] = label;
|
||||
const [labelKey, labelValue] = label;
|
||||
const [matcherKey, operator, matcherValue] = matcher;
|
||||
|
||||
if (labelKey !== matcherKey) {
|
||||
|
@ -61,7 +61,7 @@ const INVALID_FORMAT = new Error(
|
||||
*/
|
||||
export function parsePrometheusDuration(duration: string): number {
|
||||
let input = duration;
|
||||
let parts: Array<[number, string]> = [];
|
||||
const parts: Array<[number, string]> = [];
|
||||
|
||||
function matchDuration(part: string) {
|
||||
const match = DURATION_REGEXP.exec(part);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user