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; | ||
| }; | ||
| }; | ||
| }; |
There was a problem hiding this comment.
Have you considered using stylua's behavior with unspecified options rather than specifying the default options here? It would be strange if upstream does something like change a default value and that change is not reflected with a wrapped stylua.
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.
|
That is a good advice and a good practice I should keep.
|
MacaylaMarvelous81
left a comment
There was a problem hiding this comment.
Test run on x86_64-linux (success)
[jomarm@dell-inspiron7773:~/nix-wrapper-modules]$ nix-build --arg pkgs 'import <nixpkgs> {}' --arg self 'import ./. {}' --arg tlib '(import <nixpkgs> {}).callPackage ./ci/test-lib.nix { self = import ./. {}; }' wrapperModules/s/stylua/check.nix
these 6 derivations will be built:
/nix/store/jh5yw0g9zaq09n4z2d625jsm28v74nap-stylua-2.5.2.drv
/nix/store/knjrymdkj5kmq8mixai1l5i26ww9w18n-stylua-2.5.2.drv
/nix/store/l9ymi7gc05c3bpqbmdabfxy22phli3jw-stylua-2.5.2.drv
/nix/store/rjys6hz4y4fyriffvg01n0bsbifyfy25-stylua-2.5.2.drv
/nix/store/y0f336s8admwbm59fahcnnw1qyl9b06d-stylua-2.5.2.drv
/nix/store/hsmimpzv2d4k6cr9h28s93v3hpp6vjsb-stylua-test.drv
these 11 paths will be fetched (2.9 MiB download, 12.8 MiB unpacked):
/nix/store/l22fp7vhwvf6zvhk3mf7wmra6llb1pv7-python3.13-colorama-0.4.6
/nix/store/mclvsxxbggf9v0lh98jpw8n79apb56v8-python3.13-remarshal-1.3.0
/nix/store/7szlv37z4k1dz4b57h6hjkpv3rgxzbv1-python3.13-rich-argparse-1.7.2
/nix/store/grx6892wf0s7dw1kjx3librplg1cgw06-python3.13-ruamel-base-1.0.0
/nix/store/qa0cja0wgm7408k8z4bj84bx12scnpip-python3.13-ruamel-yaml-0.19.1
/nix/store/jmmdz0vkj4cphlyf6y7gdngm5hfhwisl-python3.13-ruamel-yaml-clib-0.2.15
/nix/store/07nsvnamhq2xpn0zixw2xbvizs43sj71-python3.13-tomli-2.4.0
/nix/store/rahjag01h0a9dmi3iljk7y60aal13iyq-python3.13-tomlkit-0.14.0
/nix/store/12gwm2lik7f59iyan5m7bh5ygpfv8664-python3.13-u-msgpack-python-2.8.0
/nix/store/pr27j8nm0xl52pq4ylncj9kwjw3b84mk-stdenv-linux
/nix/store/8y5ars30x2axzqjwdhg2364sg9gb7kz5-stylua-2.5.2
copying path '/nix/store/pr27j8nm0xl52pq4ylncj9kwjw3b84mk-stdenv-linux' from 'https://cache.nixos.org'...
copying path '/nix/store/8y5ars30x2axzqjwdhg2364sg9gb7kz5-stylua-2.5.2' from 'https://cache.nixos.org'...
copying path '/nix/store/rahjag01h0a9dmi3iljk7y60aal13iyq-python3.13-tomlkit-0.14.0' from 'https://cache.nixos.org'...
copying path '/nix/store/jmmdz0vkj4cphlyf6y7gdngm5hfhwisl-python3.13-ruamel-yaml-clib-0.2.15' from 'https://cache.nixos.org'...
copying path '/nix/store/l22fp7vhwvf6zvhk3mf7wmra6llb1pv7-python3.13-colorama-0.4.6' from 'https://cache.nixos.org'...
copying path '/nix/store/7szlv37z4k1dz4b57h6hjkpv3rgxzbv1-python3.13-rich-argparse-1.7.2' from 'https://cache.nixos.org'...
copying path '/nix/store/07nsvnamhq2xpn0zixw2xbvizs43sj71-python3.13-tomli-2.4.0' from 'https://cache.nixos.org'...
copying path '/nix/store/12gwm2lik7f59iyan5m7bh5ygpfv8664-python3.13-u-msgpack-python-2.8.0' from 'https://cache.nixos.org'...
copying path '/nix/store/grx6892wf0s7dw1kjx3librplg1cgw06-python3.13-ruamel-base-1.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/qa0cja0wgm7408k8z4bj84bx12scnpip-python3.13-ruamel-yaml-0.19.1' from 'https://cache.nixos.org'...
copying path '/nix/store/mclvsxxbggf9v0lh98jpw8n79apb56v8-python3.13-remarshal-1.3.0' from 'https://cache.nixos.org'...
building '/nix/store/jh5yw0g9zaq09n4z2d625jsm28v74nap-stylua-2.5.2.drv'...
building '/nix/store/knjrymdkj5kmq8mixai1l5i26ww9w18n-stylua-2.5.2.drv'...
building '/nix/store/l9ymi7gc05c3bpqbmdabfxy22phli3jw-stylua-2.5.2.drv'...
building '/nix/store/rjys6hz4y4fyriffvg01n0bsbifyfy25-stylua-2.5.2.drv'...
building '/nix/store/y0f336s8admwbm59fahcnnw1qyl9b06d-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
/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
/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
/nix/store/8y5ars30x2axzqjwdhg2364sg9gb7kz5-stylua-2.5.2/bin:
stylua: File exists
Patching self-references in specified files...
Running phase: updateAutotoolsGnuConfigScriptsPhase
/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: buildPhase
Running phase: installPhase
Running phase: installPhase
building '/nix/store/hsmimpzv2d4k6cr9h28s93v3hpp6vjsb-stylua-test.drv'...
call_parentheses = "None"
column_width = 100
quote_style = "ForceSingle"
You have not generated stylua.toml. You can use -i|--add-doc option to add a stylua.toml with only documentation included.
# Enable requires sorting [enabled = true|false]
quote_style = "ForceSingle"
cp_stylua_toml [-h|--help|-i|--add-doc]
-i|--add-doc Add the configuration doccumentation to the end of the stylua.toml
cp_stylua_toml [-h|--help|-i|--add-doc]
-i|--add-doc Add the configuration doccumentation to the end of the stylua.toml
# Enable requires sorting [enabled = true|false]
# Enable requires sorting [enabled = true|false]
/nix/store/n4vwp561brcbbcka1zg8c45ccdr1dccl-stylua-test
This looks good. Thanks for working with me!
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.