Add lint for unused locals (#8007)

This commit is contained in:
J. Ryan Stinnett 2022-03-09 12:05:16 +00:00 committed by GitHub
parent c7dfaa8f64
commit 65691202f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 46 additions and 115 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright 2016 - 2021 The Matrix.org Foundation C.I.C.
Copyright 2016 - 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { PushRuleAction, PushRuleKind } from "matrix-js-sdk/src/@types/PushRules";
import { IAnnotatedPushRule, PushRuleAction } from "matrix-js-sdk/src/@types/PushRules";
import { logger } from "matrix-js-sdk/src/logger";
import { _td } from '../languageHandler';
@ -26,32 +26,29 @@ type StateToActionsMap = {
[state in VectorState]?: PushRuleAction[];
};
interface IProps {
kind: PushRuleKind;
interface IVectorPushRuleDefinition {
description: string;
vectorStateToActions: StateToActionsMap;
}
class VectorPushRuleDefinition {
private kind: PushRuleKind;
private description: string;
public readonly description: string;
public readonly vectorStateToActions: StateToActionsMap;
constructor(opts: IProps) {
this.kind = opts.kind;
constructor(opts: IVectorPushRuleDefinition) {
this.description = opts.description;
this.vectorStateToActions = opts.vectorStateToActions;
}
// Translate the rule actions and its enabled value into vector state
public ruleToVectorState(rule): VectorPushRuleDefinition {
public ruleToVectorState(rule: IAnnotatedPushRule): VectorState {
let enabled = false;
if (rule) {
enabled = rule.enabled;
}
for (const stateKey in PushRuleVectorState.states) { // eslint-disable-line guard-for-in
const state = PushRuleVectorState.states[stateKey];
const state: VectorState = PushRuleVectorState.states[stateKey];
const vectorStateToActions = this.vectorStateToActions[state];
if (!vectorStateToActions) {
@ -78,6 +75,7 @@ class VectorPushRuleDefinition {
return undefined;
}
}
export type { VectorPushRuleDefinition };
/**
* The descriptions of rules managed by the Vector UI.
@ -85,7 +83,6 @@ class VectorPushRuleDefinition {
export const VectorPushRulesDefinitions = {
// Messages containing user's display name
".m.rule.contains_display_name": new VectorPushRuleDefinition({
kind: PushRuleKind.Override,
description: _td("Messages containing my display name"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: { // The actions for each vector state, or null to disable the rule.
[VectorState.On]: StandardActions.ACTION_NOTIFY,
@ -96,7 +93,6 @@ export const VectorPushRulesDefinitions = {
// Messages containing user's username (localpart/MXID)
".m.rule.contains_user_name": new VectorPushRuleDefinition({
kind: PushRuleKind.Override,
description: _td("Messages containing my username"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: { // The actions for each vector state, or null to disable the rule.
[VectorState.On]: StandardActions.ACTION_NOTIFY,
@ -107,7 +103,6 @@ export const VectorPushRulesDefinitions = {
// Messages containing @room
".m.rule.roomnotif": new VectorPushRuleDefinition({
kind: PushRuleKind.Override,
description: _td("Messages containing @room"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: { // The actions for each vector state, or null to disable the rule.
[VectorState.On]: StandardActions.ACTION_NOTIFY,
@ -118,7 +113,6 @@ export const VectorPushRulesDefinitions = {
// Messages just sent to the user in a 1:1 room
".m.rule.room_one_to_one": new VectorPushRuleDefinition({
kind: PushRuleKind.Underride,
description: _td("Messages in one-to-one chats"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: {
[VectorState.On]: StandardActions.ACTION_NOTIFY,
@ -129,7 +123,6 @@ export const VectorPushRulesDefinitions = {
// Encrypted messages just sent to the user in a 1:1 room
".m.rule.encrypted_room_one_to_one": new VectorPushRuleDefinition({
kind: PushRuleKind.Underride,
description: _td("Encrypted messages in one-to-one chats"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: {
[VectorState.On]: StandardActions.ACTION_NOTIFY,
@ -142,7 +135,6 @@ export const VectorPushRulesDefinitions = {
// 1:1 room messages are catched by the .m.rule.room_one_to_one rule if any defined
// By opposition, all other room messages are from group chat rooms.
".m.rule.message": new VectorPushRuleDefinition({
kind: PushRuleKind.Underride,
description: _td("Messages in group chats"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: {
[VectorState.On]: StandardActions.ACTION_NOTIFY,
@ -155,7 +147,6 @@ export const VectorPushRulesDefinitions = {
// Encrypted 1:1 room messages are catched by the .m.rule.encrypted_room_one_to_one rule if any defined
// By opposition, all other room messages are from group chat rooms.
".m.rule.encrypted": new VectorPushRuleDefinition({
kind: PushRuleKind.Underride,
description: _td("Encrypted messages in group chats"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: {
[VectorState.On]: StandardActions.ACTION_NOTIFY,
@ -166,7 +157,6 @@ export const VectorPushRulesDefinitions = {
// Invitation for the user
".m.rule.invite_for_me": new VectorPushRuleDefinition({
kind: PushRuleKind.Underride,
description: _td("When I'm invited to a room"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: {
[VectorState.On]: StandardActions.ACTION_NOTIFY,
@ -177,7 +167,6 @@ export const VectorPushRulesDefinitions = {
// Incoming call
".m.rule.call": new VectorPushRuleDefinition({
kind: PushRuleKind.Underride,
description: _td("Call invitation"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: {
[VectorState.On]: StandardActions.ACTION_NOTIFY,
@ -188,7 +177,6 @@ export const VectorPushRulesDefinitions = {
// Notifications from bots
".m.rule.suppress_notices": new VectorPushRuleDefinition({
kind: PushRuleKind.Override,
description: _td("Messages sent by bot"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: {
// .m.rule.suppress_notices is a "negative" rule, we have to invert its enabled value for vector UI
@ -200,7 +188,6 @@ export const VectorPushRulesDefinitions = {
// Room upgrades (tombstones)
".m.rule.tombstone": new VectorPushRuleDefinition({
kind: PushRuleKind.Override,
description: _td("When rooms are upgraded"), // passed through _t() translation in src/components/views/settings/Notifications.js
vectorStateToActions: { // The actions for each vector state, or null to disable the rule.
[VectorState.On]: StandardActions.ACTION_NOTIFY,