Skip to content

Commit

Permalink
Make linter happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Nov 26, 2024
1 parent 0c9e952 commit a12f47d
Show file tree
Hide file tree
Showing 40 changed files with 237 additions and 427 deletions.
44 changes: 30 additions & 14 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import mocha from "eslint-plugin-mocha";
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import react from "eslint-plugin-react";

import chai from "eslint-plugin-chai-expect";

export default [
{
ignores: ["lib/**/*", "contrib/**/*"],
},
...tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommended,
{
files: ["src/**/*.ts", "scripts/*.ts"],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
],
rules: {
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "warn",
Expand All @@ -23,16 +28,21 @@ export default [
},
),
...tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommended,
mocha.configs.flat.recommended,
{
files: ["test/**/*.ts"],
files: ["tests/**/*.ts", "tests/**/*.spec.ts"],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
mocha.configs.flat.recommended,
chai.configs["recommended-flat"],
],
rules: {
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": "warn",
camelcase: ["always", {
// Chai assertions don't call functions
"@typescript-eslint/no-unused-expressions": "off",
camelcase: ["error", {
properties: "never",
ignoreDestructuring: true,
}],
Expand All @@ -43,11 +53,20 @@ export default [
},
),
...tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommended,
react.configs.flat.recommended,
{
settings: {
react: {
pragma: "Preact",
version: "17",
}
},
files: ["web/**/*.ts", "web/**/*.tsx"],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
react.configs.flat.recommended,
react.configs.flat['jsx-runtime'],
],
rules: {
"no-console": "off",
"no-unused-vars": "off",
Expand All @@ -58,9 +77,6 @@ export default [
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
},
settings: {
pragma: "Preact",
},
},
),
];
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"test:e2e": "yarn node --experimental-vm-modules $(yarn bin jest)",
"test:cover": "nyc --reporter=lcov --reporter=text yarn test",
"lint": "yarn run lint:js && yarn run lint:rs",
"lint:js": "eslint 'src/**/*.ts' 'tests/**/*.ts' 'web/**/*.ts' 'web/**/*.tsx'",
"lint:js": "eslint",
"lint:rs": "cargo fmt --all -- --check && cargo clippy -- -Dwarnings",
"lint:rs:apply": "cargo clippy --fix && cargo fmt --all",
"generate-default-config": "ts-node src/config/Defaults.ts --config > config.sample.yml",
Expand Down Expand Up @@ -109,6 +109,7 @@
"busboy": "^1.6.0",
"chai": "^5.1.2",
"eslint": "^9.15.0",
"eslint-plugin-chai-expect": "^3.1.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-react": "^7.37.2",
"homerunner-client": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/AdminRoom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import "reflect-metadata";
import { AdminAccountData, AdminRoomCommandHandler, Category } from "./AdminRoomCommandHandler";
import { botCommand, compileBotCommands, handleCommand, BotCommands, HelpFunction } from "./BotCommands";
Expand Down
2 changes: 1 addition & 1 deletion src/AdminRoomCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export enum Category {


export interface AdminAccountData {
// eslint-disable-next-line camelcase
admin_user: string;
github?: {
notifications?: {
Expand Down
2 changes: 1 addition & 1 deletion src/CommentProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const log = new Logger("CommentProcessor");
const mime = import('mime');

interface IMatrixCommentEvent extends MatrixMessageContent {
// eslint-disable-next-line camelcase
external_url: string;
"uk.half-shot.matrix-hookshot.github.comment": {
id: number;
Expand Down
2 changes: 1 addition & 1 deletion src/Connections/GithubIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface GitHubIssueConnectionState {
repo: string;
state: string;
issues: string[];
// eslint-disable-next-line camelcase
comments_processed: number;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Connections/GithubProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ConfigGrantChecker, GrantChecker } from "../grants/GrantCheck";
import { BridgeConfig } from "../config/Config";

export interface GitHubProjectConnectionState {
// eslint-disable-next-line camelcase
project_id: number;
state: "open"|"closed";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Connections/GithubUserSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class GitHubUserSpace extends BaseConnection implements IConnection {
throw Error("Could not find repo");
}

// eslint-disable-next-line camelcase
let avatarState: {type: "m.room.avatar", state_key: "", content: { url: string}}|undefined;
try {
if (avatarUrl) {
Expand Down
2 changes: 1 addition & 1 deletion src/Gitlab/Types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable camelcase */
export interface GitLabAuthor {
id: number;
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/Gitlab/WebhookTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable camelcase */

export interface IGitLabWebhookEvent {
object_kind: string;
Expand Down
8 changes: 3 additions & 5 deletions src/MatrixEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable camelcase */
export interface MatrixEvent<T extends MatrixEventContent|unknown> {
content: T;
event_id: string;
Expand All @@ -8,10 +8,8 @@ export interface MatrixEvent<T extends MatrixEventContent|unknown> {
type: string;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface MatrixEventContent {

}

type MatrixEventContent = object;

export interface MatrixMemberContent extends MatrixEventContent {
avatar_url: string|null;
Expand Down
2 changes: 1 addition & 1 deletion src/Notifications/UserNotificationWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class UserNotificationWatcher {
[...this.userIntervals.values()].forEach((v) => {
v.stop();
});
this.queue.stop ? this.queue.stop() : undefined;
this.queue.stop?.();
}

public removeUser(userId: string, type: "github"|"gitlab", instanceUrl?: string) {
Expand Down
8 changes: 4 additions & 4 deletions src/NotificationsProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ export interface IssueDiff {
merged: boolean;
mergedBy: null|{
login: string;
// eslint-disable-next-line camelcase
html_url: string;
};
user: {
login: string;
// eslint-disable-next-line camelcase
html_url: string;
};
}

export interface CachedReviewData {
// eslint-disable-next-line camelcase
requested_reviewers: PullsListRequestedReviewersResponseData;
reviews: PullsListReviewsResponseData;
}
Expand All @@ -41,7 +41,7 @@ type PROrIssue = IssuesGetResponseData|PullGetResponseData;

export class NotificationProcessor {

// eslint-disable-next-line camelcase
private static formatUser(user: {login: string, html_url: string}) {
return `**[${user.login}](${user.html_url})**`;
}
Expand Down
26 changes: 14 additions & 12 deletions src/config/Config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */

import YAML from "yaml";
import { promises as fs } from "fs";
import { IAppserviceRegistration, LogLevel, MatrixClient } from "matrix-bot-sdk";
Expand Down Expand Up @@ -48,11 +50,11 @@ interface BridgeConfigGitHubYAML {
secret: string;
};
oauth?: {
// eslint-disable-next-line camelcase
client_id: string;
// eslint-disable-next-line camelcase
client_secret: string;
// eslint-disable-next-line camelcase
redirect_uri: string;
};
defaultOptions?: GitHubRepoConnectionOptions;
Expand All @@ -71,11 +73,11 @@ export class BridgeConfigGitHub {
};
@configKey("Settings for allowing users to sign in via OAuth.", true)
readonly oauth?: {
// eslint-disable-next-line camelcase
client_id: string;
// eslint-disable-next-line camelcase
client_secret: string;
// eslint-disable-next-line camelcase
redirect_uri: string;
};
@configKey("Default options for GitHub connections.", true)
Expand Down Expand Up @@ -108,18 +110,18 @@ export class BridgeConfigGitHub {
}

export interface BridgeConfigJiraCloudOAuth {
// eslint-disable-next-line camelcase
client_id: string;
// eslint-disable-next-line camelcase
client_secret: string;
// eslint-disable-next-line camelcase
redirect_uri: string;
}

export interface BridgeConfigJiraOnPremOAuth {
consumerKey: string;
privateKey: string;
// eslint-disable-next-line camelcase
redirect_uri: string;
}

Expand Down Expand Up @@ -776,11 +778,11 @@ export async function parseRegistrationFile(filename: string) {
if (require.main === module) {
Logger.configure({console: "info"});
BridgeConfig.parseConfig(process.argv[2] || "config.yml", process.env).then(() => {
// eslint-disable-next-line no-console
console.log('Config successfully validated.');
process.exit(0);
}).catch(ex => {
// eslint-disable-next-line no-console
console.error('Error in config:', ex);
process.exit(1);
});
Expand Down
8 changes: 5 additions & 3 deletions src/config/Defaults.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */

import { BridgeConfig, BridgeConfigRoot } from "./Config";
import { getConfigKeyMetadata, keyIsHidden } from "./Decorators";
import { Node, YAMLSeq, default as YAML } from "yaml";
Expand Down Expand Up @@ -246,19 +248,19 @@ async function renderRegistrationFile(configPath?: string) {
rooms: [],
},
};
// eslint-disable-next-line no-console
console.log(YAML.stringify(obj));
}


// Can be called directly
if (require.main === module) {
if (process.argv[2] === '--config') {
// eslint-disable-next-line no-console
console.log(renderDefaultConfig());
} else if (process.argv[2] === '--registration') {
renderRegistrationFile(process.argv[3]).catch(ex => {
// eslint-disable-next-line no-console
console.error(ex);
process.exit(1);
});
Expand Down
2 changes: 1 addition & 1 deletion src/github/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type CreateInstallationAccessTokenDataType = Endpoints["POST /app/install

export const NAMELESS_ORG_PLACEHOLDER = "No name";

/* eslint-disable camelcase */
export interface GitHubUserNotification {
id: string;
reason: "assign"|"author"|"comment"|"invitation"|"manual"|"mention"|"review_requested"|
Expand Down
2 changes: 1 addition & 1 deletion src/jira/GrantChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class JiraGrantChecker extends GrantChecker<JiraGrantConnectionId> {
try {
await JiraProjectConnection.assertUserHasAccessToProject(this.tokenStore, sender, connectionId.url);
return true;
} catch (ex) {
} catch {
return false;
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/jira/client/CloudClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ const ACCESSIBLE_RESOURCE_CACHE_TTL_MS = 60000;


export class HookshotCloudJiraApi extends HookshotJiraApi {
constructor(options: JiraApi.JiraApiOptions, res: JiraAPIAccessibleResource) {
super(options, res);
}


async getIssue(issueIdOrKey: string): Promise<JiraIssue> {
return this.apiRequest<JiraIssue>(`/rest/api/3/issue/${issueIdOrKey}`);
}
Expand Down Expand Up @@ -90,7 +85,7 @@ export class JiraCloudClient implements JiraClient {
if (existingPromise) {
return await existingPromise;
}
} catch (ex) {
} catch {
// Existing failed promise, break out and try again.
JiraCloudClient.resourceCache.delete(this.bearer);
}
Expand Down
Loading

0 comments on commit a12f47d

Please sign in to comment.