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

ci: consistently enforce Lua coding style #1029

Merged
merged 2 commits into from
May 15, 2024

Conversation

mikavilpas
Copy link
Contributor

This commit adds a GitHub Actions workflow that checks the lua files against the yazi lua coding style.

The workflow uses the stylua tool, which can be installed using cargo:

cargo install stylua --features lua54

I picked the options for the formatter in a way that forced minimal changes to the existing style.

https://github.com/JohnnyMorganz/StyLua?tab=readme-ov-file#options

@mikavilpas
Copy link
Contributor Author

Hmm, looks like lua 5.4 is not picked up correctly. I will investigate.

@mikavilpas
Copy link
Contributor Author

The formatting is failing because, as I have now learned, stylua does not support ::continue:: because it can't decide whether it's a jump label or a luau type cast operator (https://create.roblox.com/docs/luau/type-checking#type-casts)

This can be solved (at least) the following ways:

  1. yazi developers need to install (and use) a stylua version that does not include luau features built in
  2. lua code using labels can be refactored to not use them to work around this
  3. lua files using labels can be ignored from stylua
  4. yazi can have a breaking change and start to use a lua version that's better supported in stylua (this is a bit drastic but listing for completeness)
  5. another formatter can be taken into use instead with hopefully better support
  6. autoformatting can simply not be implemented at all
  7. autoformatting can be implemented on a "best effort" basis: simply let it fail for some files, and don't require autoformatting in CI (can still help ensure consistency)

What would you prefer? My favorite options are 2, 7, and 3.

@sxyazi
Copy link
Owner

sxyazi commented May 14, 2024

I think we can simply ignore it, i.e. ./yazi-plugin/preset/plugins/mime.lua

.github/workflows/check.yml Outdated Show resolved Hide resolved
stylua.toml Outdated Show resolved Hide resolved
This commit adds a GitHub Actions workflow that checks the lua files
against the yazi lua coding style.

The workflow uses the `stylua` tool, which can be installed using cargo:

```sh
cargo install stylua --features lua54
```

I picked the options for the formatter in a way that forced minimal
changes to the existing style.

<https://github.com/JohnnyMorganz/StyLua?tab=readme-ov-file#options>

Update .github/workflows/check.yml

Co-authored-by: 三咲雅 · Misaki Masa <sxyazi@gmail.com>
@sxyazi sxyazi changed the title ci: consistently enforce the yazi lua coding style ci: consistently enforce Lua coding style May 15, 2024
Copy link
Owner

@sxyazi sxyazi left a comment

Choose a reason for hiding this comment

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

Thanks!

@sxyazi sxyazi merged commit f0108db into sxyazi:main May 15, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants