Skip to content

Commit

Permalink
TSLint -> ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattheis committed Sep 12, 2020
1 parent 33c0e01 commit 0d65ca6
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 180 deletions.
2 changes: 2 additions & 0 deletions ui/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/setupTests.ts
src/registerServiceWorker.ts
87 changes: 87 additions & 0 deletions ui/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
- plugin:@typescript-eslint/recommended-requiring-type-checking
- plugin:react/recommended
- plugin:import/errors
- plugin:import/typescript
- plugin:jest/recommended
- prettier
env:
browser: true
es6: true
node: true
parser: "@typescript-eslint/parser"
parserOptions:
project: tsconfig.json
sourceType: module
plugins:
- "@typescript-eslint"
- react
- import
- unicorn
settings:
react:
version: detect
rules:
consistent-return: error
default-case: error
default-param-last: error
no-loop-func: off
arrow-body-style: [error, as-needed]

import/no-useless-path-segments: error
import/group-exports: off
import/extensions: [error, never]
import/no-duplicates: error
import/first: error
import/no-unused-modules: error

unicorn/no-abusive-eslint-disable: error
unicorn/no-array-instanceof: error
unicorn/no-unreadable-array-destructuring: error
unicorn/no-zero-fractions: error

react/jsx-key: error
react/jsx-pascal-case: error
react/destructuring-assignment: warn
react/function-component-definition: [error, {namedComponents: arrow-function, unnamedComponents: arrow-function}]
react/no-array-index-key: error
react/no-deprecated: error
react/no-string-refs: error
react/no-this-in-sfc: error
react/no-typos: error
react/no-unknown-property: error
react/prefer-stateless-function: error
react/prop-types: off

jest/expect-expect: off
jest/no-jasmine-globals: off
"@typescript-eslint/require-await": off

"@typescript-eslint/array-type": [error, {default: array-simple}]
"@typescript-eslint/await-thenable": error
"@typescript-eslint/no-unused-vars": error
"@typescript-eslint/no-use-before-define": off
"@typescript-eslint/consistent-type-assertions": [error, {assertionStyle: as}]

"@typescript-eslint/no-extra-non-null-assertion": error
"@typescript-eslint/no-inferrable-types": error
"@typescript-eslint/no-this-alias": error
"@typescript-eslint/no-throw-literal": error
"@typescript-eslint/prefer-nullish-coalescing": error
"@typescript-eslint/prefer-optional-chain": error
"@typescript-eslint/prefer-readonly": error
"@typescript-eslint/unbound-method": error
"@typescript-eslint/no-empty-function": off
"@typescript-eslint/explicit-module-boundary-types": off
"@typescript-eslint/no-floating-promises": off
"@typescript-eslint/no-unsafe-member-access": off
"@typescript-eslint/no-unsafe-return": off
"@typescript-eslint/no-unsafe-assignment": off
"@typescript-eslint/restrict-plus-operands": off
"@typescript-eslint/no-misused-promises": off

"@typescript-eslint/no-explicit-any": error
13 changes: 9 additions & 4 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"build": "react-scripts build",
"test": "react-scripts test --env=node",
"eject": "react-scripts eject",
"lint": "tslint --project .",
"lintfix": "tslint --fix --project .",
"lint": "eslint \"src/*.{ts,tsx}\"",
"format": "prettier \"src/**/*.{ts,tsx}\" --write",
"testformat": "prettier \"src/**/*.{ts,tsx}\" --list-different"
},
Expand All @@ -52,14 +51,20 @@
"@types/react-router-dom": "^5.1.5",
"@types/remove-markdown": "^0.1.1",
"@types/rimraf": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^24.0.0",
"eslint-plugin-prefer-arrow": "^1.2.2",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-unicorn": "^21.0.0",
"get-port": "^5.1.1",
"prettier": "^2.1.1",
"puppeteer": "^5.3.0",
"react-scripts": "^3.4.3",
"rimraf": "^3.0.2",
"tree-kill": "^1.2.0",
"tslint": "^6.1.2",
"tslint-sonarts": "^1.7.0",
"typescript": "4.0.2",
"wait-on": "^5.2.0"
},
Expand Down
68 changes: 35 additions & 33 deletions ui/src/CurrentUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class CurrentUser {
return '';
};

private setToken = (token: string) => {
private readonly setToken = (token: string) => {
this.tokenCache = token;
window.localStorage.setItem(tokenKey, token);
};
Expand All @@ -53,6 +53,7 @@ export class CurrentUser {
url: config.get('url') + 'client',
method: 'POST',
data: {name},
// eslint-disable-next-line @typescript-eslint/naming-convention
headers: {Authorization: 'Basic ' + Base64.encode(username + ':' + password)},
})
.then((resp: AxiosResponse<IClient>) => {
Expand Down Expand Up @@ -81,36 +82,39 @@ export class CurrentUser {
return Promise.reject();
}

return axios
.create()
.get(config.get('url') + 'current/user', {headers: {'X-Gotify-Key': this.token()}})
.then((passThrough) => {
this.user = passThrough.data;
this.loggedIn = true;
this.connectionErrorMessage = null;
this.reconnectTime = 7500;
return passThrough;
})
.catch((error: AxiosError) => {
if (!error || !error.response) {
this.connectionError('No network connection or server unavailable.');
return Promise.reject(error);
}

if (error.response.status >= 500) {
this.connectionError(
`${error.response.statusText} (code: ${error.response.status}).`
);
return Promise.reject(error);
}
return (
axios
.create()
// eslint-disable-next-line @typescript-eslint/naming-convention
.get(config.get('url') + 'current/user', {headers: {'X-Gotify-Key': this.token()}})
.then((passThrough) => {
this.user = passThrough.data;
this.loggedIn = true;
this.connectionErrorMessage = null;
this.reconnectTime = 7500;
return passThrough;
})
.catch((error: AxiosError) => {
if (!error || !error.response) {
this.connectionError('No network connection or server unavailable.');
return Promise.reject(error);
}

if (error.response.status >= 500) {
this.connectionError(
`${error.response.statusText} (code: ${error.response.status}).`
);
return Promise.reject(error);
}

this.connectionErrorMessage = null;
this.connectionErrorMessage = null;

if (error.response.status >= 400 && error.response.status < 500) {
this.logout();
}
return Promise.reject(error);
});
if (error.response.status >= 400 && error.response.status < 500) {
this.logout();
}
return Promise.reject(error);
})
);
};

public logout = async () => {
Expand All @@ -119,9 +123,7 @@ export class CurrentUser {
.then((resp: AxiosResponse<IClient[]>) => {
resp.data
.filter((client) => client.token === this.tokenCache)
.forEach((client) => {
return axios.delete(config.get('url') + 'client/' + client.id);
});
.forEach((client) => axios.delete(config.get('url') + 'client/' + client.id));
})
.catch(() => Promise.resolve());
window.localStorage.removeItem(tokenKey);
Expand All @@ -143,7 +145,7 @@ export class CurrentUser {
});
};

private connectionError = (message: string) => {
private readonly connectionError = (message: string) => {
this.connectionErrorMessage = message;
if (this.reconnectTimeoutId !== null) {
window.clearTimeout(this.reconnectTimeoutId);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const defaultProdConfig = {
url: urlWithSlash,
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
declare global {
// tslint:disable-next-line
interface Window {
config: config.IConfig;
}
Expand Down
20 changes: 9 additions & 11 deletions ui/src/inject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ export interface StoreMapping {
export type AllStores = Extract<keyof StoreMapping, string>;
export type Stores<T extends AllStores> = Pick<StoreMapping, T>;

export const inject = <I extends AllStores>(...stores: I[]) => {
return <P extends {}>(
node: React.ComponentType<P>
): React.ComponentType<Pick<P, Exclude<keyof P, I>>> => {
// tslint:disable-next-line:no-any
return mobxInject(...stores)(node) as any;
};
};
// eslint-disable-next-line @typescript-eslint/ban-types
export const inject = <I extends AllStores>(...stores: I[]) => <P extends {}>(
node: React.ComponentType<P>
): React.ComponentType<Pick<P, Exclude<keyof P, I>>> =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mobxInject(...stores)(node) as any;

export const InjectProvider: React.SFC<{stores: StoreMapping}> = ({children, stores}) => {
return <Provider {...stores}>{children}</Provider>;
};
export const InjectProvider: React.SFC<{stores: StoreMapping}> = ({children, stores}) => (
<Provider {...stores}>{children}</Provider>
);
2 changes: 1 addition & 1 deletion ui/src/message/extras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const contentType = (extras?: IMessageExtras): RenderMode => {
return valid ? type : RenderMode.Plain;
};

// tslint:disable-next-line:no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const extract = (extras: IMessageExtras | undefined, key: string, path: string): any => {
if (!extras) {
return null;
Expand Down
1 change: 0 additions & 1 deletion ui/src/registerServiceWorker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// tslint:disable
// In production, we register a service worker to serve assets from local cache.

// This lets the app load faster on subsequent visits in production, and gives
Expand Down
2 changes: 1 addition & 1 deletion ui/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('Client', () => {

expect(await count(page, $table.rows())).toBe(2);
});
// tslint:disable-next-line:no-identical-functions
// eslint-disable-next-line
it('deletes own client', async () => {
await page.click($table.cell(1, Col.Delete, '.delete'));

Expand Down
4 changes: 2 additions & 2 deletions ui/src/tests/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ beforeAll(async () => {

afterAll(async () => await gotify.close());

// tslint:disable-next-line
// eslint-disable-next-line
const axiosAuth = {auth: {username: 'admin', password: 'admin'}};

let windowsServerToken: string;
Expand All @@ -35,7 +35,7 @@ const navigate = async (appName: string) => {
await waitForExists(page, selector.heading(), appName);
};

// tslint:disable-next-line
// eslint-disable-next-line
describe('Messages', () => {
it('does login', async () => await auth.login(page));
it('is on messages', async () => {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface IMessage {
}

export interface IMessageExtras {
[key: string]: any; // tslint:disable-line no-any
[key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
}

export interface IPagedMessages {
Expand Down
Loading

0 comments on commit 0d65ca6

Please sign in to comment.