Skip to content

Commit a69c7d3

Browse files
authored
Merge pull request #154 from onflow/vishal/add_cadence_linter
Add Cadence lint target to Makefile
2 parents e08ba49 + 7641e9d commit a69c7d3

14 files changed

+51
-42
lines changed

.github/workflows/cadence_tests.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ jobs:
3333
path: ./imports
3434
key: flow-deps-${{ hashFiles('flow.json') }}
3535
- name: Install Flow CLI
36-
env:
37-
FLOW_CLI_VERSION: v2.7.2
38-
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)"
36+
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v2.15.3
3937
- name: Update PATH and show Flow version
4038
run: |
4139
echo "/root/.local/bin" >> $GITHUB_PATH
@@ -45,7 +43,7 @@ jobs:
4543
- name: Install dependencies
4644
run: flow deps install --skip-alias --skip-deployments
4745
- name: Run tests
48-
run: flow test --cover --covercode="contracts" --coverprofile="coverage.lcov" ./cadence/tests/*_test.cdc
46+
run: make ci
4947
- name: Upload coverage report
5048
uses: codecov/codecov-action@v5
5149
with:

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PHONY: test
2+
test:
3+
flow test --cover --covercode="contracts" --coverprofile="coverage.lcov" ./cadence/tests/*_test.cdc
4+
5+
.PHONY: lint
6+
lint:
7+
find cadence/contracts -name "*.cdc" | xargs flow cadence lint \
8+
| tee /dev/stderr | tail -n2 | grep -q "Lint passed"
9+
10+
.PHONY: ci
11+
ci: lint test

cadence/contracts/FlowALPHealth.cdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ access(all) contract FlowALPHealth {
163163
initial: FlowALPModels.Balance,
164164
target: FlowALPModels.Balance
165165
): UFix128 {
166-
let Credit = FlowALPModels.BalanceDirection.Credit
166+
let Credit = FlowALPModels.BalanceDirection.Credit
167167
let Debit = FlowALPModels.BalanceDirection.Debit
168168

169169
if target.direction == Credit && initial.direction == Credit {
@@ -194,7 +194,7 @@ access(all) contract FlowALPHealth {
194194
initial: FlowALPModels.Balance,
195195
target: FlowALPModels.Balance
196196
): UFix128 {
197-
let Credit = FlowALPModels.BalanceDirection.Credit
197+
let Credit = FlowALPModels.BalanceDirection.Credit
198198
let Debit = FlowALPModels.BalanceDirection.Debit
199199

200200
if target.direction == Debit && initial.direction == Debit {

cadence/contracts/FlowALPInterestRates.cdc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ access(all) contract FlowALPInterestRates {
3434
self.yearlyRate = yearlyRate
3535
}
3636

37-
access(all) fun interestRate(creditBalance: UFix128, debitBalance: UFix128): UFix128 {
37+
access(all) fun interestRate(
38+
creditBalance _creditBalance: UFix128,
39+
debitBalance _debitBalance: UFix128
40+
): UFix128 {
3841
return self.yearlyRate
3942
}
4043
}

cadence/contracts/FlowALPModels.cdc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,8 @@ access(all) contract FlowALPModels {
579579
let newDebt = self.effectiveDebtByToken
580580

581581
// Remove old entries for this token from both maps
582-
newCollateral.remove(key: tokenType)
583-
newDebt.remove(key: tokenType)
582+
let _oldCollateral = newCollateral.remove(key: tokenType)
583+
let _oldDebt = newDebt.remove(key: tokenType)
584584

585585
// Add new entry based on direction (only if non-zero)
586586
if effectiveBalance.quantity > 0.0 {
@@ -951,7 +951,7 @@ access(all) contract FlowALPModels {
951951
/// Gets a swapper from the DEX for the given token pair. See PoolConfig.getSwapperForLiquidation.
952952
access(all) fun getSwapperForLiquidation(seizeType: Type, debtType: Type): {DeFiActions.Swapper} {
953953
return self.dex.getSwapper(inType: seizeType, outType: debtType)
954-
?? panic("No DEX swapper configured for liquidation pair: ".concat(seizeType.identifier).concat(" -> ").concat(debtType.identifier))
954+
?? panic("No DEX swapper configured for liquidation pair: \(seizeType.identifier) -> \(debtType.identifier)")
955955
}
956956

957957
// Setters
@@ -2202,7 +2202,7 @@ access(all) contract FlowALPModels {
22022202

22032203
/// Returns an authorized reference to the draw-down sink, or nil if none is configured.
22042204
access(EImplementation) fun borrowDrawDownSink(): auth(FungibleToken.Withdraw) &{DeFiActions.Sink}? {
2205-
return &self.drawDownSink as auth(FungibleToken.Withdraw) &{DeFiActions.Sink}?
2205+
return &self.drawDownSink
22062206
}
22072207

22082208
/// Sets the draw-down sink. Sink must accept MOET deposits, or be nil.
@@ -2218,7 +2218,7 @@ access(all) contract FlowALPModels {
22182218

22192219
/// Returns an authorized reference to the top-up source, or nil if none is configured.
22202220
access(EImplementation) fun borrowTopUpSource(): auth(FungibleToken.Withdraw) &{DeFiActions.Source}? {
2221-
return &self.topUpSource as auth(FungibleToken.Withdraw) &{DeFiActions.Source}?
2221+
return &self.topUpSource
22222222
}
22232223

22242224
/// Sets the top-up source. See InternalPosition.setTopUpSource.

cadence/contracts/FlowALPPositionResources.cdc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ access(all) contract FlowALPPositionResources {
104104
}
105105

106106
/// Returns the maximum amount of the given token type that could be deposited into this position
107-
access(all) fun getDepositCapacity(type: Type): UFix64 {
107+
access(all) fun getDepositCapacity(type _: Type): UFix64 {
108108
// There's no limit on deposits from the position's perspective
109109
return UFix64.max
110110
}
@@ -181,7 +181,7 @@ access(all) contract FlowALPPositionResources {
181181
type: Type,
182182
pushToDrawDownSink: Bool
183183
): {DeFiActions.Sink} {
184-
let pool = self.pool.borrow()!
184+
let _pool = self.pool.borrow()!
185185
return PositionSink(
186186
id: self.id,
187187
pool: self.pool,
@@ -212,7 +212,7 @@ access(all) contract FlowALPPositionResources {
212212
type: Type,
213213
pullFromTopUpSource: Bool
214214
): {DeFiActions.Source} {
215-
let pool = self.pool.borrow()!
215+
let _pool = self.pool.borrow()!
216216
return PositionSource(
217217
id: self.id,
218218
pool: self.pool,

cadence/contracts/FlowALPRebalancerv1.cdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ access(all) contract FlowALPRebalancerv1 {
9696
txFunder: {DeFiActions.Sink, DeFiActions.Source}
9797
) {
9898
pre {
99-
interval > UInt64(0):
99+
interval > 0:
100100
"Invalid interval: \(interval) - must be greater than 0"
101101
interval < UInt64(UFix64.max) - UInt64(getCurrentBlock().timestamp):
102102
"Invalid interval: \(interval) - must be less than the maximum interval of \(UInt64(UFix64.max) - UInt64(getCurrentBlock().timestamp))"
@@ -171,7 +171,7 @@ access(all) contract FlowALPRebalancerv1 {
171171
/// @param id: The id of the scheduled transaction
172172
/// @param data: The data that was passed when the transaction was originally scheduled
173173
///
174-
access(FlowTransactionScheduler.Execute) fun executeTransaction(id: UInt64, data: AnyStruct?) {
174+
access(FlowTransactionScheduler.Execute) fun executeTransaction(id: UInt64, data _: AnyStruct?) {
175175
// we want to panic and not keep spending fees on scheduled transactions if borrow fails
176176
let positionRebalanceCap = self._positionRebalanceCapability.borrow()!
177177
positionRebalanceCap.rebalance(force: self.recurringConfig.getForceRebalance())

cadence/contracts/FlowALPSupervisorv1.cdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ access(all) contract FlowALPSupervisorv1 {
4747
/// Scheduler callback: on each tick, call fixReschedule on every registered paid rebalancer,
4848
/// recovering any that failed to schedule their next transaction. Stale UUIDs (rebalancer
4949
/// deleted without being removed from this set) are pruned automatically.
50-
access(FlowTransactionScheduler.Execute) fun executeTransaction(id: UInt64, data: AnyStruct?) {
50+
access(FlowTransactionScheduler.Execute) fun executeTransaction(id: UInt64, data _: AnyStruct?) {
5151
emit Executed(id: id)
5252
for positionID in self.paidRebalancers.keys {
5353
let found = FlowALPRebalancerPaidv1.fixReschedule(positionID: positionID)

cadence/contracts/FlowALPv0.cdc

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ access(all) contract FlowALPv0 {
865865
/// the target health, given pre-adjusted effective collateral and debt values.
866866
///
867867
/// @param position The position reference.
868-
/// @param initialBalanceSheet The position's current balance sheet
868+
/// @param initialBalanceSheet The position's current balance sheet
869869
/// @param targetHealth The minimum health to maintain after withdrawal.
870870
/// @return The maximum withdrawable amount of withdrawType.
871871
access(self) fun computeAvailableWithdrawal(
@@ -971,7 +971,6 @@ access(all) contract FlowALPv0 {
971971

972972
// assign issuance & repayment connectors within the InternalPosition
973973
let iPos = self._borrowPosition(pid: id)
974-
let fundsType = funds.getType()
975974
iPos.setDrawDownSink(issuanceSink)
976975
if repaymentSource != nil {
977976
iPos.setTopUpSource(repaymentSource)
@@ -987,12 +986,10 @@ access(all) contract FlowALPv0 {
987986

988987
// Create a capability to the Pool for the Position resource
989988
// The Pool is stored in the FlowALPv0 contract account
990-
let poolCap = FlowALPv0.account.capabilities.storage.issue<auth(FlowALPModels.EPosition) &{FlowALPModels.PositionPool}>(
991-
FlowALPv0.PoolStoragePath
992-
)
989+
let poolCap = FlowALPv0.account.capabilities.storage
990+
.issue<auth(FlowALPModels.EPosition) &{FlowALPModels.PositionPool}>(FlowALPv0.PoolStoragePath)
993991

994992
// Create and return the Position resource
995-
996993
let position <- FlowALPPositionResources.createPosition(id: id, pool: poolCap)
997994

998995
self.unlockPosition(id)
@@ -1214,7 +1211,7 @@ access(all) contract FlowALPv0 {
12141211
withdrawType: type,
12151212
withdrawAmount: amount
12161213
)
1217-
1214+
12181215
let pulledVault <- topUpSource.withdrawAvailable(maxAmount: targetHealthDeposit)
12191216
assert(pulledVault.getType() == purportedTopUpType, message: "topUpSource returned unexpected token type")
12201217
self._depositEffectsOnly(
@@ -1302,7 +1299,7 @@ access(all) contract FlowALPv0 {
13021299
/// Returns a mutable reference to the pool's configuration.
13031300
/// Use this to update config fields that don't require events or side effects.
13041301
access(FlowALPModels.EGovernance) fun borrowConfig(): auth(FlowALPModels.EImplementation) &{FlowALPModels.PoolConfig} {
1305-
return &self.config as auth(FlowALPModels.EImplementation) &{FlowALPModels.PoolConfig}
1302+
return &self.config
13061303
}
13071304

13081305
/// Pauses the pool, temporarily preventing further withdrawals, deposits, and liquidations
@@ -1508,7 +1505,7 @@ access(all) contract FlowALPv0 {
15081505

15091506
// Recalculate currentCreditRate for a given token to reflect the new stability rate
15101507
tsRef.updateInterestRates()
1511-
1508+
15121509
FlowALPEvents.emitStabilityFeeRateUpdated(
15131510
poolUUID: self.uuid,
15141511
tokenType: tokenType.identifier,
@@ -1858,7 +1855,7 @@ access(all) contract FlowALPv0 {
18581855
}
18591856

18601857
if insuranceAmountUFix64 > reserveVault.balance {
1861-
// do not collect the insurance fee if the reserve doesn't have enough tokens to cover the full amount
1858+
// do not collect the insurance fee if the reserve doesn't have enough tokens to cover the full amount
18621859
return nil
18631860
}
18641861

@@ -1914,11 +1911,11 @@ access(all) contract FlowALPv0 {
19141911
}
19151912

19161913
if stabilityAmountUFix64 > reserveVault.balance {
1917-
// do not collect the stability fee if the reserve doesn't have enough tokens to cover the full amount
1914+
// do not collect the stability fee if the reserve doesn't have enough tokens to cover the full amount
19181915
return nil
19191916
}
19201917

1921-
let stabilityVault <- reserveVault.withdraw(amount: stabilityAmountUFix64)
1918+
let stabilityVault <- reserveVault.withdraw(amount: stabilityAmountUFix64)
19221919
tokenState.setLastStabilityFeeCollectionTime(currentTime)
19231920
return <-stabilityVault
19241921
}
@@ -2135,7 +2132,7 @@ access(all) contract FlowALPv0 {
21352132
)
21362133
FlowALPv0.account.storage.save(<-pool, to: FlowALPv0.PoolStoragePath)
21372134
let cap = FlowALPv0.account.capabilities.storage.issue<&Pool>(FlowALPv0.PoolStoragePath)
2138-
FlowALPv0.account.capabilities.unpublish(FlowALPv0.PoolPublicPath)
2135+
let _ = FlowALPv0.account.capabilities.unpublish(FlowALPv0.PoolPublicPath)
21392136
FlowALPv0.account.capabilities.publish(cap, at: FlowALPv0.PoolPublicPath)
21402137
}
21412138
}
@@ -2167,6 +2164,5 @@ access(all) contract FlowALPv0 {
21672164
<-create PoolFactory(),
21682165
to: self.PoolFactoryPath
21692166
)
2170-
let factory = self.account.storage.borrow<&PoolFactory>(from: self.PoolFactoryPath)!
21712167
}
21722168
}

cadence/contracts/MOET.cdc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ access(all) contract MOET : FungibleToken {
2525
/// and store the returned Vault in their storage in order to allow their
2626
/// account to be able to receive deposits of this token type.
2727
///
28-
access(all) fun createEmptyVault(vaultType: Type): @MOET.Vault {
28+
access(all) fun createEmptyVault(vaultType _: Type): @MOET.Vault {
2929
return <- create Vault(balance: 0.0)
3030
}
3131

32-
access(all) view fun getContractViews(resourceType: Type?): [Type] {
32+
access(all) view fun getContractViews(resourceType _: Type?): [Type] {
3333
return [
3434
Type<FungibleTokenMetadataViews.FTView>(),
3535
Type<FungibleTokenMetadataViews.FTDisplay>(),
@@ -38,7 +38,7 @@ access(all) contract MOET : FungibleToken {
3838
]
3939
}
4040

41-
access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
41+
access(all) fun resolveContractView(resourceType _: Type?, viewType: Type): AnyStruct? {
4242
switch viewType {
4343
case Type<FungibleTokenMetadataViews.FTView>():
4444
return FungibleTokenMetadataViews.FTView(

0 commit comments

Comments
 (0)