Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Part 1] Fixed lint errors #1225

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .eslintrc
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting this because we should use the core config

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"cypress:run": "cypress run",
"osd": "node ../../scripts/osd",
"opensearch": "node ../../scripts/opensearch",
"lint": "node ../../scripts/eslint .",
"lint": "node ../../scripts/eslint",
"plugin-helpers": "node ../../scripts/plugin_helpers",
"test:jest": "../../node_modules/.bin/jest --config ./test/jest.config.js",
"test:jest:dev": "../../node_modules/.bin/jest --watch --config ./test/jest.config.js",
Expand Down
3 changes: 1 addition & 2 deletions public/components/Modal/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import { EuiButton, EuiOverlayMask, EuiModal } from '@elastic/eui';
import { render, fireEvent } from '@testing-library/react';
import ModalRoot from './ModalRoot';
import { ModalConsumer, ModalProvider } from './Modal';
import { SecurityAnalyticsContext, SaContextConsumer } from '../../services';
import { SecurityAnalyticsContext, SaContextConsumer, MetricsService } from '../../services';
import services from '../../../test/mocks/services';
import { MetricsContext } from '../../metrics/MetricsContext';
import MetricsService from '../../services/MetricsService';
import httpClientMock from '../../../test/mocks/services/httpClient.mock';

describe('<ModalRoot /> spec', () => {
Expand Down
6 changes: 3 additions & 3 deletions public/metrics/DetectorMetricsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { CreateDetectorSteps, CreateDetectorStepValue } from '../../types';
import MetricsService from '../services/MetricsService';
import { MetricsService } from '../services';

export class DetectorMetricsManager {
private static initialCheckpoint = CreateDetectorStepValue[CreateDetectorSteps.notStarted];
Expand All @@ -31,7 +31,7 @@ export class DetectorMetricsManager {
[stepNameForCounter || step]: 1,
},
});
this.stepsLogged |= stepValue;
this.stepsLogged |= stepValue; // eslint-disable-line no-bitwise
}
}

Expand All @@ -40,6 +40,6 @@ export class DetectorMetricsManager {
}

private metricEmittedForStep(stepValue: number): boolean {
return (this.stepsLogged & stepValue) === stepValue;
return (this.stepsLogged & stepValue) === stepValue; // eslint-disable-line no-bitwise
}
}
2 changes: 1 addition & 1 deletion public/metrics/MetricsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import MetricsService from '../services/MetricsService';
import { MetricsService } from '../services';
import { DetectorMetricsManager } from './DetectorMetricsManager';

export class MetricsContext {
Expand Down
6 changes: 3 additions & 3 deletions public/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
NotificationsService,
IndexPatternsService,
LogTypeService,
CorrelationService,
MetricsService,
ThreatIntelService,
} from '../services';
import CorrelationService from '../services/CorrelationService';
import MetricsService from '../services/MetricsService';
import ThreatIntelService from '../services/ThreatIntelService';

export interface BrowserServices {
detectorsService: DetectorsService;
Expand Down
6 changes: 3 additions & 3 deletions public/pages/Alerts/containers/Alerts/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import {
DEFAULT_EMPTY_DATA,
MAX_RECENTLY_USED_TIME_RANGES,
} from '../../../../utils/constants';
import AlertsService from '../../../../services/AlertsService';
import DetectorService from '../../../../services/DetectorService';
import { AlertsService } from '../../../../services/AlertsService';
import { DetectorsService } from '../../../../services/DetectorService';
import { AlertFlyout } from '../../components/AlertFlyout/AlertFlyout';
import { CorrelationAlertFlyout } from '../../components/CorrelationAlertFlyout/CorrelationAlertFlyout';
import {
Expand Down Expand Up @@ -85,7 +85,7 @@ type FilterAlertParams =

export interface AlertsProps extends RouteComponentProps, DataSourceProps {
alertService: AlertsService;
detectorService: DetectorService;
detectorService: DetectorsService;
findingService: FindingsService;
opensearchService: OpenSearchService;
correlationService: CorrelationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ exports[`<Alerts /> spec renders the component 1`] = `
"getFindings": [Function],
"getThreatIntelFindings": [Function],
"httpClient": [MockFunction],
"notifications": undefined,
"notifications": Object {
"toasts": Object {
"addDanger": [MockFunction],
"addInfo": [MockFunction],
"addSuccess": [MockFunction],
"addWarning": [MockFunction],
},
},
}
}
match={[MockFunction]}
Expand Down Expand Up @@ -133,7 +140,14 @@ exports[`<Alerts /> spec renders the component 1`] = `
"getFindings": [Function],
"getThreatIntelFindings": [Function],
"httpClient": [MockFunction],
"notifications": undefined,
"notifications": Object {
"toasts": Object {
"addDanger": [MockFunction],
"addInfo": [MockFunction],
"addSuccess": [MockFunction],
"addWarning": [MockFunction],
},
},
}
}
history={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ import {
EuiSpacer,
EuiCallOut,
EuiTextColor,
EuiTitle,
EuiText,
} from '@elastic/eui';
import { FormFieldHeader } from '../../../../../../components/FormFieldHeader/FormFieldHeader';
import { IndexOption } from '../../../../../Detectors/models/interfaces';
import { MIN_NUM_DATA_SOURCES } from '../../../../../Detectors/utils/constants';
import IndexService from '../../../../../../services/IndexService';
import { NotificationsStart } from 'opensearch-dashboards/public';
import { getDataSources } from '../../../../../../utils/helpers';
import _ from 'lodash';
import { FieldMappingService } from '../../../../../../services';
import { FieldMappingService, IndexService } from '../../../../../../services';
import { DataSourceProps } from '../../../../../../../types';

interface DetectorDataSourceProps extends DataSourceProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@

import React, { Component } from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { EuiSmallButton, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiTitle, EuiText } from '@elastic/eui';
import {
EuiSmallButton,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
EuiTitle,
EuiText,
} from '@elastic/eui';
import { FieldMapping } from '../../../../../models/interfaces';
import FieldMappingService from '../../../../services/FieldMappingService';
import { FieldMappingService } from '../../../../services/FieldMappingService';
import { DetectorHit, SearchDetectorsResponse } from '../../../../../server/models/interfaces';
import { BREADCRUMBS, EMPTY_DEFAULT_DETECTOR, ROUTES } from '../../../../utils/constants';
import { DetectorsService } from '../../../../services';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,13 @@ exports[`<DetectorDetails /> spec renders the component 1`] = `
"deleteVisualization": [Function],
"getDashboard": [Function],
"getDashboards": [Function],
"indexService": undefined,
"indexService": Object {
"getAliases": [MockFunction],
"getIndexFields": [MockFunction],
"getIndices": [Function],
"httpClient": [MockFunction],
"updateAliases": [MockFunction],
},
"savedObjectsClient": Object {
"delete": [MockFunction],
"get": [MockFunction],
Expand Down Expand Up @@ -1042,7 +1048,13 @@ exports[`<DetectorDetails /> spec renders the component 1`] = `
"deleteVisualization": [Function],
"getDashboard": [Function],
"getDashboards": [Function],
"indexService": undefined,
"indexService": Object {
"getAliases": [MockFunction],
"getIndexFields": [MockFunction],
"getIndices": [Function],
"httpClient": [MockFunction],
"updateAliases": [MockFunction],
},
"savedObjectsClient": Object {
"delete": [MockFunction],
"get": [MockFunction],
Expand Down Expand Up @@ -1468,7 +1480,13 @@ exports[`<DetectorDetails /> spec renders the component 1`] = `
"deleteVisualization": [Function],
"getDashboard": [Function],
"getDashboards": [Function],
"indexService": undefined,
"indexService": Object {
"getAliases": [MockFunction],
"getIndexFields": [MockFunction],
"getIndices": [Function],
"httpClient": [MockFunction],
"updateAliases": [MockFunction],
},
"savedObjectsClient": Object {
"delete": [MockFunction],
"get": [MockFunction],
Expand Down Expand Up @@ -2743,7 +2761,13 @@ exports[`<DetectorDetails /> spec renders the component 1`] = `
"deleteVisualization": [Function],
"getDashboard": [Function],
"getDashboards": [Function],
"indexService": undefined,
"indexService": Object {
"getAliases": [MockFunction],
"getIndexFields": [MockFunction],
"getIndices": [Function],
"httpClient": [MockFunction],
"updateAliases": [MockFunction],
},
"savedObjectsClient": Object {
"delete": [MockFunction],
"get": [MockFunction],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import FieldMappingsTable from '../../../CreateDetector/components/ConfigureFieldMapping/components/RequiredFieldMapping';
import { ContentPanel } from '../../../../components/ContentPanel';
import { FieldMapping } from '../../../../../models/interfaces';
import FieldMappingService from '../../../../services/FieldMappingService';
import { FieldMappingService } from '../../../../services/FieldMappingService';
import { MappingViewType } from '../../../CreateDetector/components/ConfigureFieldMapping/components/RequiredFieldMapping/FieldMappingsTable';
import { Detector } from '../../../../../types';
import { FieldMappingsTableItem } from '../../../CreateDetector/models/interfaces';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,34 @@

import React from 'react';
import { render } from '@testing-library/react';
import { expect } from '@jest/globals';
import { DetectionVisualEditor } from './DetectionVisualEditor';
import DetectionVisualEditorMock from '../../../../../test/mocks/Rules/components/RuleEditor/DetectionVisualEditor.mock';

describe('<SelectionExpField /> spec', () => {
beforeAll(() => {
function at(this: any[], n: number) {
// ToInteger() abstract op
n = Math.trunc(n) || 0;
// Allow negative indexing from the end
if (n < 0) n += this.length;
// OOB access is guaranteed to return undefined
if (n < 0 || n >= this.length) return undefined;
// Otherwise, this is just normal property access
return this[n];
}

const TypedArray = Reflect.getPrototypeOf(Int8Array);
for (const C of [Array, String, TypedArray]) {
Object.defineProperty((C as any).prototype, 'at', {
value: at,
writable: true,
enumerable: false,
configurable: true,
});
}
});

it('renders the component', () => {
const tree = render(<DetectionVisualEditor {...DetectionVisualEditorMock} />);
expect(tree).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { BREADCRUMBS, ROUTES, defaultIntervalUnitOptions } from '../../../../utils/constants';
import { Interval } from '../../../CreateDetector/components/DefineDetector/components/DetectorSchedule/Interval';
import { RouteComponentProps } from 'react-router-dom';
import ThreatIntelService from '../../../../services/ThreatIntelService';
import { ThreatIntelService } from '../../../../services';
import {
FileUploadSource,
S3ConnectionSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
EuiTabbedContent,
EuiTabbedContentTab,
EuiText,
EuiTitle,
} from '@elastic/eui';
import React, { MouseEventHandler, useCallback, useEffect, useMemo } from 'react';
import { BREADCRUMBS, ROUTES } from '../../../../utils/constants';
Expand All @@ -30,7 +29,7 @@ import { RouteComponentProps } from 'react-router-dom';
import { ThreatIntelSourcesList } from '../../components/ThreatIntelSourcesList/ThreatIntelSourcesList';
import { deriveFormModelFromConfig, getThreatIntelNextStepsProps } from '../../utils/helpers';
import { ThreatIntelOverviewActions } from '../../components/ThreatIntelOverviewActions/ThreatIntelOverviewActions';
import ThreatIntelService from '../../../../services/ThreatIntelService';
import { ThreatIntelService } from '../../../../services';
import { ThreatIntelLogScanConfig } from '../../components/ThreatIntelLogScanConfig/ThreatIntelLogScanConfig';
import { setBreadcrumbs } from '../../../../utils/helpers';
import { PageHeader } from '../../../../components/PageHeader/PageHeader';
Expand Down Expand Up @@ -237,7 +236,7 @@ export const ThreatIntelOverview: React.FC<ThreatIntelOverviewProps> = ({
</EuiFlexGroup>
</EuiAccordion>
<EuiSpacer />
<EuiTabbedContent tabs={tabs} initialSelectedTab={tabs[0]} size="s"/>
<EuiTabbedContent tabs={tabs} initialSelectedTab={tabs[0]} size="s" />
{flyoutContent && (
<EuiFlyout onClose={() => setFlyoutContent(null)}>
<EuiSpacer />
Expand Down
8 changes: 4 additions & 4 deletions public/services/AlertsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import {
import { dataSourceInfo } from './utils/constants';
import { errorNotificationToast } from '../utils/helpers';

export default class AlertsService {
export class AlertsService {
constructor(private httpClient: HttpSetup, private notifications: NotificationsStart) {}

getAlerts = async (
getAlertsParams: GetAlertsParams
): Promise<ServerResponse<GetAlertsResponse>> => {
const {
detectorType,
detector_id,
detector_id, // eslint-disable-line @typescript-eslint/naming-convention
size,
sortOrder,
startIndex,
Expand Down Expand Up @@ -59,9 +59,9 @@ export default class AlertsService {

acknowledgeAlerts = async (
alertIds: string[],
detector_id: string
detectorId: string
): Promise<ServerResponse<AcknowledgeAlertsResponse>> => {
const url = API.ACKNOWLEDGE_ALERTS.replace('{detector_id}', detector_id);
const url = API.ACKNOWLEDGE_ALERTS.replace('{detector_id}', detectorId);
const body = JSON.stringify({ alerts: alertIds });
return await this.httpClient.post(`..${url}`, {
body,
Expand Down
Loading
Loading