Skip to content

Commit 7b9643e

Browse files
committed
apply prettier
1 parent e7e2488 commit 7b9643e

Some content is hidden

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

65 files changed

+2495
-3719
lines changed

.eslintrc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
"one-var": ["warn"],
1515
"padded-blocks": ["warn"],
1616
"no-extend-native": ["warn"],
17-
camelcase: ["warn"],
17+
"camelcase": ["warn"],
1818
"no-multi-spaces": ["error", { ignoreEOLComments: true }],
1919
"space-before-function-paren": [
2020
"error",
@@ -26,8 +26,8 @@ module.exports = {
2626
],
2727
"arrow-parens": "off",
2828
"prefer-promise-reject-errors": "off",
29-
quotes: "off",
30-
indent: "off",
29+
"quotes": "off",
30+
"indent": "off",
3131
"no-constant-condition": "off",
3232
"no-async-promise-executor": "off",
3333
},
@@ -39,7 +39,7 @@ module.exports = {
3939
// TypeScript has its own version of this
4040
"babel/no-invalid-this": "off",
4141

42-
quotes: "off",
42+
"quotes": "off",
4343
},
4444
},
4545
{
@@ -49,4 +49,4 @@ module.exports = {
4949
},
5050
},
5151
],
52-
}
52+
};

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
- name: Check Linting Rules and Types
2424
run: yarn lint
25-
25+
2626
- name: Check Formatting
2727
run: yarn prettier:check
2828

.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require("eslint-plugin-matrix-org/.prettierrc.js");
1+
module.exports = require("eslint-plugin-matrix-org/.prettierrc.js");

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"editor.formatOnSave": false
2+
"editor.formatOnSave": false
33
}

README.md

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,34 @@ to instantiate the `WidgetApi` class.
3636
The general usage for this would be:
3737

3838
```typescript
39-
const widgetId = null // if you know the widget ID, supply it.
40-
const api = new WidgetApi(widgetId)
39+
const widgetId = null; // if you know the widget ID, supply it.
40+
const api = new WidgetApi(widgetId);
4141

4242
// Before doing anything else, request capabilities:
43-
api.requestCapability(MatrixCapabilities.Screenshots)
44-
api.requestCapabilities(StickerpickerCapabilities)
43+
api.requestCapability(MatrixCapabilities.Screenshots);
44+
api.requestCapabilities(StickerpickerCapabilities);
4545

4646
// Add custom action handlers (if needed)
47-
api.on(
48-
`action:${WidgetApiToWidgetAction.UpdateVisibility}`,
49-
(ev: CustomEvent<IVisibilityActionRequest>) => {
50-
ev.preventDefault() // we're handling it, so stop the widget API from doing something.
51-
console.log(ev.detail) // custom handling here
52-
api.transport.reply(ev.detail, <IWidgetApiRequestEmptyData>{})
53-
},
54-
)
55-
api.on(
56-
"action:com.example.my_action",
57-
(ev: CustomEvent<ICustomActionRequest>) => {
58-
ev.preventDefault() // we're handling it, so stop the widget API from doing something.
59-
console.log(ev.detail) // custom handling here
60-
api.transport.reply(ev.detail, { custom: "reply" })
61-
},
62-
)
47+
api.on(`action:${WidgetApiToWidgetAction.UpdateVisibility}`, (ev: CustomEvent<IVisibilityActionRequest>) => {
48+
ev.preventDefault(); // we're handling it, so stop the widget API from doing something.
49+
console.log(ev.detail); // custom handling here
50+
api.transport.reply(ev.detail, <IWidgetApiRequestEmptyData>{});
51+
});
52+
api.on("action:com.example.my_action", (ev: CustomEvent<ICustomActionRequest>) => {
53+
ev.preventDefault(); // we're handling it, so stop the widget API from doing something.
54+
console.log(ev.detail); // custom handling here
55+
api.transport.reply(ev.detail, { custom: "reply" });
56+
});
6357

6458
// Start the messaging
65-
api.start()
59+
api.start();
6660

6761
// If waitForIframeLoad is false, tell the client that we're good to go
68-
api.sendContentLoaded()
62+
api.sendContentLoaded();
6963

7064
// Later, do something else (if needed)
71-
api.setAlwaysOnScreen(true)
72-
api.transport.send("com.example.my_action", { isExample: true })
65+
api.setAlwaysOnScreen(true);
66+
api.transport.send("com.example.my_action", { isExample: true });
7367
```
7468

7569
For a more complete example, see the `examples` directory of this repo.
@@ -83,17 +77,15 @@ SDK to provide an interface for other platforms.
8377
TODO: Improve this
8478

8579
```typescript
86-
const driver = new CustomDriver() // an implementation of WidgetDriver
87-
const api = new ClientWidgetApi(widget, iframe, driver)
80+
const driver = new CustomDriver(); // an implementation of WidgetDriver
81+
const api = new ClientWidgetApi(widget, iframe, driver);
8882

8983
// The API is automatically started, so we just have to wait for a ready before doing something
9084
api.on("ready", () => {
91-
api.updateVisibility(true).then(() =>
92-
console.log("Widget knows it is visible now"),
93-
)
94-
api.transport.send("com.example.my_action", { isExample: true })
95-
})
85+
api.updateVisibility(true).then(() => console.log("Widget knows it is visible now"));
86+
api.transport.send("com.example.my_action", { isExample: true });
87+
});
9688

9789
// Eventually, stop the API handling
98-
api.stop()
90+
api.stop();
9991
```

examples/widget/index.html

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,63 +56,57 @@
5656
<!-- The actual widget functionality -->
5757
<script type="text/javascript">
5858
try {
59-
const qs = parseFragment()
60-
const widgetId = assertParam(qs, "widgetId")
61-
const userId = assertParam(qs, "userId")
59+
const qs = parseFragment();
60+
const widgetId = assertParam(qs, "widgetId");
61+
const userId = assertParam(qs, "userId");
6262
// Allow all origins
63-
const targetOrigin = "*"
64-
let isSticky = false
63+
const targetOrigin = "*";
64+
let isSticky = false;
6565

6666
// Set up the widget API as soon as possible to avoid problems with the client
67-
const widgetApi = new mxwidgets.WidgetApi(
68-
widgetId,
69-
targetOrigin,
70-
)
71-
widgetApi.requestCapability(
72-
mxwidgets.MatrixCapabilities.AlwaysOnScreen,
73-
)
67+
const widgetApi = new mxwidgets.WidgetApi(widgetId, targetOrigin);
68+
widgetApi.requestCapability(mxwidgets.MatrixCapabilities.AlwaysOnScreen);
7469

7570
widgetApi.on("ready", function () {
7671
// Fill in the basic widget details now that we're allowed to operate.
7772
document.getElementById("container").innerHTML =
7873
"Hello <span id='userId'></span>!<br /><br />" +
7974
"Currently stuck on screen: <span id='stickyState'></span><br /><br />" +
80-
"<button onclick='toggleSticky()'>Toggle sticky state</button>"
75+
"<button onclick='toggleSticky()'>Toggle sticky state</button>";
8176

8277
// Fill in the user ID using innerText to avoid XSS
83-
document.getElementById("userId").innerText = userId
78+
document.getElementById("userId").innerText = userId;
8479

8580
// Update the UI and ensure that we end up not sticky to start
86-
sendStickyState()
87-
})
81+
sendStickyState();
82+
});
8883

8984
// Start the widget as soon as possible too, otherwise the client might time us out.
90-
widgetApi.start()
85+
widgetApi.start();
9186

9287
function toggleSticky() {
9388
// called by the button when clicked - toggle the sticky state
94-
isSticky = !isSticky
95-
sendStickyState()
89+
isSticky = !isSticky;
90+
sendStickyState();
9691
}
9792

9893
function updateStickyState() {
99-
document.getElementById("stickyState").innerText =
100-
isSticky.toString()
94+
document.getElementById("stickyState").innerText = isSticky.toString();
10195
}
10296

10397
function sendStickyState() {
104-
updateStickyState() // update first to make the UI go faster than the request
98+
updateStickyState(); // update first to make the UI go faster than the request
10599
widgetApi
106100
.setAlwaysOnScreen(isSticky)
107101
.then(function (r) {
108-
console.log("[Widget] Client responded with: ", r)
102+
console.log("[Widget] Client responded with: ", r);
109103
})
110104
.catch(function (e) {
111-
handleError(e)
112-
})
105+
handleError(e);
106+
});
113107
}
114108
} catch (e) {
115-
handleError(e)
109+
handleError(e);
116110
}
117111
</script>
118112
</body>

examples/widget/utils.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,17 @@
1515
*/
1616

1717
function parseFragment() {
18-
const fragmentString = window.location.hash || "?"
19-
return new URLSearchParams(
20-
fragmentString.substring(Math.max(fragmentString.indexOf("?"), 0)),
21-
)
18+
const fragmentString = window.location.hash || "?";
19+
return new URLSearchParams(fragmentString.substring(Math.max(fragmentString.indexOf("?"), 0)));
2220
}
2321

2422
function assertParam(fragment, name) {
25-
const val = fragment.get(name)
26-
if (!val)
27-
throw new Error(`${name} is not present in URL - cannot load widget`)
28-
return val
23+
const val = fragment.get(name);
24+
if (!val) throw new Error(`${name} is not present in URL - cannot load widget`);
25+
return val;
2926
}
3027

3128
function handleError(e) {
32-
console.error(e)
33-
document.getElementById("container").innerText =
34-
"There was an error with the widget. See JS console for details."
29+
console.error(e);
30+
document.getElementById("container").innerText = "There was an error with the widget. See JS console for details.";
3531
}

jest.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { env } from "process"
17+
import { env } from "process";
1818

19-
import type { Config } from "jest"
19+
import type { Config } from "jest";
2020

2121
const config: Config = {
2222
testEnvironment: "jsdom",
2323
testMatch: ["<rootDir>/test/**/*-test.[jt]s?(x)"],
2424
collectCoverageFrom: ["<rootDir>/src/**/*.{js,ts,tsx}"],
2525
coverageReporters: ["text-summary", "lcov"],
2626
testResultsProcessor: "@casualbot/jest-sonar-reporter",
27-
}
27+
};
2828

2929
// if we're running under GHA, enable the GHA reporter
3030
if (env["GITHUB_ACTIONS"] !== undefined) {
31-
config.reporters = [["github-actions", { silent: false }], "summary"]
31+
config.reporters = [["github-actions", { silent: false }], "summary"];
3232
}
3333

34-
export default config
34+
export default config;

0 commit comments

Comments
 (0)