Skip to content

Commit 1368304

Browse files
authored
Add lint for index imports (#1787)
1 parent 408120f commit 1368304

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

.eslintrc.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ module.exports = {
3737
// Restrict importing BN from bn.js
3838
"group": ["bn.js"],
3939
"message": "Import BN from @drift-labs/sdk instead",
40-
}
40+
},
41+
{
42+
// Prevent imports from index files within the same package
43+
group: [
44+
'**/index',
45+
'**/index.ts',
46+
],
47+
message:
48+
'Do not import from index file within the same package. Import directly from source files instead. This prevents barrel imports.',
49+
},
4150
],
4251
},
4352
],

sdk/src/events/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
FuelSeasonRecord,
2222
InsuranceFundSwapRecord,
2323
TransferProtocolIfSharesToRevenuePoolRecord,
24-
} from '../index';
24+
} from '../types';
2525
import { EventEmitter } from 'events';
2626

2727
export type EventSubscriptionOptions = {

sdk/src/math/insurance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PERCENTAGE_PRECISION, ZERO } from '../constants/numericConstants';
2-
import { BN, SpotMarketAccount, SpotBalanceType } from '../index';
32
import { getTokenAmount } from '../math/spotBalance';
3+
import { BN } from '@coral-xyz/anchor';
4+
import { SpotBalanceType, SpotMarketAccount } from '../types';
45

56
export function nextRevenuePoolSettleApr(
67
spotMarket: SpotMarketAccount,

sdk/src/math/oracles.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { AMM, OracleGuardRails, isVariant } from '../types';
1+
import {
2+
AMM,
3+
HistoricalOracleData,
4+
OracleGuardRails,
5+
OracleSource,
6+
PerpMarketAccount,
7+
isVariant,
8+
} from '../types';
29
import { OraclePriceData } from '../oracles/types';
310
import {
411
BID_ASK_SPREAD_PRECISION,
@@ -9,13 +16,8 @@ import {
916
FIVE_MINUTE,
1017
PERCENTAGE_PRECISION,
1118
} from '../constants/numericConstants';
12-
import {
13-
BN,
14-
HistoricalOracleData,
15-
OracleSource,
16-
PerpMarketAccount,
17-
} from '../index';
1819
import { assert } from '../assert/assert';
20+
import { BN } from '@coral-xyz/anchor';
1921

2022
export function oraclePriceBands(
2123
market: PerpMarketAccount,

sdk/src/orderSubscriber/OrderSubscriber.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import { PollingSubscription } from './PollingSubscription';
1313
import { WebsocketSubscription } from './WebsocketSubscription';
1414
import StrictEventEmitter from 'strict-event-emitter-types';
1515
import { EventEmitter } from 'events';
16-
import { calculateOrderBaseAssetAmount, ZERO } from '../index';
1716
import { BN } from '@coral-xyz/anchor';
1817
import { ProtectMakerParamsMap } from '../dlob/types';
1918
import { decodeUser } from '../decode/user';
2019
import { grpcSubscription } from './grpcSubscription';
2120
import { isUserProtectedMaker } from '../math/userStatus';
21+
import { calculateOrderBaseAssetAmount } from '../math/orders';
22+
import { ZERO } from '../constants/numericConstants';
2223

2324
export class OrderSubscriber {
2425
driftClient: DriftClient;

sdk/tests/bn/test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { BN, numberToSafeBN } from '../../src/index';
21
import { expect } from 'chai';
32
import { BigNum } from '../../src/factory/bigNum';
43
import {
@@ -7,6 +6,8 @@ import {
76
BASE_PRECISION_EXP,
87
TEN_THOUSAND,
98
} from '../../src/constants/numericConstants';
9+
import { BN } from '@coral-xyz/anchor';
10+
import { numberToSafeBN } from '../../src/math/utils';
1011

1112
// if you used the '@types/mocha' method to install mocha type definitions, uncomment the following line
1213
// import 'mocha';

0 commit comments

Comments
 (0)