Skip to content

lint fixes#131

Open
mts1715 wants to merge 12 commits intomainfrom
taras/lint-fixes
Open

lint fixes#131
mts1715 wants to merge 12 commits intomainfrom
taras/lint-fixes

Conversation

@mts1715
Copy link
Contributor

@mts1715 mts1715 commented Feb 4, 2026

  • fixed problems that was found by flow cadence lint.
  • added lint stage before test stage in the CI workflow

Update: problem bellow was solved in onflow/cadence-tools#586 .

But some problems were left unresolved due to a bug with the linter:

var out: [UInt8] = []    // type annotation is redundant, type can be inferred
var out = []             // cannot infer type: requires an explicit type annotation. add an explicit type annotation to resolve the ambiguity
var out = [] as [UInt8]  // static cast is redundant

Also, it's impossible to use a long string template across multiple lines, so in order to prevent long lines, it should be written like this:

panic("Deposit token type \(self.depositVaultType.identifier) has not been onboarded to the VM bridge - "
                .concat("Ensure the Cadence token type is associated with an EVM contract via the VM bridge"))

But the linter suggests: string concatenation can be replaced with string template

@vishalchangrani vishalchangrani requested a review from a team February 4, 2026 18:57
@mts1715 mts1715 self-assigned this Feb 5, 2026
# Conflicts:
#	cadence/contracts/connectors/evm/UniswapV3SwapConnectors.cdc
#	cadence/tests/UniswapV3SwapConnectors_test.cdc
@mts1715 mts1715 requested a review from holyfuchs February 23, 2026 11:41
# Conflicts:
#	cadence/contracts/connectors/evm/UniswapV3SwapConnectors.cdc
Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall!
Left a few suggestions for using the type-annotation over casting/conversion.

let full = wordToUInt(w)
if nBits >= 256 { return full }
let mask: UInt = (UInt(1) << UInt(nBits)) - UInt(1)
let mask = (1 as UInt << UInt(nBits)) - 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if it would make sense to make the nBits parameter UInt type, instead of Int. I don't really know where this wordToUIntN is used, so might depends on the use-cases.

If we could do that, then it's possible to just keep the type-annotation for the mask variable (LHS), and remove all the castings/conversions from the RHS of the assignment. e.g:

Suggested change
let mask = (1 as UInt << UInt(nBits)) - 1
let mask: UInt = (1 << nBits) - 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if it would make sense to make the nBits parameter UInt type, instead of Int. I don't really know where this wordToUIntN is used, so might depends on the use-cases.

this code is inside the fun:

            fun wordToUIntN(_ w: [UInt8], _ nBits: Int): UInt {
                let full = wordToUInt(w)
                if nBits >= 256 { return full }
                let mask: UInt = (1 << UInt(nBits)) - 1
                return full & mask
            }

so it should return UInt

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the parameter nBits: Int to nBits: UInt wouldn't impact the return type. It seems all call-sites to this function pass a number-literal (e.g: wordToUIntN(s0w[0], 160) and wordToUIntN(words(liqRes!.data)[0], 128)), so that change would be compatible with the call-sites too.

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for cleaning this up

Comment on lines 9 to 18
@@ -15,7 +15,7 @@ transaction(victimAddress: Address, victimPublicPath: PublicPath, attackerStorag
self.victimConfig = victimAB.getRecurringConfig() ?? panic("Victim AutoBalancer does not have a recurring config")

// get attacker's AutoBalancer
self.attackerAB = signer.storage.borrow<&DeFiActions.AutoBalancer>(from: attackerStoragePath)
self.attackerAB = signer.storage.borrow<auth(DeFiActions.Configure) &DeFiActions.AutoBalancer>(from: attackerStoragePath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why where the authorizations added here? These changes don't seem to be related to fixing linting errors, so maybe propose them in a separate PR

prepare(signer: auth(BorrowValue) &Account) {
self.autoBalancer = signer.storage.borrow<auth(DeFiActions.Schedule) &DeFiActions.AutoBalancer>(from: storagePath)
self.autoBalancer = signer.storage.borrow<auth(DeFiActions.Configure) &DeFiActions.AutoBalancer>(from: storagePath)
?? panic("AutoBalancer was not found in signer's storage at \(storagePath)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: Maybe propose these changes unrelated to fixing linter warnings in a separate PR

Comment on lines +8 to +11
let autoBalancer: auth(DeFiActions.Schedule) &DeFiActions.AutoBalancer

prepare(signer: auth(BorrowValue) &Account) {
self.autoBalancer = signer.storage.borrow<auth(DeFiActions.Auto) &DeFiActions.AutoBalancer>(from: storagePath)
self.autoBalancer = signer.storage.borrow<auth(DeFiActions.Schedule) &DeFiActions.AutoBalancer>(from: storagePath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: Maybe propose these changes unrelated to fixing linter warnings in a separate PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants