Skip to content

Format: fix indent of nested array elements#7450

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
makenowjust:formatter-nested-indentation
Feb 21, 2019
Merged

Format: fix indent of nested array elements#7450
straight-shoota merged 1 commit intocrystal-lang:masterfrom
makenowjust:formatter-nested-indentation

Conversation

@makenowjust
Copy link
Copy Markdown
Contributor

Fixed #7443

With more precision, this change treats multiline elements.
This change detects multiline elenent and keeps current indent in this case, or elements will be aligned at start column.

Now, the formatter keeps these formats:

# #7048
[
  {
    "some" => "hash",
    "with" => "values",
  }, {
    "another"  => "hash",
    "will get" => "deindented",
  }, {
    "now" => "totally",
  }, {
    "flat" => "against the left",
  },
]

# #7443
very_long_variable_name = [{
  :foo => :bar,
}]

very_long_variable_name = [
  {
    :foo => :bar,
  }, {
    :bar => :baz,
  },
]

very_long_variable_name = [
  {
    :foo => :bar,
  },
  {
    :bar => :baz,
  },
]

# single-line elements case

foo = [1, 2, 3,
       4, 5, 6]

foo = [1, 2, 3, # foo
       4, 5, 6]

foo = [
  1, 2, 3,
  4, 5, 6,
]

@asterite Sorry. I know you are working for #7443 just now. However I wrote this patch yesterday (but I wrote a spec today.)

Fixed crystal-lang#7443

With more precision, not nested array elements, but multiline elements.
This change detects multiline elenent and keeps current indent in this
case, or elements will be aligned at start column.
@asterite
Copy link
Copy Markdown
Member

@makenowjust Thank you! I didn't start working on this yet, it was just my intention if it was too hard to implement. But you did it so it's great!

@Sija
Copy link
Copy Markdown
Contributor

Sija commented Feb 18, 2019

You guys are awesome, thanks! 🙇

@kostya
Copy link
Copy Markdown
Contributor

kostya commented Feb 18, 2019

will this fix #5988?

@asterite
Copy link
Copy Markdown
Member

@kostya I don't think so. However, an idea to fix that is to use the start line and end line of the hash/namedtuple to know what to align. After this is merged I can fix it (or @makenowjust might ^_^)

@sdogruyol sdogruyol added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter labels Feb 18, 2019
Copy link
Copy Markdown
Member

@sdogruyol sdogruyol left a comment

Choose a reason for hiding this comment

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

Thank you @makenowjust 👍

@straight-shoota straight-shoota merged commit 2ca522f into crystal-lang:master Feb 21, 2019
@straight-shoota straight-shoota added this to the 0.28.0 milestone Feb 21, 2019
@makenowjust makenowjust deleted the formatter-nested-indentation branch February 21, 2019 17:06
urde-graven pushed a commit to urde-graven/crystal that referenced this pull request Feb 25, 2019
Fixed crystal-lang#7443

With more precision, not nested array elements, but multiline elements.
This change detects multiline elenent and keeps current indent in this
case, or elements will be aligned at start column.
urde-graven pushed a commit to urde-graven/crystal that referenced this pull request Feb 27, 2019
* fixes:
  Foreign exceptions: basic support
  Added support for `.so' libraries, fixed segfault, small bugs
  OptionParser: optional options and arguments shifting
  XML: workaround for bug in libxml2 2.9.9 (crystal-lang#7477)
  Implement resource owner credentials (crystal-lang#7424)
  Implement #annotations (crystal-lang#7326)
  Handle signals in a separate fiber
  Compiler: reactively compute a union's type, and check for missing types
  Compiler: fix as? casting when target doesn't have a type yet
  Compiler: fix as casting when target doesn't have a type yet
  Compiler: give pare error when assigning a constant inside a multiassign
  Format: fix indent of nested array elements (crystal-lang#7450)
  Disable double write buffering in OpenSSL sockets (crystal-lang#7460)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants