Skip to content

Commit

Permalink
client: fix all new linter errros
Browse files Browse the repository at this point in the history
  • Loading branch information
brunnre8 committed May 4, 2024
1 parent c0a68d5 commit 2f5b9b5
Show file tree
Hide file tree
Showing 36 changed files with 83 additions and 82 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Expand Up @@ -93,6 +93,7 @@ const tsRules = defineConfig({
// note you must disable the base rule as it can report incorrect errors
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
"@typescript-eslint/no-redundant-type-constituents": "off",
},
}).rules;

Expand Down
11 changes: 6 additions & 5 deletions client/components/Chat.vue
Expand Up @@ -136,6 +136,7 @@ import ListIgnored from "./Special/ListIgnored.vue";
import {defineComponent, PropType, ref, computed, watch, nextTick, onMounted, Component} from "vue";
import type {ClientNetwork, ClientChan} from "../js/types";
import {useStore} from "../js/store";
import {SpecialChanType, ChanType} from "../../shared/types/chan";
export default defineComponent({
name: "Chat",
Expand All @@ -161,13 +162,13 @@ export default defineComponent({
const specialComponent = computed(() => {
switch (props.channel.special) {
case "list_bans":
case SpecialChanType.BANLIST:
return ListBans as Component;
case "list_invites":
case SpecialChanType.INVITELIST:
return ListInvites as Component;
case "list_channels":
case SpecialChanType.CHANNELLIST:
return ListChannels as Component;
case "list_ignored":
case SpecialChanType.IGNORELIST:
return ListIgnored as Component;
}
Expand All @@ -194,7 +195,7 @@ export default defineComponent({
};
const editTopic = () => {
if (props.channel.type === "channel") {
if (props.channel.type === ChanType.CHANNEL) {
props.channel.editTopic = true;
}
};
Expand Down
3 changes: 2 additions & 1 deletion client/components/ChatInput.vue
Expand Up @@ -63,6 +63,7 @@ import eventbus from "../js/eventbus";
import {watch, defineComponent, nextTick, onMounted, PropType, ref, onUnmounted} from "vue";
import type {ClientNetwork, ClientChan} from "../js/types";
import {useStore} from "../js/store";
import {ChanType} from "../../shared/types/chan";
const formattingHotkeys = {
"mod+k": "\x03",
Expand Down Expand Up @@ -130,7 +131,7 @@ export default defineComponent({
};
const getInputPlaceholder = (channel: ClientChan) => {
if (channel.type === "channel" || channel.type === "query") {
if (channel.type === ChanType.CHANNEL || channel.type === ChanType.QUERY) {
return `Write to ${channel.name}`;
}
Expand Down
12 changes: 10 additions & 2 deletions client/components/MessageCondensed.vue
Expand Up @@ -20,6 +20,7 @@
<script lang="ts">
import {computed, defineComponent, PropType, ref} from "vue";
import {condensedTypes} from "../../shared/irc";
import {MessageType} from "../../shared/types/msg";
import {ClientMessage, ClientNetwork} from "../js/types";
import Message from "./Message.vue";
Expand Down Expand Up @@ -57,16 +58,23 @@ export default defineComponent({
for (const message of props.messages) {
// special case since one MODE message can change multiple modes
if (message.type === "mode") {
if (message.type === MessageType.MODE) {
// syntax: +vv-t maybe-some targets
// we want the number of mode changes in the message, so count the
// number of chars other than + and - before the first space
const modeChangesCount = message.text
const text = message.text ? message.text : "";
const modeChangesCount = text
.split(" ")[0]
.split("")
.filter((char) => char !== "+" && char !== "-").length;
obj[message.type] += modeChangesCount;
} else {
if (!message.type) {
/* eslint-disable no-console */
console.log(`empty message type, this should not happen: ${message.id}`);
continue;
}
obj[message.type]++;
}
}
Expand Down
22 changes: 12 additions & 10 deletions client/components/MessageList.vue
Expand Up @@ -59,6 +59,8 @@

<script lang="ts">
import {condensedTypes} from "../../shared/irc";
import {ChanType} from "../../shared/types/chan";
import {MessageType, SharedMsg} from "../../shared/types/msg";
import eventbus from "../js/eventbus";
import clipboard from "../js/clipboard";
import socket from "../js/socket";
Expand All @@ -79,7 +81,6 @@ import {
} from "vue";
import {useStore} from "../js/store";
import {ClientChan, ClientMessage, ClientNetwork, ClientLinkPreview} from "../js/types";
import {SharedMsg} from "../../shared/types/msg";
type CondensedMessageContainer = {
type: "condensed";
Expand All @@ -103,7 +104,7 @@ export default defineComponent({
channel: {type: Object as PropType<ClientChan>, required: true},
focused: Number,
},
setup(props, {emit}) {
setup(props) {
const store = useStore();
const chat = ref<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -177,14 +178,14 @@ export default defineComponent({
});
const condensedMessages = computed(() => {
if (props.channel.type !== "channel" && props.channel.type !== "query") {
if (props.channel.type !== ChanType.CHANNEL && props.channel.type !== ChanType.QUERY) {
return props.channel.messages;
}
// If actions are hidden, just return a message list with them excluded
if (store.state.settings.statusMessages === "hidden") {
return props.channel.messages.filter(
(message) => !condensedTypes.has(message.type)
(message) => !condensedTypes.has(message.type || "")
);
}
Expand All @@ -200,7 +201,7 @@ export default defineComponent({
for (const message of props.channel.messages) {
// If this message is not condensable, or its an action affecting our user,
// then just append the message to container and be done with it
if (message.self || message.highlight || !condensedTypes.has(message.type)) {
if (message.self || message.highlight || !condensedTypes.has(message.type || "")) {
lastCondensedContainer = null;
condensed.push(message);
Expand Down Expand Up @@ -242,7 +243,7 @@ export default defineComponent({
});
const shouldDisplayDateMarker = (
message: SharedMsg | ClientMessage | CondensedMessageContainer,
message: SharedMsg | CondensedMessageContainer,
id: number
) => {
const previousMessage = condensedMessages.value[id - 1];
Expand Down Expand Up @@ -270,12 +271,13 @@ export default defineComponent({
return false;
};
const isPreviousSource = (currentMessage: ClientMessage | SharedMsg, id: number) => {
const isPreviousSource = (currentMessage: ClientMessage, id: number) => {
const previousMessage = condensedMessages.value[id - 1];
return !!(
return (
previousMessage &&
currentMessage.type === "message" &&
previousMessage.type === "message" &&
currentMessage.type === MessageType.MESSAGE &&
previousMessage.type === MessageType.MESSAGE &&
currentMessage.from &&
previousMessage.from &&
currentMessage.from.nick === previousMessage.from.nick
);
Expand Down
2 changes: 1 addition & 1 deletion client/components/Windows/NetworkEdit.vue
Expand Up @@ -48,7 +48,7 @@ export default defineComponent({
watch(
() => route.params.uuid,
(newValue) => {
() => {
setNetworkData();
}
);
Expand Down
8 changes: 4 additions & 4 deletions client/js/autocompletion.ts
@@ -1,13 +1,14 @@
import constants from "./constants";

import Mousetrap from "mousetrap";
import {Strategy, Textcomplete, StrategyProps} from "@textcomplete/core";
import {Textcomplete, StrategyProps} from "@textcomplete/core";
import {TextareaEditor} from "@textcomplete/textarea";

import fuzzy from "fuzzy";

import emojiMap from "./helpers/simplemap.json";
import {store} from "./store";
import {ChanType} from "../../shared/types/chan";

export default enableAutocomplete;

Expand Down Expand Up @@ -38,7 +39,6 @@ const nicksStrategy: StrategyProps = {

if (term[0] === "@") {
// TODO: type
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
callback(completeNicks(term.slice(1), true).map((val) => ["@" + val[0], "@" + val[1]]));
} else {
callback(completeNicks(term, true));
Expand Down Expand Up @@ -292,7 +292,7 @@ function rawNicks() {
const otherUser = store.state.activeChannel.channel.name;

// If this is a query, add their name to autocomplete
if (me !== otherUser && store.state.activeChannel.channel.type === "query") {
if (me !== otherUser && store.state.activeChannel.channel.type === ChanType.QUERY) {
return [otherUser, me];
}

Expand Down Expand Up @@ -332,7 +332,7 @@ function completeChans(word: string) {
if (store.state.activeChannel) {
for (const channel of store.state.activeChannel.network.channels) {
// Push all channels that start with the same CHANTYPE
if (channel.type === "channel" && channel.name[0] === word[0]) {
if (channel.type === ChanType.CHANNEL && channel.name[0] === word[0]) {
words.push(channel.name);
}
}
Expand Down
7 changes: 4 additions & 3 deletions client/js/chan.ts
@@ -1,11 +1,12 @@
import {ClientChan, ClientMessage} from "./types";
import {SharedNetworkChan} from "../../shared/types/network";
import {SharedMsg} from "../../shared/types/msg";
import {SharedMsg, MessageType} from "../../shared/types/msg";
import {ChanType} from "../../shared/types/chan";

export function toClientChan(shared: SharedNetworkChan): ClientChan {
const history: string[] = [""].concat(
shared.messages
.filter((m) => m.self && m.text && m.type === "message")
.filter((m) => m.self && m.text && m.type === MessageType.MESSAGE)
// TS is too stupid to see the nil guard on filter... so we monkey patch it
.map((m): string => (m.text ? m.text : ""))
.reverse()
Expand All @@ -21,7 +22,7 @@ export function toClientChan(shared: SharedNetworkChan): ClientChan {
historyLoading: false,
scrolledToBottom: true,
users: [],
usersOutdated: shared.type === "channel" ? true : false,
usersOutdated: shared.type === ChanType.CHANNEL ? true : false,
moreHistoryAvailable: shared.totalMessages > shared.messages.length,
inputHistory: history,
messages: sharedMsgToClientMsg(messages),
Expand Down
9 changes: 5 additions & 4 deletions client/js/helpers/contextMenu.ts
Expand Up @@ -4,6 +4,7 @@ import type {ClientChan, ClientNetwork, ClientUser} from "../types";
import {switchToChannel} from "../router";
import {TypedStore} from "../store";
import useCloseChannel from "../hooks/use-close-channel";
import {ChanType} from "../../../shared/types/chan";

type BaseContextMenuItem = {
label: string;
Expand Down Expand Up @@ -61,7 +62,7 @@ export function generateChannelContextMenu(
];

// Add menu items for lobbies
if (channel.type === "lobby") {
if (channel.type === ChanType.LOBBY) {
items = [
...items,
{
Expand Down Expand Up @@ -121,7 +122,7 @@ export function generateChannelContextMenu(
}

// Add menu items for channels
if (channel.type === "channel") {
if (channel.type === ChanType.CHANNEL) {
items.push({
label: "Edit topic",
type: "item",
Expand All @@ -145,7 +146,7 @@ export function generateChannelContextMenu(
}

// Add menu items for queries
if (channel.type === "query") {
if (channel.type === ChanType.QUERY) {
items.push(
{
label: "User information",
Expand Down Expand Up @@ -173,7 +174,7 @@ export function generateChannelContextMenu(
);
}

if (channel.type === "channel" || channel.type === "query") {
if (channel.type === ChanType.CHANNEL || channel.type === ChanType.QUERY) {
items.push({
label: "Clear history",
type: "item",
Expand Down
3 changes: 1 addition & 2 deletions client/js/helpers/parse.ts
Expand Up @@ -185,8 +185,7 @@ function parse(text: string, message?: ClientMessage, network?: ClientNetwork) {
} else if (textPart.emoji) {
const emojiWithoutModifiers = textPart.emoji.replace(emojiModifiersRegex, "");
const title = emojiMap[emojiWithoutModifiers]
? // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`Emoji: ${emojiMap[emojiWithoutModifiers]}`
? `Emoji: ${emojiMap[emojiWithoutModifiers]}`
: null;

return createElement(
Expand Down
3 changes: 2 additions & 1 deletion client/js/hooks/use-close-channel.ts
@@ -1,10 +1,11 @@
import eventbus from "../eventbus";
import socket from "../socket";
import {ClientChan} from "../types";
import {ChanType} from "../../../shared/types/chan";

export default function useCloseChannel(channel: ClientChan) {
return () => {
if (channel.type === "lobby") {
if (channel.type === ChanType.LOBBY) {
eventbus.emit(
"confirm-dialog",
{
Expand Down
3 changes: 2 additions & 1 deletion client/js/keybinds.ts
Expand Up @@ -6,6 +6,7 @@ import isChannelCollapsed from "./helpers/isChannelCollapsed";
import isIgnoredKeybind from "./helpers/isIgnoredKeybind";
import listenForTwoFingerSwipes from "./helpers/listenForTwoFingerSwipes";
import {ClientChan} from "./types";
import {ChanType} from "../../shared/types/chan";

// Switch to the next/previous window in the channel list.
Mousetrap.bind(["alt+up", "alt+down"], function (e, keys) {
Expand Down Expand Up @@ -73,7 +74,7 @@ Mousetrap.bind(["alt+shift+up", "alt+shift+down"], function (e, keys) {
index = store.state.networks.findIndex((n) => n === store.state.activeChannel?.network);

// If we're in a channel, and it's not the lobby, jump to lobby of this network when going up
if (direction !== -1 || store.state.activeChannel?.channel.type === "lobby") {
if (direction !== -1 || store.state.activeChannel?.channel.type === ChanType.LOBBY) {
index = (((index + direction) % length) + length) % length;
}
}
Expand Down
1 change: 0 additions & 1 deletion client/js/router.ts
Expand Up @@ -162,7 +162,6 @@ async function navigate(routeName: string, params: any = {}) {
// If current route is null, replace the history entry
// This prevents invalid entries from lingering in history,
// and then the route guard preventing proper navigation
// eslint-disable-next-line @typescript-eslint/no-empty-function
await router.replace({name: routeName, params}).catch(() => {});
}
}
Expand Down
1 change: 0 additions & 1 deletion client/js/settings.ts
Expand Up @@ -2,7 +2,6 @@ import socket from "./socket";
import type {TypedStore} from "./store";

const defaultSettingConfig = {
// eslint-disable-next-line @typescript-eslint/no-empty-function
apply() {},
default: null,
sync: null,
Expand Down
4 changes: 2 additions & 2 deletions client/js/socket-events/more.ts
Expand Up @@ -2,7 +2,7 @@ import {nextTick} from "vue";

import socket from "../socket";
import {store} from "../store";
import type {ClientChan, ClientMessage} from "../types";
import {MessageType} from "../../../shared/types/msg";

socket.on("more", async (data) => {
const channel = store.getters.findChannel(data.chan)?.channel;
Expand All @@ -13,7 +13,7 @@ socket.on("more", async (data) => {

channel.inputHistory = channel.inputHistory.concat(
data.messages
.filter((m) => m.self && m.text && m.type === "message")
.filter((m) => m.self && m.text && m.type === MessageType.MESSAGE)
// TS is too stupid to see the guard in .filter(), so we monkey patch it
// to please the compiler
.map((m) => (m.text ? m.text : ""))
Expand Down

0 comments on commit 2f5b9b5

Please sign in to comment.