Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format Lua files #3819

Merged
merged 3 commits into from
Dec 6, 2023

Conversation

scarf005
Copy link
Member

@scarf005 scarf005 commented Dec 4, 2023

Purpose of change

Using formatter improves readability and diff output.

Describe the solution

use https://github.com/RubixDev/dprint-plugin-stylua to format Lua files.

Why dprint?

  • compatibility: being written in WASM, plugins are cross-platform and works on browser.
  • low friction: deno uses dprint internally, so it's easy to migrate in the future.
  • unification: in the future, we'd be able to format JSON, markdown, typescript, Lua, C++ files with
    • dprint VSCode extension
    • deno task dprint fmt

Alternatives

migrate formatting ecosystem to use dprint with its configuration set to match with deno.

Additional Context

followup task for #3165

we choose to use dprint because:
- its plugin system is useful when unifying formatters
- deno uses dprint internally, thus less migration debt
- lua IDE formatter is hard to set up
@github-actions github-actions bot added docs PRs releated to docs page JSON related to game datas in JSON format. tests changes related to tests mods PR changes related to mods. labels Dec 4, 2023
Copy link
Member

@chaosvolt chaosvolt left a comment

Choose a reason for hiding this comment

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

I'm really not qualified to review this since zero LUA experience but Scarf kept pestering me to do so in the discord, so uh. This looks like a relevant error in the check failure log:

Log:
(~[slow] ~[.],starting_items)=> -------------------------------------------------------------------------------
(~[slow] ~[.],starting_items)=> lua_runtime_error
(~[slow] ~[.],starting_items)=> -------------------------------------------------------------------------------
(~[slow] ~[.],starting_items)=> /home/runner/work/Cataclysm-BN/Cataclysm-BN/tests/catalua_test.cpp:121
(~[slow] ~[.],starting_items)=> ...............................................................................
(~[slow] ~[.],starting_items)=> 
(~[slow] ~[.],starting_items)=> /home/runner/work/Cataclysm-BN/Cataclysm-BN/tests/catalua_test.cpp:134: FAILED:
(~[slow] ~[.],starting_items)=>   REQUIRE_THROWS_MATCHES( run_lua_test_script( lua, "runtime_error.lua" ), std::runtime_error, Catch::Message( expected ) )
(~[slow] ~[.],starting_items)=> with expansion:
(~[slow] ~[.],starting_items)=>   Script runtime error in tests/lua/runtime_error.lua: tests/lua/runtime_error.
(~[slow] ~[.],starting_items)=>   lua:2: attempt to index a nil value (global 'table_with_typo')
(~[slow] ~[.],starting_items)=>   stack traceback:
(~[slow] ~[.],starting_items)=>   	tests/lua/runtime_error.lua:2: in main chunk exception message matches
(~[slow] ~[.],starting_items)=>   "Script runtime error in tests/lua/runtime_error.lua: tests/lua/
(~[slow] ~[.],starting_items)=>   runtime_error.lua:3: attempt to index a nil value (global 'table_with_typo')
(~[slow] ~[.],starting_items)=>   stack traceback:
(~[slow] ~[.],starting_items)=>   	tests/lua/runtime_error.lua:3: in main chunk"
(~[slow] ~[.],starting_items)=> 
(~[slow] ~[.],starting_items)=> -------------------------------------------------------------------------------
(~[slow] ~[.],starting_items)=> lua_called_error_on_lua_side
(~[slow] ~[.],starting_items)=> -------------------------------------------------------------------------------
(~[slow] ~[.],starting_items)=> /home/runner/work/Cataclysm-BN/Cataclysm-BN/tests/catalua_test.cpp:141
(~[slow] ~[.],starting_items)=> ...............................................................................
(~[slow] ~[.],starting_items)=> 
(~[slow] ~[.],starting_items)=> /home/runner/work/Cataclysm-BN/Cataclysm-BN/tests/catalua_test.cpp:155: FAILED:
(~[slow] ~[.],starting_items)=>   REQUIRE_THROWS_MATCHES( run_lua_test_script( lua, "called_error_on_lua_side.lua" ), std::runtime_error, Catch::Message( expected ) )
(~[slow] ~[.],starting_items)=> with expansion:
(~[slow] ~[.],starting_items)=>   Script runtime error in tests/lua/called_error_on_lua_side.lua: tests/lua/
(~[slow] ~[.],starting_items)=>   called_error_on_lua_side.lua:2: Error called on Lua side!
(~[slow] ~[.],starting_items)=>   stack traceback:
(~[slow] ~[.],starting_items)=>   	[C]: in function 'base.error'
(~[slow] ~[.],starting_items)=>   	tests/lua/called_error_on_lua_side.lua:2: in main chunk exception message
(~[slow] ~[.],starting_items)=>   matches "Script runtime error in tests/lua/called_error_on_lua_side.lua:
(~[slow] ~[.],starting_items)=>   tests/lua/called_error_on_lua_side.lua:3: Error called on Lua side!
(~[slow] ~[.],starting_items)=>   stack traceback:
(~[slow] ~[.],starting_items)=>   	[C]: in function 'base.error'
(~[slow] ~[.],starting_items)=>   	tests/lua/called_error_on_lua_side.lua:3: in main chunk"
(~[slow] ~[.],starting_items)=> 
(~[slow] ~[.],starting_items)=> -------------------------------------------------------------------------------
(~[slow] ~[.],starting_items)=> lua_called_error_on_cpp_side
(~[slow] ~[.],starting_items)=> -------------------------------------------------------------------------------
(~[slow] ~[.],starting_items)=> /home/runner/work/Cataclysm-BN/Cataclysm-BN/tests/catalua_test.cpp:167
(~[slow] ~[.],starting_items)=> ...............................................................................
(~[slow] ~[.],starting_items)=> 
(~[slow] ~[.],starting_items)=> /home/runner/work/Cataclysm-BN/Cataclysm-BN/tests/catalua_test.cpp:183: FAILED:
(~[slow] ~[.],starting_items)=>   REQUIRE_THROWS_MATCHES( run_lua_test_script( lua, "called_error_on_cpp_side.lua" ), std::runtime_error, Catch::Message( expected ) )
(~[slow] ~[.],starting_items)=> with expansion:
(~[slow] ~[.],starting_items)=>   Script runtime error in tests/lua/called_error_on_cpp_side.lua: tests/lua/
(~[slow] ~[.],starting_items)=>   called_error_on_cpp_side.lua:2: Error called on Cpp side!
(~[slow] ~[.],starting_items)=>   stack traceback:
(~[slow] ~[.],starting_items)=>   	[C]: in function 'base.cpp_call_error'
(~[slow] ~[.],starting_items)=>   	tests/lua/called_error_on_cpp_side.lua:2: in main chunk exception message
(~[slow] ~[.],starting_items)=>   matches "Script runtime error in tests/lua/called_error_on_cpp_side.lua:
(~[slow] ~[.],starting_items)=>   tests/lua/called_error_on_cpp_side.lua:3: Error called on Cpp side!
(~[slow] ~[.],starting_items)=>   stack traceback:
(~[slow] ~[.],starting_items)=>   	[C]: in function 'base.cpp_call_error'
(~[slow] ~[.],starting_items)=>   	tests/lua/called_error_on_cpp_side.lua:3: in main chunk"
(~[slow] ~[.],starting_items)=> 
(~[slow] ~[.],starting_items)=> [sol2] An exception occurred: Exception thrown on Cpp side!
(~[slow] ~[.],starting_items)=> -------------------------------------------------------------------------------
(~[slow] ~[.],starting_items)=> lua_called_cpp_func_throws
(~[slow] ~[.],starting_items)=> -------------------------------------------------------------------------------
(~[slow] ~[.],starting_items)=> /home/runner/work/Cataclysm-BN/Cataclysm-BN/tests/catalua_test.cpp:196
(~[slow] ~[.],starting_items)=> ...............................................................................
(~[slow] ~[.],starting_items)=> 
(~[slow] ~[.],starting_items)=> /home/runner/work/Cataclysm-BN/Cataclysm-BN/tests/catalua_test.cpp:212: FAILED:
(~[slow] ~[.],starting_items)=>   REQUIRE_THROWS_MATCHES( run_lua_test_script( lua, "called_cpp_func_throws.lua" ), std::runtime_error, Catch::Message( expected ) )
(~[slow] ~[.],starting_items)=> with expansion:
(~[slow] ~[.],starting_items)=>   Script runtime error in tests/lua/called_cpp_func_throws.lua: Exception
(~[slow] ~[.],starting_items)=>   thrown on Cpp side!
(~[slow] ~[.],starting_items)=>   stack traceback:
(~[slow] ~[.],starting_items)=>   	[C]: in function 'base.cpp_throw_exception'
(~[slow] ~[.],starting_items)=>   	tests/lua/called_cpp_func_throws.lua:2: in main chunk exception message

@scarf005
Copy link
Member Author

scarf005 commented Dec 6, 2023

...right, because the code is formatted the errors are also formatted, so i need to change the tests as well.

@scarf005
Copy link
Member Author

scarf005 commented Dec 6, 2023

alright, local tests pass this time.
image

Copy link
Member

@chaosvolt chaosvolt left a comment

Choose a reason for hiding this comment

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

In that case, yeet.

@scarf005 scarf005 added this pull request to the merge queue Dec 6, 2023
Merged via the queue into cataclysmbnteam:upload with commit f3d7db3 Dec 6, 2023
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs PRs releated to docs page JSON related to game datas in JSON format. mods PR changes related to mods. tests changes related to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants