Skip to content

Commit

Permalink
chore: update lint
Browse files Browse the repository at this point in the history
  • Loading branch information
embbnux committed Oct 23, 2023
1 parent 29ef8b5 commit d4ef72d
Show file tree
Hide file tree
Showing 21 changed files with 3,800 additions and 863 deletions.
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
"rules": {
"import/default": "off",
"import/no-unresolved": "off", // to capture direct deps in TS
"import/no-default-export": "off",
"no-dupe-class-members": "off", // to enable TS overload
"no-undef": "off", //FIXME @see https://github.com/eslint/typescript-eslint-parser/issues/75
"import/named": "off", //FIXME @see https://github.com/eslint/typescript-eslint-parser/issues/75
"no-unused-expressions": "off", // tests
"react/sort-comp": "off",
"react/prop-types": "off",
"prefer-const": "warn",
"sonarjs/no-nested-template-literals": "off",
"ringcentral/specified-comment-with-task-id": "off",
"@typescript-eslint/camelcase": "off", // OAuth responses
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-var-requires": "off" // conditional require in Externals
},
"env": {
Expand Down
4,452 changes: 3,686 additions & 766 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"dependencies": {
"coveralls": "^3.1.1",
"dotenv-cli": "^1.4.0",
"eslint": "^5.8.0",
"eslint-config-ringcentral-typescript": "0.1.0",
"eslint": "^8.52.0",
"eslint-config-ringcentral-typescript": "^7.0.3",
"husky": "^1.1.3",
"lerna": "^6.6.2",
"lint-staged": "^12.5.0",
Expand Down
4 changes: 2 additions & 2 deletions react-demo/src/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default class Dashboard extends Component<any, DashboardState> {

public render() {
const {error, user} = this.state;
if (error) return <div>{error}</div>;
if (!user) return <div>Loading</div>;
if (error) {return <div>{error}</div>;}
if (!user) {return <div>Loading</div>;}
return <pre>{JSON.stringify(user, null, 2)}</pre>;
}
}
2 changes: 1 addition & 1 deletion react-demo/src/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {withAuthGate} from '@ringcentral/react';
import {sdk} from './lib';

const Login = ({authError, loginUrl, authorizing}: any) => {
if (authorizing) return <div>Loading...</div>;
if (authorizing) {return <div>Loading...</div>;}

const login = () => window.location.assign(loginUrl({implicit: true}));

Expand Down
2 changes: 1 addition & 1 deletion react-demo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import Router from './Router';

render(<Router />, document.getElementById('app'));

if (module.hot) module.hot.accept();
if (module.hot) {module.hot.accept();}
8 changes: 7 additions & 1 deletion react/src/AuthGate.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {Component} from 'react';

import {SDK} from '@ringcentral/sdk';

function getDisplayName(WrappedComponent) {
Expand Down Expand Up @@ -32,6 +33,11 @@ export class AuthGate extends Component<AuthGateProps, AuthGateState> {
authError: null,
};

// default props
public static defaultProps = {
ensure: false,
};

/**
* purposely going through antipattern because we can't cancel promises for now
* we still cancel subscriptions etc., but we can't guarantee when storage promises will resolve
Expand Down Expand Up @@ -93,7 +99,7 @@ export class AuthGate extends Component<AuthGateProps, AuthGateState> {
try {
const platform = this.props.sdk.platform();
const loginOptions = platform.parseLoginRedirect(search);
if (!loginOptions.code && !loginOptions.access_token) throw new Error('No authorization information');
if (!loginOptions.code && !loginOptions.access_token) {throw new Error('No authorization information');}
return platform.login(loginOptions);
} catch (e) {
await this.error(e);
Expand Down
2 changes: 1 addition & 1 deletion redux-demo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const store = createStore();

render(<Router store={store} storeConnector={storeConnector} />, rootEl);

if (module.hot) module.hot.accept();
if (module.hot) {module.hot.accept();}
4 changes: 2 additions & 2 deletions redux-demo/src/pages/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class Index extends Component<any, IndexState> {
public render() {
const {error, user} = this.state;

if (error) return <div>Error: {error.toString()}</div>;
if (error) {return <div>Error: {error.toString()}</div>;}

if (!user) return <div>Loading...</div>;
if (!user) {return <div>Loading...</div>;}

return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion redux-demo/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface LoginProps extends RouteComponentProps {
error: null | Error;
}

let Login: FunctionComponent<LoginProps> = ({error, location: {pathname, search, hash}}) => {
const Login: FunctionComponent<LoginProps> = ({error, location: {pathname, search, hash}}) => {
const query = sdk.parseLoginRedirect(search || hash);

// code is defined in redirect from OAuth
Expand Down
2 changes: 1 addition & 1 deletion redux/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class Actions {
}

public login = query => {
if (query.error_description) return this.authError(new Error(query.error_description));
if (query.error_description) {return this.authError(new Error(query.error_description));}
this.sdk.login(query); // we ignore promise result because we listen to all events already
return {type: LOGIN};
};
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/core/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class Cache {

public getItemSync(key) {
const item = this._externals.localStorage.getItem(this._prefixKey(key));
if (!item) return null;
if (!item) {return null;}
return JSON.parse(item);
}

Expand Down
10 changes: 5 additions & 5 deletions sdk/src/core/Externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export default class Externals implements ExternalsOptions {
Headers: HeadersImpl,
localStorage,
}: ExternalsOptions = {}) {
if (fetchImpl) this.fetch = fetchImpl;
if (RequestImpl) this.Request = RequestImpl;
if (ResponseImpl) this.Response = ResponseImpl;
if (HeadersImpl) this.Headers = HeadersImpl;
if (localStorage) this.localStorage = localStorage;
if (fetchImpl) {this.fetch = fetchImpl;}
if (RequestImpl) {this.Request = RequestImpl;}
if (ResponseImpl) {this.Response = ResponseImpl;}
if (HeadersImpl) {this.Headers = HeadersImpl;}
if (localStorage) {this.localStorage = localStorage;}

/* istanbul ignore next */
if (!this.fetch || !this.Response || !this.Request || !this.Headers) {
Expand Down
32 changes: 16 additions & 16 deletions sdk/src/http/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Externals from '../core/Externals';
function findHeaderName(name, headers) {
name = name.toLowerCase();
return Object.keys(headers).reduce((res, key) => {
if (res) return res;
if (name === key.toLowerCase()) return key;
if (res) {return res;}
if (name === key.toLowerCase()) {return key;}
return res;
}, null);
}
Expand Down Expand Up @@ -75,7 +75,7 @@ export default class Client extends EventEmitter {

response = await this._loadResponse(request);

if (!response.ok) throw new Error('Response has unsuccessful status');
if (!response.ok) {throw new Error('Response has unsuccessful status');}

this.emit(this.events.requestSuccess, response, request);

Expand Down Expand Up @@ -113,8 +113,8 @@ export default class Client extends EventEmitter {
init.headers = init.headers || {};

// Sanity checks
if (!init.url) throw new Error('Url is not defined');
if (!init.method) init.method = 'GET';
if (!init.url) {throw new Error('Url is not defined');}
if (!init.method) {init.method = 'GET';}
init.method = init.method.toUpperCase();
if (init.method && Client._allowedMethods.indexOf(init.method) < 0) {
throw new Error(`Method has wrong value: ${init.method}`);
Expand Down Expand Up @@ -183,13 +183,13 @@ export default class Client extends EventEmitter {
}

public async multipart(response: Response): Promise<Response[]> {
if (!this.isMultipart(response)) throw new Error('Response is not multipart');
if (!this.isMultipart(response)) {throw new Error('Response is not multipart');}

// Step 1. Split multipart response

const text = await response.text();

if (!text) throw new Error('No response body');
if (!text) {throw new Error('No response body');}

let boundary;

Expand All @@ -199,14 +199,14 @@ export default class Client extends EventEmitter {
throw new Error('Cannot find boundary');
}

if (!boundary) throw new Error('Cannot find boundary');
if (!boundary) {throw new Error('Cannot find boundary');}

const parts = text.toString().split(Client._boundarySeparator + boundary);

if (parts[0].trim() === '') parts.shift();
if (parts[parts.length - 1].trim() === Client._boundarySeparator) parts.pop();
if (parts[0].trim() === '') {parts.shift();}
if (parts[parts.length - 1].trim() === Client._boundarySeparator) {parts.pop();}

if (parts.length < 1) throw new Error('No parts in body');
if (parts.length < 1) {throw new Error('No parts in body');}

// Step 2. Parse status info

Expand Down Expand Up @@ -234,7 +234,7 @@ export default class Client extends EventEmitter {
const key = split.shift().trim();
const value = split.join(Client._headerSeparator).trim();

if (key) headers.append(key, value);
if (key) {headers.append(key, value);}
});

return new this._externals.Response(text, {
Expand All @@ -245,16 +245,16 @@ export default class Client extends EventEmitter {
}

public async error(response: Response, skipOKCheck = false): Promise<string> {
if (response.ok && !skipOKCheck) return null;
if (response.ok && !skipOKCheck) {return null;}

let msg = (response.status ? `${response.status} ` : '') + (response.statusText ? response.statusText : '');

try {
const {message, error_description, description} = await response.clone().json();

if (message) msg = message;
if (error_description) msg = error_description;
if (description) msg = description;
if (message) {msg = message;}
if (error_description) {msg = error_description;}
if (description) {msg = description;}
} catch (e) {} //eslint-disable-line

return msg;
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/platform/Discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ export default class Discovery extends EventEmitter {
private _externalFetchPromise?: Promise<ExternalDiscoveryData>;
private _externalRefreshPromise?: Promise<void>;

private _initialized: boolean = false;
private _initialized = false;

private _refreshHandicapMs: number;
private _refreshDelayMs: number;

private _initialRetryCount: number = 0;
private _initialRetryCount = 0;
private _initialRetryMaxCount: number;
private _initialRetryInterval: number;

private _externalRetryCount: number = 0;
private _externalRetryCount = 0;
private _externalRetryMaxCount: number;
private _externalRetryInterval: number;
private _externalRetryCycleTimeout?: ReturnType<typeof setTimeout> = null;
Expand Down Expand Up @@ -344,7 +344,7 @@ export default class Discovery extends EventEmitter {
}
await this._cache.setItem(this._externalCacheId, {
...newData,
expireTime: expireTime,
expireTime,
});
}

Expand Down
20 changes: 10 additions & 10 deletions sdk/src/platform/Platform-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ describe('RingCentral.platform.Platform', () => {
apiCall('GET', '/.well-known/entry-points/initial?clientId=whatever', {description: 'Fail'}, 500);
apiCall('GET', '/.well-known/entry-points/initial?clientId=whatever', {description: 'Fail'}, 500);
apiCall('GET', '/.well-known/entry-points/initial?clientId=whatever', {description: 'Fail'}, 500);
const sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
const platform = sdk.platform();
const requestErrorSpy = spy(() => {});
sdk.client().on(sdk.client().events.requestError, requestErrorSpy);
Expand All @@ -1147,7 +1147,7 @@ describe('RingCentral.platform.Platform', () => {
it('should fetch initial discovery on loginUrlWithDiscovery', async () => {
const initialDiscoveryData = getInitialDiscoveryMockData();
apiCall('GET', '/.well-known/entry-points/initial?clientId=whatever', initialDiscoveryData);
const sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
const platform = sdk.platform();
expect(
(await platform.loginUrlWithDiscovery()).indexOf(initialDiscoveryData.authApi.authorizationUri),
Expand All @@ -1157,7 +1157,7 @@ describe('RingCentral.platform.Platform', () => {
it('should not throw error when fetch initial discovery error with cache data on loginUrlWithDiscovery', async function() {
const initialDiscoveryData = getInitialDiscoveryMockData();
apiCall('GET', '/.well-known/entry-points/initial?clientId=whatever', initialDiscoveryData);
const sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
const platform = sdk.platform();
if (platform.discoveryInitPromise) {
await platform.discoveryInitPromise;
Expand All @@ -1173,7 +1173,7 @@ describe('RingCentral.platform.Platform', () => {
it('should throw error when fetch initial discovery error without cache data on loginUrlWithDiscovery', async function() {
const initialDiscoveryData = getInitialDiscoveryMockData();
apiCall('GET', '/.well-known/entry-points/initial?clientId=whatever', initialDiscoveryData);
const sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
const platform = sdk.platform();
if (platform.discoveryInitPromise) {
await platform.discoveryInitPromise;
Expand All @@ -1199,7 +1199,7 @@ describe('RingCentral.platform.Platform', () => {
apiCall('GET', '/.well-known/entry-points/external', externalDiscoveryData);
authentication();

const sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
const platform = sdk.platform();
await platform.login({
code: 'whatever',
Expand All @@ -1219,7 +1219,7 @@ describe('RingCentral.platform.Platform', () => {
apiCall('GET', '/.well-known/entry-points/external', externalDiscoveryData);
authentication();

const sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
const platform = sdk.platform();
await platform.login({
code: 'whatever',
Expand All @@ -1239,7 +1239,7 @@ describe('RingCentral.platform.Platform', () => {
apiCall('GET', '/.well-known/entry-points/external', externalDiscoveryData);
authentication();

const sdk = createSdk({
sdk = createSdk({
enableDiscovery: true,
discoveryServer: 'http://whatever',
discoveryAutoInit: false,
Expand All @@ -1262,7 +1262,7 @@ describe('RingCentral.platform.Platform', () => {
apiCall('GET', '/.well-known/entry-points/external', externalDiscoveryData);
authentication();

const sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
const platform = sdk.platform();
await platform.login({code: 'whatever'});
const externalData = await platform.discovery().externalData();
Expand All @@ -1279,7 +1279,7 @@ describe('RingCentral.platform.Platform', () => {
apiCall('GET', '/.well-known/entry-points/external', externalDiscoveryData);
authentication();

const sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
const platform = sdk.platform();
await platform.login({
code: 'whatever',
Expand All @@ -1301,7 +1301,7 @@ describe('RingCentral.platform.Platform', () => {
apiCall('GET', '/.well-known/entry-points/external', null, 500);
authentication();

const sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
sdk = createSdk({enableDiscovery: true, discoveryServer: 'http://whatever', server: ''});
const platform = sdk.platform();
const clientFetchErrorSpy = spy(() => {});
sdk.client().on(sdk.client().events.requestError, clientFetchErrorSpy);
Expand Down
Loading

0 comments on commit d4ef72d

Please sign in to comment.