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

Autoformat issues with v2.11.1 #482

Open
vytis opened this issue Jan 12, 2023 · 3 comments
Open

Autoformat issues with v2.11.1 #482

vytis opened this issue Jan 12, 2023 · 3 comments

Comments

@vytis
Copy link

vytis commented Jan 12, 2023

I have updated rubocop-shopify to 2.11.1 and fixing the layout with bundle exec rubocop -A produced some weird changes.

The code before:

    def collection
      Service.not_deleted.includes(
        { vault_teams:
            [:github_team_vault_teams, :teams] },
        { app:
            [{ runtimes:
                 [:runtime_instances, :app] },
             :runtimes,
             :repo,] },
        :repo,
        :app,
        :monorepo_mobile_app,
        :bugsnag_project,
        :slack_channels,
        :vault_teams,
        :vault_users,
      ).joins(:app)
    end

The code after:

    def collection
      Service.not_deleted.includes(
        {
          vault_teams:
                      [:github_team_vault_teams, :teams],
        },
        {
          app:
                      [
                        {
                          runtimes:
                                           [:runtime_instances, :app],
                        },
                        :runtimes,
                        :repo,
                      ],
        },
        :repo,
        :app,
        :monorepo_mobile_app,
        :bugsnag_project,
        :slack_channels,
        :vault_teams,
        :vault_users,
      ).joins(:app)
    end

There are more extreme examples in this file.

It seems the problem doesn't happen if the opening bracket (or whole entry) is on the same line:

Before

    def collection
      Service.not_deleted.includes(
        { vault_teams:[:github_team_vault_teams, :teams] },
        { app:[
          { runtimes: [:runtime_instances, :app] },
             :runtimes,
             :repo,] },
        :repo,
        :app,
        :monorepo_mobile_app,
        :bugsnag_project,
        :slack_channels,
        :vault_teams,
        :vault_users,
      ).joins(:app)
    end

After

    def collection
      Service.not_deleted.includes(
        { vault_teams: [:github_team_vault_teams, :teams] },
        {
          app: [
            { runtimes: [:runtime_instances, :app] },
            :runtimes,
            :repo,
          ],
        },
        :repo,
        :app,
        :monorepo_mobile_app,
        :bugsnag_project,
        :slack_channels,
        :vault_teams,
        :vault_users,
      ).joins(:app)
    end
@sambostock
Copy link
Contributor

I have a branch where I'm adding "integration tests". I'll add these so we can be sure when we've fixed it (either by tweaking config, or fixing correction upstream).

@sambostock
Copy link
Contributor

sambostock commented Jan 13, 2023

I think the problem is with Layout/FirstHashElementLineBreak. When I disable that, the crazy indenting goes away (although it doesn't break the line, so it's still possible that it's a combination of cops).

cc. @Korri

@Korri
Copy link
Contributor

Korri commented Feb 10, 2023

I think the problem is with Layout/FirstHashElementLineBreak. When I disable that, the crazy indenting goes away (although it doesn't break the line, so it's still possible that it's a combination of cops).

cc. @Korri

Yeah this is a combination of the opening tag already being on a newline originally + the new mapping + us not having a rule that forces the opening element to be on the same line not one that forces a specific indentation Hash values when it's not on the same line as the key.

Like all of the following are ok:

{
  a:
        :foo,
  b:
    :bar,
  c:
                                   :bat,
}

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

No branches or pull requests

3 participants