Skip to content

Commit

Permalink
chore: add linter (#3674)
Browse files Browse the repository at this point in the history
  • Loading branch information
huhuanming authored Oct 19, 2023
1 parent 81e1a58 commit 841c872
Show file tree
Hide file tree
Showing 32 changed files with 1,632 additions and 163 deletions.
1 change: 1 addition & 0 deletions undefined

Large diffs are not rendered by default.

155 changes: 155 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
const isDev = process.env.NODE_ENV !== 'production';
const jsRules = {
// eslint-disable-next-line global-require
'prettier/prettier': ['error', require('./.prettierrc.js')],
'no-unused-vars': 'off',
'no-use-before-define': 'off',
'no-shadow': 'off',
'import/no-extraneous-dependencies': 'off',
'no-restricted-exports': 'off',
'func-names': 'off',
'class-methods-use-this': 'off',
'import/extensions': 'off',
'react/function-component-definition': 'off',
'react/jsx-props-no-spreading': 'off',
'react/no-unused-prop-types': 'off',
'react/no-unstable-nested-components': 'warn',
'react/jsx-no-useless-fragment': ['error', { allowExpressions: true }],
'react-hooks/exhaustive-deps': [
'warn',
{
'additionalHooks': '(usePromiseResult|useAsyncCall)',
},
],
'global-require': 'off',
'import/no-unresolved': 'off', // tsc can check this
'no-promise-executor-return': 'off',
'default-param-last': 'off',
'import/no-cycle': 'error',
// 'no-console': [isDev ? 'warn' : 'off'],
};
const tsRules = {
'@typescript-eslint/default-param-last': 'off',
'@typescript-eslint/consistent-type-imports': [
'error',
{ disallowTypeAnnotations: false },
],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unused-vars': [isDev ? 'warn' : 'error'],
'@typescript-eslint/no-use-before-define': ['error'],
'@typescript-eslint/no-shadow': ['error'],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'sort-imports': [
'error',
{
'ignoreMemberSort': false,
'ignoreDeclarationSort': true,
},
],
'import/order': [
'warn',
{
'groups': [
'builtin',
'internal',
'index',
'external',
'parent',
'sibling',
'object',
'type',
],
'pathGroups': [
{
'pattern': 'react',
'group': 'builtin',
'position': 'before',
},
{
'pattern': '@onekeyhq/**',
'group': 'external',
'position': 'after',
},
],
'alphabetize': {
'order': 'asc',
'caseInsensitive': true,
},
'newlines-between': 'always',
'pathGroupsExcludedImportTypes': ['builtin'],
'warnOnUnassignedImports': true,
},
],
'no-restricted-syntax': [
'error',
{
selector:
"ImportDeclaration[source.value='react'][specifiers.0.type='ImportDefaultSpecifier']",
message: 'Default React import not allowed',
},
],
};
module.exports = {
ignorePatterns: [
'packages/components/src/Icon/*',
'packages/desktop/public/static/js-sdk/*',
// 临时忽略以下目录的检查,迭代后会逐步开启
'packages/app',
'packages/blockchain-libs',
'packages/kit/src/store',
'packages/desktop',
'packages/engine',
'packages/ext',
'packages/kit-bg',
'packages/shared',
'packages/web',
'packages/web-embed',
],
env: {
browser: true,
es6: true,
webextensions: true,
serviceworker: true,
worker: true,
},
overrides: [
{
files: ['*.js', '*.jsx', '*.text-js'],
extends: ['wesbos'],
rules: {
...jsRules,
},
},
{
files: ['*.ts', '*.tsx'],
extends: ['wesbos/typescript'],
rules: {
...jsRules,
...tsRules,
},
},
// test files rules must be at LAST
{
files: ['test/**/*.js', 'test/**/*.ts', '**/*.test.ts'],
extends: ['plugin:jest/recommended'],
env: {
jest: true,
},
rules: {
'jest/expect-expect': 'off',
'jest/no-disabled-tests': 'off',
'jest/no-conditional-expect': 'off',
'jest/valid-title': 'off',
'jest/no-interpolation-in-snapshots': 'off',
'jest/no-export': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
},
},
],
};
3 changes: 3 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'**/*': 'prettier --write --ignore-unknown',
};
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
singleQuote: true,
trailingComma: 'all',
quoteProps: 'preserve', // let eslint fix quoteProps
// "printWidth": 120,
// "tabWidth": 8,
};
80 changes: 80 additions & 0 deletions @types/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* eslint-disable no-var,vars-on-top */
import type { LocaleIds } from '@onekeyhq/components/src/locale';
import type { IBackgroundApi } from '@onekeyhq/kit-bg/src/IBackgroundApi';

import type { JsBridgeBase } from '@onekeyfe/cross-inpage-provider-core';
import type { ProviderPrivate } from '@onekeyfe/onekey-private-provider';
import type { EnhancedStore } from '@reduxjs/toolkit';
import type WebView from 'react-native-webview';

declare const self: ServiceWorkerGlobalScope;

type IWindowOneKeyHub = {
$private: ProviderPrivate;
};
declare global {
// eslint-disable-next-line
// var onekey: WindowOneKey;

var $appIsReduxReady: boolean;
var $onekey: IWindowOneKeyHub;
var $backgroundApiProxy: IBackgroundApi;
var $backgroundApi: IBackgroundApi;

var $$navigationShortcuts: any;
var $$simpleDb: any;
var $$appEventBus: any;
var $$appUIEventBus: any;
var $$appStore: EnhancedStore;
var $$appDispatch: any;
var $$appSelector: any;
var $$appStorage: any;
var $$platformEnv: any;
var $$debugLogger: any;
var $$localforage: any;
var $$navigationActions: any;
var $$wcTransports: any;
var $$onekeyDisabledSetTimeout: boolean | undefined;
var $$onekeyDisabledSetInterval: boolean | undefined;
var $$onekeyPerfTrace:
| {
log: (options: { name: string; payload?: any }) => void;
timeline: Array<{
time: string;
elapsed: number;
lag: number;
name: string;
payload?: any;
}>;
}
| undefined;

var chrome: typeof chrome; // chrome api
var browser: typeof chrome; // firefox api

interface Window {
// All website
ethereum: any;
web3: any;
$onekey: IWindowOneKeyHub;

// Native App webview content
ReactNativeWebView: WebView;

// Desktop internal (main,renderer)
// ONEKEY_DESKTOP_GLOBALS: Record<any, any>;

// Ext internal (ui,background,contentScript)
extJsBridgeUiToBg: JsBridgeBase;
extJsBridgeOffscreenToBg: JsBridgeBase;
ONEKEY_DESKTOP_DEEP_LINKS: any[];
}
}

declare global {
namespace FormatjsIntl {
interface Message {
ids: LocaleIds;
}
}
}
1 change: 1 addition & 0 deletions @types/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@onekeyfe/cross-inpage-provider-types';
2 changes: 1 addition & 1 deletion apps/ext/src/background/serviceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
// export default {
// disableCacheInBackground,
// };
console.log('serviceWorker')
console.log('serviceWorker');
2 changes: 1 addition & 1 deletion apps/ext/src/entry/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@
// offscreenApiProxy.adaSdk.sayHello().then(console.log);
// offscreenApiProxy.xmrSdk.showMe().then(console.log);
// }
console.log('background.ts')
console.log('background.ts');
export {};
36 changes: 18 additions & 18 deletions apps/ext/src/entry/content-script-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '@onekeyhq/shared/src/polyfills/polyfillsExtContentScript';
import { consts } from '@onekeyfe/cross-inpage-provider-core';
import { bridgeSetup } from '@onekeyfe/extension-bridge-hosted';

import type { IOneKeyWalletInfo } from '@onekeyhq/kit-bg/src/providers/ProviderApiPrivate';
// import type { IOneKeyWalletInfo } from '@onekeyhq/kit-bg/src/providers/ProviderApiPrivate';
import platformEnv from '@onekeyhq/shared/src/platformEnv';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -61,23 +61,23 @@ if (shouldInject()) {

bridgeSetup.contentScript.setupMessagePort();

if (process.env.NODE_ENV !== 'production') {
try {
if (consts.WALLET_INFO_LOACAL_KEY) {
const walletInfo: IOneKeyWalletInfo = JSON.parse(
localStorage.getItem(consts.WALLET_INFO_LOACAL_KEY) || '{}',
);
console.log(walletInfo);
if (walletInfo && walletInfo.enableExtContentScriptReloadButton) {
setTimeout(() => {
devToolsButton.inject();
}, 2000);
}
}
} catch (error) {
console.error(error);
}
}
// if (process.env.NODE_ENV !== 'production') {
// try {
// if (consts.WALLET_INFO_LOACAL_KEY) {
// const walletInfo: IOneKeyWalletInfo = JSON.parse(
// localStorage.getItem(consts.WALLET_INFO_LOACAL_KEY) || '{}',
// );
// console.log(walletInfo);
// if (walletInfo && walletInfo.enableExtContentScriptReloadButton) {
// setTimeout(() => {
// devToolsButton.inject();
// }, 2000);
// }
// }
// } catch (error) {
// console.error(error);
// }
// }

if (process.env.NODE_ENV !== 'production') {
console.log('==== injected script tag done >>>>>>>', performance.now());
Expand Down
2 changes: 1 addition & 1 deletion apps/ext/src/entry/offscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
// }
// }
// timer = setInterval(checkPortEstablished, getTimeDurationMs({ seconds: 5 }));
console.log('offscreen')
console.log('offscreen');
4 changes: 2 additions & 2 deletions apps/mobile/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/no-unused-vars, import/first, import/order */
import '@onekeyhq/shared/src/polyfills';

console.log('polyfills----')
console.log('polyfills----');
import { KitProvider } from '@onekeyhq/kit';

console.log('KitProvider', KitProvider)
console.log('KitProvider', KitProvider);

export default KitProvider;
24 changes: 23 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"app:ios": "yarn workspace @onekeyhq/mobile ios",
"app:ios:device": "yarn workspace @onekeyhq/mobile ios:device",
"app:android": "yarn workspace @onekeyhq/mobile android",
"app:android:device": "yarn workspace @onekeyhq/mobile android:device"
"app:android:device": "yarn workspace @onekeyhq/mobile android:device",
"_lint": "sh -c 'npx eslint . --ext .ts,.tsx --fix --cache --cache-location \"$(yarn config get cacheFolder)\"'",
"lint:project": "yarn _lint",
"lint": "ultra lint:project"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.38",
Expand All @@ -41,6 +44,7 @@
"@vespaiach/axios-fetch-adapter": "^0.3.1",
"crypto-browserify": "^3.12.0",
"ejs-loader": "^0.5.0",
"eslint": "^8.25.0",
"expo": "~49.0.13",
"expo-status-bar": "~1.6.0",
"memoizee": "^0.4.15",
Expand All @@ -65,8 +69,13 @@
"@open-wc/webpack-import-meta-loader": "^0.4.7",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
"@tamagui/babel-plugin": "1.71.0",
"@types/chrome": "^0.0.248",
"@types/lodash": "^4.14.200",
"@types/memoizee": "^0.4.10",
"@types/react": "^18.2.29",
"@types/react-dom": "^18.2.13",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.46.1",
"axios": "^1.5.1",
"babel-loader": "^9.1.3",
"babel-plugin-import": "^1.13.5",
Expand All @@ -80,14 +89,27 @@
"css-loader": "^6.8.1",
"date-fns": "^2.30.0",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-wesbos": "^3.1.4",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.7",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"html-webpack-plugin": "^5.5.3",
"node-notifier": "^10.0.1",
"patch-package": "^7.0.0",
"prettier": "^2.8.1",
"progress-bar-webpack-plugin": "^2.1.0",
"react-dev-utils": "^12.0.1",
"react-refresh": "^0.14.0",
"style-loader": "^3.3.3",
"tamagui-loader": "1.71.0",
"ultra-runner": "^3.10.5",
"webpack": "5.88.2",
"webpack-bundle-analyzer": "^4.9.1",
"webpack-cli": "5.1.4",
Expand Down
Loading

0 comments on commit 841c872

Please sign in to comment.