feat(wrapperModulers.stylua): init#569
Conversation
MacaylaMarvelous81
left a comment
There was a problem hiding this comment.
Works well! It's possible that users might want to use a different path than bin/cp_stylua_toml for the copy script, such as if they want to use a different name, so I suggest an option to easily customize that. Maybe something like cpScript.enable and cpScript.path?
I also think a check that tests the program functionality might be useful so that breakage from future changes are not silent.
Imperative test process
[jomarm@dell-inspiron7773:~/nix-wrapper-modules]$ echo "print 'ugly and bad but or and good'"
> test.lua
[jomarm@dell-inspiron7773:~/nix-wrapper-modules]$ nix-shell -p '(import ./. {}).wrappers.stylua.wrap { pkgs = import <nixpkgs> {}; customStyle = { call_parentheses = "None"; quote_style = "AutoPreferSingle"; }; }' --command 'stylua -c test.lua'
[jomarm@dell-inspiron7773:~/nix-wrapper-modules]$ echo $?
0
[jomarm@dell-inspiron7773:~/nix-wrapper-modules]$ nix-shell -p '(import ./. {}).wrappers.stylua.wrap { pkgs = import <nixpkgs> {}; }' --command 'stylua -c test.lua' Diff in test.lua:
1 |-print 'ugly and bad but or and good'
1 |+print("ugly and bad but or and good")
[jomarm@dell-inspiron7773:~/nix-wrapper-modules]$ nix-shell -p '(import ./. {}).wrappers.stylua.wrap { pkgs = import <nixpkgs> {}; customStyle = { call_parentheses = "None"; quote_style = "AutoPreferSingle"; }; generateCpScript = true; }' --command 'cp_stylua_toml' && cat stylua.toml
this derivation will be built:
/nix/store/imkcpm20j9sqmiqvac00p9gq8mkhcd6p-stylua-2.5.2.drv
building '/nix/store/imkcpm20j9sqmiqvac00p9gq8mkhcd6p-stylua-2.5.2.drv'...
/nix/store/8y5ars30x2axzqjwdhg2364sg9gb7kz5-stylua-2.5.2/bin:
stylua: File exists
Patching self-references in specified files...
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: buildPhase
Running phase: installPhase
block_newline_gaps = "Never"
call_parentheses = "None"
collapse_simple_statement = "Never"
column_width = 120
indent_type = "Tabs"
indent_width = 4
line_endings = "Unix"
quote_style = "AutoPreferSingle"
space_after_function_names = "Never"
syntax = "All"
[sort_requires]
enabled = false| defaultStyle = lib.mkOption { | ||
| type = lib.types.attrs; | ||
| readOnly = true; | ||
| description = '' | ||
| Default settings for the `stylua.toml` (read only). | ||
| ''; | ||
| default = { | ||
| syntax = "All"; | ||
| column_width = 120; | ||
| line_endings = "Unix"; | ||
| indent_type = "Tabs"; | ||
| indent_width = 4; | ||
| quote_style = "AutoPreferDouble"; | ||
| call_parentheses = "Always"; | ||
| collapse_simple_statement = "Never"; | ||
| space_after_function_names = "Never"; | ||
| block_newline_gaps = "Never"; | ||
| sort_requires = { | ||
| enabled = false; | ||
| }; | ||
| }; | ||
| }; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
My consideration was letting people copy default style to the project they are working on so that they can easily customize it without memorizing all possible options. config.customStyle will deeply merge with it so the customized style file also include the default settings. It is an issue that if the upstream changes defaults somehow. Do you think it is better to remove the defaultStyle here and only left the customStyle?
There was a problem hiding this comment.
In my opinion it makes sense for users to review the documentation for their version, but including the default values here is fine as well. It is probably unlikely that something causes the default style in this module to diverge from upstream's values since that would affect people who depend on default behavior.
There was a problem hiding this comment.
Yes,it unlikely changes.
I'm lazy that I don't want to check the doc everytime I want to customize. I will remove the defaultStyle and update the description of customStyle about how to find the doc easily. Or I can update the script to print some information about the doc since stylua provides it.
I will check and update the wrapper, and add the check.nix as well.
This PR add a wrapper for stylua.
It mainly used to configure the style of the stylua. You can add nix expression of the configuration and it will generate the stylua.toml file for you. Additionally, you can enable the wrapper to generate a copy script which copy the generated configuration file into CWD in case people want to customize individual style or want to include it into the repo.