jedib0t / go-pretty

Table-writer and more in golang!
MIT License
3.06k stars 120 forks source link

fix(table): SuppressTrailingSpaces also removed spaces from the beginning #295

Closed ilya-lesikov closed 10 months ago

ilya-lesikov commented 10 months ago

Proposed Changes

mytable.SuppressTrailingSpaces() suppressing not only trailing spaces, but also spaces from the beginning. This fixes it.

Before fix

RESOURCE (→READY)               STATE    INFO
Deployment/lesikovtestttt       WAITING  Ready:0/1
• Pod/lesikovtestttt-78568f8d  CREATED  Status:CrashLoopBack
77-dkznh                                 Off  Errors:1  LastE
rror:"CrashLoopBackO
ff: back-off 5m0s re
starting failed cont
ainer=alpine pod=les
ikovtestttt-78568f8d
77-dkznh_nelm-basic(
a1e1ac7e-c64d-4531-9
d0d-b20b5e9f0a61)"

After fix

RESOURCE (→READY)               STATE    INFO
Deployment/lesikovtestttt       WAITING  Ready:0/1
 • Pod/lesikovtestttt-78568f8d  CREATED  Status:CrashLoopBack
77-dkznh                                 Off  Errors:1  LastE
                                         rror:"CrashLoopBackO
                                         ff: back-off 2m40s r
                                         estarting failed con
                                         tainer=alpine pod=le
                                         sikovtestttt-78568f8
                                         d77-dkznh_nelm-basic
                                         (a1e1ac7e-c64d-4531-
                                         9d0d-b20b5e9f0a61)"
ilya-lesikov commented 10 months ago

I see some units failing since they for some reason expect SuppressTrailingSpaces to also remove spaces in the beginning. I'll fix the tests if you are fine with the PR.

jedib0t commented 10 months ago

@ilya-lesikov Code looks okay to me, but you have to fix the failing unit-test along with it. Change the code in the test from:

    tw.Style().Options = OptionsNoBordersAndSeparators
    compareOutput(t, tw.Render(), `
ID    TEXT1                                   DATE              TEXT2
U2    Hey                                     2021-04-19 13:37  Yuh yuh yuh
S12   Uhhhh                                   2021-04-19 13:37  Some dummy data here
R123  Lobsters                                2021-04-19 13:37  I like lobsters
R123  Some big name here and it's pretty big  2021-04-19 13:37  Abcdefghijklmnopqrstuvwxyz
R123  Small name                              2021-04-19 13:37  Abcdefghijklmnopqrstuvwxyz`)

to:

    tw.Style().Options = OptionsNoBordersAndSeparators
    compareOutput(t, tw.Render(), `
 ID    TEXT1                                   DATE              TEXT2
 U2    Hey                                     2021-04-19 13:37  Yuh yuh yuh
 S12   Uhhhh                                   2021-04-19 13:37  Some dummy data here
 R123  Lobsters                                2021-04-19 13:37  I like lobsters
 R123  Some big name here and it's pretty big  2021-04-19 13:37  Abcdefghijklmnopqrstuvwxyz
 R123  Small name                              2021-04-19 13:37  Abcdefghijklmnopqrstuvwxyz`)

The new code has leading spaces in each line of output.

sonarcloud[bot] commented 10 months ago

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

coveralls commented 10 months ago

Pull Request Test Coverage Report for Build 7696662338


Totals Coverage Status
Change from base Build 7456312488: 0.0%
Covered Lines: 3434
Relevant Lines: 3434

💛 - Coveralls
ilya-lesikov commented 10 months ago

@jedib0t Fixed units.

jedib0t commented 10 months ago

Thanks for the contribution @ilya-lesikov !

jedib0t commented 10 months ago

I've cut a release for your use: https://github.com/jedib0t/go-pretty/releases/tag/v6.5.4