Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: while loop formatting is off #4953

Closed
delaaxe opened this issue Jan 29, 2024 · 11 comments · Fixed by #4958
Closed

feat: while loop formatting is off #4953

delaaxe opened this issue Jan 29, 2024 · 11 comments · Fixed by #4958
Labels
enhancement New feature or request

Comments

@delaaxe
Copy link
Contributor

delaaxe commented Jan 29, 2024

i believe it should stay as before (red), after running scarb fmt (green):

Screenshot 2024-01-29 at 14 56 01
@delaaxe delaaxe added the enhancement New feature or request label Jan 29, 2024
@orizi
Copy link
Collaborator

orizi commented Jan 30, 2024

are using the latest version? locally this does not replicate for me.

@delaaxe
Copy link
Contributor Author

delaaxe commented Jan 30, 2024

Yes 2.5.1. Did you try with dotted access? Inside a contract? Here's a minimal text example, try reformatting it pls:

#[starknet::interface]
trait IPool<TContractState> {
    fn create_pool(ref self: TContractState, asset_params: Span<AssetParams>, ltv_params: Span<LTVParams>) -> felt252;
}

#[starknet::contract]
mod Pool {
    #[abi(embed_v0)]
    impl poolImpl of super::IPool<ContractState> {
        fn create_pool(
            ref self: ContractState, mut asset_params: Span<AssetParams>, mut ltv_params: Span<LTVParams>,
        ) -> felt252 {
            while !asset_params.is_empty() {
                let params = *asset_params.pop_front().unwrap();
                assert(params.floor != 0, 'floor-zero');
            };

            while !ltv_params.is_empty() {
                let params = *ltv_params.pop_front().unwrap();
                self.max_position_ltvs.write((params.foo, params.bar), params.ltv);
            };

            42
        }
    }
}

@orizi
Copy link
Collaborator

orizi commented Jan 30, 2024

Thanks for the full example - now it replicates - will fix soon.

orizi added a commit that referenced this issue Jan 30, 2024
orizi added a commit that referenced this issue Jan 30, 2024
@delaaxe
Copy link
Contributor Author

delaaxe commented Feb 1, 2024

Thanks. this problem is also common in almost every project. should i create another issue for it? (should be green, formats to red)

Screenshot 2024-01-31 at 12 03 17

@orizi
Copy link
Collaborator

orizi commented Feb 1, 2024

fell free to add here - but do note that sending pictures is not usable - as everything is context dependent.

@delaaxe
Copy link
Contributor Author

delaaxe commented Feb 1, 2024

sure, the pictures show diffs better. here's the text:

#[starknet::contract]
mod DefaultExtension {
    #[storage]
    struct Storage {}

    #[abi(embed_v0)]
    impl ExtensionImpl of IExtension<ContractState> {
        fn rate_accumulator(self: @ContractState) -> (u256, u256) {
            self.interest_rate_model.rate_accumulator(
                pool_id, asset, utilization, last_updated, last_rate_accumulator, last_full_utilization_rate
            )
        }
    }
}

@orizi
Copy link
Collaborator

orizi commented Feb 1, 2024

The actual result for this is:

#[starknet::contract]
mod DefaultExtension {
    #[storage]
    struct Storage {}

    #[abi(embed_v0)]
    impl ExtensionImpl of IExtension<ContractState> {
        fn rate_accumulator(self: @ContractState) -> (u256, u256) {
            self
                .interest_rate_model
                .rate_accumulator(
                    pool_id,
                    asset,
                    utilization,
                    last_updated,
                    last_rate_accumulator,
                    last_full_utilization_rate
                )
        }
    }
}

Which is correct since the line is longer than 100 chars.

@delaaxe
Copy link
Contributor Author

delaaxe commented Feb 1, 2024 via email

@delaaxe
Copy link
Contributor Author

delaaxe commented Feb 1, 2024

Here it is the proposal for line legnth 100:

#[starknet::contract]
mod DefaultExtension {
    #[storage]
    struct Storage {}

    #[abi(embed_v0)]
    impl ExtensionImpl of IExtension<ContractState> {
        fn rate_accumulator(self: @ContractState) -> (u256, u256) {
            self.interest_rate_model.rate_accumulator(
                pool_id,
                asset,
                utilization,
                last_updated,
                last_rate_accumulator,
                last_full_utilization_rate
            )
        }
    }
}

instead of:

#[starknet::contract]
mod DefaultExtension {
    #[storage]
    struct Storage {}

    #[abi(embed_v0)]
    impl ExtensionImpl of IExtension<ContractState> {
        fn rate_accumulator(self: @ContractState) -> (u256, u256) {
            self
                .interest_rate_model
                .rate_accumulator(
                    pool_id,
                    asset,
                    utilization,
                    last_updated,
                    last_rate_accumulator,
                    last_full_utilization_rate
                )
        }
    }
}

@orizi
Copy link
Collaborator

orizi commented Feb 1, 2024

This needs to include a more complex algorithm than we are planning in the scope of the basic formatter - at it needs to try multiple different attempts at splitting the text - which would be to complex for the basic.
When there's an external formatter project it is likely to perform such analysis.

@delaaxe
Copy link
Contributor Author

delaaxe commented Mar 6, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants