Skip to content

Commit

Permalink
Merge pull request #911 from ambrosus/AMB-4978
Browse files Browse the repository at this point in the history
chore: implement automation of sorting import
  • Loading branch information
ArturHoncharuk authored Dec 19, 2024
2 parents c9a3793 + c71f6b0 commit fe90979
Show file tree
Hide file tree
Showing 802 changed files with 3,291 additions and 2,408 deletions.
51 changes: 49 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:prettier/recommended'
'plugin:prettier/recommended',
'plugin:import/recommended',
'plugin:import/typescript'
],
parserOptions: {
ecmaVersion: 2018,
Expand All @@ -17,14 +19,48 @@ module.exports = {
jsx: true
}
},
plugins: ['react-hooks', 'eslint-plugin-prettier'],
plugins: ['react-hooks', 'eslint-plugin-prettier', 'import'],
rules: {
'react/prop-types': 'off',
'react/display-name': 'off',
'react/react-in-jsx-scope': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-unresolved': 'error',
'import/order': [
'error',
{
groups: [
'external', // External libraries like 'react', 'react-native'
'builtin', // Built-in Node.js modules like 'fs'
'internal', // Internal imports (e.g., aliases like '@components')
['sibling', 'parent'], // Relative imports
'index', // Index imports like './'
'object', // Imports of objects
'type' // Type imports (TypeScript)
],
pathGroups: [
{
pattern: 'react',
group: 'external',
position: 'before'
},
{
pattern: 'react-native',
group: 'external',
position: 'before'
}
],
pathGroupsExcludedImportTypes: ['react', 'react-native'],
alphabetize: {
order: 'asc',
caseInsensitive: true
}
}
],
'prettier/prettier': [
'error',
{
Expand All @@ -39,5 +75,16 @@ module.exports = {
'prefer-arrow-callback': 'error',
'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 1 }]
},
settings: {
'import/core-modules': ['react', 'react-native'],
'import/resolver': {
typescript: {
alwaysTryTypes: true // TypeScript paths are respected
},
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
}
}
}
};
2 changes: 1 addition & 1 deletion Providers.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { combineComponents } from '@utils/combineComponents';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { LocalizationProvider } from '@contexts';
Expand All @@ -10,6 +9,7 @@ import { BridgeContextProvider } from '@features/bridge/context';
import { SwapContextProvider } from '@features/swap/context';
import { WalletConnectContextProvider } from '@features/wallet-connect/context';
import Config from '@constants/config';
import { combineComponents } from '@utils';

const queryClient = new QueryClient();

Expand Down
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
module.exports = {
preset: 'jest-expo',
transform: {
'\\.tsx?$': '<rootDir>/node_modules/babel-jest',
'\\.jsx?$': '<rootDir>/node_modules/babel-jest'
'\\.ts?$': '<rootDir>/node_modules/babel-jest',
'\\.js?$': '<rootDir>/node_modules/babel-jest'
},
moduleNameMapper: {
'^@features/(.*)$': '<rootDir>/src/features/$1',
'^@constants/(.*)$': '<rootDir>/src/constants/$1'
},
testMatch: ['**/?(*.)+(spec|test).ts'],
setupFiles: ['<rootDir>/jest/setup.js'],
transformIgnorePatterns: [
'node_modules/(?!(@neverdull-agency/expo-unlimited-secure-store|node_modules))(?!victory-native)/|node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)'
Expand Down
100 changes: 66 additions & 34 deletions jest/setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'react-native-gesture-handler/jestSetup';
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';

const ETH_ADDRESS = '0x0000000000000000000000000000000000000000';

const mockIsPackageInstalled = jest.fn((value) => ({
value,
isInstalled: true
Expand All @@ -20,6 +22,7 @@ jest.mock('@react-navigation/native', () => {
});

jest.mock('react-native-reanimated', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Reanimated = require('react-native-reanimated/mock');
const ReanimatedLayoutAnimation = {
stiffness: jest.fn(() => ReanimatedLayoutAnimation),
Expand All @@ -38,22 +41,14 @@ jest.mock('react-native-reanimated', () => {
Reanimated.Layout = ReanimatedLayoutAnimation;
Reanimated.FadeInRight = ReanimatedLayoutAnimation;

// eslint-disable-next-line @typescript-eslint/no-empty-function
Reanimated.default.call = () => {};
Reanimated.__reanimatedWorkletInit = jest.fn();
return Reanimated;
});

jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);

// () => {
// const inset = { top: 0, right: 0, bottom: 0, left: 0 };
// return {
// SafeAreaProvider: jest.fn().mockImplementation(({ children }) => children),
// SafeAreaView: jest.fn().mockImplementation(({ children }) => children),
// useSafeAreaInsets: jest.fn().mockImplementation(() => inset)
// };
// });

jest.mock('@utils/createContextSelector', () => ({
createContextSelector: () => [{}, jest.fn()]
}));
Expand Down Expand Up @@ -123,36 +118,73 @@ jest.mock('@shopify/react-native-skia', () => ({
}));

jest.mock('ethers', () => {
class MockContract {
constructor(address, abi, signerOrProvider) {
this.address = address;
this.abi = abi;
this.signerOrProvider = signerOrProvider;
}
}
const MockContract = jest.fn().mockImplementation(() => {
return {
address: ETH_ADDRESS,
abi: [],
getSigner: jest.fn().mockReturnValue({}),
call: jest.fn().mockResolvedValue(true)
};
});

class MockWallet {
constructor(privateKey, provider) {
this.privateKey = privateKey;
this.provider = provider;
}
}
const MockWallet = jest.fn().mockImplementation((privateKey, provider) => {
return {
privateKey,
provider,
connect: jest.fn().mockReturnValue({
getAddress: jest.fn().mockResolvedValue(ETH_ADDRESS)
})
};
});

class MockJsonRpcProvider {
constructor(url) {
this.url = url;
}
const MockJsonRpcProvider = jest.fn().mockImplementation((url) => {
return {
url,
getBlockNumber: jest.fn().mockResolvedValue(12345),
getNetwork: jest.fn().mockResolvedValue({ chainId: 1 }), // Mock network
getGasPrice: jest.fn().mockResolvedValue('10000000000'),
sendTransaction: jest.fn().mockResolvedValue('0xTransactionHash')
};
});

async getBlockNumber() {
return 12345;
}
}
const MockStaticJsonRpcProvider = jest.fn().mockImplementation((url) => {
return {
url,
getBlockNumber: jest.fn().mockResolvedValue(12345),
getGasPrice: jest.fn().mockResolvedValue('10000000000')
};
});

const MockWeb3Provider = jest.fn().mockImplementation((provider) => {
return {
provider,
getSigner: jest.fn().mockReturnValue({
getAddress: jest.fn().mockResolvedValue(ETH_ADDRESS)
}),
getNetwork: jest.fn().mockResolvedValue({ chainId: 1 }),
getBlockNumber: jest.fn().mockResolvedValue(12345)
};
});

return {
Contract: MockContract,
Wallet: MockWallet,
providers: {
JsonRpcProvider: MockJsonRpcProvider
__esModule: true,
ethers: {
providers: {
Provider: jest.fn(),
JsonRpcProvider: MockJsonRpcProvider,
StaticJsonRpcProvider: MockStaticJsonRpcProvider,
Web3Provider: MockWeb3Provider
},
lib: {
utils: {
isAddress: jest.fn()
}
},
constants: {
AddressZero: ETH_ADDRESS
},
Contract: MockContract,
Wallet: MockWallet
}
};
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"create-hash": "^1.2.0",
"crypto-js": "^4.2.0",
"elliptic": "^6.5.4",
"eslint-import-resolver-typescript": "^3.7.0",
"ethereumjs-util": "^7.1.5",
"ethers": "^5.7.2",
"ethjs-provider-http": "^0.1.6",
Expand Down Expand Up @@ -163,7 +164,7 @@
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-standard-with-typescript": "^34.0.1",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
Expand Down
10 changes: 5 additions & 5 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import axios from 'axios';
import { AMBTokenDTO, StakingPoolDTO } from '@models/dtos';
import { bridgeService } from '@api/bridge-service';
import { PriceSnapshot } from '@appTypes';
import Config from '@constants/config';
import { AMBToken } from '@models';
import { watcherService } from './watcher-service';
import { explorerService } from './explorer-service';
import { AMBTokenDTO, StakingPoolDTO } from '@models/dtos';
import { cryptoService } from './crypto-service';
import Config from '@constants/config';
import { bridgeService } from '@api/bridge-service';
import { explorerService } from './explorer-service';
import { watcherService } from './watcher-service';

const getAMBTokenData = async (): Promise<AMBTokenDTO> => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/api/bridge-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';
import Config from '@constants/config';
import { Config as BridgeConfig } from '@lib/bridgeSDK/models/types';
import { BridgeTransactionHistoryDTO } from '@models/dtos/Bridge';
import Config from '@constants/config';

const BRIDGE_TRANSACTIONS_HISTORY_URL = Config.BRIDGE_HISTORY_URL;

Expand Down
6 changes: 3 additions & 3 deletions src/api/explorer-service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable camelcase */
import axios from 'axios';
import { TransactionType } from '@appTypes';
import { PaginatedResponseBody } from '@appTypes/Pagination';
import Config from '@constants/config';
import {
ExplorerAccountDTO,
ExplorerInfoDTO,
Token,
TokenDTO,
TransactionDTO
} from '@models';
import { TransactionType } from '@appTypes';
import { PaginatedResponseBody } from '@appTypes/Pagination';
import Config from '@constants/config';
import { SearchSort } from '@screens/Settings/screens/Explore/Search.types';
// deprecated
// const exploreApiUrl = Config.EXPLORER_API_URL;
Expand Down
4 changes: 3 additions & 1 deletion src/api/harbor/harbor-service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { RawRecord } from '@nozbe/watermelondb';

Check warning on line 1 in src/api/harbor/harbor-service.ts

View workflow job for this annotation

GitHub Actions / Run Lint

'/home/runner/work/airdao-mobile/airdao-mobile/node_modules/@nozbe/watermelondb/index.js' imported multiple times
import { BigNumber, ethers } from 'ethers';
import { parseEther } from 'ethers/lib/utils';
import moment from 'moment/moment';
import { RawRecord } from '@nozbe/watermelondb';

Check failure on line 5 in src/api/harbor/harbor-service.ts

View workflow job for this annotation

GitHub Actions / Run Lint

'@nozbe/watermelondb' import is duplicated

Check failure on line 5 in src/api/harbor/harbor-service.ts

View workflow job for this annotation

GitHub Actions / Run Lint

`@nozbe/watermelondb` import should occur before import of `ethers`

Check warning on line 5 in src/api/harbor/harbor-service.ts

View workflow job for this annotation

GitHub Actions / Run Lint

'/home/runner/work/airdao-mobile/airdao-mobile/node_modules/@nozbe/watermelondb/index.js' imported multiple times
import Config from '@constants/config';

Check warning on line 6 in src/api/harbor/harbor-service.ts

View workflow job for this annotation

GitHub Actions / Run Lint

'/home/runner/work/airdao-mobile/airdao-mobile/src/constants/config.ts' imported multiple times
import { HARBOR_ABI } from '@api/harbor/abi/harbor';

Check failure on line 7 in src/api/harbor/harbor-service.ts

View workflow job for this annotation

GitHub Actions / Run Lint

`@api/harbor/abi/harbor` import should occur before import of `@constants/config`
import { Cache, CacheKey } from '@lib/cache';
import { UNSTAKE_LOG_ABI } from '@api/harbor/abi/harbor-unstake-log-abi';

Check failure on line 8 in src/api/harbor/harbor-service.ts

View workflow job for this annotation

GitHub Actions / Run Lint

`@api/harbor/abi/harbor-unstake-log-abi` import should occur before import of `@constants/config`
import Config from '@constants/config';

Check failure on line 9 in src/api/harbor/harbor-service.ts

View workflow job for this annotation

GitHub Actions / Run Lint

'@constants/config' import is duplicated

Check warning on line 9 in src/api/harbor/harbor-service.ts

View workflow job for this annotation

GitHub Actions / Run Lint

'/home/runner/work/airdao-mobile/airdao-mobile/src/constants/config.ts' imported multiple times
import { ILogs } from '@entities/harbor/model/types';
import { Cache, CacheKey } from '@lib/cache';
import {
CustomAppEvents,
sendFirebaseEvent
Expand Down
2 changes: 1 addition & 1 deletion src/api/staking/staking-service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BigNumber, ethers, utils } from 'ethers';
import Config from '@constants/config';
import { poolAbi, poolsAbi } from '@api/staking/abi';
import {
PoolDetailsArgs,
ReturnedPoolDetails,
StakeArgs
} from '@api/staking/types';
import Config from '@constants/config';
import { Cache, CacheKey } from '@lib/cache';
import {
CustomAppEvents,
Expand Down
6 changes: 3 additions & 3 deletions src/api/watcher-service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable camelcase */
import axios from 'axios';
import { NotificationSettings } from '@appTypes';
import Config from '@constants/config';
import { DefaultNotificationSettings } from '@constants/variables';
import { NotificationService, UID } from '@lib';
import { Cache, CacheKey } from '@lib/cache';
import { WatcherInfoDTO } from '@models';
import Config from '@constants/config';
import { NotificationSettings } from '@appTypes';
import { DefaultNotificationSettings } from '@constants/variables';

const updatePushTokenAPI = `${Config.WALLET_API_URL}/api/v1`;
const watcherAPI = `${Config.WALLET_API_URL}/api/v1/watcher`;
Expand Down
4 changes: 2 additions & 2 deletions src/appTypes/navigation/common.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CompositeNavigationProp } from '@react-navigation/native';
import { BottomTabNavigationProp } from '@react-navigation/bottom-tabs';
import { CompositeNavigationProp } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { TabsParamsList } from './tabs';
import { ListsOfAddressType } from '@appTypes/ListsOfAddressGroup';
import { AccountList } from '@models';
import { PasscodeParams } from './passcode-params';
import { TabsParamsList } from './tabs';

export type CommonStackParamsList = {
Address: { address: ListsOfAddressType['addressId'] };
Expand Down
4 changes: 2 additions & 2 deletions src/appTypes/navigation/harbor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CompositeNavigationProp } from '@react-navigation/native';
import { BottomTabNavigationProp } from '@react-navigation/bottom-tabs';
import { TabsParamsList } from '@appTypes';
import { CompositeNavigationProp } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { TabsParamsList } from '@appTypes';

export type HarborTabParamsList = {
StakeHarborScreen: undefined;
Expand Down
1 change: 0 additions & 1 deletion src/appTypes/navigation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './common';
export * from './search';
export * from './lists';
export * from './root';
export * from './search';
export * from './settings';
export * from './tabs';
export * from './wallets';
4 changes: 2 additions & 2 deletions src/appTypes/navigation/lists.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CompositeNavigationProp } from '@react-navigation/native';
import { BottomTabNavigationProp } from '@react-navigation/bottom-tabs';
import { SettingsTabParamsList } from '@appTypes';
import { CompositeNavigationProp } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { SettingsTabParamsList } from '@appTypes';
import { CommonStackParamsList } from './common';

export type PortfolioParamsPortfolio = {
Expand Down
Loading

0 comments on commit fe90979

Please sign in to comment.