From 9c2037d369cbadab84a44f01c4b6e8d7d95635dd Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 08:38:24 +1000 Subject: [PATCH 01/35] feat(practices): options and parameters --- book/style_guide.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 book/style_guide.md diff --git a/book/style_guide.md b/book/style_guide.md new file mode 100644 index 00000000000..9f26b6529ea --- /dev/null +++ b/book/style_guide.md @@ -0,0 +1,9 @@ +# Best practices + +## Options and parameters of custom commands + +- **Always** keep count of all positional parameters less than or equal to 4, for remaining inputs use options. +- **Always** use positional parameters unless they can't be used due to rules listed here or technical restrictions. + For instance, when there are several kinds of optional parameters (but at least one parameter should be provided) + use options. Great example of this is `ansi gradient` command where at least foreground or background must be passed. +- **Always** provide both long and short options. From efc10cb1b9d6cfa85872ca3488cdbed51fd316e6 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 10:34:29 +1000 Subject: [PATCH 02/35] feat(practices): require docs for exported things --- book/style_guide.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/book/style_guide.md b/book/style_guide.md index 9f26b6529ea..b3674769dbb 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -7,3 +7,8 @@ For instance, when there are several kinds of optional parameters (but at least one parameter should be provided) use options. Great example of this is `ansi gradient` command where at least foreground or background must be passed. - **Always** provide both long and short options. + +## Documentation + +- **Always** provide documentation for all exported entities (like custom commands) and their + inputs (like custom command parameters and options). From 1338aacf33af9aae65174bdbf0ff163ed4eca301 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 10:54:14 +1000 Subject: [PATCH 03/35] feat(practices): explain formatting --- book/style_guide.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/book/style_guide.md b/book/style_guide.md index b3674769dbb..de06f97c9d8 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -1,5 +1,15 @@ # Best practices +## Formatting + +- **Always** put one space before and after pipe `|` symbol. +- **Always** put pipe `|` symbol before `\n` and indent next command one level more first command in pipeline + when dealing with long pipelines. By long pipeline here we mean a such one that takes more than 80 characters counting + from the first character of the first command name of this pipeline. +- **Always** spread blocks and closures over several lines putting first brace `}` on a separate line. +- **Always** put zero spaces between square brackets `[]` for custom commands without parameters. +- **Always** put all custom command parameters on separate lines indented one level more than `def`. + ## Options and parameters of custom commands - **Always** keep count of all positional parameters less than or equal to 4, for remaining inputs use options. From 1b63ecfc53295e76d981c3040666d16224b68e28 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 10:57:56 +1000 Subject: [PATCH 04/35] feat(practices): add example --- book/style_guide.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/book/style_guide.md b/book/style_guide.md index de06f97c9d8..3a6bb8a97c5 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -10,6 +10,16 @@ - **Always** put zero spaces between square brackets `[]` for custom commands without parameters. - **Always** put all custom command parameters on separate lines indented one level more than `def`. +```nushell +export def "log ERROR_LEVEL_PREFIX" [ +--short (-s) # incorrect: "--short (-s)" indent should be one \t; fix: add \t before "--short (-s)" +] { + if $short { "E" # incorrect: `{}` content should be on it's own lines; fix: move "E" on a separate line + } else { + "ERR" } # incorrect: `{}` content should be on it's own lines; fix: move "}" on a separate line +} +``` + ## Options and parameters of custom commands - **Always** keep count of all positional parameters less than or equal to 4, for remaining inputs use options. From d649d4a6f4506d595d8bc3c83a6849d93aa28590 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 10:58:57 +1000 Subject: [PATCH 05/35] feat(practices): extend first formatting rule --- book/style_guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index 3a6bb8a97c5..2fb12c8d48b 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -2,7 +2,7 @@ ## Formatting -- **Always** put one space before and after pipe `|` symbol. +- **Always** put one space before and after pipe `|` symbol, commands, subcommands, their options and arguments. - **Always** put pipe `|` symbol before `\n` and indent next command one level more first command in pipeline when dealing with long pipelines. By long pipeline here we mean a such one that takes more than 80 characters counting from the first character of the first command name of this pipeline. From 89bf85b9c11a293e6023153ef90f23182e2410a1 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 11:52:50 +1000 Subject: [PATCH 06/35] feat(practices): rewrite formatting rules --- book/style_guide.md | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 2fb12c8d48b..ec10841d2f3 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -2,13 +2,44 @@ ## Formatting +### Defaults + +- **Always** assume that by default no spaces or tabs allowed, but the following rules define where they are allowed. + +### Basic + - **Always** put one space before and after pipe `|` symbol, commands, subcommands, their options and arguments. -- **Always** put pipe `|` symbol before `\n` and indent next command one level more first command in pipeline - when dealing with long pipelines. By long pipeline here we mean a such one that takes more than 80 characters counting - from the first character of the first command name of this pipeline. -- **Always** spread blocks and closures over several lines putting first brace `}` on a separate line. -- **Always** put zero spaces between square brackets `[]` for custom commands without parameters. -- **Always** put all custom command parameters on separate lines indented one level more than `def`. + +#### One-line format + +One-line format is a format for writting all commands in one line. + +- **Always** put no spaces before and after pipe `|` symbol denoting block or closure parameter list beginning, +- **Always** put one space after comma `,` after block, closure parameter or record key. +- **Always** put no space before and one space after pipe `|` symbol denoting block or closure parameter list end. +- **Always** put one space before first record key and after last record key value. +- **Always** put one space after `:` after record key. +- **Always** put one space before opening square `[` or curly brace `{`. +- **Always** put one space after closing square `]` or curly brace `{`. +- **Always** put no spaces between square `[]` or curly brackets `{}` with nothing between them. + +#### Multi-line format + +Multi-line format is a format for writting all commands in several lines. It inherits all rules from one-line format +and modifies them slightly. When not stated explicitly, rule is inherited without change. + +- **Always** put zero trailing spaces after pipe `|` symbol when `\n\t` follows it. +- **Always** put no space before and one `\n` after pipe `|` symbol denoting block or closure parameter list end. +- **Always** put one `\n\t` before first record key and `\n` after last record key value. +- **Always** put `\t` before list value or record key. + +When referring to `\t` it's supposed that it's done relatively to the current indentation level. + +### Spreading long lines + +- **Always** default to short format unless you are writting scripts. +- **Always** default to short format in scripts for lists unless they more than 80 characters long. +- **Always** use long format for pipelines more than 80 characters long. ```nushell export def "log ERROR_LEVEL_PREFIX" [ From 1e8c1d87cef47cae5c4045d70261af8f8026d131 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 12:10:26 +1000 Subject: [PATCH 07/35] feat(practices): add examples --- book/style_guide.md | 75 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index ec10841d2f3..83fb7385ac6 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -10,6 +10,18 @@ - **Always** put one space before and after pipe `|` symbol, commands, subcommands, their options and arguments. +Correct: + +```nushell +'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff' +``` + +Incorrect: + +```nushell +'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff' # two many spaces after "|" +``` + #### One-line format One-line format is a format for writting all commands in one line. @@ -19,10 +31,30 @@ One-line format is a format for writting all commands in one line. - **Always** put no space before and one space after pipe `|` symbol denoting block or closure parameter list end. - **Always** put one space before first record key and after last record key value. - **Always** put one space after `:` after record key. -- **Always** put one space before opening square `[` or curly brace `{`. +- **Always** put one space before opening square `[` or curly brace `{` if preceding symbol is not the same. - **Always** put one space after closing square `]` or curly brace `{`. - **Always** put no spaces between square `[]` or curly brackets `{}` with nothing between them. +Correct: + +```nushell +[[status]; [UP] [UP]] | all {|el| $el.status == UP } +[1 2 3 4] | reduce {|it, acc| $it + $acc } +{ x: 1, y: 2 } +[1 2] | zip [3 4] +[] +``` + +Incorrect: + +```nushell +[[status]; [UP] [UP]] | all { |el| $el.status == UP } # two many spaces before "|el|" +[1 2 3 4] | reduce {|it , acc | $it + $acc } # two many spaces after "it"; two many spaces before "| $it + $acc" +{x: 1, y : 2 } # two few spaces before "x: 1"; two many spaces before ": 2" +[1 2] | zip [3 4] # two many spaces before "[3 4]" +[ ] # two many spaces before "]" +``` + #### Multi-line format Multi-line format is a format for writting all commands in several lines. It inherits all rules from one-line format @@ -35,6 +67,47 @@ and modifies them slightly. When not stated explicitly, rule is inherited withou When referring to `\t` it's supposed that it's done relatively to the current indentation level. +Correct: + +```nushell +[[status]; [UP] [UP]] | all {|el| + $el.status == UP +} + +[ + 1 + 2 + 3 + 4 +] | reduce {|it, acc| + $it + $acc +} + +{ + x: 1, + y: 2 +} +``` + +Incorrect: + +```nushell +[[status]; [UP] [UP]] | all {|el| + $el.status == UP } # two many spaces before "}"; two few "\n" before "}" + +[ 1 # two many spaces before "}"; two few "\n" before "}" + 2 + 3 + 4 +] | reduce {|it, acc| + $it + $acc +} + +{ x: 1, # two many spaces before "x: 1"; two few "\n" before "x: 1" + y: 2 +} +``` + ### Spreading long lines - **Always** default to short format unless you are writting scripts. From 062e1d097408fcccbbf7ad51478ac7004a5bb0ad Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 12:13:08 +1000 Subject: [PATCH 08/35] feat(practices): note about keeping indent --- book/style_guide.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index 83fb7385ac6..736a2922f86 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -61,9 +61,10 @@ Multi-line format is a format for writting all commands in several lines. It inh and modifies them slightly. When not stated explicitly, rule is inherited without change. - **Always** put zero trailing spaces after pipe `|` symbol when `\n\t` follows it. + Keep this indentation for all pipeline commands. - **Always** put no space before and one `\n` after pipe `|` symbol denoting block or closure parameter list end. - **Always** put one `\n\t` before first record key and `\n` after last record key value. -- **Always** put `\t` before list value or record key. + Keep this indentation for all record keys. When referring to `\t` it's supposed that it's done relatively to the current indentation level. From ecfb91c021a541f387194fbb233d57c21c7451af Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 12:14:41 +1000 Subject: [PATCH 09/35] feat(practices): add list formatting --- book/style_guide.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/book/style_guide.md b/book/style_guide.md index 736a2922f86..90dfae143d0 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -65,6 +65,8 @@ and modifies them slightly. When not stated explicitly, rule is inherited withou - **Always** put no space before and one `\n` after pipe `|` symbol denoting block or closure parameter list end. - **Always** put one `\n\t` before first record key and `\n` after last record key value. Keep this indentation for all record keys. +- **Always** put one `\n\t` before first list value and `\n` after last list value. + Keep this indentation for all list values. When referring to `\t` it's supposed that it's done relatively to the current indentation level. From 89806778b52cbf5bce53c9d9368198e240731c11 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 16:48:37 +1000 Subject: [PATCH 10/35] feat(practices): make rules sound more polite --- book/style_guide.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 90dfae143d0..c3479d53d14 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -4,11 +4,11 @@ ### Defaults -- **Always** assume that by default no spaces or tabs allowed, but the following rules define where they are allowed. +- **It's recommended to** assume that by default no spaces or tabs allowed, but the following rules define where they are allowed. ### Basic -- **Always** put one space before and after pipe `|` symbol, commands, subcommands, their options and arguments. +- **It's recommended to** put one space before and after pipe `|` symbol, commands, subcommands, their options and arguments. Correct: @@ -26,14 +26,14 @@ Incorrect: One-line format is a format for writting all commands in one line. -- **Always** put no spaces before and after pipe `|` symbol denoting block or closure parameter list beginning, -- **Always** put one space after comma `,` after block, closure parameter or record key. -- **Always** put no space before and one space after pipe `|` symbol denoting block or closure parameter list end. -- **Always** put one space before first record key and after last record key value. -- **Always** put one space after `:` after record key. -- **Always** put one space before opening square `[` or curly brace `{` if preceding symbol is not the same. -- **Always** put one space after closing square `]` or curly brace `{`. -- **Always** put no spaces between square `[]` or curly brackets `{}` with nothing between them. +- **It's recommended to** put no spaces before and after pipe `|` symbol denoting block or closure parameter list beginning, +- **It's recommended to** put one space after comma `,` after block, closure parameter or record key. +- **It's recommended to** put no space before and one space after pipe `|` symbol denoting block or closure parameter list end. +- **It's recommended to** put one space before first record key and after last record key value. +- **It's recommended to** put one space after `:` after record key. +- **It's recommended to** put one space before opening square `[` or curly brace `{` if preceding symbol is not the same. +- **It's recommended to** put one space after closing square `]` or curly brace `{`. +- **It's recommended to** put no spaces between square `[]` or curly brackets `{}` with nothing between them. Correct: @@ -60,12 +60,12 @@ Incorrect: Multi-line format is a format for writting all commands in several lines. It inherits all rules from one-line format and modifies them slightly. When not stated explicitly, rule is inherited without change. -- **Always** put zero trailing spaces after pipe `|` symbol when `\n\t` follows it. +- **It's recommended to** put zero trailing spaces after pipe `|` symbol when `\n\t` follows it. Keep this indentation for all pipeline commands. -- **Always** put no space before and one `\n` after pipe `|` symbol denoting block or closure parameter list end. -- **Always** put one `\n\t` before first record key and `\n` after last record key value. +- **It's recommended to** put no space before and one `\n` after pipe `|` symbol denoting block or closure parameter list end. +- **It's recommended to** put one `\n\t` before first record key and `\n` after last record key value. Keep this indentation for all record keys. -- **Always** put one `\n\t` before first list value and `\n` after last list value. +- **It's recommended to** put one `\n\t` before first list value and `\n` after last list value. Keep this indentation for all list values. When referring to `\t` it's supposed that it's done relatively to the current indentation level. @@ -113,9 +113,9 @@ Incorrect: ### Spreading long lines -- **Always** default to short format unless you are writting scripts. -- **Always** default to short format in scripts for lists unless they more than 80 characters long. -- **Always** use long format for pipelines more than 80 characters long. +- **It's recommended to** default to short format unless you are writting scripts. +- **It's recommended to** default to short format in scripts for lists unless they more than 80 characters long. +- **It's recommended to** use long format for pipelines more than 80 characters long. ```nushell export def "log ERROR_LEVEL_PREFIX" [ @@ -129,13 +129,13 @@ export def "log ERROR_LEVEL_PREFIX" [ ## Options and parameters of custom commands -- **Always** keep count of all positional parameters less than or equal to 4, for remaining inputs use options. -- **Always** use positional parameters unless they can't be used due to rules listed here or technical restrictions. +- **It's recommended to** keep count of all positional parameters less than or equal to 4, for remaining inputs use options. +- **It's recommended to** use positional parameters unless they can't be used due to rules listed here or technical restrictions. For instance, when there are several kinds of optional parameters (but at least one parameter should be provided) use options. Great example of this is `ansi gradient` command where at least foreground or background must be passed. -- **Always** provide both long and short options. +- **It's recommended to** provide both long and short options. ## Documentation -- **Always** provide documentation for all exported entities (like custom commands) and their +- **It's recommended to** provide documentation for all exported entities (like custom commands) and their inputs (like custom command parameters and options). From d8aca9f30d5a30c3c1c0f9c5bb31f592bc054789 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 18:08:36 +1000 Subject: [PATCH 11/35] feat(practices): add note --- book/style_guide.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index c3479d53d14..668a2529a5e 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -1,5 +1,9 @@ # Best practices +This page lists our best practices we advice to follow. Keep in mind that they are not required to be +used in external repositories (not ours), you can change them in the way you want, +but please be consistent and follow your rules. + ## Formatting ### Defaults @@ -24,7 +28,7 @@ Incorrect: #### One-line format -One-line format is a format for writting all commands in one line. +One-line format is a format for writing all commands in one line. - **It's recommended to** put no spaces before and after pipe `|` symbol denoting block or closure parameter list beginning, - **It's recommended to** put one space after comma `,` after block, closure parameter or record key. @@ -57,7 +61,7 @@ Incorrect: #### Multi-line format -Multi-line format is a format for writting all commands in several lines. It inherits all rules from one-line format +Multi-line format is a format for writing all commands in several lines. It inherits all rules from one-line format and modifies them slightly. When not stated explicitly, rule is inherited without change. - **It's recommended to** put zero trailing spaces after pipe `|` symbol when `\n\t` follows it. @@ -113,7 +117,7 @@ Incorrect: ### Spreading long lines -- **It's recommended to** default to short format unless you are writting scripts. +- **It's recommended to** default to short format unless you are writing scripts. - **It's recommended to** default to short format in scripts for lists unless they more than 80 characters long. - **It's recommended to** use long format for pipelines more than 80 characters long. From ef39d60b8d16c1a0a9178a6e9809d2650b19ce08 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 18:36:13 +1000 Subject: [PATCH 12/35] feat(practices): clarify one-line format rules --- book/style_guide.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 668a2529a5e..dfbf29c5c42 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -23,7 +23,7 @@ Correct: Incorrect: ```nushell -'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff' # two many spaces after "|" +'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff' # two many spaces after "|": 2 instead of 1 ``` #### One-line format @@ -36,7 +36,7 @@ One-line format is a format for writing all commands in one line. - **It's recommended to** put one space before first record key and after last record key value. - **It's recommended to** put one space after `:` after record key. - **It's recommended to** put one space before opening square `[` or curly brace `{` if preceding symbol is not the same. -- **It's recommended to** put one space after closing square `]` or curly brace `{`. +- **It's recommended to** put one space after closing square `]` or curly brace `}` if following symbol is not the same. - **It's recommended to** put no spaces between square `[]` or curly brackets `{}` with nothing between them. Correct: @@ -52,11 +52,13 @@ Correct: Incorrect: ```nushell -[[status]; [UP] [UP]] | all { |el| $el.status == UP } # two many spaces before "|el|" -[1 2 3 4] | reduce {|it , acc | $it + $acc } # two many spaces after "it"; two many spaces before "| $it + $acc" -{x: 1, y : 2 } # two few spaces before "x: 1"; two many spaces before ": 2" -[1 2] | zip [3 4] # two many spaces before "[3 4]" -[ ] # two many spaces before "]" +[[status]; [UP] [UP]] | all { |el| $el.status == UP } # two many spaces before "|el|": 2 instead of 0 +[1 2 3 4] | reduce {|it , acc | $it + $acc } # two many spaces after "it": 1 instead of 0 + # two many spaces before "| $it + $acc": 1 instead of 0 +{x: 1, y : 2 } # two few spaces before "x: 1": 0 instead of 1 + # two many spaces before ": 2": 1 instead of 0 +[1 2] | zip [3 4] # two many spaces before "[3 4]": 2 instead of 1 +[ ] # two many spaces before "]": 1 instead of 0 ``` #### Multi-line format From 3fdc3d37f201916b674f7e7680b038712f8f763d Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 19:18:36 +1000 Subject: [PATCH 13/35] feat(practice): clean-up --- book/style_guide.md | 81 +++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index dfbf29c5c42..1ad45aa518b 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -8,11 +8,11 @@ but please be consistent and follow your rules. ### Defaults -- **It's recommended to** assume that by default no spaces or tabs allowed, but the following rules define where they are allowed. +**It's recommended to** assume that by default no spaces or tabs allowed, but the following rules define where they are allowed. ### Basic -- **It's recommended to** put one space before and after pipe `|` symbol, commands, subcommands, their options and arguments. +**It's recommended to** put one space before and after pipe `|` symbol, commands, subcommands, their options and arguments. Correct: @@ -30,14 +30,23 @@ Incorrect: One-line format is a format for writing all commands in one line. -- **It's recommended to** put no spaces before and after pipe `|` symbol denoting block or closure parameter list beginning, -- **It's recommended to** put one space after comma `,` after block, closure parameter or record key. -- **It's recommended to** put no space before and one space after pipe `|` symbol denoting block or closure parameter list end. -- **It's recommended to** put one space before first record key and after last record key value. -- **It's recommended to** put one space after `:` after record key. -- **It's recommended to** put one space before opening square `[` or curly brace `{` if preceding symbol is not the same. -- **It's recommended to** put one space after closing square `]` or curly brace `}` if following symbol is not the same. -- **It's recommended to** put no spaces between square `[]` or curly brackets `{}` with nothing between them. +1. parameters: + 1. **It's recommended to** put no spaces before and after pipe `|` symbol denoting block or closure parameter list beginning. + 2. **It's recommended to** put one space after comma `,` after block or closure parameter parameter. + 3. **It's recommended to** put no space before and one space after pipe `|` symbol denoting block or closure parameter list end. +2. block and closure bodies: + 1. **It's recommended to** put one space before closing block or closure curly brace `}`. +3. records: + 1. **It's recommended to** put one space before first record key and after last record key value. + 2. **It's recommended to** put one space after `:` after record key. + 3. **It's recommended to** put one space after comma `,` after key value. +4. lists: + 1. **It's recommended to** put no spaces before first list value and after last list value. + 2. **It's recommended to** put one space after comma `,` after list value. +5. surrounding constructs: + 1. **It's recommended to** put one space before opening square `[` or curly brace `{` if preceding symbol is not the same. + 2. **It's recommended to** put one space after closing square `]` or curly brace `}` if following symbol is not the same. + 3. **It's recommended to** put no spaces between square `[]` or curly brackets `{}` with nothing between them. Correct: @@ -64,17 +73,20 @@ Incorrect: #### Multi-line format Multi-line format is a format for writing all commands in several lines. It inherits all rules from one-line format -and modifies them slightly. When not stated explicitly, rule is inherited without change. - -- **It's recommended to** put zero trailing spaces after pipe `|` symbol when `\n\t` follows it. - Keep this indentation for all pipeline commands. -- **It's recommended to** put no space before and one `\n` after pipe `|` symbol denoting block or closure parameter list end. -- **It's recommended to** put one `\n\t` before first record key and `\n` after last record key value. - Keep this indentation for all record keys. -- **It's recommended to** put one `\n\t` before first list value and `\n` after last list value. - Keep this indentation for all list values. - -When referring to `\t` it's supposed that it's done relatively to the current indentation level. +and modifies them slightly. + +1. general: + 1. **It's recommended to omit** trailing spaces. +2. block and closure bodies: + 1. **It's recommended to** put each body pipeline on a separate line. + 2. **It's recommended to** put each body pipeline on a separate line. +3. records: + 1. **It's recommended to** put each record key-value pair on separate line. +4. lists: + 1. **It's recommended to** put each list item on separate line. +5. surrounding constructs: + 1. **It's recommended to** put one `\n` before opening square `[` or curly brace `{` if preceding symbol is not the same. + 2. **It's recommended to** put one `\n` after closing square `]` or curly brace `}` if following symbol is not the same. Correct: @@ -96,15 +108,26 @@ Correct: x: 1, y: 2 } + +[ + { + name: "Teresa", + age: 24 + }, + { + name: "Thomas", + age: 26 + } +] ``` Incorrect: ```nushell [[status]; [UP] [UP]] | all {|el| - $el.status == UP } # two many spaces before "}"; two few "\n" before "}" + $el.status == UP } # two many spaces before "}": 1 instead of "\n" -[ 1 # two many spaces before "}"; two few "\n" before "}" +[ 1 # two many spaces before "1": 1 instead of "\n" 2 3 4 @@ -112,9 +135,19 @@ Incorrect: $it + $acc } -{ x: 1, # two many spaces before "x: 1"; two few "\n" before "x: 1" +{ x: 1, # two many spaces before "x: 1": 1 instead of "\n" y: 2 } + +[{ # two few "\n" before "{": 0 instead of 1 + name: "Teresa", + age: 24 + } , # two many spaces before ",": 1 instead of 0 + { + name: "Thomas", + age: 26 + } +] ``` ### Spreading long lines From aedbc9c64d3a8c17cddaa1eeb393037ca7610bf2 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 21:44:11 +1000 Subject: [PATCH 14/35] fix(practices): remove duplicates --- book/style_guide.md | 1 - 1 file changed, 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index 1ad45aa518b..773e915fb84 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -79,7 +79,6 @@ and modifies them slightly. 1. **It's recommended to omit** trailing spaces. 2. block and closure bodies: 1. **It's recommended to** put each body pipeline on a separate line. - 2. **It's recommended to** put each body pipeline on a separate line. 3. records: 1. **It's recommended to** put each record key-value pair on separate line. 4. lists: From 930df0de7e55a0cc21b35a7490a83ba3edfbf2a6 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 21:48:15 +1000 Subject: [PATCH 15/35] feat(practices): update examples --- book/style_guide.md | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 773e915fb84..accc6a57c30 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -155,13 +155,37 @@ Incorrect: - **It's recommended to** default to short format in scripts for lists unless they more than 80 characters long. - **It's recommended to** use long format for pipelines more than 80 characters long. +Correct (in scripts): + ```nushell -export def "log ERROR_LEVEL_PREFIX" [ ---short (-s) # incorrect: "--short (-s)" indent should be one \t; fix: add \t before "--short (-s)" -] { - if $short { "E" # incorrect: `{}` content should be on it's own lines; fix: move "E" on a separate line - } else { - "ERR" } # incorrect: `{}` content should be on it's own lines; fix: move "}" on a separate line +[1, 2, 3, 4] | reduce {|it, acc| + $it + $acc +} + +[1 2 3 4] | reduce {|it acc| + $it + $acc +} +``` + +Incorrect (in scripts): + +```nushell +[ + 1, + 2, + 3, + 4 +] | reduce {|it, acc| + $it + $acc +} + +[ + 1 + 2 + 3 + 4 +] | reduce {|it acc| + $it + $acc } ``` From 0639f717a04b8a58ebd6bbf5ded76a16a1ef56fa Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 21:54:29 +1000 Subject: [PATCH 16/35] feat(practices): recommend omit commas --- book/style_guide.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index accc6a57c30..738f4b2463c 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -12,7 +12,8 @@ but please be consistent and follow your rules. ### Basic -**It's recommended to** put one space before and after pipe `|` symbol, commands, subcommands, their options and arguments. +- **It's recommended to** put one space before and after pipe `|` symbol, commands, subcommands, their options and arguments. +- **It's recommended to** omit commas between list items. Correct: From ca6ce667d64d4b9aa89f8dcbe6a4af8389f41b63 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Thu, 11 May 2023 22:01:38 +1000 Subject: [PATCH 17/35] feat(practices): allow short format more --- book/style_guide.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index 738f4b2463c..58235f35686 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -153,7 +153,8 @@ Incorrect: ### Spreading long lines - **It's recommended to** default to short format unless you are writing scripts. -- **It's recommended to** default to short format in scripts for lists unless they more than 80 characters long. +- **It's recommended to** default to short format in scripts for lists and records unless they more than 80 characters long + or contain nested lists or records. - **It's recommended to** use long format for pipelines more than 80 characters long. Correct (in scripts): @@ -166,6 +167,11 @@ Correct (in scripts): [1 2 3 4] | reduce {|it acc| $it + $acc } + +[ + { name: "Teresa", age: 24 }, + { name: "Thomas", age: 26 } +] ``` Incorrect (in scripts): @@ -188,6 +194,17 @@ Incorrect (in scripts): ] | reduce {|it acc| $it + $acc } + +[ + { + name: "Teresa", + age: 24 + }, + { + name: "Thomas", + age: 26 + } +] ``` ## Options and parameters of custom commands From a2dac576dce5109fb7a9688633fab2fc1b30ce4e Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sat, 13 May 2023 14:42:04 +1000 Subject: [PATCH 18/35] feat(practices): make intro less authoritative --- book/style_guide.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 58235f35686..e34b3866d98 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -1,8 +1,11 @@ # Best practices -This page lists our best practices we advice to follow. Keep in mind that they are not required to be -used in external repositories (not ours), you can change them in the way you want, -but please be consistent and follow your rules. +This page is a working document collecting syntax guidelines and best practices we have discovered so far. +The goal of this document is to eventually land on a canonical Nushell code style, but as for now it is still work in +progress and subject to change. We welcome discussion and contributions. + +Keep in mind that they are not required to be used in external repositories (not ours), you can change them in the +way you want, but please be consistent and follow your rules. ## Formatting From b8de74f691e16b0819b573c95f359a48a46f516c Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sat, 13 May 2023 14:49:23 +1000 Subject: [PATCH 19/35] feat(practices): move comments on separate lines --- book/style_guide.md | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index e34b3866d98..3034927d066 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -27,7 +27,8 @@ Correct: Incorrect: ```nushell -'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff' # two many spaces after "|": 2 instead of 1 +# - two many spaces after "|": 2 instead of 1 +'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff' ``` #### One-line format @@ -65,13 +66,22 @@ Correct: Incorrect: ```nushell -[[status]; [UP] [UP]] | all { |el| $el.status == UP } # two many spaces before "|el|": 2 instead of 0 -[1 2 3 4] | reduce {|it , acc | $it + $acc } # two many spaces after "it": 1 instead of 0 - # two many spaces before "| $it + $acc": 1 instead of 0 -{x: 1, y : 2 } # two few spaces before "x: 1": 0 instead of 1 - # two many spaces before ": 2": 1 instead of 0 -[1 2] | zip [3 4] # two many spaces before "[3 4]": 2 instead of 1 -[ ] # two many spaces before "]": 1 instead of 0 +# - two many spaces before "|el|": 2 instead of 0: +[[status]; [UP] [UP]] | all { |el| $el.status == UP } + +# - two many spaces after "it": 1 instead of 0 +# - two many spaces before "| $it + $acc": 1 instead of 0 +[1 2 3 4] | reduce {|it , acc | $it + $acc } + +# - two few spaces before "x: 1": 0 instead of 1 +# - two many spaces before ": 2": 1 instead of 0 +{x: 1, y : 2 } + +# - two many spaces before "[3 4]": 2 instead of 1 +[1 2] | zip [3 4] + +# - two many spaces before "]": 1 instead of 0 +[ ] ``` #### Multi-line format @@ -127,10 +137,12 @@ Correct: Incorrect: ```nushell +# - two many spaces before "}": 1 instead of "\n" [[status]; [UP] [UP]] | all {|el| - $el.status == UP } # two many spaces before "}": 1 instead of "\n" + $el.status == UP } -[ 1 # two many spaces before "1": 1 instead of "\n" +# - two many spaces before "1": 1 instead of "\n" +[ 1 2 3 4 @@ -138,14 +150,17 @@ Incorrect: $it + $acc } -{ x: 1, # two many spaces before "x: 1": 1 instead of "\n" +# - two many spaces before "x: 1": 1 instead of "\n" +{ x: 1, y: 2 } -[{ # two few "\n" before "{": 0 instead of 1 +# - two few "\n" before "{": 0 instead of 1 +[{ name: "Teresa", age: 24 - } , # two many spaces before ",": 1 instead of 0 + # - two many spaces before ",": 1 instead of 0 + } , { name: "Thomas", age: 26 From d18a100821b643bb46d0aff035974531ff28f389 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sat, 13 May 2023 14:56:29 +1000 Subject: [PATCH 20/35] feat(practices): note about escape sequences --- book/style_guide.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/book/style_guide.md b/book/style_guide.md index 3034927d066..ffdc9d810fd 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -7,6 +7,9 @@ progress and subject to change. We welcome discussion and contributions. Keep in mind that they are not required to be used in external repositories (not ours), you can change them in the way you want, but please be consistent and follow your rules. +All escape sequences should not be interpreted literally, unless it's told to do so. In other words, +treat something like `\n` like new line character and not literal slash followed by `n`. + ## Formatting ### Defaults From aef4ac85886826d40bf8ffdf9ebef95036e2dfb1 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sat, 13 May 2023 15:02:10 +1000 Subject: [PATCH 21/35] feat(practices): unify collection syntax --- book/style_guide.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index ffdc9d810fd..0c11c338d0b 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -45,7 +45,7 @@ One-line format is a format for writing all commands in one line. 2. block and closure bodies: 1. **It's recommended to** put one space before closing block or closure curly brace `}`. 3. records: - 1. **It's recommended to** put one space before first record key and after last record key value. + 1. **It's recommended to** put no spaces before first record key and after last record key value. 2. **It's recommended to** put one space after `:` after record key. 3. **It's recommended to** put one space after comma `,` after key value. 4. lists: @@ -61,7 +61,7 @@ Correct: ```nushell [[status]; [UP] [UP]] | all {|el| $el.status == UP } [1 2 3 4] | reduce {|it, acc| $it + $acc } -{ x: 1, y: 2 } +{x: 1, y: 2} [1 2] | zip [3 4] [] ``` @@ -76,9 +76,9 @@ Incorrect: # - two many spaces before "| $it + $acc": 1 instead of 0 [1 2 3 4] | reduce {|it , acc | $it + $acc } -# - two few spaces before "x: 1": 0 instead of 1 +# - two many spaces before "x: 1": 1 instead of 0 # - two many spaces before ": 2": 1 instead of 0 -{x: 1, y : 2 } +{ x: 1, y : 2} # - two many spaces before "[3 4]": 2 instead of 1 [1 2] | zip [3 4] @@ -190,8 +190,8 @@ Correct (in scripts): } [ - { name: "Teresa", age: 24 }, - { name: "Thomas", age: 26 } + {name: "Teresa", age: 24}, + {name: "Thomas", age: 26} ] ``` From 1cfefeaa561cc72c56e37487e279dd920d2ed299 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sat, 13 May 2023 15:13:35 +1000 Subject: [PATCH 22/35] feat(practices): narrow down amount of args --- book/style_guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index 0c11c338d0b..2ea33a9d0a7 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -230,7 +230,7 @@ Incorrect (in scripts): ## Options and parameters of custom commands -- **It's recommended to** keep count of all positional parameters less than or equal to 4, for remaining inputs use options. +- **It's recommended to** keep count of all positional parameters less than or equal to 2, for remaining inputs use options. Assume that command can expect source and destination parameter, like `mv`: source and target file or directory. - **It's recommended to** use positional parameters unless they can't be used due to rules listed here or technical restrictions. For instance, when there are several kinds of optional parameters (but at least one parameter should be provided) use options. Great example of this is `ansi gradient` command where at least foreground or background must be passed. From 6a22d9df0874603fed5f4fe6042e4e1898150d79 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sat, 13 May 2023 18:10:23 +1000 Subject: [PATCH 23/35] fix(practices): deduplicate terms --- book/style_guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index 2ea33a9d0a7..3dec67542c8 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -40,7 +40,7 @@ One-line format is a format for writing all commands in one line. 1. parameters: 1. **It's recommended to** put no spaces before and after pipe `|` symbol denoting block or closure parameter list beginning. - 2. **It's recommended to** put one space after comma `,` after block or closure parameter parameter. + 2. **It's recommended to** put one space after comma `,` after block or closure parameter. 3. **It's recommended to** put no space before and one space after pipe `|` symbol denoting block or closure parameter list end. 2. block and closure bodies: 1. **It's recommended to** put one space before closing block or closure curly brace `}`. From 5efba816c2e7be62d30c1d53731b8c740461da7c Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sat, 13 May 2023 18:14:00 +1000 Subject: [PATCH 24/35] fix(practices): require trailing space omission --- book/style_guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index 3dec67542c8..8492583d474 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -93,7 +93,7 @@ Multi-line format is a format for writing all commands in several lines. It inhe and modifies them slightly. 1. general: - 1. **It's recommended to omit** trailing spaces. + 1. **It's required to omit** trailing spaces. 2. block and closure bodies: 1. **It's recommended to** put each body pipeline on a separate line. 3. records: From c9f61d2364e33ed82d58ea3ac998c22c2fdbf340 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Sat, 13 May 2023 08:19:03 -0500 Subject: [PATCH 25/35] tweaked some grammar, removed some optional commas --- book/style_guide.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 8492583d474..372d9604ab5 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -4,11 +4,11 @@ This page is a working document collecting syntax guidelines and best practices The goal of this document is to eventually land on a canonical Nushell code style, but as for now it is still work in progress and subject to change. We welcome discussion and contributions. -Keep in mind that they are not required to be used in external repositories (not ours), you can change them in the +Keep in mind that these guidelines are not required to be used in external repositories (not ours), you can change them in the way you want, but please be consistent and follow your rules. -All escape sequences should not be interpreted literally, unless it's told to do so. In other words, -treat something like `\n` like new line character and not literal slash followed by `n`. +All escape sequences should not be interpreted literally, unless directed to do so. In other words, +treat something like `\n` like the new line character and not a literal slash followed by `n`. ## Formatting @@ -61,7 +61,9 @@ Correct: ```nushell [[status]; [UP] [UP]] | all {|el| $el.status == UP } [1 2 3 4] | reduce {|it, acc| $it + $acc } +[1 2 3 4] | reduce {|it acc| $it + $acc } {x: 1, y: 2} +{x: 1 y: 2} [1 2] | zip [3 4] [] ``` @@ -193,6 +195,11 @@ Correct (in scripts): {name: "Teresa", age: 24}, {name: "Thomas", age: 26} ] + +[ + {name: "Teresa" age: 24}, + {name: "Thomas" age: 26} +] ``` Incorrect (in scripts): From cd765c2ffe322be43ebbc812047f9393427f1570 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sun, 14 May 2023 17:14:21 +1000 Subject: [PATCH 26/35] feat(practices): join sections --- book/style_guide.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 8492583d474..7c7c5e4811b 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -38,6 +38,13 @@ Incorrect: One-line format is a format for writing all commands in one line. +**It's recommended to** default to this format: + +1. unless you are writing scripts +2. in scripts for lists and records unless they more than 80 characters long or contain nested lists or records + +Rules: + 1. parameters: 1. **It's recommended to** put no spaces before and after pipe `|` symbol denoting block or closure parameter list beginning. 2. **It's recommended to** put one space after comma `,` after block or closure parameter. @@ -92,6 +99,14 @@ Incorrect: Multi-line format is a format for writing all commands in several lines. It inherits all rules from one-line format and modifies them slightly. +**It's recommended to** default to this format: + +1. while you are writing scripts +2. in scripts for lists and records while they more than 80 characters long or contain nested lists or records +3. for pipelines more than 80 characters long. + +Rules: + 1. general: 1. **It's required to omit** trailing spaces. 2. block and closure bodies: @@ -171,13 +186,6 @@ Incorrect: ] ``` -### Spreading long lines - -- **It's recommended to** default to short format unless you are writing scripts. -- **It's recommended to** default to short format in scripts for lists and records unless they more than 80 characters long - or contain nested lists or records. -- **It's recommended to** use long format for pipelines more than 80 characters long. - Correct (in scripts): ```nushell From 6852d1ee1e665a43bed2a67fe1a9df592c8388b2 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sun, 14 May 2023 19:54:17 +1000 Subject: [PATCH 27/35] feat(practices): clarify when use and what format --- book/style_guide.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 27cd100ad48..a6f12c2427a 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -41,7 +41,11 @@ One-line format is a format for writing all commands in one line. **It's recommended to** default to this format: 1. unless you are writing scripts -2. in scripts for lists and records unless they more than 80 characters long or contain nested lists or records +2. in scripts for lists and records unless they either: + 1. more than 80 characters long + 2. contain nested lists or records +3. for pipelines less than 80 characters long not containing items should be formatted with + a long format Rules: @@ -104,8 +108,10 @@ and modifies them slightly. **It's recommended to** default to this format: 1. while you are writing scripts -2. in scripts for lists and records while they more than 80 characters long or contain nested lists or records -3. for pipelines more than 80 characters long. +2. in scripts for lists and records while they either: + 1. more than 80 characters long + 2. contain nested lists or records +3. for pipelines more 80 characters long Rules: From 80af021a5abd20e0bc2d5c93bda05315cc112dee Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 17 May 2023 16:30:58 +1000 Subject: [PATCH 28/35] feat(practices): update examples --- book/style_guide.md | 129 +++++++++----------------------------------- 1 file changed, 24 insertions(+), 105 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index a6f12c2427a..8c3d38b1cee 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -82,21 +82,19 @@ Correct: Incorrect: ```nushell -# - two many spaces before "|el|": 2 instead of 0: +# two many spaces before "|el|": no space is allowed [[status]; [UP] [UP]] | all { |el| $el.status == UP } -# - two many spaces after "it": 1 instead of 0 -# - two many spaces before "| $it + $acc": 1 instead of 0 -[1 2 3 4] | reduce {|it , acc | $it + $acc } +# two many spaces before ",": no space is allowed +[1 2 3 4] | reduce {|it , acc| $it + $acc } -# - two many spaces before "x: 1": 1 instead of 0 -# - two many spaces before ": 2": 1 instead of 0 -{ x: 1, y : 2} +# two many spaces before "x": no space is allowed +{ x: 1, y: 2} -# - two many spaces before "[3 4]": 2 instead of 1 +# two many spaces before "[3": one space is required [1 2] | zip [3 4] -# - two many spaces before "]": 1 instead of 0 +# two many spaces before "]": no space is allowed [ ] ``` @@ -134,119 +132,40 @@ Correct: $el.status == UP } -[ - 1 - 2 - 3 - 4 -] | reduce {|it, acc| - $it + $acc -} - -{ - x: 1, - y: 2 -} - -[ - { - name: "Teresa", - age: 24 - }, - { - name: "Thomas", - age: 26 - } -] -``` - -Incorrect: - -```nushell -# - two many spaces before "}": 1 instead of "\n" -[[status]; [UP] [UP]] | all {|el| - $el.status == UP } - -# - two many spaces before "1": 1 instead of "\n" -[ 1 - 2 - 3 - 4 -] | reduce {|it, acc| +[1 2 3 4] | reduce {|it, acc| $it + $acc } -# - two many spaces before "x: 1": 1 instead of "\n" -{ x: 1, - y: 2 -} - -# - two few "\n" before "{": 0 instead of 1 -[{ - name: "Teresa", - age: 24 - # - two many spaces before ",": 1 instead of 0 - } , - { - name: "Thomas", - age: 26 - } -] -``` - -Correct (in scripts): - -```nushell -[1, 2, 3, 4] | reduce {|it, acc| - $it + $acc -} - -[1 2 3 4] | reduce {|it acc| - $it + $acc -} +{x: 1, y: 2} [ {name: "Teresa", age: 24}, {name: "Thomas", age: 26} ] - -[ - {name: "Teresa" age: 24}, - {name: "Thomas" age: 26} -] ``` -Incorrect (in scripts): +Incorrect: ```nushell -[ - 1, - 2, - 3, - 4 -] | reduce {|it, acc| +# too many spaces before "|el|": no space is allowed (like in one-line format) +[[status]; [UP] [UP]] | all { |el| + # too few "\n" before "}": one "\n" is required + $el.status == UP} + +# too many spaces before "2": one space is required (like in one-line format) +[1 2 3 4] | reduce {|it, acc| $it + $acc } -[ - 1 - 2 - 3 - 4 -] | reduce {|it acc| - $it + $acc +{ + # too many "\n" before "x": one-line format required as no nested lists or record exist + x: 1, + y: 2 } -[ - { - name: "Teresa", - age: 24 - }, - { - name: "Thomas", - age: 26 - } -] +# too few "\n" before "{": multi-line format required as there are two nested records +[{name: "Teresa", age: 24}, + {name: "Thomas", age: 26}] ``` ## Options and parameters of custom commands From 42696915d14745ed98d17c4d5be80636fd7205c8 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 17 May 2023 16:47:01 +1000 Subject: [PATCH 29/35] feat(practices): dealing with parenthesis --- book/style_guide.md | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 8c3d38b1cee..6a911c99e8d 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -63,9 +63,9 @@ Rules: 1. **It's recommended to** put no spaces before first list value and after last list value. 2. **It's recommended to** put one space after comma `,` after list value. 5. surrounding constructs: - 1. **It's recommended to** put one space before opening square `[` or curly brace `{` if preceding symbol is not the same. - 2. **It's recommended to** put one space after closing square `]` or curly brace `}` if following symbol is not the same. - 3. **It's recommended to** put no spaces between square `[]` or curly brackets `{}` with nothing between them. + 1. **It's recommended to** put one space before opening square `[`, curly brace `{`, or parenthesis `(` if preceding symbol (one out of mentioned in this sentence) is not the same. + 2. **It's recommended to** put one space after closing square `]`, curly brace `}`, or parenthesis `)` if following symbol (one out of mentioned in this sentence) is not the same. + 3. **It's recommended to** put no spaces between square `[]`, curly brackets `{}`, parenthesis `()` with nothing between them. Correct: @@ -77,25 +77,29 @@ Correct: {x: 1 y: 2} [1 2] | zip [3 4] [] +(1 + 2) * 3 ``` Incorrect: ```nushell -# two many spaces before "|el|": no space is allowed +# too many spaces before "|el|": no space is allowed [[status]; [UP] [UP]] | all { |el| $el.status == UP } -# two many spaces before ",": no space is allowed +# too many spaces before ",": no space is allowed [1 2 3 4] | reduce {|it , acc| $it + $acc } -# two many spaces before "x": no space is allowed +# too many spaces before "x": no space is allowed { x: 1, y: 2} -# two many spaces before "[3": one space is required +# too many spaces before "[3": one space is required [1 2] | zip [3 4] -# two many spaces before "]": no space is allowed +# too many spaces before "]": no space is allowed [ ] + +# too many spaces before ")": no space is allowed +(1 + 2 ) * 3 ``` #### Multi-line format @@ -122,8 +126,8 @@ Rules: 4. lists: 1. **It's recommended to** put each list item on separate line. 5. surrounding constructs: - 1. **It's recommended to** put one `\n` before opening square `[` or curly brace `{` if preceding symbol is not the same. - 2. **It's recommended to** put one `\n` after closing square `]` or curly brace `}` if following symbol is not the same. + 1. **It's recommended to** put one `\n` before opening square `[`, curly brace `{`, or parenthesis `(` if preceding symbol (one out of mentioned in this sentence) is not the same. + 2. **It's recommended to** put one `\n` after closing square `]`, curly brace `}`, or parenthesis `)` if following symbol (one out of mentioned in this sentence) is not the same. Correct: @@ -142,6 +146,10 @@ Correct: {name: "Teresa", age: 24}, {name: "Thomas", age: 26} ] + +let selectedProfile = (for it in ($credentials | transpose name credentials) { + echo $it.name +}) ``` Incorrect: @@ -166,6 +174,12 @@ Incorrect: # too few "\n" before "{": multi-line format required as there are two nested records [{name: "Teresa", age: 24}, {name: "Thomas", age: 26}] + +let selectedProfile = ( + # too many "\n" before "foo": no "\n" is allowed + for it in ($credentials | transpose name credentials) { + echo $it.name +}) ``` ## Options and parameters of custom commands From 300cf67c11318dd35c3fa421c60e360df008136b Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 17 May 2023 16:51:44 +1000 Subject: [PATCH 30/35] feat(practices): forbid consecutive spaces --- book/style_guide.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/style_guide.md b/book/style_guide.md index 6a911c99e8d..0ac138d2b36 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -19,6 +19,7 @@ treat something like `\n` like the new line character and not a literal slash fo ### Basic - **It's recommended to** put one space before and after pipe `|` symbol, commands, subcommands, their options and arguments. +- **It's recommended to** never put several consecutive spaces unless they are part of string. - **It's recommended to** omit commas between list items. Correct: From 4b473664c86541b8b30b54c2a08c679976f7d9a2 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 17 May 2023 16:56:28 +1000 Subject: [PATCH 31/35] feat(practices): add spacing between constructs --- book/style_guide.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 0ac138d2b36..68d8b8754af 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -64,8 +64,8 @@ Rules: 1. **It's recommended to** put no spaces before first list value and after last list value. 2. **It's recommended to** put one space after comma `,` after list value. 5. surrounding constructs: - 1. **It's recommended to** put one space before opening square `[`, curly brace `{`, or parenthesis `(` if preceding symbol (one out of mentioned in this sentence) is not the same. - 2. **It's recommended to** put one space after closing square `]`, curly brace `}`, or parenthesis `)` if following symbol (one out of mentioned in this sentence) is not the same. + 1. **It's recommended to** put one space before opening square `[`, curly brace `{`, or parenthesis `(` if preceding symbol (one out of these: `[`, `{`, `(`, `]`, `}`, `)`) is not the same. + 2. **It's recommended to** put one space after closing square `]`, curly brace `}`, or parenthesis `)` if following symbol (one out of these: `[`, `{`, `(`, `]`, `}`, `)`) is not the same. 3. **It's recommended to** put no spaces between square `[]`, curly brackets `{}`, parenthesis `()` with nothing between them. Correct: @@ -127,8 +127,8 @@ Rules: 4. lists: 1. **It's recommended to** put each list item on separate line. 5. surrounding constructs: - 1. **It's recommended to** put one `\n` before opening square `[`, curly brace `{`, or parenthesis `(` if preceding symbol (one out of mentioned in this sentence) is not the same. - 2. **It's recommended to** put one `\n` after closing square `]`, curly brace `}`, or parenthesis `)` if following symbol (one out of mentioned in this sentence) is not the same. + 1. **It's recommended to** put one `\n` before opening square `[`, curly brace `{`, or parenthesis `(` if preceding symbol (one out of these: `[`, `{`, `(`, `]`, `}`, `)`) is not the same. + 2. **It's recommended to** put one `\n` after closing square `]`, curly brace `}`, or parenthesis `)` if following symbol (one out of these: `[`, `{`, `(`, `]`, `}`, `)`) is not the same. Correct: From 88565ff3fcaefeb99cd141e0dd92394e6d718d16 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 17 May 2023 17:18:08 +1000 Subject: [PATCH 32/35] feat(practices): simplify rules --- book/style_guide.md | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index 68d8b8754af..e091f6564cd 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -51,22 +51,18 @@ One-line format is a format for writing all commands in one line. Rules: 1. parameters: - 1. **It's recommended to** put no spaces before and after pipe `|` symbol denoting block or closure parameter list beginning. - 2. **It's recommended to** put one space after comma `,` after block or closure parameter. - 3. **It's recommended to** put no space before and one space after pipe `|` symbol denoting block or closure parameter list end. + 1. **It's recommended to** put one space after comma `,` after block or closure parameter. + 2. **It's recommended to** put one space after pipe `|` symbol denoting block or closure parameter list end. 2. block and closure bodies: 1. **It's recommended to** put one space before closing block or closure curly brace `}`. 3. records: - 1. **It's recommended to** put no spaces before first record key and after last record key value. - 2. **It's recommended to** put one space after `:` after record key. - 3. **It's recommended to** put one space after comma `,` after key value. + 1. **It's recommended to** put one space after `:` after record key. + 2. **It's recommended to** put one space after comma `,` after key value. 4. lists: - 1. **It's recommended to** put no spaces before first list value and after last list value. - 2. **It's recommended to** put one space after comma `,` after list value. + 1. **It's recommended to** put one space after comma `,` after list value. 5. surrounding constructs: - 1. **It's recommended to** put one space before opening square `[`, curly brace `{`, or parenthesis `(` if preceding symbol (one out of these: `[`, `{`, `(`, `]`, `}`, `)`) is not the same. - 2. **It's recommended to** put one space after closing square `]`, curly brace `}`, or parenthesis `)` if following symbol (one out of these: `[`, `{`, `(`, `]`, `}`, `)`) is not the same. - 3. **It's recommended to** put no spaces between square `[]`, curly brackets `{}`, parenthesis `()` with nothing between them. + 1. **It's recommended to** put one space before opening square `[`, curly brace `{`, or parenthesis `(` if preceding symbol is not the same. + 2. **It's recommended to** put one space after closing square `]`, curly brace `}`, or parenthesis `)` if following symbol is not the same. Correct: From d9695211399ca79840548811aa674abfd6a4bc64 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 17 May 2023 17:20:03 +1000 Subject: [PATCH 33/35] feat(practices): clarify rules for parenthesis --- book/style_guide.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/style_guide.md b/book/style_guide.md index e091f6564cd..1e7542f5d2d 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -123,8 +123,8 @@ Rules: 4. lists: 1. **It's recommended to** put each list item on separate line. 5. surrounding constructs: - 1. **It's recommended to** put one `\n` before opening square `[`, curly brace `{`, or parenthesis `(` if preceding symbol (one out of these: `[`, `{`, `(`, `]`, `}`, `)`) is not the same. - 2. **It's recommended to** put one `\n` after closing square `]`, curly brace `}`, or parenthesis `)` if following symbol (one out of these: `[`, `{`, `(`, `]`, `}`, `)`) is not the same. + 1. **It's recommended to** put one `\n` before opening square `[`, curly brace `{`, or parenthesis `(` if preceding symbol is not the and applying this rule produce line with a singular parenthesis. + 2. **It's recommended to** put one `\n` after closing square `]`, curly brace `}`, or parenthesis `)` if following symbol is not the same and applying this rule produce line with a singular parenthesis. Correct: From ebf66a4a1c734e8950b643361a0dd3b4dcd950b6 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 17 May 2023 21:00:57 +1000 Subject: [PATCH 34/35] feat(practices): spacing when no params defined --- book/style_guide.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index 1e7542f5d2d..c8c54e3c3b7 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -54,7 +54,8 @@ Rules: 1. **It's recommended to** put one space after comma `,` after block or closure parameter. 2. **It's recommended to** put one space after pipe `|` symbol denoting block or closure parameter list end. 2. block and closure bodies: - 1. **It's recommended to** put one space before closing block or closure curly brace `}`. + 1. **It's recommended to** put one space after opening block or closure curly brace `{` if no explicit parameters defined. + 2. **It's recommended to** put one space before closing block or closure curly brace `}`. 3. records: 1. **It's recommended to** put one space after `:` after record key. 2. **It's recommended to** put one space after comma `,` after key value. From 3616f66a210dd5bb28b3cc37c7d645233aedf46b Mon Sep 17 00:00:00 2001 From: Emily Grace Seville Date: Wed, 17 May 2023 22:30:41 +1000 Subject: [PATCH 35/35] Update book/style_guide.md Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> --- book/style_guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/style_guide.md b/book/style_guide.md index c8c54e3c3b7..f23fea44623 100644 --- a/book/style_guide.md +++ b/book/style_guide.md @@ -31,7 +31,7 @@ Correct: Incorrect: ```nushell -# - two many spaces after "|": 2 instead of 1 +# - too many spaces after "|": 2 instead of 1 'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff' ```