Make SonarCloud happier (#9545)

* Make SonarCloud happier

* i18n

* Iterate

* Update AddExistingToSpaceDialog.tsx

* Update SlashCommands.tsx
This commit is contained in:
Michael Telatynski 2022-11-07 13:45:34 +00:00 committed by GitHub
parent 77764d80bc
commit 3747464b41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 131 additions and 162 deletions

View file

@ -191,14 +191,8 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
return false;
}
private allFieldsValid() {
const keys = Object.keys(this.state.fieldValid);
for (let i = 0; i < keys.length; ++i) {
if (!this.state.fieldValid[keys[i]]) {
return false;
}
}
return true;
private allFieldsValid(): boolean {
return Object.values(this.state.fieldValid).every(Boolean);
}
private findFirstInvalidField(fieldIDs: LoginField[]) {

View file

@ -224,14 +224,8 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
/**
* @returns {boolean} true if all fields were valid last time they were validated.
*/
private allFieldsValid() {
const keys = Object.keys(this.state.fieldValid);
for (let i = 0; i < keys.length; ++i) {
if (!this.state.fieldValid[keys[i]]) {
return false;
}
}
return true;
private allFieldsValid(): boolean {
return Object.values(this.state.fieldValid).every(Boolean);
}
private findFirstInvalidField(fieldIDs: RegistrationField[]) {

View file

@ -166,10 +166,8 @@ export default class DecoratedRoomAvatar extends React.PureComponent<IProps, ISt
if (otherUserId && this.props.room.getJoinedMemberCount() === 2) {
// Track presence, if available
if (isPresenceEnabled()) {
if (otherUserId) {
this.dmUser = MatrixClientPeg.get().getUser(otherUserId);
icon = this.getPresenceIcon();
}
this.dmUser = MatrixClientPeg.get().getUser(otherUserId);
icon = this.getPresenceIcon();
}
} else {
// Track publicity

View file

@ -181,7 +181,7 @@ export const AddExistingToSpace: React.FC<IAddExistingToSpaceProps> = ({
setError(null);
setProgress(0);
let error;
let error: Error | undefined;
for (const room of selectedToAdd) {
const via = calculateRoomVia(room);
@ -197,13 +197,15 @@ export const AddExistingToSpace: React.FC<IAddExistingToSpaceProps> = ({
setProgress(i => i + 1);
} catch (e) {
logger.error("Failed to add rooms to space", e);
setError(error = e);
error = e;
break;
}
}
if (!error) {
onFinished(true);
} else {
setError(error);
}
};

View file

@ -128,9 +128,6 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
this.nameField.current.focus();
}
componentWillUnmount() {
}
private onKeyDown = (event: KeyboardEvent) => {
const action = getKeyBindingsManager().getAccessibilityAction(event);
switch (action) {

View file

@ -92,12 +92,13 @@ const KeySignatureUploadFailedDialog: React.FC<IProps> = ({
/>
</div>);
} else {
let text = _t("Upload completed");
if (!success) {
text = cancelled ? _t("Cancelled signature upload") : _t("Unable to upload");
}
body = (<div>
{ success ?
<span>{ _t("Upload completed") }</span> :
cancelled ?
<span>{ _t("Cancelled signature upload") }</span> :
<span>{ _t("Unable to upload") }</span> }
<span>{ text }</span>
<DialogButtons
primaryButton={_t("OK")}
hasCancel={false}

View file

@ -61,7 +61,7 @@ type DynamicElementProps<T extends keyof JSX.IntrinsicElements> =
type IProps<T extends keyof JSX.IntrinsicElements> = DynamicHtmlElementProps<T> & {
inputRef?: React.Ref<Element>;
element?: T;
children?: ReactNode | undefined;
children?: ReactNode;
// The kind of button, similar to how Bootstrap works.
// See available classes for AccessibleButton for options.
kind?: AccessibleButtonKind | string;

View file

@ -117,8 +117,6 @@ export default class EditableText extends React.Component<IProps, IState> {
};
private onKeyDown = (ev: React.KeyboardEvent<HTMLDivElement>): void => {
// console.log("keyDown: textContent=" + ev.target.textContent + ", value=" + this.value + ", placeholder=" + this.placeholder);
if (this.placeholder) {
this.showPlaceholder(false);
}
@ -130,13 +128,9 @@ export default class EditableText extends React.Component<IProps, IState> {
ev.preventDefault();
break;
}
// console.log("keyDown: textContent=" + ev.target.textContent + ", value=" + this.value + ", placeholder=" + this.placeholder);
};
private onKeyUp = (ev: React.KeyboardEvent<HTMLDivElement>): void => {
// console.log("keyUp: textContent=" + ev.target.textContent + ", value=" + this.value + ", placeholder=" + this.placeholder);
if (!(ev.target as HTMLDivElement).textContent) {
this.showPlaceholder(true);
} else if (!this.placeholder) {
@ -152,8 +146,6 @@ export default class EditableText extends React.Component<IProps, IState> {
this.onFinish(ev);
break;
}
// console.log("keyUp: textContent=" + ev.target.textContent + ", value=" + this.value + ", placeholder=" + this.placeholder);
};
private onClickDiv = (): void => {
@ -165,8 +157,6 @@ export default class EditableText extends React.Component<IProps, IState> {
};
private onFocus = (ev: React.FocusEvent<HTMLDivElement>): void => {
//ev.target.setSelectionRange(0, ev.target.textContent.length);
const node = ev.target.childNodes[0];
if (node) {
const range = document.createRange();

View file

@ -215,12 +215,12 @@ export default class EventListSummary extends React.Component<IProps> {
repeats: number;
}[] = [];
for (let i = 0; i < transitions.length; i++) {
if (res.length > 0 && res[res.length - 1].transitionType === transitions[i]) {
for (const transition of transitions) {
if (res.length > 0 && res[res.length - 1].transitionType === transition) {
res[res.length - 1].repeats += 1;
} else {
res.push({
transitionType: transitions[i],
transitionType: transition,
repeats: 1,
});
}
@ -399,7 +399,6 @@ export default class EventListSummary extends React.Component<IProps> {
} else if (e.mxEvent.getContent().avatar_url !== e.mxEvent.getPrevContent().avatar_url) {
return TransitionType.ChangedAvatar;
}
// console.log("MELS ignoring duplicate membership join event");
return TransitionType.NoChange;
} else {
return TransitionType.Joined;

View file

@ -171,48 +171,52 @@ const MBeaconBody: React.FC<IBodyProps> = React.forwardRef(({ mxEvent, getRelati
);
};
let map: JSX.Element;
if (displayStatus === BeaconDisplayStatus.Active && !isMapDisplayError) {
map = <Map
id={mapId}
centerGeoUri={latestLocationState.uri}
onError={setError}
onClick={onClick}
className="mx_MBeaconBody_map"
>
{
({ map }) =>
<SmartMarker
map={map}
id={`${mapId}-marker`}
geoUri={latestLocationState.uri}
roomMember={markerRoomMember}
useMemberColor
/>
}
</Map>;
} else if (isMapDisplayError) {
map = <MapError
error={error.message as LocationShareError}
onClick={onClick}
className={classNames(
'mx_MBeaconBody_mapError',
// set interactive class when maximised map can be opened
{ 'mx_MBeaconBody_mapErrorInteractive':
displayStatus === BeaconDisplayStatus.Active,
},
)}
isMinimised
/>;
} else {
map = <MapFallback
isLoading={displayStatus === BeaconDisplayStatus.Loading}
className='mx_MBeaconBody_map mx_MBeaconBody_mapFallback'
/>;
}
return (
<div
className='mx_MBeaconBody'
ref={ref}
>
{ (displayStatus === BeaconDisplayStatus.Active && !isMapDisplayError) ?
<Map
id={mapId}
centerGeoUri={latestLocationState.uri}
onError={setError}
onClick={onClick}
className="mx_MBeaconBody_map"
>
{
({ map }) =>
<SmartMarker
map={map}
id={`${mapId}-marker`}
geoUri={latestLocationState.uri}
roomMember={markerRoomMember}
useMemberColor
/>
}
</Map>
: isMapDisplayError ?
<MapError
error={error.message as LocationShareError}
onClick={onClick}
className={classNames(
'mx_MBeaconBody_mapError',
// set interactive class when maximised map can be opened
{ 'mx_MBeaconBody_mapErrorInteractive':
displayStatus === BeaconDisplayStatus.Active,
},
)}
isMinimised
/> :
<MapFallback
isLoading={displayStatus === BeaconDisplayStatus.Loading}
className='mx_MBeaconBody_map mx_MBeaconBody_mapFallback'
/>
}
{ map }
{ isOwnBeacon ?
<OwnBeaconStatus
className='mx_MBeaconBody_chin'

View file

@ -88,9 +88,9 @@ export function computedStyle(element: HTMLElement) {
if (cssText == "") {
// Firefox doesn't implement ".cssText" for computed styles.
// https://bugzilla.mozilla.org/show_bug.cgi?id=137687
for (let i = 0; i < style.length; i++) {
cssText += style[i] + ":";
cssText += style.getPropertyValue(style[i]) + ";";
for (const rule of style) {
cssText += rule + ":";
cssText += style.getPropertyValue(rule) + ";";
}
}
return cssText;

View file

@ -146,7 +146,7 @@ function useHasCrossSigningKeys(cli: MatrixClient, member: User, canVerify: bool
} finally {
setUpdating(false);
}
}, [cli, member, canVerify], undefined);
}, [cli, member, canVerify]);
}
function DeviceItem({ userId, device }: { userId: string, device: IDevice }) {

View file

@ -119,7 +119,6 @@ export default class MemberList extends React.Component<IProps, IState> {
cli.on(UserEvent.LastPresenceTs, this.onUserPresenceChange);
cli.on(UserEvent.Presence, this.onUserPresenceChange);
cli.on(UserEvent.CurrentlyActive, this.onUserPresenceChange);
// cli.on("Room.timeline", this.onRoomTimeline);
}
componentWillUnmount() {
@ -199,7 +198,6 @@ export default class MemberList extends React.Component<IProps, IState> {
// member tile and re-render it. This is more efficient than every tile
// ever attaching their own listener.
const tile = this.refs[user.userId];
// console.log(`Got presence update for ${user.userId}. hasTile=${!!tile}`);
if (tile) {
this.updateList(); // reorder the membership list
}
@ -370,14 +368,9 @@ export default class MemberList extends React.Component<IProps, IState> {
// ...and then alphabetically.
// We could tiebreak instead by "last recently spoken in this room" if we wanted to.
// console.log(`Comparing userA=${this.memberString(memberA)} userB=${this.memberString(memberB)}`);
const userA = memberA.user;
const userB = memberB.user;
// if (!userA) console.log("!! MISSING USER FOR A-SIDE: " + memberA.name + " !!");
// if (!userB) console.log("!! MISSING USER FOR B-SIDE: " + memberB.name + " !!");
if (!userA && !userB) return 0;
if (userA && !userB) return -1;
if (!userA && userB) return 1;
@ -393,22 +386,18 @@ export default class MemberList extends React.Component<IProps, IState> {
const idxA = presenceIndex(userA.currentlyActive ? 'active' : userA.presence);
const idxB = presenceIndex(userB.currentlyActive ? 'active' : userB.presence);
// console.log(`userA_presenceGroup=${idxA} userB_presenceGroup=${idxB}`);
if (idxA !== idxB) {
// console.log("Comparing on presence group - returning");
return idxA - idxB;
}
}
// Second by power level
if (memberA.powerLevel !== memberB.powerLevel) {
// console.log("Comparing on power level - returning");
return memberB.powerLevel - memberA.powerLevel;
}
// Third by last active
if (this.showPresence && userA.getLastActiveTs() !== userB.getLastActiveTs()) {
// console.log("Comparing on last active timestamp - returning");
return userB.getLastActiveTs() - userA.getLastActiveTs();
}

View file

@ -274,7 +274,7 @@ export default class RoomSublist extends React.Component<IProps, IState> {
};
private onListsUpdated = () => {
const stateUpdates: IState & any = {}; // &any is to avoid a cast on the initializer
const stateUpdates = {} as IState;
const currentRooms = this.state.rooms;
const newRooms = arrayFastClone(RoomListStore.instance.orderedLists[this.props.tagId] || []);

View file

@ -353,13 +353,7 @@ export default class ChangePassword extends React.Component<IProps, IState> {
}
private allFieldsValid(): boolean {
const keys = Object.keys(this.state.fieldValid);
for (let i = 0; i < keys.length; ++i) {
if (!this.state.fieldValid[keys[i]]) {
return false;
}
}
return true;
return Object.values(this.state.fieldValid).every(Boolean);
}
private findFirstInvalidField(fieldIDs: string[]): Field {

View file

@ -50,7 +50,7 @@ export default class InlineTermsAgreement extends React.Component<IProps, IState
public componentDidMount(): void {
// Build all the terms the user needs to accept
const policies = []; // { checked, url, name }
const policies: Policy[] = [];
for (const servicePolicies of this.props.policiesAndServicePairs) {
const availablePolicies = Object.values(servicePolicies.policies);
for (const policy of availablePolicies) {