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

Fix sway formatting turns op + = into op + + = which breaks the build command because it is not a valid expression #1949

Merged
merged 3 commits into from
Jun 12, 2022

Conversation

kayagokalp
Copy link
Member

closes #1945

Until we are ready to switch to formatter v2, I am pushing a quick fix as this seems fairly easy to fix and the bug is breaking the build process.

@kayagokalp kayagokalp added bug Something isn't working formatter labels Jun 12, 2022
@kayagokalp kayagokalp self-assigned this Jun 12, 2022
Braqzen
Braqzen previously approved these changes Jun 12, 2022
Copy link
Contributor

@Braqzen Braqzen left a comment

Choose a reason for hiding this comment

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

Shouldn't this have a test case?

@kayagokalp
Copy link
Member Author

I wasn't sure whether we should have a test or not since:

  • Handling of = sign part does not have one too
  • We are going to be removing the v1 formatter soon (wasn't sure if we should add more noise)

But I think we can add one so that we are sure it does not touch += as it used to do (if you also think that would be a better approach to follow)

Does something like this seem good?:

    #[test]
    fn test_plus_equal() {
        let correct_sway_code = r#"script;
fn main() {
    let mut a = 1;
    a += 1;
}
"#;
        let sway_code = r#"script;
fn main() {
    let mut a = 1;
    a += 1;
}
"#;
        let result = get_formatted_data(sway_code.into(), OPTIONS, None);
        assert!(result.is_ok());
        let (_, formatted_code) = result.unwrap();
        assert_eq!(correct_sway_code, formatted_code);
    }

@mohammadfawaz
Copy link
Contributor

mohammadfawaz commented Jun 12, 2022

Shouldn't we also do the same for other operators: -=, *=, etc.? I suspect hey suffer from the same problem.

A list of possible operators is here: #1783

@kayagokalp
Copy link
Member Author

kayagokalp commented Jun 12, 2022

Yes, that seems correct, I can see that this happens with:

  • -=
  • *=
  • /=

but <<= and >>= seem to be formatted correctly.

@kayagokalp kayagokalp requested a review from Braqzen June 12, 2022 22:09
@kayagokalp kayagokalp changed the title Fix sway formatting turns += into + = which breaks the build command because it is not a valid expression Fix sway formatting turns op + = into op + + = which breaks the build command because it is not a valid expression Jun 12, 2022
@kayagokalp kayagokalp marked this pull request as ready for review June 12, 2022 22:17
@kayagokalp kayagokalp merged commit 37fd678 into master Jun 12, 2022
@kayagokalp kayagokalp deleted the kayagokalp/1945 branch June 12, 2022 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Sway formatting turns += into + = which breaks the build command because it is not a valid expression
3 participants