Skip to content

Commit 01e1be4

Browse files
authored
All line numbers in tables are padded to the left (#133)
Now all line numbers in tables are padded to the left. This improves readability especially for larger tables with many entries and enhances consistence in data presentation across the different outputs.
1 parent 014cbd2 commit 01e1be4

7 files changed

+61
-59
lines changed

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ Pairs by pattern: 1
999999
Check schema syntax: 1
10001000
2 issues in ./tests/schemas/demo_invalid.yml
10011001
+-------+------------------+--------------+----------------------------------------------------------------------+
1002-
| Line | id:Column | Rule | Message |
1002+
| Line | id:Column | Rule | Message |
10031003
+-------+------------------+--------------+----------------------------------------------------------------------+
10041004
| undef | 2:Float | is_float | Value "Qwerty" is not a float number |
10051005
| undef | 4:Favorite color | allow_values | Value "123" is not allowed. Allowed values: ["red", "green", "Blue"] |
@@ -1011,19 +1011,19 @@ Schema: ./tests/schemas/demo_invalid.yml
10111011
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
10121012
| Line | id:Column | Rule | Message |
10131013
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
1014-
| 1 | | allow_extra_columns | Column(s) not found in CSV: "wrong_column_name" |
1015-
| 6 | 0:Name | length_min | The length of the value "Carl" is 4, which is less than the expected "5" |
1016-
| 11 | 0:Name | length_min | The length of the value "Lois" is 4, which is less than the expected "5" |
1017-
| 1 | 1:City | ag:is_unique | Column has non-unique values. Unique: 9, total: 10 |
1018-
| 2 | 2:Float | num_max | The value "4825.185" is greater than the expected "4825.184" |
1019-
| 1 | 2:Float | ag:nth_num | The N-th value in the column is "74", which is not equal than the expected "0.001" |
1020-
| 6 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
1014+
| 1 | | allow_extra_columns | Column(s) not found in CSV: "wrong_column_name" |
1015+
| 6 | 0:Name | length_min | The length of the value "Carl" is 4, which is less than the expected "5" |
1016+
| 11 | 0:Name | length_min | The length of the value "Lois" is 4, which is less than the expected "5" |
1017+
| 1 | 1:City | ag:is_unique | Column has non-unique values. Unique: 9, total: 10 |
1018+
| 2 | 2:Float | num_max | The value "4825.185" is greater than the expected "4825.184" |
1019+
| 1 | 2:Float | ag:nth_num | The N-th value in the column is "74", which is not equal than the expected "0.001" |
1020+
| 6 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
10211021
| | | | expected "1955-05-15 00:00:00 +00:00 (1955-05-15)" |
1022-
| 8 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
1022+
| 8 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
10231023
| | | | expected "1955-05-15 00:00:00 +00:00 (1955-05-15)" |
1024-
| 9 | 3:Birthday | date_max | The date of the value "2010-07-20" is parsed as "2010-07-20 00:00:00 +00:00", which is greater than |
1024+
| 9 | 3:Birthday | date_max | The date of the value "2010-07-20" is parsed as "2010-07-20 00:00:00 +00:00", which is greater than |
10251025
| | | | the expected "2009-01-01 00:00:00 +00:00 (2009-01-01)" |
1026-
| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", "green", "Blue"] |
1026+
| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", "green", "Blue"] |
10271027
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
10281028

10291029
Summary:

src/Validators/ErrorSuite.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use JBZoo\Utils\FS;
2626
use JBZoo\Utils\Vars;
2727
use Symfony\Component\Console\Helper\Table;
28+
use Symfony\Component\Console\Helper\TableStyle;
2829
use Symfony\Component\Console\Output\BufferedOutput;
2930

3031
final class ErrorSuite
@@ -157,7 +158,8 @@ private function renderTable(): string
157158
->setColumnMaxWidth(0, $floatingSizes['line'])
158159
->setColumnMaxWidth(1, $floatingSizes['column'])
159160
->setColumnMaxWidth(2, $floatingSizes['rule'])
160-
->setColumnMaxWidth(3, $floatingSizes['message']);
161+
->setColumnMaxWidth(3, $floatingSizes['message'])
162+
->setColumnStyle(0, (new TableStyle())->setPadType(\STR_PAD_LEFT));
161163

162164
foreach ($this->errors as $error) {
163165
$table->addRow([

tests/Commands/ValidateCsvBasicTest.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public function testValidateOneCsvNegative(): void
8080
+------+------------------+--------------+----------------------------------------------------------------------------------------+
8181
| Line | id:Column | Rule | Message |
8282
+------+------------------+--------------+----------------------------------------------------------------------------------------+
83-
| 6 | 0:Name | length_max | The length of the value "Long-long-name" is 14, which is greater than the expected "7" |
84-
| 11 | 4:Favorite color | allow_values | Value "YELLOW" is not allowed. Allowed values: ["red", "green", "blue"] |
83+
| 6 | 0:Name | length_max | The length of the value "Long-long-name" is 14, which is greater than the expected "7" |
84+
| 11 | 4:Favorite color | allow_values | Value "YELLOW" is not allowed. Allowed values: ["red", "green", "blue"] |
8585
+------+------------------+--------------+----------------------------------------------------------------------------------------+
8686
8787
Summary:
@@ -112,7 +112,7 @@ public function testValidateOneCsvWithInvalidSchemaNegative(): void
112112
Check schema syntax: 1
113113
2 issues in ./tests/schemas/demo_invalid.yml
114114
+-------+------------------+--------------+----------------------------------------------------------------------+
115-
| Line | id:Column | Rule | Message |
115+
| Line | id:Column | Rule | Message |
116116
+-------+------------------+--------------+----------------------------------------------------------------------+
117117
| undef | 2:Float | is_float | Value "Qwerty" is not a float number |
118118
| undef | 4:Favorite color | allow_values | Value "123" is not allowed. Allowed values: ["red", "green", "Blue"] |
@@ -124,19 +124,19 @@ public function testValidateOneCsvWithInvalidSchemaNegative(): void
124124
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
125125
| Line | id:Column | Rule | Message |
126126
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
127-
| 1 | | allow_extra_columns | Column(s) not found in CSV: "wrong_column_name" |
128-
| 6 | 0:Name | length_min | The length of the value "Carl" is 4, which is less than the expected "5" |
129-
| 11 | 0:Name | length_min | The length of the value "Lois" is 4, which is less than the expected "5" |
130-
| 1 | 1:City | ag:is_unique | Column has non-unique values. Unique: 9, total: 10 |
131-
| 2 | 2:Float | num_max | The value "4825.185" is greater than the expected "4825.184" |
132-
| 1 | 2:Float | ag:nth_num | The N-th value in the column is "74", which is not equal than the expected "0.001" |
133-
| 6 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
127+
| 1 | | allow_extra_columns | Column(s) not found in CSV: "wrong_column_name" |
128+
| 6 | 0:Name | length_min | The length of the value "Carl" is 4, which is less than the expected "5" |
129+
| 11 | 0:Name | length_min | The length of the value "Lois" is 4, which is less than the expected "5" |
130+
| 1 | 1:City | ag:is_unique | Column has non-unique values. Unique: 9, total: 10 |
131+
| 2 | 2:Float | num_max | The value "4825.185" is greater than the expected "4825.184" |
132+
| 1 | 2:Float | ag:nth_num | The N-th value in the column is "74", which is not equal than the expected "0.001" |
133+
| 6 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
134134
| | | | expected "1955-05-15 00:00:00 +00:00 (1955-05-15)" |
135-
| 8 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
135+
| 8 | 3:Birthday | date_min | The date of the value "1955-05-14" is parsed as "1955-05-14 00:00:00 +00:00", which is less than the |
136136
| | | | expected "1955-05-15 00:00:00 +00:00 (1955-05-15)" |
137-
| 9 | 3:Birthday | date_max | The date of the value "2010-07-20" is parsed as "2010-07-20 00:00:00 +00:00", which is greater than |
137+
| 9 | 3:Birthday | date_max | The date of the value "2010-07-20" is parsed as "2010-07-20 00:00:00 +00:00", which is greater than |
138138
| | | | the expected "2009-01-01 00:00:00 +00:00 (2009-01-01)" |
139-
| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", "green", "Blue"] |
139+
| 5 | 4:Favorite color | allow_values | Value "blue" is not allowed. Allowed values: ["red", "green", "Blue"] |
140140
+------+------------------+---------------------+------------------------------------------------------------------------------------------------------+
141141
142142
Summary:
@@ -171,7 +171,7 @@ public function testInvalidSchemaNotMatched(): void
171171
Check schema syntax: 1
172172
8 issues in ./tests/schemas/invalid_schema.yml
173173
+-------+------------+--------+-------------------------------------------------------------------------+
174-
| Line | id:Column | Rule | Message |
174+
| Line | id:Column | Rule | Message |
175175
+-------+------------+--------+-------------------------------------------------------------------------+
176176
| undef | meta | schema | Unknown key: .unknow_root_option |
177177
| undef | meta | schema | Unknown key: .csv.unknow_csv_param |
@@ -219,7 +219,7 @@ public function testInvalidSchemaAndNotFoundCSV(): void
219219
Check schema syntax: 1
220220
8 issues in ./tests/schemas/invalid_schema.yml
221221
+-------+------------+--------+-------------------------------------------------------------------------+
222-
| Line | id:Column | Rule | Message |
222+
| Line | id:Column | Rule | Message |
223223
+-------+------------+--------+-------------------------------------------------------------------------+
224224
| undef | meta | schema | Unknown key: .unknow_root_option |
225225
| undef | meta | schema | Unknown key: .csv.unknow_csv_param |
@@ -269,8 +269,8 @@ public function testValidateOneCsvNoHeaderNegative(): void
269269
+------+-----------+------------------+------------------------------+
270270
| Line | id:Column | Rule | Message |
271271
+------+-----------+------------------+------------------------------+
272-
| 2 | 0: | not_allow_values | Value "Clyde" is not allowed |
273-
| 5 | 2: | not_allow_values | Value "74" is not allowed |
272+
| 2 | 0: | not_allow_values | Value "Clyde" is not allowed |
273+
| 5 | 2: | not_allow_values | Value "74" is not allowed |
274274
+------+-----------+------------------+------------------------------+
275275
276276
Summary:

0 commit comments

Comments
 (0)