mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Made ESLint lint all TypeScript files and fix a few linter errors (#273)
* Remove unused import of preact/h * Remove unused imports * Create 273.misc * Lint all TypeScript files * Re-add preact/h import * Fix a few ESLint errors * Update 273.misc * Readd eslint:recommended * Update .eslintrc.js Co-authored-by: Will Hunt <will@half-shot.uk>
This commit is contained in:
parent
f8934fb1c7
commit
7df772cda5
46
.eslintrc.js
46
.eslintrc.js
@ -2,20 +2,56 @@ module.exports = {
|
|||||||
root: true,
|
root: true,
|
||||||
parser: '@typescript-eslint/parser',
|
parser: '@typescript-eslint/parser',
|
||||||
plugins: [
|
plugins: [
|
||||||
'@typescript-eslint',
|
'@typescript-eslint'
|
||||||
'mocha'
|
|
||||||
],
|
],
|
||||||
extends: [
|
extends: [
|
||||||
'eslint:recommended',
|
'eslint:recommended',
|
||||||
'plugin:@typescript-eslint/recommended',
|
'plugin:@typescript-eslint/recommended',
|
||||||
],
|
],
|
||||||
|
// eslint-config-preact needs a Jest version to be happy, even if Jest isn't used.
|
||||||
|
// See https://github.com/preactjs/eslint-config-preact/issues/19#issuecomment-997924892
|
||||||
|
settings: {
|
||||||
|
jest: { "version": 27 },
|
||||||
|
},
|
||||||
rules: {
|
rules: {
|
||||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||||
"camelcase": ["error", { "properties": "never", "ignoreDestructuring": true }],
|
"camelcase": ["error", { "properties": "never", "ignoreDestructuring": true }],
|
||||||
"no-console": "error"
|
"no-console": "error"
|
||||||
},
|
},
|
||||||
"env": {
|
env: {
|
||||||
"node": true,
|
node: true,
|
||||||
"es6": true,
|
es6: true,
|
||||||
},
|
},
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: ["test/**/*.ts"],
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
plugins: [
|
||||||
|
'@typescript-eslint',
|
||||||
|
'mocha',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ["web/**/*.ts", "web/**/*.tsx"],
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
env: {
|
||||||
|
browser: true,
|
||||||
|
node: false,
|
||||||
|
},
|
||||||
|
extends: [
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
'preact',
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
'@typescript-eslint',
|
||||||
|
],
|
||||||
|
rules: {
|
||||||
|
"no-console": "off",
|
||||||
|
"no-unused-vars": "off",
|
||||||
|
"@typescript-eslint/no-unused-vars": ["error"],
|
||||||
|
"no-useless-constructor": "off",
|
||||||
|
"@typescript-eslint/no-useless-constructor": ["error"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
1
changelog.d/273.misc
Normal file
1
changelog.d/273.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Made ESLint lint all TypeScript files and fix a few linter errors.
|
@ -28,7 +28,7 @@
|
|||||||
"start:matrixsender": "node --require source-map-support/register lib/App/MatrixSenderApp.js",
|
"start:matrixsender": "node --require source-map-support/register lib/App/MatrixSenderApp.js",
|
||||||
"test": "mocha -r ts-node/register tests/init.ts tests/*.ts tests/**/*.ts",
|
"test": "mocha -r ts-node/register tests/init.ts tests/*.ts tests/**/*.ts",
|
||||||
"lint": "yarn run lint:js && yarn run lint:rs",
|
"lint": "yarn run lint:js && yarn run lint:rs",
|
||||||
"lint:js": "eslint -c .eslintrc.js src/**/*.ts",
|
"lint:js": "eslint -c .eslintrc.js 'src/**/*.ts' 'tests/**/*.ts' 'web/**/*.ts' 'web/**/*.tsx'",
|
||||||
"lint:rs": "cargo fmt --all -- --check",
|
"lint:rs": "cargo fmt --all -- --check",
|
||||||
"generate-default-config": "ts-node src/Config/Defaults.ts --config > config.sample.yml",
|
"generate-default-config": "ts-node src/Config/Defaults.ts --config > config.sample.yml",
|
||||||
"validate-config": "ts-node src/Config/Config.ts"
|
"validate-config": "ts-node src/Config/Config.ts"
|
||||||
@ -81,6 +81,7 @@
|
|||||||
"@typescript-eslint/parser": "^5.4.0",
|
"@typescript-eslint/parser": "^5.4.0",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"eslint": "^8.3.0",
|
"eslint": "^8.3.0",
|
||||||
|
"eslint-config-preact": "^1.3.0",
|
||||||
"eslint-plugin-mocha": "^9.0.0",
|
"eslint-plugin-mocha": "^9.0.0",
|
||||||
"mini.css": "^3.0.1",
|
"mini.css": "^3.0.1",
|
||||||
"mocha": "^8.2.1",
|
"mocha": "^8.2.1",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Appservice, MatrixClient, RichReply } from "matrix-bot-sdk";
|
import { Appservice, MatrixClient } from "matrix-bot-sdk";
|
||||||
import markdownit from "markdown-it";
|
import markdownit from "markdown-it";
|
||||||
import { FigmaPayload } from "../figma/types";
|
import { FigmaPayload } from "../figma/types";
|
||||||
import { BaseConnection } from "./BaseConnection";
|
import { BaseConnection } from "./BaseConnection";
|
||||||
|
@ -2,7 +2,6 @@ import { AdminRoomCommandHandler } from "../AdminRoomCommandHandler";
|
|||||||
import { botCommand } from "../BotCommands";
|
import { botCommand } from "../BotCommands";
|
||||||
import { JiraAPIAccessibleResource } from "./Types";
|
import { JiraAPIAccessibleResource } from "./Types";
|
||||||
import LogWrapper from "../LogWrapper";
|
import LogWrapper from "../LogWrapper";
|
||||||
import { CommandError } from "../errors";
|
|
||||||
import { CLOUD_INSTANCE } from "./Client";
|
import { CLOUD_INSTANCE } from "./Client";
|
||||||
|
|
||||||
const log = new LogWrapper('JiraBotCommands');
|
const log = new LogWrapper('JiraBotCommands');
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import axios, { Method } from 'axios';
|
import axios, { Method } from 'axios';
|
||||||
import JiraApi, { SearchUserOptions } from 'jira-client';
|
import JiraApi from 'jira-client';
|
||||||
import { JiraAccount, JiraAPIAccessibleResource, JiraProject } from './Types';
|
import { JiraAccount, JiraAPIAccessibleResource, JiraProject } from './Types';
|
||||||
|
|
||||||
export function isJiraCloudInstance(host: string) {
|
export function isJiraCloudInstance(host: string) {
|
||||||
|
@ -6,8 +6,6 @@ import LogWrapper from "../LogWrapper";
|
|||||||
import { ApiError, ErrCode } from "../provisioning/api";
|
import { ApiError, ErrCode } from "../provisioning/api";
|
||||||
import { JiraOAuthRequestCloud, JiraOAuthRequestOnPrem, JiraOAuthRequestResult } from "./OAuth";
|
import { JiraOAuthRequestCloud, JiraOAuthRequestOnPrem, JiraOAuthRequestResult } from "./OAuth";
|
||||||
import { HookshotJiraApi } from "./Client";
|
import { HookshotJiraApi } from "./Client";
|
||||||
import { createPublicKey } from "crypto";
|
|
||||||
import { readFileSync } from "fs";
|
|
||||||
|
|
||||||
const log = new LogWrapper("JiraRouter");
|
const log = new LogWrapper("JiraRouter");
|
||||||
|
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
|
|
||||||
import { JiraAPIAccessibleResource, JiraProject, JiraCloudProjectSearchResponse, JiraStoredToken, JiraOnPremProjectSearchResponse } from '../Types';
|
import { JiraAPIAccessibleResource, JiraProject, JiraStoredToken, JiraOnPremProjectSearchResponse } from '../Types';
|
||||||
import { BridgeConfigJiraOnPremOAuth } from '../../Config/Config';
|
import { BridgeConfigJiraOnPremOAuth } from '../../Config/Config';
|
||||||
import LogWrapper from '../../LogWrapper';
|
|
||||||
import { decodeJiraToken } from '../OAuth';
|
import { decodeJiraToken } from '../OAuth';
|
||||||
import { KeyObject } from 'crypto';
|
import { KeyObject } from 'crypto';
|
||||||
import { HookshotJiraApi, JiraClient } from '../Client';
|
import { HookshotJiraApi, JiraClient } from '../Client';
|
||||||
import JiraApi from 'jira-client';
|
import JiraApi from 'jira-client';
|
||||||
|
|
||||||
const log = new LogWrapper("JiraOnPremClient");
|
|
||||||
|
|
||||||
export class HookshotOnPremJiraApi extends HookshotJiraApi {
|
export class HookshotOnPremJiraApi extends HookshotJiraApi {
|
||||||
|
|
||||||
constructor(options: JiraApi.JiraApiOptions, res: JiraAPIAccessibleResource) {
|
constructor(options: JiraApi.JiraApiOptions, res: JiraAPIAccessibleResource) {
|
||||||
|
@ -58,6 +58,8 @@ export default class App extends Component<void, IState> {
|
|||||||
this.widgetApi.start();
|
this.widgetApi.start();
|
||||||
const roomState = await this.bridgeApi.state();
|
const roomState = await this.bridgeApi.state();
|
||||||
console.log('Got state', roomState);
|
console.log('Got state', roomState);
|
||||||
|
// Calling setState is ok because we've awaited a network request.
|
||||||
|
// eslint-disable-next-line react/no-did-mount-set-state
|
||||||
this.setState({
|
this.setState({
|
||||||
roomState,
|
roomState,
|
||||||
roomId,
|
roomId,
|
||||||
@ -65,6 +67,8 @@ export default class App extends Component<void, IState> {
|
|||||||
});
|
});
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`Bridge verifiation failed:`, ex);
|
console.error(`Bridge verifiation failed:`, ex);
|
||||||
|
// Calling setState is ok because we've awaited a network request.
|
||||||
|
// eslint-disable-next-line react/no-did-mount-set-state
|
||||||
this.setState({
|
this.setState({
|
||||||
error: ex.message,
|
error: ex.message,
|
||||||
busy: false,
|
busy: false,
|
||||||
@ -78,9 +82,9 @@ export default class App extends Component<void, IState> {
|
|||||||
if (this.state.error) {
|
if (this.state.error) {
|
||||||
content = <ErrorPane>{this.state.error}</ErrorPane>;
|
content = <ErrorPane>{this.state.error}</ErrorPane>;
|
||||||
} else if (this.state.roomState) {
|
} else if (this.state.roomState) {
|
||||||
content = <AdminSettings roomState={this.state.roomState}></AdminSettings>;
|
content = <AdminSettings roomState={this.state.roomState} />;
|
||||||
} else if (this.state.busy) {
|
} else if (this.state.busy) {
|
||||||
content = <div class="spinner"></div>;
|
content = <div class="spinner" />;
|
||||||
} else {
|
} else {
|
||||||
content = <b>Invalid state</b>;
|
content = <b>Invalid state</b>;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ export default class BridgeAPI {
|
|||||||
method,
|
method,
|
||||||
body: body ? JSON.stringify(body) : undefined,
|
body: body ? JSON.stringify(body) : undefined,
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${this.accessToken}`,
|
Authorization: `Bearer ${this.accessToken}`,
|
||||||
// Only set Content-Type if we send a body
|
// Only set Content-Type if we send a body
|
||||||
...(!!body && {
|
...(!!body && {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -8,10 +8,6 @@ interface IProps{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class AdminSettings extends Component<IProps> {
|
export default class AdminSettings extends Component<IProps> {
|
||||||
constructor(props) {
|
|
||||||
super(props)
|
|
||||||
}
|
|
||||||
|
|
||||||
renderGitHub() {
|
renderGitHub() {
|
||||||
const githubConfig = this.props.roomState.github;
|
const githubConfig = this.props.roomState.github;
|
||||||
if (!githubConfig.enabled) {
|
if (!githubConfig.enabled) {
|
||||||
@ -29,7 +25,7 @@ export default class AdminSettings extends Component<IProps> {
|
|||||||
Your token does not appear to work
|
Your token does not appear to work
|
||||||
</strong>;
|
</strong>;
|
||||||
}
|
}
|
||||||
return <GitHubState config={githubConfig}/>;
|
return <GitHubState config={githubConfig} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -6,7 +6,7 @@ const GitHubState: FunctionComponent<{config: BridgeRoomStateGitHub}> = ({ confi
|
|||||||
return <div class="container login-card">
|
return <div class="container login-card">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-2">
|
||||||
<img src={config.identity.avatarUrl} title="GitHub avatar"/>
|
<img src={config.identity.avatarUrl} title="GitHub avatar" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
Logged in as <span>{config.identity.name}</span>
|
Logged in as <span>{config.identity.name}</span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user