Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 35d222b

Browse files
authored
Add @typescript-eslint/no-base-to-string (#10091)
1 parent 30cc555 commit 35d222b

File tree

10 files changed

+28
-14
lines changed

10 files changed

+28
-14
lines changed

.eslintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = {
22
plugins: ["matrix-org"],
33
extends: ["plugin:matrix-org/babel", "plugin:matrix-org/react", "plugin:matrix-org/a11y"],
4+
parserOptions: {
5+
project: ["./tsconfig.json"],
6+
},
47
env: {
58
browser: true,
69
node: true,
@@ -168,6 +171,12 @@ module.exports = {
168171
"@typescript-eslint/explicit-member-accessibility": "off",
169172
},
170173
},
174+
{
175+
files: ["cypress/**/*.ts"],
176+
parserOptions: {
177+
project: ["./cypress/tsconfig.json"],
178+
},
179+
},
171180
],
172181
settings: {
173182
react: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
"eslint-plugin-deprecate": "^0.7.0",
191191
"eslint-plugin-import": "^2.25.4",
192192
"eslint-plugin-jsx-a11y": "^6.5.1",
193-
"eslint-plugin-matrix-org": "0.9.0",
193+
"eslint-plugin-matrix-org": "0.10.0",
194194
"eslint-plugin-react": "^7.28.0",
195195
"eslint-plugin-react-hooks": "^4.3.0",
196196
"eslint-plugin-unicorn": "^45.0.0",

src/components/views/dialogs/ServerOfflineDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export default class ServerOfflineDialog extends React.PureComponent<IProps> {
4848
private renderTimeline(): React.ReactElement[] {
4949
return EchoStore.instance.contexts.map((c, i) => {
5050
if (!c.firstFailedTime) return null; // not useful
51-
if (!(c instanceof RoomEchoContext)) throw new Error("Cannot render unknown context: " + c);
51+
if (!(c instanceof RoomEchoContext))
52+
throw new Error("Cannot render unknown context: " + c.constructor.name);
5253
const header = (
5354
<div className="mx_ServerOfflineDialog_content_context_timeline_header">
5455
<RoomAvatar width={24} height={24} room={c.room} />

src/components/views/settings/ProfileSettings.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ export default class ProfileSettings extends React.Component<{}, IState> {
185185
withDisplayName: true,
186186
});
187187

188+
// False negative result from no-base-to-string rule, doesn't seem to account for Symbol.toStringTag
189+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
190+
const avatarUrl = this.state.avatarUrl?.toString();
191+
188192
return (
189193
<form onSubmit={this.saveProfile} autoComplete="off" noValidate={true} className="mx_ProfileSettings">
190194
<input
@@ -216,7 +220,7 @@ export default class ProfileSettings extends React.Component<{}, IState> {
216220
</p>
217221
</div>
218222
<AvatarSetting
219-
avatarUrl={this.state.avatarUrl?.toString()}
223+
avatarUrl={avatarUrl}
220224
avatarName={this.state.displayName || this.state.userId}
221225
avatarAltText={_t("Profile picture")}
222226
uploadAvatar={this.uploadAvatar}

src/rageshake/submit-rageshake.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export async function downloadBugReport(opts: IOpts = {}): Promise<void> {
260260
reader.readAsArrayBuffer(value as Blob);
261261
});
262262
} else {
263-
metadata += `${key} = ${value}\n`;
263+
metadata += `${key} = ${value as string}\n`;
264264
}
265265
}
266266
tape.append("issue.txt", metadata);

src/stores/widgets/StopGapWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export class StopGapWidget extends EventEmitter {
389389
// Now open the integration manager
390390
// TODO: Spec this interaction.
391391
const data = ev.detail.data;
392-
const integType = data?.integType;
392+
const integType = data?.integType as string;
393393
const integId = <string>data?.integId;
394394

395395
// noinspection JSIgnoredPromiseFromCall

src/utils/FileUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function presentableTextForFile(
6969
// it since it is "ugly", users generally aren't aware what it
7070
// means and the type of the attachment can usually be inferred
7171
// from the file extension.
72-
text += " (" + filesize(content.info.size) + ")";
72+
text += " (" + <string>filesize(content.info.size) + ")";
7373
}
7474
return text;
7575
}

src/utils/Whenable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import { logger } from "matrix-js-sdk/src/logger";
1919
import { IDestroyable } from "./IDestroyable";
2020
import { arrayFastClone } from "./arrays";
2121

22-
export type WhenFn<T> = (w: Whenable<T>) => void;
22+
export type WhenFn<T extends string | number> = (w: Whenable<T>) => void;
2323

2424
/**
2525
* Whenables are a cheap way to have Observable patterns mixed with typical
2626
* usage of Promises, without having to tear down listeners or calls. Whenables
2727
* are intended to be used when a condition will be met multiple times and
2828
* the consumer needs to know *when* that happens.
2929
*/
30-
export abstract class Whenable<T> implements IDestroyable {
30+
export abstract class Whenable<T extends string | number> implements IDestroyable {
3131
private listeners: { condition: T | null; fn: WhenFn<T> }[] = [];
3232

3333
/**

src/utils/exportUtils/HtmlExport.tsx

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

17-
import React, { ReactNode } from "react";
17+
import React from "react";
1818
import ReactDOM from "react-dom";
1919
import { Room } from "matrix-js-sdk/src/models/room";
2020
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
@@ -65,7 +65,7 @@ export default class HTMLExporter extends Exporter {
6565
this.threadsEnabled = SettingsStore.getValue("feature_threadenabled");
6666
}
6767

68-
protected async getRoomAvatar(): Promise<ReactNode> {
68+
protected async getRoomAvatar(): Promise<string> {
6969
let blob: Blob | undefined = undefined;
7070
const avatarUrl = Avatar.avatarUrlForRoom(this.room, 32, 32, "crop");
7171
const avatarPath = "room.png";

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,10 +4226,10 @@ eslint-plugin-jsx-a11y@^6.5.1:
42264226
minimatch "^3.1.2"
42274227
semver "^6.3.0"
42284228

4229-
eslint-plugin-matrix-org@0.9.0:
4230-
version "0.9.0"
4231-
resolved "https://registry.yarnpkg.com/eslint-plugin-matrix-org/-/eslint-plugin-matrix-org-0.9.0.tgz#b2a5186052ddbfa7dc9878779bafa5d68681c7b4"
4232-
integrity sha512-+j6JuMnFH421Z2vOxc+0YMt5Su5vD76RSatviy3zHBaZpgd+sOeAWoCLBHD5E7mMz5oKae3Y3wewCt9LRzq2Nw==
4229+
eslint-plugin-matrix-org@0.10.0:
4230+
version "0.10.0"
4231+
resolved "https://registry.yarnpkg.com/eslint-plugin-matrix-org/-/eslint-plugin-matrix-org-0.10.0.tgz#8d0998641a4d276343cae2abf253a01bb4d4cc60"
4232+
integrity sha512-L7ail0x1yUlF006kn4mHc+OT8/aYZI++i852YXPHxCbM1EY7jeg/fYAQ8tCx5+x08LyqXeS7inAVSL784m0C6Q==
42334233

42344234
eslint-plugin-react-hooks@^4.3.0:
42354235
version "4.6.0"

0 commit comments

Comments
 (0)