Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ break_before_table_rb: true
chop_down_table: false
chop_down_kv_table: true
table_sep: ","
column_table_limit: column_limit
Copy link
Owner

Choose a reason for hiding this comment

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

The default value of column_table_limit is not a reference to column_limit .
Consider this config file:

column_limit: 120

The value of column_table_limit is 80, not 120.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I figured it out.
I fixed it by checking the config file and updating its value with column_limit .

extra_sep_at_table_end: false
break_after_operator: true
double_quote_to_single_quote: false
Expand Down
42 changes: 42 additions & 0 deletions docs/Style-Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,48 @@ x = {
k3 = v3, k4 = v4
}
```
### column_table_limit

type: int, default: column_limit

The column limit of each line of a table. Default value the same as column_limit value.

```lua
Copy link
Contributor

Choose a reason for hiding this comment

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

Change the examples to something like:

column_table_limit: column_limit
[...]
column_table_limit: 20
[...]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

--column_table_limit: column_limit
test = {
image = "test",
list = {
{
ref = "testRef",
tags = {"tagTest"},
time = 10,

materials = {{materialId = 123, count = 10}}
}
}
}

--column_table_limit: 20
test = {
image = "test",
list = {
{
ref = "testRef",
tags = {
"tagTest"
},
time = 10,

materials = {
{
materialId = 123,
count = 10
}
}
}
}
}
```

### table_sep

Expand Down
10 changes: 10 additions & 0 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Config::Config() {
node_["chop_down_kv_table"] = true;
node_["table_sep"] = ",";
node_["extra_sep_at_table_end"] = false;
node_["column_table_limit"] = node_["column_limit"];

node_["break_after_operator"] = true;

Expand All @@ -59,11 +60,20 @@ void Config::readFromFile(const string& file) {
YAML::Node n = YAML::LoadFile(file);

// Keys are always strings
bool given = false;
string CTL = "column_table_limit";
string CL = "column_limit";
for (auto kv : n) {
auto key = kv.first.as<string>();
if (node_[key]) {
node_[key] = kv.second;
}
if (key == CTL) {
given = true;
}
}
if (!given) {
node_[CTL] = node_[CL];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/FormatVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ antlrcpp::Any FormatVisitor::visitTableconstructor(LuaParser::TableconstructorCo
int length = cur_writer().firstLineColumn();
int lines = cur_writer().lines();
popWriter();
beyondLimit = cur_columns() + length > config_.get<int>("column_limit") || lines > 1;
beyondLimit = cur_columns() + length > config_.get<int>("column_table_limit") || lines > 1;
}
bool breakAfterLb = false;
if (beyondLimit) {
Expand Down Expand Up @@ -1570,7 +1570,7 @@ antlrcpp::Any FormatVisitor::visitFieldlist(LuaParser::FieldlistContext* ctx) {
int length = cur_writer().firstLineColumn();
popWriter();
if (i != n - 1 || config_.get<bool>("extra_sep_at_table_end")) length++; // calc a ',' if exp >1
beyondLimit = cur_columns() + length > config_.get<int>("column_limit");
beyondLimit = cur_columns() + length > config_.get<int>("column_table_limit");
if (beyondLimit) {
if (config_.get<bool>("align_table_field")) {
cur_writer() << commentAfterNewLine(ctx->fieldsep()[i - 1], NONE_INDENT);
Expand Down
11 changes: 11 additions & 0 deletions test/test_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ TEST_CASE("table", "config") {
config.set("break_after_table_lb", false);
config.set("break_before_table_rb", false);
REQUIRE("x = {1, 2, 3,\n 4, 5, 6, 7}\n" == lua_format("x = {1,2,3,4,5,6,7}", config));

config.set("column_limit", 250);
config.set("indent_width", 2);
config.set("tab_width", 2);
config.set("continuation_indent_width", 2);
config.set("chop_down_table", true);
config.set("chop_down_kv_table", true);
config.set("column_table_limit", 80);

REQUIRE("test = {\n image = {1, 2, 3},\n list = {\n {\n ref = {4, 5, 9, 8, 2},\n tags = {1, 2, 8, 6},\n time = 10,\n\n materials = {{materialId = 123, count = 10}}\n }\n }\n}\n" ==
lua_format("test = {\n image = {1,2,3},\n list = {\n {\n ref = {4,5,9,8,2},\n tags = { 1, 2, 8, 6 },\n time = 10,\n\n materials = {\n {\n materialId = 123,\n count = 10\n }\n },\n },\n },\n}", config));
}

TEST_CASE("break_after_operator", "config") {
Expand Down
3 changes: 3 additions & 0 deletions test/test_format_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-62_1.lua");
TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-62_2.lua");
TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-62_3.lua");
TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-70.lua");
TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-98.lua");
TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-98_1.lua");
TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-80.lua");


TEST_FILE(PROJECT_PATH "/test/testdata/keep_simple_block_one_line/default.lua");
TEST_FILE(PROJECT_PATH "/test/testdata/keep_simple_block_one_line/keep_simple_function_one_line_false.lua");
TEST_FILE(PROJECT_PATH "/test/testdata/keep_simple_block_one_line/keep_simple_control_block_one_line_false.lua");
Expand Down
12 changes: 12 additions & 0 deletions test/testdata/issues/_issue-98.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test = {
image = "test",
list = {
{
ref = "testRef",
tags = {"tagTest"},
time = 10,

materials = {{materialId = 123, count = 10}}
}
}
}
14 changes: 14 additions & 0 deletions test/testdata/issues/_issue-98_1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
test = {
image = "test",
list = {
{
ref = "testRef",
tags = {"tagTest"},
time = 10,

materials = {
{materialId = 123, count = 10}
}
}
}
}
7 changes: 7 additions & 0 deletions test/testdata/issues/issue-98.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
column_limit: 250
indent_width: 2
tab_width: 2
continuation_indent_width: 2
chop_down_table: true
chop_down_kv_table: true
column_table_limit: 80
17 changes: 17 additions & 0 deletions test/testdata/issues/issue-98.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test = {
image = "test",
list = {
{
ref = "testRef",
tags = { "tagTest" },
time = 10,

materials = {
{
materialId = 123,
count = 10
}
},
},
},
}
7 changes: 7 additions & 0 deletions test/testdata/issues/issue-98_1.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
column_limit: 250
indent_width: 2
tab_width: 2
continuation_indent_width: 2
chop_down_table: true
chop_down_kv_table: true
column_table_limit: 40
17 changes: 17 additions & 0 deletions test/testdata/issues/issue-98_1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
test = {
image = "test",
list = {
{
ref = "testRef",
tags = { "tagTest" },
time = 10,

materials = {
{
materialId = 123,
count = 10
}
},
},
},
}