Skip to content

reformatted lua files with StyLua#9

Merged
aaronik merged 3 commits intoaaronik:mainfrom
rcampos2029:format
May 13, 2025
Merged

reformatted lua files with StyLua#9
aaronik merged 3 commits intoaaronik:mainfrom
rcampos2029:format

Conversation

@rcampos2029
Copy link
Copy Markdown
Contributor

It would improve the readability of the code if there were consistent formatting across all lua files. StyLua was used to meet this need.

@aaronik
Copy link
Copy Markdown
Owner

aaronik commented May 11, 2025

This is fine, but I ask two things:

  1. I'm not really down with 8 spaces per indent level. Can you please change it to 2, or at most 4
  2. The tests need to keep passing

If those two check out I'm happy to merge.

Thanks for the PR!

@rcampos2029
Copy link
Copy Markdown
Contributor Author

  1. I'm not really down with 8 spaces per indent level. Can you please change it to 2, or at most 4

Stylua uses 1 tab per indent level by default. This may be rendered as 8 spaces on your neovim setup if you have kept the tabstop variable in its default value of 8. The following command would make the tabs appear smaller:

:set ts=2

I prefer tabs for this reason, as the amount of whitespace in which the tab is rendered is an editor-specific setting. I personally keep ts=4 as this is enough for me to see the block separation easier.

However, I am fine using any number of spaces, if that is what you would prefer. I've added a configuration file, stylua.toml, which stylua automatically uses for its formatting and we can codify the desired format:

indent_type = "Spaces"
indent_width = 2

Please let me know if there's any other modifications to stylua.toml that you would like (column width, quote-style, etc.)! ^_^

@aaronik
Copy link
Copy Markdown
Owner

aaronik commented May 12, 2025

Ok almost there - can you also add a rule into the existing CI workflow, similar to the luacheck rule

@rcampos2029
Copy link
Copy Markdown
Contributor Author

rcampos2029 commented May 12, 2025

wrt:

  1. The tests need to keep passing

I believe this test is failing due to a race condition. I ran this locally multiple times and only received the error occasionally. Based on the implementation in cmd.lua, I think that done is being set to true before the on_read function completes. This could be avoided with the following change:

  if args.onread then
    uv.read_start(stdout, function(err, data)
      args.onread(err, data)
      stdout_done = true
    end)
    uv.read_start(stderr, function(_, err)
      args.onread(err, nil)
      stderr_done = true
    end)
  end

  local is_done = function()
    if args.onread then
      return done and stdout_done and stderr_done
    end
    return done
  end

I could make a commit in this pr, unless a follow-up would be better?

Calling `make fmt` will run stylua against the code in the lua
directory.
@aaronik
Copy link
Copy Markdown
Owner

aaronik commented May 12, 2025

I believe this test is failing due to a race condition.

Oh snap I didn't know there was an actual failure in the test suite - don't feel obligated to fix that if it's unrelated to this. Honestly that whole module should die - there are probably neovim primitives now that do that just fine.

For the CI, stylelua needs to be installed before it'll pass

@rcampos2029
Copy link
Copy Markdown
Contributor Author

rcampos2029 commented May 12, 2025

s
Run make check-fmt
stylua --check lua/
make: stylua: No such file or directory
make: *** [Makefile:33: check-fmt] Error [1](https://github.com/aaronik/GPTModels.nvim/actions/runs/14982465509/job/42090988824#step:10:1)27
Error: Process completed with exit code 2.

Hm, I thought adding that clause to the pre-commit config would've done it...
I can install via apt-get instead

Edit: nvm I misunderstood this mechanism.

@aaronik aaronik merged commit f1c0e02 into aaronik:main May 13, 2025
1 check passed
@aaronik
Copy link
Copy Markdown
Owner

aaronik commented May 13, 2025

Awesome, merged. Thank you!

Any interest in doing the same for my other plugin, Treewalker.nvim?

@rcampos2029
Copy link
Copy Markdown
Contributor Author

Awesome, merged. Thank you!

Any interest in doing the same for my other plugin, Treewalker.nvim?

I never heard of this plugin before but I'm immediately finding it to be super useful! Especially for large yamls. I'd be happy to contribute to it.

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.

2 participants