-
Notifications
You must be signed in to change notification settings - Fork 50
feat(wrapperModulers.stylua): init #569
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
Open
kuppo
wants to merge
8
commits into
BirdeeHub:main
Choose a base branch
from
kuppo:stylua
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+219
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9ed5585
feat(wrapperModulers.stylua): init
e638bd7
feat(wrapperModules.stylua): remove the defaultStyle option
04455cb
feat(wrapperModules.stylua): update the cp script
08de140
docs(wrapperModules.stylua): update doc
7737f00
style(wrapperModules.stylua): reformat the code a bit
4fb88ac
fix(wrapperModules.stylua): add condition to generate file
8a699a4
test(wrapperModules.stylua): add test for stylua wrapper
1fe53c8
style(wapperModules.stylua): format code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| { | ||
| pkgs, | ||
| self, | ||
| tlib, | ||
| ... | ||
| }: | ||
| let | ||
| inherit (tlib) | ||
| fileContains | ||
| isDirectory | ||
| isFile | ||
| notIsFile | ||
| areEqual | ||
| test | ||
| ; | ||
| in | ||
| test { wrapper = "stylua"; } { | ||
| "stylua wrapper test" = | ||
| let | ||
| default = self.wrappers.stylua.wrap { | ||
| inherit pkgs; | ||
| }; | ||
| styluaWrapper = default.wrap { | ||
| customStyle = { | ||
| call_parentheses = "Always"; | ||
| column_width = 100; | ||
| }; | ||
| }; | ||
| cpScriptWrapper = styluaWrapper.wrap { | ||
| generateCpScript = { | ||
| enable = true; | ||
| }; | ||
| }; | ||
| cpScriptNameWrapper = cpScriptWrapper.wrap { | ||
| generateCpScript = { | ||
| name = "./bin/test_script"; | ||
| }; | ||
| }; | ||
| styluaTomlContent = '' | ||
| call_parentheses = "Always" | ||
| column_width = 100 | ||
| ''; | ||
| in | ||
| [ | ||
| (isDirectory default) | ||
| (notIsFile "${default}/styles/stylua.toml") | ||
| (notIsFile "${default}/bin/cp_stylua_toml") | ||
|
|
||
| (isDirectory styluaWrapper) | ||
| (isFile "${styluaWrapper}/styles/stylua.toml") | ||
| (fileContains "${styluaWrapper}/styles/stylua.toml" "${styluaTomlContent}") | ||
| (notIsFile "${styluaWrapper}/bin/cp_stylua_toml") | ||
|
|
||
| (isDirectory cpScriptWrapper) | ||
| (isFile "${cpScriptWrapper}/styles/stylua.toml") | ||
| (fileContains "${cpScriptWrapper}/styles/stylua.toml" "${styluaTomlContent}") | ||
| (isFile "${cpScriptWrapper}/bin/cp_stylua_toml") | ||
| (fileContains "${cpScriptWrapper}/bin/cp_stylua_toml" "bin/sh") | ||
|
|
||
| (isDirectory cpScriptNameWrapper) | ||
| (isFile "${cpScriptNameWrapper}/styles/stylua.toml") | ||
| (fileContains "${cpScriptNameWrapper}/styles/stylua.toml" "${styluaTomlContent}") | ||
| (isFile "${cpScriptNameWrapper}/bin/test_script") | ||
| (fileContains "${cpScriptNameWrapper}/bin/test_script" "bin/sh") | ||
|
|
||
| # test the copy script | ||
| '' | ||
| cd /tmp && ${cpScriptNameWrapper}/bin/test_script && \ | ||
| [[ -e /tmp/stylua.toml ]] && [[ -w /tmp/stylua.toml ]] && \ | ||
| grep -i "always" /tmp/stylua.toml && rm -f /tmp/stylua.toml | ||
| '' | ||
|
|
||
| '' | ||
| ${cpScriptNameWrapper}/bin/test_script -h | | ||
| grep -i "add-doc" | ||
| '' | ||
|
|
||
| '' | ||
| ${cpScriptNameWrapper}/bin/test_script --help | | ||
| grep -i "add-doc" | ||
| '' | ||
|
|
||
| '' | ||
| cd /tmp && ${cpScriptNameWrapper}/bin/test_script -i && \ | ||
| [[ -e /tmp/stylua.toml ]] && [[ -w /tmp/stylua.toml ]] && \ | ||
| grep -i "formatting options" /tmp/stylua.toml && rm -f /tmp/stylua.toml | ||
| '' | ||
|
|
||
| '' | ||
| cd /tmp && ${cpScriptNameWrapper}/bin/test_script --add-doc && \ | ||
| [[ -e /tmp/stylua.toml ]] && [[ -w /tmp/stylua.toml ]] && \ | ||
| grep -i "formatting options" /tmp/stylua.toml && rm -f /tmp/stylua.toml | ||
| '' | ||
| ]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| { | ||
| wlib, | ||
| lib, | ||
| config, | ||
| pkgs, | ||
| ... | ||
| }: | ||
| { | ||
| imports = [ wlib.modules.default ]; | ||
|
|
||
| options = { | ||
| customStyle = lib.mkOption { | ||
| type = wlib.types.structuredValueWith { | ||
| nullable = false; | ||
| typeName = "TOML"; | ||
| }; | ||
| default = { }; | ||
| description = '' | ||
| nix configuration for the stylua. | ||
|
|
||
| Check [StyLua options](https://github.com/JohnnyMorganz/StyLua/blob/main/README.md#options). | ||
| ''; | ||
| example = lib.literalExpression '' | ||
| settings = { | ||
| call_parentheses = "Always"; | ||
| column_width = 100; | ||
| collapse_simple_statement = "Always"; | ||
| indent_type = "Spaces"; | ||
| indent_width = 2; | ||
| quote_style = "ForceDouble"; | ||
| sort_requires.enabled = true; | ||
| }; | ||
| ''; | ||
| }; | ||
| generateCpScript = lib.mkOption { | ||
| default = { }; | ||
| description = '' | ||
| Options for copy script which help you quickly copy your | ||
| settings into `$CWD` for further customization. | ||
|
|
||
| The script `cp_stylua_toml` (name is customizable) copys the generated | ||
| `stylua.toml` file into '$CWD' in case you want to include it in the | ||
| repo or customize it. | ||
|
|
||
| With the `-i|--add-doc` option, it will add the configuraiton | ||
| documentation to the end of the copied file. | ||
| ''; | ||
| type = lib.types.submodule { | ||
| options = { | ||
| enable = lib.mkEnableOption '' | ||
| generating a copy script. | ||
| ''; | ||
| name = lib.mkOption { | ||
| type = lib.types.str; | ||
| default = "cp_stylua_toml"; | ||
| description = '' | ||
| Customize the name of the copy script. If the name has `/` in it, | ||
| the wrapper will only take the file's base name. | ||
| ''; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
| }; | ||
| config = { | ||
| package = lib.mkDefault pkgs.stylua; | ||
| constructFiles.generatedConfig = lib.mkIf (config.customStyle != { }) { | ||
| content = builtins.toJSON config.customStyle; | ||
| relPath = "styles/stylua.toml"; | ||
| builder = ''${pkgs.remarshal}/bin/json2toml "$1" "$2"''; | ||
| }; | ||
| constructFiles."${baseNameOf config.generateCpScript.name}" = | ||
| lib.mkIf config.generateCpScript.enable | ||
| { | ||
| relPath = "bin/${baseNameOf config.generateCpScript.name}"; | ||
| builder = "cp $1 $2 && chmod +x $2"; | ||
| content = '' | ||
| #!${pkgs.bash}/bin/sh | ||
| help=$'cp_stylua_toml [-h|--help|-i|--add-doc]\nCopy stylua files.\nOptions:\n\t-h|--help\tPrint this help\n\t-i|--add-doc\tAdd the configuration doccumentation to the end of the stylua.toml' | ||
|
|
||
| target=$(pwd)/stylua.toml | ||
|
|
||
| doc=$(${placeholder config.outputName}/bin/stylua --help \ | ||
| | ${pkgs.gnused}/bin/sed -n \ | ||
| '/^FORMATTING OPTIONS:$/,$ {1d;s/^[[:space:]]*/ /;s/^[[:space:]]*--/** /;s/^/# /;p}') | ||
|
|
||
| if [ "$#" -ne 1 ]; then | ||
| cp -f ${placeholder config.outputName}/styles/stylua.toml $(pwd)/ \ | ||
| && chmod u+w "$target" | ||
| elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then | ||
| echo "$help" | ||
| exit 0 | ||
| elif [ "$1" == "-i" ] || [ "$1" == "--add-doc" ]; then | ||
| cp -f ${placeholder config.outputName}/styles/stylua.toml $(pwd)/ \ | ||
| && chmod u+w "$target" && echo >> "$target" && echo "$doc" >> "$target" | ||
| fi | ||
| ''; | ||
| }; | ||
| flags."--config-path" = lib.mkIf ( | ||
| config.customStyle != { } | ||
| ) config.constructFiles.generatedConfig.path; | ||
| meta = { | ||
| maintainers = with wlib.maintainers; [ | ||
| kuppo | ||
| ]; | ||
| description = '' | ||
| Wrapper Module for [Stylua](https://github.com/JohnnyMorganz/StyLua). | ||
|
|
||
| The wrapper is used to customize the `stylua.toml` file. | ||
| You can add you options into `config.customStyle` with pure nix expressions. | ||
|
|
||
| The wrapper also provides a script which copys the generated `stylua.toml` | ||
| into `$CWD`, in case you want to include the confitugation into the repo or | ||
| customize it somehow. | ||
| ''; | ||
| }; | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test run (success) on x86_64-linux
Test run (success) on x86_64-darwin
I think that it would be good for the behavior of the wrapped program to be checked as well. For example, if you expand the "imperative test process" in my previous comment, you can see how I tested check mode with stylua.