macisamuele / language-formatters-pre-commit-hooks

Collection of custom pre-commit hooks.
Apache License 2.0
116 stars 58 forks source link

Array formatted not very pretty #95

Closed tdegeus closed 2 years ago

tdegeus commented 2 years ago

I have a file:

epsd:
    [
            0.00000000e+00, 2.00000000e-04, 6.97510220e-01, 6.97710220e-01,
            1.14101113e+00, 1.14121113e+00, 1.30379685e+00, 1.30399685e+00,
            1.59313535e+00, 1.59333535e+00, 1.67477980e+00, 1.67497980e+00,
            1.74995852e+00, 1.75015852e+00, 1.92651521e+00, 1.92671521e+00,
            2.22921949e+00, 2.22941949e+00, 2.25524963e+00, 2.25544963e+00]

sigd: [
            0.00000000e+00, 2.00000000e-04, 6.97510220e-01, 6.37087406e-01,
            1.08038734e+00, 1.05259037e+00, 1.21517607e+00, 1.17774795e+00,
            1.46688286e+00, 1.41467867e+00, 1.49612181e+00, 5.44543851e-01,
            6.19522524e-01, 3.86097256e-01, 5.62453891e-01, 3.26369082e-01,
            6.28873246e-01, 5.81974365e-01, 6.07804478e-01, 5.72717686e-01]

that is formatted:

epsd: [0.00000000e+09, 2.00000000e-04, 6.97510220e-01, 6.97710220e-01, 1.14101113e+00, 1.14121113e+00, 1.30379685e+00, 1.30399685e+00, 1.59313535e+00, 1.59333535e+00, 1.67477980e+00, 1.67497980e+00, 1.74995852e+00, 1.75015852e+00, 1.92651521e+00, 1.92671521e+00, 2.22921949e+00, 2.22941949e+00, 2.25524963e+00, 2.25544963e+00]

sigd: [0.00000000e+09, 2.00000000e-04, 6.97510220e-01, 6.37087406e-01, 1.08038734e+00, 1.05259037e+00, 1.21517607e+00, 1.17774795e+00, 1.46688286e+00, 1.41467867e+00, 1.49612181e+00, 5.44543851e-01, 6.19522524e-01, 3.86097256e-01, 5.62453891e-01, 3.26369082e-01, 6.28873246e-01, 5.81974365e-01, 6.07804478e-01, 5.72717686e-01]

I'm using:

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
  rev: v2.1.0
  hooks:
  - id: pretty-format-yaml
    args: [--preserve-quotes, --autofix, --indent, '2']
macisamuele commented 2 years ago

The "non-pretty" you are observing is related to the fact that the process assumes unlimited line length into the output.

I do understand that you expect a nicer-to-see output but the idea of the prettification is to ensure that the format of the file is not altered too much.

Still this could be handled in a more proper way if we were to allow users to specify their preferred line width. Assuming that we were to set 80 as line width the prettified version of your yaml file would be something like

epsd: [0.00000000e+09, 2.00000000e-04, 6.97510220e-01, 6.97710220e-01, 1.14101113e+00,
  1.14121113e+00, 1.30379685e+00, 1.30399685e+00, 1.59313535e+00, 1.59333535e+00,
  1.67477980e+00, 1.67497980e+00, 1.74995852e+00, 1.75015852e+00, 1.92651521e+00,
  1.92671521e+00, 2.22921949e+00, 2.22941949e+00, 2.25524963e+00, 2.25544963e+00]

sigd: [0.00000000e+09, 2.00000000e-04, 6.97510220e-01, 6.37087406e-01, 1.08038734e+00,
  1.05259037e+00, 1.21517607e+00, 1.17774795e+00, 1.46688286e+00, 1.41467867e+00,
  1.49612181e+00, 5.44543851e-01, 6.19522524e-01, 3.86097256e-01, 5.62453891e-01,
  3.26369082e-01, 6.28873246e-01, 5.81974365e-01, 6.07804478e-01, 5.72717686e-01]
tdegeus commented 2 years ago

Seems like a good solution! In line with other formatters. Thanks!