Skip to content

Commit d4bbacd

Browse files
authored
Reformat using Prettier CLI and add doc to developer guide (opensearch-project#168)
Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
1 parent a7e2b94 commit d4bbacd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+370
-313
lines changed

.cypress/integration/ad/workflow/create_detector.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* GitHub history for details.
1010
*/
1111

12-
1312
import { CREATE_AD } from '../../../utils/constants';
1413
import { buildAdAppUrl } from '../../../utils/helpers';
1514

.cypress/support/commands.ts

+109-101
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* GitHub history for details.
1010
*/
1111

12-
1312
import {
1413
DETECTORS,
1514
INDICES_PATH,
@@ -43,117 +42,126 @@ Cypress.Commands.overwrite('visit', (orig, url, options) => {
4342
}
4443
});
4544

46-
Cypress.Commands.add('mockGetDetectorOnAction', function (
47-
fixtureFileName: string,
48-
funcMockedOn: VoidFunction
49-
) {
50-
cy.server();
51-
cy.route2(buildAdApiUrl(DETECTORS + '*'), { fixture: fixtureFileName }).as(
52-
'getDetectors'
53-
);
54-
55-
funcMockedOn();
56-
57-
cy.wait('@getDetectors');
58-
});
59-
60-
Cypress.Commands.add('mockCreateDetectorOnAction', function (
61-
fixtureFileName: string,
62-
funcMockedOn: VoidFunction
63-
) {
64-
cy.server();
65-
cy.route2(buildAdApiUrl(DETECTORS + '*'), { fixture: fixtureFileName }).as(
66-
'createDetector'
67-
);
68-
69-
funcMockedOn();
70-
71-
cy.wait('@createDetector');
72-
});
73-
74-
Cypress.Commands.add('mockSearchIndexOnAction', function (
75-
fixtureFileName: string,
76-
funcMockedOn: VoidFunction
77-
) {
78-
cy.server();
79-
cy.route2(buildAdApiUrl(INDICES_PATH + '*'), { fixture: fixtureFileName }).as(
80-
'getIndices'
81-
);
82-
83-
funcMockedOn();
84-
85-
cy.wait('@getIndices');
86-
});
87-
88-
Cypress.Commands.add('mockSearchOnAction', function (
89-
fixtureFileName: string,
90-
funcMockedOn: VoidFunction
91-
) {
92-
cy.server();
93-
cy.route2(buildAdApiUrl(SEARCH_PATH), { fixture: fixtureFileName }).as(
94-
'searchOpenSearch'
95-
);
45+
Cypress.Commands.add(
46+
'mockGetDetectorOnAction',
47+
function (fixtureFileName: string, funcMockedOn: VoidFunction) {
48+
cy.server();
49+
cy.route2(buildAdApiUrl(DETECTORS + '*'), { fixture: fixtureFileName }).as(
50+
'getDetectors'
51+
);
9652

97-
funcMockedOn();
53+
funcMockedOn();
9854

99-
cy.wait('@searchOpenSearch');
100-
});
55+
cy.wait('@getDetectors');
56+
}
57+
);
10158

102-
Cypress.Commands.add('mockGetIndexMappingsOnAction', function (
103-
fixtureFileName: string,
104-
funcMockedOn: VoidFunction
105-
) {
106-
cy.server();
107-
cy.route2(buildAdApiUrl(MAPPINGS_PATH + '*'), {
108-
fixture: fixtureFileName,
109-
}).as('getMappings');
59+
Cypress.Commands.add(
60+
'mockCreateDetectorOnAction',
61+
function (fixtureFileName: string, funcMockedOn: VoidFunction) {
62+
cy.server();
63+
cy.route2(buildAdApiUrl(DETECTORS + '*'), { fixture: fixtureFileName }).as(
64+
'createDetector'
65+
);
11066

111-
funcMockedOn();
67+
funcMockedOn();
11268

113-
cy.wait('@getMappings');
114-
});
69+
cy.wait('@createDetector');
70+
}
71+
);
11572

116-
Cypress.Commands.add('mockStartDetectorOnAction', function (
117-
fixtureFileName: string,
118-
detectorId: string,
119-
funcMockedOn: VoidFunction
120-
) {
121-
cy.server();
122-
cy.route2(buildAdApiUrl([DETECTORS, detectorId, START_PATH].join(SLASH)), {
123-
fixture: fixtureFileName,
124-
}).as('startDetector');
73+
Cypress.Commands.add(
74+
'mockSearchIndexOnAction',
75+
function (fixtureFileName: string, funcMockedOn: VoidFunction) {
76+
cy.server();
77+
cy.route2(buildAdApiUrl(INDICES_PATH + '*'), {
78+
fixture: fixtureFileName,
79+
}).as('getIndices');
12580

126-
funcMockedOn();
81+
funcMockedOn();
12782

128-
cy.wait('@startDetector');
129-
});
83+
cy.wait('@getIndices');
84+
}
85+
);
13086

131-
Cypress.Commands.add('mockStopDetectorOnAction', function (
132-
fixtureFileName: string,
133-
detectorId: string,
134-
funcMockedOn: VoidFunction
135-
) {
136-
cy.server();
137-
cy.route2(buildAdApiUrl([DETECTORS, detectorId, STOP_PATH].join(SLASH)), {
138-
fixture: fixtureFileName,
139-
}).as('stopDetector');
87+
Cypress.Commands.add(
88+
'mockSearchOnAction',
89+
function (fixtureFileName: string, funcMockedOn: VoidFunction) {
90+
cy.server();
91+
cy.route2(buildAdApiUrl(SEARCH_PATH), { fixture: fixtureFileName }).as(
92+
'searchOpenSearch'
93+
);
14094

141-
funcMockedOn();
95+
funcMockedOn();
14296

143-
cy.wait('@stopDetector');
144-
});
97+
cy.wait('@searchOpenSearch');
98+
}
99+
);
145100

146-
Cypress.Commands.add('mockDeleteDetectorOnAction', function (
147-
fixtureFileName: string,
148-
detectorId: string,
149-
funcMockedOn: VoidFunction
150-
) {
151-
cy.server();
152-
cy.route2(buildAdApiUrl([DETECTORS, detectorId].join(SLASH)), {
153-
fixture: fixtureFileName,
154-
}).as('deleteDetector');
101+
Cypress.Commands.add(
102+
'mockGetIndexMappingsOnAction',
103+
function (fixtureFileName: string, funcMockedOn: VoidFunction) {
104+
cy.server();
105+
cy.route2(buildAdApiUrl(MAPPINGS_PATH + '*'), {
106+
fixture: fixtureFileName,
107+
}).as('getMappings');
155108

156-
funcMockedOn();
109+
funcMockedOn();
157110

158-
cy.wait('@deleteDetector');
159-
});
111+
cy.wait('@getMappings');
112+
}
113+
);
114+
115+
Cypress.Commands.add(
116+
'mockStartDetectorOnAction',
117+
function (
118+
fixtureFileName: string,
119+
detectorId: string,
120+
funcMockedOn: VoidFunction
121+
) {
122+
cy.server();
123+
cy.route2(buildAdApiUrl([DETECTORS, detectorId, START_PATH].join(SLASH)), {
124+
fixture: fixtureFileName,
125+
}).as('startDetector');
126+
127+
funcMockedOn();
128+
129+
cy.wait('@startDetector');
130+
}
131+
);
132+
133+
Cypress.Commands.add(
134+
'mockStopDetectorOnAction',
135+
function (
136+
fixtureFileName: string,
137+
detectorId: string,
138+
funcMockedOn: VoidFunction
139+
) {
140+
cy.server();
141+
cy.route2(buildAdApiUrl([DETECTORS, detectorId, STOP_PATH].join(SLASH)), {
142+
fixture: fixtureFileName,
143+
}).as('stopDetector');
144+
145+
funcMockedOn();
146+
147+
cy.wait('@stopDetector');
148+
}
149+
);
150+
151+
Cypress.Commands.add(
152+
'mockDeleteDetectorOnAction',
153+
function (
154+
fixtureFileName: string,
155+
detectorId: string,
156+
funcMockedOn: VoidFunction
157+
) {
158+
cy.server();
159+
cy.route2(buildAdApiUrl([DETECTORS, detectorId].join(SLASH)), {
160+
fixture: fixtureFileName,
161+
}).as('deleteDetector');
162+
163+
funcMockedOn();
164+
165+
cy.wait('@deleteDetector');
166+
}
167+
);

.cypress/support/index.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* GitHub history for details.
1010
*/
1111

12-
1312
declare namespace Cypress {
1413
interface Chainable<Subject> {
1514
mockGetDetectorOnAction(

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.yml
2+
release-notes/

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"trailingComma": "es5",
33
"singleQuote": true,
44
"printWidth": 80
5-
}
5+
}

DEVELOPER_GUIDE.md

+10
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,13 @@ In the base OpenSearch Dashboards directory, run
6969

7070
Runs end-to-end tests on a currently running OpenSearch Dashboards server. Defaults to run the tests on `localhost:5601`, although you can change this to run on any
7171
OpenSearch Dashboards server with the command `yarn cy:run --config baseUrl=<your-custom-URL>`
72+
73+
### Formatting
74+
75+
This codebase uses Prettier as our code formatter. All new code that is added has to be reformatted using the Prettier version listed in `package.json`. In order to keep consistent formatting across the project developers should only use the prettier CLI to reformat their code using the following command:
76+
77+
```
78+
yarn prettier --write <relative file path>
79+
```
80+
81+
> NOTE: There also exists prettier plugins on several editors that allow for automatic reformatting on saving the file. However using this is discouraged as you must ensure that the plugin uses the correct version of prettier (listed in `package.json`) before using such a plugin.

babel.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* GitHub history for details.
1010
*/
1111

12-
1312
module.exports = {
1413
presets: [
1514
require('@babel/preset-env'),

public/hooks/useDelayedLoader.ts

+12-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* GitHub history for details.
1010
*/
1111

12-
1312
import { useState, useEffect, useCallback } from 'react';
1413

1514
export const useDelayedLoader = (isLoading: boolean): boolean => {
@@ -27,20 +26,17 @@ export const useDelayedLoader = (isLoading: boolean): boolean => {
2726
setTimer(timer);
2827
}, []);
2928

30-
useEffect(
31-
() => {
32-
if (isLoading) {
33-
handleSetTimer();
34-
} else {
35-
clearTimeout(timer);
36-
setLoader(false);
37-
}
38-
//Cleanup incase component unmounts
39-
return () => {
40-
clearTimeout(timer);
41-
};
42-
},
43-
[isLoading]
44-
);
29+
useEffect(() => {
30+
if (isLoading) {
31+
handleSetTimer();
32+
} else {
33+
clearTimeout(timer);
34+
setLoader(false);
35+
}
36+
//Cleanup incase component unmounts
37+
return () => {
38+
clearTimeout(timer);
39+
};
40+
}, [isLoading]);
4541
return loaderState;
4642
};

public/hooks/useSticky.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* GitHub history for details.
1010
*/
1111

12-
1312
import { useState, useEffect, useRef } from 'react';
1413

1514
export const useSticky = (ref: any, offset: number): boolean => {

public/pages/AnomalyCharts/components/AlertsFlyout/alertsFlyout.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Modifications Copyright OpenSearch Contributors. See
99
* GitHub history for details.
1010
*/
11-
11+
1212
.euiStep__title {
1313
display: contents;
1414
}

public/pages/DetectorDetail/hooks/useFetchMonitorInfo.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ import { searchMonitors } from '../../../redux/reducers/alerting';
1919
//A hook which gets AD monitor.
2020
export const useFetchMonitorInfo = (
2121
detectorId: string
22-
):
23-
{
22+
): {
2423
monitor: Monitor | undefined;
2524
fetchMonitorError: boolean;
26-
isLoadingMonitor: boolean
25+
isLoadingMonitor: boolean;
2726
} => {
2827
const dispatch = useDispatch();
2928
useEffect(() => {
@@ -33,7 +32,9 @@ export const useFetchMonitorInfo = (
3332
fetchAdMonitors();
3433
}, []);
3534

36-
const isMonitorRequesting = useSelector((state: AppState) => state.alerting.requesting);
35+
const isMonitorRequesting = useSelector(
36+
(state: AppState) => state.alerting.requesting
37+
);
3738
const monitors = useSelector((state: AppState) => state.alerting.monitors);
3839
const monitor = get(monitors, `${detectorId}.0`);
3940
const hasError = useSelector(

public/pages/DetectorResults/utils/constants.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* GitHub history for details.
1010
*/
1111

12-
1312
import {
1413
SORT_DIRECTION,
1514
AD_DOC_FIELDS,

public/pages/DetectorResults/utils/utils.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* GitHub history for details.
1010
*/
1111

12-
1312
import { Detector } from '../../../models/interfaces';
1413
import {
1514
NO_FULL_SHINGLE_ERROR_MESSAGE,

public/pages/DetectorsList/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@
99
* GitHub history for details.
1010
*/
1111

12-
1312
export { DetectorList } from './containers/List/List';

public/pages/DetectorsList/utils/__tests__/helpers.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* GitHub history for details.
1010
*/
1111

12-
1312
import { SORT_DIRECTION } from '../../../../../server/utils/constants';
1413
import {
1514
getURLQueryParams,

0 commit comments

Comments
 (0)