Skip to content

Commit 3efe3d8

Browse files
authored
(chore) Configure prettier (openmrs#838)
* (chore) Configure prettier * Commit API doc updates
1 parent 4ab6f53 commit 3efe3d8

File tree

485 files changed

+6844
-9931
lines changed

Some content is hidden

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

485 files changed

+6844
-9931
lines changed

.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": ["ts-react-important-stuff", "plugin:prettier/recommended"],
2+
"extends": ["ts-react-important-stuff"],
33
"parser": "@typescript-eslint/parser",
44
"ignorePatterns": ["**/*.test.tsx"],
55
"rules": {

.husky/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
set -e # die on error
55

66
yarn turbo extract-translations
7-
yarn pretty-quick --staged
7+
yarn prettier && npx lint-staged
88
yarn turbo document --since main

e2e/core/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./test";
1+
export * from './test';

e2e/core/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test as base } from "@playwright/test";
1+
import { test as base } from '@playwright/test';
22

33
// This file sets up our custom test harness using the custom fixtures.
44
// See https://playwright.dev/docs/test-fixtures#creating-a-fixture for details.

e2e/pages/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./login-page";
1+
export * from './login-page';

e2e/pages/login-page.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page } from "@playwright/test";
1+
import { Page } from '@playwright/test';
22

33
export class LoginPage {
44
constructor(readonly page: Page) {}

e2e/specs/login.spec.ts

+19-23
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
1-
import { test } from "../core";
2-
import { expect } from "@playwright/test";
3-
import { LoginPage } from "../pages";
1+
import { test } from '../core';
2+
import { expect } from '@playwright/test';
3+
import { LoginPage } from '../pages';
44

5-
test("Should login as Admin", async ({ page }) => {
5+
test('Should login as Admin', async ({ page }) => {
66
const loginPage = new LoginPage(page);
77

8-
await test.step("When I goto the login page", async () => {
8+
await test.step('When I goto the login page', async () => {
99
await loginPage.goto();
1010
});
1111

12-
await test.step("And I enter the username", async () => {
13-
await page
14-
.locator("#username")
15-
.fill(`${process.env.E2E_USER_ADMIN_USERNAME}`);
16-
await page.getByText("Continue").click();
12+
await test.step('And I enter the username', async () => {
13+
await page.locator('#username').fill(`${process.env.E2E_USER_ADMIN_USERNAME}`);
14+
await page.getByText('Continue').click();
1715
});
1816

19-
await test.step("And I enter the password", async () => {
20-
await page
21-
.locator("#password")
22-
.fill(`${process.env.E2E_USER_ADMIN_PASSWORD}`);
17+
await test.step('And I enter the password', async () => {
18+
await page.locator('#password').fill(`${process.env.E2E_USER_ADMIN_PASSWORD}`);
2319
});
2420

25-
await test.step("And I click login buttion", async () => {
26-
await page.getByText("Log in").click();
21+
await test.step('And I click login buttion', async () => {
22+
await page.getByText('Log in').click();
2723
});
2824

29-
await test.step("And I choose the location", async () => {
30-
await page.getByText("Outpatient clinic").click();
31-
await page.getByText("Confirm").click();
25+
await test.step('And I choose the location', async () => {
26+
await page.getByText('Outpatient clinic').click();
27+
await page.getByText('Confirm').click();
3228
});
3329

34-
await test.step("Then I should be logged in", async () => {
30+
await test.step('Then I should be logged in', async () => {
3531
await expect(page).toHaveURL(`${process.env.E2E_BASE_URL}/spa/home`);
3632
});
3733

38-
await test.step("Then I logged out", async () => {
39-
await page.getByRole("button", { name: "Users" }).click();
40-
await page.getByText("Logout").click();
34+
await test.step('Then I logged out', async () => {
35+
await page.getByRole('button', { name: 'Users' }).click();
36+
await page.getByText('Logout').click();
4137
});
4238
});

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"build:apps": "turbo run build --filter='@openmrs/*-app'",
2020
"setup": "yarn install && turbo run build",
2121
"verify": "turbo run lint && turbo run test && turbo run typescript",
22-
"prettier": "prettier \"packages/**/src/**/*\" --write",
22+
"prettier": "prettier --config prettier.config.js --write \"packages/**/*.{ts,tsx,css,scss}\" \"e2e/**/*.ts\"",
2323
"postinstall": "husky install",
2424
"test": "cross-env TZ=UTC jest --config jest.config.json --verbose false --passWithNoTests",
2525
"test-watch": "cross-env TZ=UTC jest --watch --config jest.config.json",
@@ -56,10 +56,10 @@
5656
"jest": "^29.7.0",
5757
"jest-cli": "^29.7.0",
5858
"jest-environment-jsdom": "^29.7.0",
59+
"lint-staged": "^15.2.0",
5960
"openmrs": "workspace:*",
6061
"postcss": "^8.4.6",
61-
"prettier": "^2.0.5",
62-
"pretty-quick": "^3.0.0",
62+
"prettier": "^3.1.0",
6363
"swc-loader": "^0.2.3",
6464
"systemjs-webpack-interop": "^2.3.7",
6565
"timezone-mock": "^1.2.2",
@@ -71,6 +71,9 @@
7171
"typescript": "~4.6.4",
7272
"webpack": "^5.88.0"
7373
},
74+
"lint-staged": {
75+
"*.{js,jsx,ts,tsx}": "eslint --cache --fix"
76+
},
7477
"resolutions": {
7578
"minipass": "3.3.5"
7679
},
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
module.exports = {
22
transform: {
3-
"\\.tsx?$": ["@swc/jest"],
3+
'\\.tsx?$': ['@swc/jest'],
44
},
5-
setupFiles: ["<rootDir>/src/setup-tests.tsx"],
5+
setupFiles: ['<rootDir>/src/setup-tests.tsx'],
66
moduleNameMapper: {
7-
"\\.(css)$": "identity-obj-proxy",
8-
"@openmrs/esm-framework": "@openmrs/esm-framework/mock.tsx",
7+
'\\.(css)$': 'identity-obj-proxy',
8+
'@openmrs/esm-framework': '@openmrs/esm-framework/mock.tsx',
99
},
1010
globals: {
1111
System: {
1212
Node: null,
1313
},
1414
},
15-
testEnvironment: "jsdom",
15+
testEnvironment: 'jsdom',
1616
testEnvironmentOptions: {
17-
url: "http://localhost/",
17+
url: 'http://localhost/',
1818
},
1919
};

packages/apps/esm-devtools-app/src/declarations.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
declare module "@carbon/react";
1+
declare module '@carbon/react';
22

33
declare namespace JSX {
44
interface IntrinsicElements {
5-
"import-map-overrides-list": any;
5+
'import-map-overrides-list': any;
66
}
77
}
88

9-
declare module "*.css" {
9+
declare module '*.css' {
1010
const styles: any;
1111
export default styles;
1212
}
1313

14-
declare module "*.scss" {
14+
declare module '*.scss' {
1515
const styles: any;
1616
export default styles;
1717
}

packages/apps/esm-devtools-app/src/devtools/devtools-popup.component.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import React from "react";
2-
import ImportMap from "./import-map.component";
3-
import styles from "./devtools-popup.styles.css";
1+
import React from 'react';
2+
import ImportMap from './import-map.component';
3+
import styles from './devtools-popup.styles.css';
44

55
export default function DevToolsPopup(props: DevToolsPopupProps) {
66
return (
77
<div className={styles.popup}>
88
<ImportMap toggleOverridden={props.toggleOverridden} />
99
<div className={styles.farRight}>
1010
<button onClick={props.close} className={styles.closeButton}>
11-
{"\u24e7"}
11+
{'\u24e7'}
1212
</button>
1313
</div>
1414
</div>

packages/apps/esm-devtools-app/src/devtools/devtools.component.test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from "react";
2-
import Root from "./devtools.component";
3-
import { render } from "@testing-library/react";
1+
import React from 'react';
2+
import Root from './devtools.component';
3+
import { render } from '@testing-library/react';
44

55
describe(`<Root />`, () => {
66
it(`renders without dying`, () => {

packages/apps/esm-devtools-app/src/devtools/devtools.component.tsx

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import React, { useState } from "react";
2-
import classNames from "classnames";
3-
import { importMapOverridden } from "./import-map.component";
4-
import DevToolsPopup from "./devtools-popup.component";
5-
import styles from "./devtools.styles.css";
1+
import React, { useState } from 'react';
2+
import classNames from 'classnames';
3+
import { importMapOverridden } from './import-map.component';
4+
import DevToolsPopup from './devtools-popup.component';
5+
import styles from './devtools.styles.css';
66

77
export default function Root(props) {
8-
return window.spaEnv === "development" ||
9-
Boolean(localStorage.getItem("openmrs:devtools")) ? (
8+
return window.spaEnv === 'development' || Boolean(localStorage.getItem('openmrs:devtools')) ? (
109
<DevTools {...props} />
1110
) : null;
1211
}
@@ -24,12 +23,7 @@ function DevTools() {
2423
[styles.overridden]: isOverridden,
2524
})}
2625
/>
27-
{devToolsOpen && (
28-
<DevToolsPopup
29-
close={toggleDevTools}
30-
toggleOverridden={toggleOverridden}
31-
/>
32-
)}
26+
{devToolsOpen && <DevToolsPopup close={toggleDevTools} toggleOverridden={toggleOverridden} />}
3327
</>
3428
);
3529

packages/apps/esm-devtools-app/src/devtools/import-map.component.tsx

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
import React, { useRef, useEffect } from "react";
2-
import styles from "./import-map.styles.css";
1+
import React, { useRef, useEffect } from 'react';
2+
import styles from './import-map.styles.css';
33

44
export default function ImportMap(props: ImportMapProps) {
55
const importMapListRef = useRef<HTMLElement>(null);
66

77
useEffect(() => {
8-
window.addEventListener(
9-
"import-map-overrides:change",
10-
handleImportMapChange
11-
);
12-
return () =>
13-
window.removeEventListener(
14-
"import-map-overrides:change",
15-
handleImportMapChange
16-
);
8+
window.addEventListener('import-map-overrides:change', handleImportMapChange);
9+
return () => window.removeEventListener('import-map-overrides:change', handleImportMapChange);
1710

1811
function handleImportMapChange(evt) {
1912
props.toggleOverridden(importMapOverridden());
@@ -22,23 +15,17 @@ export default function ImportMap(props: ImportMapProps) {
2215

2316
return (
2417
<div className={styles.importMap}>
25-
<import-map-overrides-list
26-
ref={importMapListRef}
27-
></import-map-overrides-list>
18+
<import-map-overrides-list ref={importMapListRef}></import-map-overrides-list>
2819
</div>
2920
);
3021
}
3122

3223
export function importMapOverridden(): boolean {
33-
return (
34-
Object.keys(window.importMapOverrides.getOverrideMap().imports).length > 0
35-
);
24+
return Object.keys(window.importMapOverrides.getOverrideMap().imports).length > 0;
3625
}
3726

3827
export function isOverriddenInImportMap(esmName: string): boolean {
39-
return window.importMapOverrides
40-
.getOverrideMap()
41-
.imports.hasOwnProperty(esmName);
28+
return window.importMapOverrides.getOverrideMap().imports.hasOwnProperty(esmName);
4229
}
4330

4431
type ImportMapProps = {
+4-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { getAsyncLifecycle } from "@openmrs/esm-framework";
1+
import { getAsyncLifecycle } from '@openmrs/esm-framework';
22

33
export const importTranslation = () => Promise.resolve();
44

55
const options = {
6-
featureName: "devtools",
7-
moduleName: "@openmrs/esm-devtools-app",
6+
featureName: 'devtools',
7+
moduleName: '@openmrs/esm-devtools-app',
88
};
99

10-
export const devtools = getAsyncLifecycle(
11-
() => import("./devtools/devtools.component"),
12-
options
13-
);
10+
export const devtools = getAsyncLifecycle(() => import('./devtools/devtools.component'), options);
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require("openmrs/default-webpack-config");
1+
module.exports = require('openmrs/default-webpack-config');
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
1-
const React = require("react");
2-
const reactI18next = require("react-i18next");
1+
const React = require('react');
2+
const reactI18next = require('react-i18next');
33

4-
const hasChildren = (node) =>
5-
node && (node.children || (node.props && node.props.children));
4+
const hasChildren = (node) => node && (node.children || (node.props && node.props.children));
65

7-
const getChildren = (node) =>
8-
node && node.children ? node.children : node.props && node.props.children;
6+
const getChildren = (node) => (node && node.children ? node.children : node.props && node.props.children);
97

108
const renderNodes = (reactNodes) => {
11-
if (typeof reactNodes === "string") {
9+
if (typeof reactNodes === 'string') {
1210
return reactNodes;
1311
}
1412

1513
return Object.keys(reactNodes).map((key, i) => {
1614
const child = reactNodes[key];
1715
const isElement = React.isValidElement(child);
1816

19-
if (typeof child === "string") {
17+
if (typeof child === 'string') {
2018
return child;
2119
}
2220
if (hasChildren(child)) {
2321
const inner = renderNodes(getChildren(child));
2422
return React.cloneElement(child, { ...child.props, key: i }, inner);
2523
}
26-
if (typeof child === "object" && !isElement) {
27-
return Object.keys(child).reduce(
28-
(str, childKey) => `${str}${child[childKey]}`,
29-
""
30-
);
24+
if (typeof child === 'object' && !isElement) {
25+
return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, '');
3126
}
3227

3328
return child;
3429
});
3530
};
3631

3732
const useMock = [(k) => k, {}];
38-
useMock.t = (k, o) => (o && o.defaultValue) || (typeof o === "string" ? o : k);
33+
useMock.t = (k, o) => (o && o.defaultValue) || (typeof o === 'string' ? o : k);
3934
useMock.i18n = {};
4035

4136
module.exports = {
@@ -50,5 +45,5 @@ module.exports = {
5045
setDefaults: reactI18next.setDefaults,
5146
getDefaults: reactI18next.getDefaults,
5247
setI18n: reactI18next.setI18n,
53-
getI18n: reactI18next.getI18n
48+
getI18n: reactI18next.getI18n,
5449
};
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
module.exports = {
22
transform: {
3-
"^.+\\.tsx?$": ["@swc/jest"],
3+
'^.+\\.tsx?$': ['@swc/jest'],
44
},
55
globals: {
66
System: {},
77
},
88
moduleNameMapper: {
9-
"lodash-es": "lodash",
10-
"\\.(s?css)$": "identity-obj-proxy",
11-
"@openmrs/esm-framework": "@openmrs/esm-framework/mock.tsx",
12-
dexie: require.resolve("dexie"),
9+
'lodash-es': 'lodash',
10+
'\\.(s?css)$': 'identity-obj-proxy',
11+
'@openmrs/esm-framework': '@openmrs/esm-framework/mock.tsx',
12+
dexie: require.resolve('dexie'),
1313
},
14-
testEnvironment: "jsdom",
14+
testEnvironment: 'jsdom',
1515
testEnvironmentOptions: {
16-
url: "http://localhost/",
16+
url: 'http://localhost/',
1717
},
1818
};

0 commit comments

Comments
 (0)