Skip to content

Commit f14855c

Browse files
authored
style: clean eslintrc config (#2)
1 parent 0c31f0b commit f14855c

File tree

10 files changed

+1435
-976
lines changed

10 files changed

+1435
-976
lines changed

.eslintrc

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": [
3+
"wesbos/typescript"
4+
],
5+
"rules": {
6+
"no-console": "off",
7+
"prettier/prettier": [
8+
"error",
9+
{
10+
"trailingComma": "es5",
11+
"singleQuote": true,
12+
"printWidth": 100,
13+
"tabWidth": 2
14+
}
15+
],
16+
"no-plusplus": "off",
17+
"no-shadow": "off",
18+
"@typescript-eslint/no-shadow": "off",
19+
"@typescript-eslint/no-unsafe-return": "off",
20+
"@typescript-eslint/no-unsafe-assignment": "off",
21+
"@typescript-eslint/no-unsafe-member-access": "off",
22+
"@typescript-eslint/no-unsafe-call": "off",
23+
"@typescript-eslint/no-unsafe-argument": "off"
24+
}
25+
}

.eslintrc.js

-49
This file was deleted.

package.json

+20-13
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,34 @@
1111
"packages/*"
1212
],
1313
"scripts": {
14-
"bootstrap": "lerna bootstrap"
14+
"bootstrap": "lerna bootstrap",
15+
"build": "lerna run build"
1516
},
1617
"devDependencies": {
18+
"@babel/core": "^7.16.0",
19+
"@babel/eslint-parser": "^7.16.3",
20+
"@babel/preset-react": "^7.16.0",
1721
"@rollup/plugin-babel": "^5.3.1",
1822
"@rollup/plugin-typescript": "^8.3.2",
1923
"@types/jest": "^27.5.1",
20-
"@types/node": "^17.0.32",
21-
"@typescript-eslint/eslint-plugin": "^5.23.0",
22-
"@typescript-eslint/parser": "^5.23.0",
23-
"eslint": "^8.15.0",
24-
"eslint-config-prettier": "^8.5.0",
25-
"eslint-config-standard": "^17.0.0",
26-
"eslint-plugin-import": "^2.26.0",
27-
"eslint-plugin-n": "^15.2.0",
24+
"@types/node": "^16.11.12",
25+
"@typescript-eslint/eslint-plugin": "^5.6.0",
26+
"@typescript-eslint/parser": "^5.6.0",
27+
"eslint": "^8.4.1",
28+
"eslint-config-airbnb": "^19.0.2",
29+
"eslint-config-airbnb-typescript": "^16.1.0",
30+
"eslint-config-prettier": "^8.3.0",
31+
"eslint-config-wesbos": "3.0.2",
32+
"eslint-plugin-html": "^6.2.0",
33+
"eslint-plugin-import": "^2.25.3",
34+
"eslint-plugin-jsx-a11y": "^6.5.1",
2835
"eslint-plugin-prettier": "^4.0.0",
29-
"eslint-plugin-promise": "^6.0.0",
36+
"eslint-plugin-react": "^7.27.1",
37+
"eslint-plugin-react-hooks": "^4.3.0",
3038
"lerna": "^4.0.0",
31-
"prettier": "^2.6.2",
32-
"prettier-eslint": "^14.0.2",
39+
"prettier": "^2.5.1",
3340
"rollup": "^2.73.0",
3441
"rollup-plugin-dts": "^4.2.1",
35-
"typescript": "^4.6.4"
42+
"typescript": "^4.5.2"
3643
}
3744
}

packages/hd-transport-http/src/http.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ export type HttpRequestOptions = {
77

88
// slight hack to make Flow happy, but to allow Node to set its own fetch
99
// Request, RequestOptions and Response are built-in types of Flow for fetch API
10-
let _fetch: (input: string | Request, init?: any) => Promise<Response> =
10+
let innerFetch: (input: string | Request, init?: any) => Promise<Response> =
1111
typeof window === 'undefined'
1212
? () => Promise.reject(new Error('Not Browser environment'))
1313
: window.fetch;
1414

15-
let _isNode = false;
15+
let isNode = false;
1616

17-
export function setFetch(fetch: any, isNode?: boolean) {
18-
_fetch = fetch;
19-
_isNode = !!isNode;
17+
export function setFetch(fetch: any, node?: boolean) {
18+
innerFetch = fetch;
19+
isNode = !!node;
2020
}
2121

2222
function contentType(body: any) {
@@ -61,14 +61,14 @@ export async function request(options: HttpRequestOptions) {
6161
}
6262

6363
// Node applications must spoof origin for bridge CORS
64-
if (_isNode) {
64+
if (isNode) {
6565
fetchOptions.headers = {
6666
...fetchOptions.headers,
6767
Origin: 'https://node.onekey.so',
6868
};
6969
}
7070

71-
const res = await _fetch(options.url, fetchOptions);
71+
const res = await innerFetch(options.url, fetchOptions);
7272
const resText = await res.text();
7373
if (res.ok) {
7474
return parseResult(resText);

packages/hd-transport-http/src/index.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import transport from '@onekeyfe/hd-transport';
2+
import type { AcquireInput, OneKeyDeviceInfoWithSession } from '@onekeyfe/hd-transport';
23
import { request as http } from './http';
34
import { DEFAULT_URL, DEFAULT_VERSION_URL } from './constants';
4-
import type { AcquireInput, OneKeyDeviceInfoWithSession } from '@onekeyfe/hd-transport';
55

66
const { check, buildOne, receiveOne, parseConfigure } = transport;
77

@@ -12,13 +12,21 @@ type IncompleteRequestOptions = {
1212

1313
export default class HttpTransport {
1414
_messages: ReturnType<typeof transport.parseConfigure> | undefined;
15+
1516
bridgeVersion?: string;
17+
1618
configured = false;
19+
1720
debug = false;
21+
1822
isOutdated?: boolean;
23+
1924
newestVersionUrl: string;
25+
2026
stopped = false;
27+
2128
url: string;
29+
2230
version = '';
2331

2432
constructor(url?: string, newestVersionUrl?: string) {
@@ -58,7 +66,7 @@ export default class HttpTransport {
5866
await http({
5967
url: `${this.newestVersionUrl}?${Date.now()}`,
6068
method: 'GET',
61-
}),
69+
})
6270
);
6371
// TODO: 这里需要进行版本比较,可以使用 semver 比较,不引入其他工具类
6472
// this.isOutdated = versionUtils.isNewer(newVersion, this.version);
@@ -154,6 +162,7 @@ export default class HttpTransport {
154162
return check.call(jsonData);
155163
}
156164

165+
// eslint-disable-next-line class-methods-use-this
157166
requestDevice() {
158167
// eslint-disable-next-line prefer-promise-reject-errors
159168
return Promise.reject();

packages/hd-transport/.eslintrc

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"rules": {
3+
"no-console": "error",
4+
"@typescript-eslint/no-non-null-assertion": "off",
5+
"@typescript-eslint/no-explicit-any": "off",
6+
"@typescript-eslint/ban-ts-ignore": "off",
7+
// We need empty functions for mocking modules for react-native
8+
"@typescript-eslint/no-empty-function": "off",
9+
"no-useless-constructor": "off",
10+
"@typescript-eslint/no-useless-constructor": "error",
11+
// valid case of class method overloads in typescript
12+
"no-dupe-class-members": "off",
13+
"@typescript-eslint/ban-ts-comment": "off",
14+
// Missing return type on function
15+
"@typescript-eslint/explicit-module-boundary-types": "off",
16+
// note you must disable the base rule as it can report incorrect errors
17+
"no-use-before-define": "off",
18+
"@typescript-eslint/no-use-before-define": ["error"],
19+
"require-await": ["error"]
20+
}
21+
}

packages/hd-transport/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { buildOne, receiveOne, parseConfigure } from './serialization';
2-
import * as check from './utils/highlevel-checks';
31
import * as protobuf from 'protobufjs/light';
42
import * as Long from 'long';
3+
import { buildOne, receiveOne, parseConfigure } from './serialization';
4+
import * as check from './utils/highlevel-checks';
55

66
protobuf.util.Long = Long;
77
protobuf.configure();

packages/hd-transport/src/serialization/protocol/encode.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function encode(data: ByteBuffer, options: Options<true>): Buffer[];
1212
function encode(data: ByteBuffer, options: Options<false>): Buffer;
1313
function encode(data: any, options: any): any {
1414
const { addTrezorHeaders, chunked, messageType } = options;
15+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
1516
const fullSize = (addTrezorHeaders ? HEADER_SIZE : HEADER_SIZE - 2) + data.limit;
1617

1718
const encodedByteBuffer = new ByteBuffer(fullSize);

packages/hd-transport/src/types/transport.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type Transport = {
2525
session: string,
2626
name: string,
2727
data: Record<string, any>,
28-
debugLink: boolean,
28+
debugLink: boolean
2929
): Promise<MessageFromOneKey>;
3030
post(session: string, name: string, data: Record<string, any>, debugLink: boolean): Promise<void>;
3131
read(session: string, debugLink: boolean): Promise<MessageFromOneKey>;

0 commit comments

Comments
 (0)