Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Commit 8c143b8

Browse files
authored
Merge pull request matrix-org#6293 from matrix-org/jryans/lint-media-apis
Lint MXC APIs to centralise access
2 parents 6b8c38a + 2baace7 commit 8c143b8

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

.eslintrc.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ module.exports = {
2424
// It's disabled here, but we should using it sparingly.
2525
"react/jsx-no-bind": "off",
2626
"react/jsx-key": ["error"],
27+
28+
"no-restricted-properties": [
29+
"error",
30+
...buildRestrictedPropertiesOptions(
31+
["window.innerHeight", "window.innerWidth", "window.visualViewport"],
32+
"Use UIStore to access window dimensions instead.",
33+
),
34+
...buildRestrictedPropertiesOptions(
35+
["*.mxcUrlToHttp", "*.getHttpUriForMxc"],
36+
"Use Media helper instead to centralise access for customisation.",
37+
),
38+
],
2739
},
2840
overrides: [{
2941
files: [
@@ -49,21 +61,16 @@ module.exports = {
4961
"@typescript-eslint/no-explicit-any": "off",
5062
// We'd rather not do this but we do
5163
"@typescript-eslint/ban-ts-comment": "off",
52-
53-
"no-restricted-properties": [
54-
"error",
55-
...buildRestrictedPropertiesOptions(
56-
["window.innerHeight", "window.innerWidth", "window.visualViewport"],
57-
"Use UIStore to access window dimensions instead",
58-
),
59-
],
6064
},
6165
}],
6266
};
6367

6468
function buildRestrictedPropertiesOptions(properties, message) {
6569
return properties.map(prop => {
66-
const [object, property] = prop.split(".");
70+
let [object, property] = prop.split(".");
71+
if (object === "*") {
72+
object = undefined;
73+
}
6774
return {
6875
object,
6976
property,

src/customisations/Media.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export class Media {
7575
* The HTTP URL for the source media.
7676
*/
7777
public get srcHttp(): string {
78+
// eslint-disable-next-line no-restricted-properties
7879
return this.client.mxcUrlToHttp(this.srcMxc);
7980
}
8081

@@ -84,6 +85,7 @@ export class Media {
8485
*/
8586
public get thumbnailHttp(): string | undefined | null {
8687
if (!this.hasThumbnail) return null;
88+
// eslint-disable-next-line no-restricted-properties
8789
return this.client.mxcUrlToHttp(this.thumbnailMxc);
8890
}
8991

@@ -100,6 +102,7 @@ export class Media {
100102
// scale using the device pixel ratio to keep images clear
101103
width = Math.floor(width * window.devicePixelRatio);
102104
height = Math.floor(height * window.devicePixelRatio);
105+
// eslint-disable-next-line no-restricted-properties
103106
return this.client.mxcUrlToHttp(this.thumbnailMxc, width, height, mode);
104107
}
105108

@@ -114,6 +117,7 @@ export class Media {
114117
// scale using the device pixel ratio to keep images clear
115118
width = Math.floor(width * window.devicePixelRatio);
116119
height = Math.floor(height * window.devicePixelRatio);
120+
// eslint-disable-next-line no-restricted-properties
117121
return this.client.mxcUrlToHttp(this.srcMxc, width, height, mode);
118122
}
119123

0 commit comments

Comments
 (0)