From efc0153207e2c49637abd0119ce5e0d24a85ab9b Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 1 Aug 2025 11:59:50 +0000 Subject: [PATCH 01/10] - Add ability to choose a different formatter (internal, none, shfmt) --- lib/bashly.rb | 2 +- lib/bashly/exceptions.rb | 1 + lib/bashly/extensions/string.rb | 4 +-- lib/bashly/libraries/settings/settings.yml | 22 +++++++----- lib/bashly/script/formatter.rb | 40 ++++++++++++++++++++++ lib/bashly/script/wrapper.rb | 8 ++++- lib/bashly/settings.rb | 5 +++ schemas/settings.json | 11 ++++++ support/schema/settings.yml | 11 ++++++ 9 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 lib/bashly/script/formatter.rb diff --git a/lib/bashly.rb b/lib/bashly.rb index 1255c93f..016e2e2d 100644 --- a/lib/bashly.rb +++ b/lib/bashly.rb @@ -22,7 +22,7 @@ module Bashly module Script autoloads 'bashly/script', %i[ Argument Base CatchAll Command Dependency EnvironmentVariable Flag - Variable Wrapper + Formatter Variable Wrapper ] module Introspection diff --git a/lib/bashly/exceptions.rb b/lib/bashly/exceptions.rb index 7617d3f6..85264db3 100644 --- a/lib/bashly/exceptions.rb +++ b/lib/bashly/exceptions.rb @@ -3,4 +3,5 @@ class Interrupt < Interrupt; end class Error < StandardError; end class InitError < Error; end class ConfigurationError < Error; end + class DependencyError < Error; end end diff --git a/lib/bashly/extensions/string.rb b/lib/bashly/extensions/string.rb index 0eb66e6e..7c7c20f2 100644 --- a/lib/bashly/extensions/string.rb +++ b/lib/bashly/extensions/string.rb @@ -44,8 +44,8 @@ def wrap(length = 80) end * "\n" end - def lint - gsub(/\s+\n/m, "\n\n").lines.grep_v(/^\s*##/).join + def remove_private_comments + lines.grep_v(/^\s*##/).join end def remove_front_matter diff --git a/lib/bashly/libraries/settings/settings.yml b/lib/bashly/libraries/settings/settings.yml index b6bc1ddd..2baf32ed 100644 --- a/lib/bashly/libraries/settings/settings.yml +++ b/lib/bashly/libraries/settings/settings.yml @@ -41,16 +41,22 @@ partials_extension: sh #------------------------------------------------------------------------------- # Configure the bash options that will be added to the initialize function: -# strict: true Bash strict mode (set -euo pipefail) -# strict: false Only exit on errors (set -e) -# strict: '' Do not add any 'set' directive -# strict: Add any other custom 'set' directive +# strict: true # Bash strict mode (set -euo pipefail) +# strict: false # Only exit on errors (set -e) +# strict: '' # Do not add any 'set' directive +# strict: # Add any other custom 'set' directive strict: false # When true, the generated script will use tab indentation instead of spaces # (every 2 leading spaces will be converted to a tab character) tab_indent: false +# Choose a post-processor for the generated script: +# formatter: internal # Use Bashly's internal formatter (compacts newlines) +# formatter: none # Disable all post-processing +# formatter: shfmt # Use shfmt if installed +formatter: internal + #------------------------------------------------------------------------------- # INTERFACE OPTIONS @@ -100,10 +106,10 @@ env: development # Tweak the script output by enabling or disabling some script output. # These options accept one of the following strings: -# - production render this feature only when env == production -# - development render this feature only when env == development -# - always render this feature in any environment -# - never do not render this feature +# - production # render this feature only when env == production +# - development # render this feature only when env == development +# - always # render this feature in any environment +# - never # do not render this feature enable_header_comment: always enable_bash3_bouncer: always enable_view_markers: development diff --git a/lib/bashly/script/formatter.rb b/lib/bashly/script/formatter.rb new file mode 100644 index 00000000..20a406b9 --- /dev/null +++ b/lib/bashly/script/formatter.rb @@ -0,0 +1,40 @@ +require 'open3' + +module Bashly + module Script + class Formatter + MODES = %i[internal none shfmt] + + attr_reader :script, :mode + + def initialize(script, mode: nil) + @script = script + @mode = MODES.include?(mode&.to_sym) ? mode.to_sym : MODES.first + end + + def formatted_script + case mode + when :internal then script.gsub(/\s+\n/m, "\n\n") + when :shfmt then shfmt_result + else script + end + end + + private + + def shfmt_result + unless system 'command -v shfmt > /dev/null 2>&1' + raise DependencyError, + 'Cannot find g`shfmt`.\nEither install it or change to the g`internal` formatter.' + end + + output, error, status = + Open3.capture3 %w[shfmt --case-indent --indent 2], stdin_data: script + + raise DependencyError, "Failed running g`shfmt`:\n\n#{error}" unless status.success? + + output + end + end + end +end diff --git a/lib/bashly/script/wrapper.rb b/lib/bashly/script/wrapper.rb index dd59e198..c80639a3 100644 --- a/lib/bashly/script/wrapper.rb +++ b/lib/bashly/script/wrapper.rb @@ -23,7 +23,13 @@ def base_code [header, body] end - result.join("\n").lint + clean_code result.join("\n") + end + + def clean_code(script) + script.remove_private_comments + formatter = Formatter.new script, mode: Settings.formatter + formatter.formatted_script end def header diff --git a/lib/bashly/settings.rb b/lib/bashly/settings.rb index b59d5512..ac8b30ef 100644 --- a/lib/bashly/settings.rb +++ b/lib/bashly/settings.rb @@ -15,6 +15,7 @@ class << self :enable_inspect_args, :enable_sourcing, :enable_view_markers, + :formatter, :function_names, :lib_dir, :partials_extension, @@ -86,6 +87,10 @@ def env=(value) @env = value&.to_sym end + def formatter + @formatter ||= get :formatter + end + def full_lib_dir "#{source_dir}/#{lib_dir}" end diff --git a/schemas/settings.json b/schemas/settings.json index b52fb408..0898ea6d 100644 --- a/schemas/settings.json +++ b/schemas/settings.json @@ -213,6 +213,17 @@ ], "default": "development" }, + "formatter": { + "title": "formatter", + "description": "Choose how to post-process the generated script\nhttps://bashly.dev/usage/settings/#formatter", + "type": "string", + "enum": [ + "internal", + "none", + "shfmt" + ], + "default": "internal" + }, "partials_extension": { "title": "partials extension", "description": "The extension to use when reading/writing partial script snippets\nhttps://bashly.dev/usage/settings/#partials_extension", diff --git a/support/schema/settings.yml b/support/schema/settings.yml index 8b4c4c17..b40fab7c 100644 --- a/support/schema/settings.yml +++ b/support/schema/settings.yml @@ -181,6 +181,17 @@ properties: type: string enum: *feature_toggles default: development + formatter: + title: formatter + description: |- + Choose how to post-process the generated script + https://bashly.dev/usage/settings/#formatter + type: string + enum: + - internal + - none + - shfmt + default: internal partials_extension: title: partials extension description: |- From c870e6ca0e20d9f39d4f9993f7b329ed4344eef5 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 1 Aug 2025 13:20:26 +0000 Subject: [PATCH 02/10] fix specs --- examples/render-mandoc/docs/download.1 | 2 +- examples/render-mandoc/docs/download.md | 2 +- lib/bashly/script/wrapper.rb | 4 ++-- spec/approvals/examples/render-mandoc | 2 +- spec/approvals/examples/stacktrace | 4 ++-- spec/bashly/extensions/string_spec.rb | 18 ++++-------------- 6 files changed, 11 insertions(+), 21 deletions(-) diff --git a/examples/render-mandoc/docs/download.1 b/examples/render-mandoc/docs/download.1 index 7b8e71c9..3303044c 100644 --- a/examples/render-mandoc/docs/download.1 +++ b/examples/render-mandoc/docs/download.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 3.2 .\" -.TH "download" "1" "July 2025" "Version 0.1.0" "Sample application" +.TH "download" "1" "August 2025" "Version 0.1.0" "Sample application" .SH NAME \f[B]download\f[R] \- Sample application .SH SYNOPSIS diff --git a/examples/render-mandoc/docs/download.md b/examples/render-mandoc/docs/download.md index 1a750aef..b4f08c4a 100644 --- a/examples/render-mandoc/docs/download.md +++ b/examples/render-mandoc/docs/download.md @@ -1,6 +1,6 @@ % download(1) Version 0.1.0 | Sample application % Lana Lang -% July 2025 +% August 2025 NAME ================================================== diff --git a/lib/bashly/script/wrapper.rb b/lib/bashly/script/wrapper.rb index c80639a3..537766e4 100644 --- a/lib/bashly/script/wrapper.rb +++ b/lib/bashly/script/wrapper.rb @@ -27,8 +27,8 @@ def base_code end def clean_code(script) - script.remove_private_comments - formatter = Formatter.new script, mode: Settings.formatter + result = script.remove_private_comments + formatter = Formatter.new result, mode: Settings.formatter formatter.formatted_script end diff --git a/spec/approvals/examples/render-mandoc b/spec/approvals/examples/render-mandoc index 96bc2eee..fca583fc 100644 --- a/spec/approvals/examples/render-mandoc +++ b/spec/approvals/examples/render-mandoc @@ -44,4 +44,4 @@ ISSUE TRACKER AUTHORS Lana Lang. -Version 0.1.0 July 2025 download(1) +Version 0.1.0 August 2025 download(1) diff --git a/spec/approvals/examples/stacktrace b/spec/approvals/examples/stacktrace index 79a6529d..1b4e3915 100644 --- a/spec/approvals/examples/stacktrace +++ b/spec/approvals/examples/stacktrace @@ -51,5 +51,5 @@ Examples: Stack trace: from ./download:15 in `root_command` - from ./download:260 in `run` - from ./download:266 in `main` + from ./download:259 in `run` + from ./download:265 in `main` diff --git a/spec/bashly/extensions/string_spec.rb b/spec/bashly/extensions/string_spec.rb index deb0449b..f29b7eb0 100644 --- a/spec/bashly/extensions/string_spec.rb +++ b/spec/bashly/extensions/string_spec.rb @@ -125,21 +125,11 @@ end end - describe '#lint' do - context 'with a string that contains multiple consecutive newlines' do - subject { "one\n two\n \n three\n \n \nfour\n\n\n\n" } + describe '#remove_private_comments' do + subject { "this is important\n## SECRET\n ## ANOTHER SECRET\n also important\n" } - it 'replaces two or more newlines with two newlines' do - expect(subject.lint).to eq "one\n two\n\n three\n\nfour\n\n" - end - end - - context 'with a string that contains double-hash comments' do - subject { "this is important\n## SECRET\n ## ANOTHER SECRET\n also important\n" } - - it 'removes these comments' do - expect(subject.lint).to eq "this is important\n also important\n" - end + it 'removes these comments' do + expect(subject.remove_private_comments).to eq "this is important\n also important\n" end end From cefdc59070562184905ec1cd3bbb49d965872493 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 1 Aug 2025 14:01:50 +0000 Subject: [PATCH 03/10] fix shfmt formatter and add support for custom command --- lib/bashly/libraries/settings/settings.yml | 11 ++++++----- lib/bashly/script/formatter.rb | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/bashly/libraries/settings/settings.yml b/lib/bashly/libraries/settings/settings.yml index 2baf32ed..dc89d23b 100644 --- a/lib/bashly/libraries/settings/settings.yml +++ b/lib/bashly/libraries/settings/settings.yml @@ -52,11 +52,12 @@ strict: false tab_indent: false # Choose a post-processor for the generated script: -# formatter: internal # Use Bashly's internal formatter (compacts newlines) -# formatter: none # Disable all post-processing -# formatter: shfmt # Use shfmt if installed -formatter: internal - +# formatter: :internal # Use Bashly's internal formatter (compacts newlines) +# formatter: :none # Disable all post-processing +# formatter: :shfmt # Use shfmt if installed +# formatter: shfmt -mn # Use any other string, assuming the command accepts +# # the script as stdin and outputs it to stdout +formatter: :internal #------------------------------------------------------------------------------- # INTERFACE OPTIONS diff --git a/lib/bashly/script/formatter.rb b/lib/bashly/script/formatter.rb index 20a406b9..14dac290 100644 --- a/lib/bashly/script/formatter.rb +++ b/lib/bashly/script/formatter.rb @@ -1,4 +1,5 @@ require 'open3' +require 'shellwords' module Bashly module Script @@ -9,29 +10,28 @@ class Formatter def initialize(script, mode: nil) @script = script - @mode = MODES.include?(mode&.to_sym) ? mode.to_sym : MODES.first + @mode = mode end def formatted_script case mode when :internal then script.gsub(/\s+\n/m, "\n\n") when :shfmt then shfmt_result - else script + when :none then script + else custom_formatter_result mode end end private def shfmt_result - unless system 'command -v shfmt > /dev/null 2>&1' - raise DependencyError, - 'Cannot find g`shfmt`.\nEither install it or change to the g`internal` formatter.' - end - - output, error, status = - Open3.capture3 %w[shfmt --case-indent --indent 2], stdin_data: script + custom_formatter_result %w[shfmt --case-indent --indent 2] + end - raise DependencyError, "Failed running g`shfmt`:\n\n#{error}" unless status.success? + def custom_formatter_result(command) + command = Shellwords.split command if command.is_a? String + output, error, status = Open3.capture3 *command, stdin_data: script + raise DependencyError, "Failed running g`#{command}`:\n\n#{error}" unless status.success? output end From 149ce5fd98fbfed61f479483a876053508f8016b Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 1 Aug 2025 14:22:41 +0000 Subject: [PATCH 04/10] fix settings schema --- schemas/settings.json | 20 ++++++++++++++------ support/schema/settings.yml | 15 +++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/schemas/settings.json b/schemas/settings.json index 0898ea6d..32ca2d92 100644 --- a/schemas/settings.json +++ b/schemas/settings.json @@ -216,13 +216,21 @@ "formatter": { "title": "formatter", "description": "Choose how to post-process the generated script\nhttps://bashly.dev/usage/settings/#formatter", - "type": "string", - "enum": [ - "internal", - "none", - "shfmt" + "anyOf": [ + { + "type": "string", + "enum": [ + ":internal", + ":none", + ":shfmt" + ] + }, + { + "type": "string", + "minLength": 1 + } ], - "default": "internal" + "default": ":internal" }, "partials_extension": { "title": "partials extension", diff --git a/support/schema/settings.yml b/support/schema/settings.yml index b40fab7c..334264ce 100644 --- a/support/schema/settings.yml +++ b/support/schema/settings.yml @@ -186,12 +186,15 @@ properties: description: |- Choose how to post-process the generated script https://bashly.dev/usage/settings/#formatter - type: string - enum: - - internal - - none - - shfmt - default: internal + anyOf: + - type: string + enum: + - :internal + - :none + - :shfmt + - type: string + minLength: 1 + default: :internal partials_extension: title: partials extension description: |- From 914e7b6d67fd94bb00e6a1a1bc10f0fdb201eaec Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 1 Aug 2025 14:55:22 +0000 Subject: [PATCH 05/10] add formatter specs --- lib/bashly/exceptions.rb | 1 - lib/bashly/script/formatter.rb | 13 ++++-- spec/approvals/formatter/error-failure | 1 + spec/approvals/formatter/error-not-found | 1 + spec/approvals/formatter/internal | 14 +++++++ spec/approvals/formatter/shfmt | 16 +++++++ spec/approvals/formatter/shfmt-custom | 17 ++++++++ spec/bashly/script/formatter_spec.rb | 53 ++++++++++++++++++++++++ spec/fixtures/formatter/simple.sh | 18 ++++++++ 9 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 spec/approvals/formatter/error-failure create mode 100644 spec/approvals/formatter/error-not-found create mode 100644 spec/approvals/formatter/internal create mode 100644 spec/approvals/formatter/shfmt create mode 100644 spec/approvals/formatter/shfmt-custom create mode 100644 spec/bashly/script/formatter_spec.rb create mode 100644 spec/fixtures/formatter/simple.sh diff --git a/lib/bashly/exceptions.rb b/lib/bashly/exceptions.rb index 85264db3..7617d3f6 100644 --- a/lib/bashly/exceptions.rb +++ b/lib/bashly/exceptions.rb @@ -3,5 +3,4 @@ class Interrupt < Interrupt; end class Error < StandardError; end class InitError < Error; end class ConfigurationError < Error; end - class DependencyError < Error; end end diff --git a/lib/bashly/script/formatter.rb b/lib/bashly/script/formatter.rb index 14dac290..88b94890 100644 --- a/lib/bashly/script/formatter.rb +++ b/lib/bashly/script/formatter.rb @@ -10,7 +10,7 @@ class Formatter def initialize(script, mode: nil) @script = script - @mode = mode + @mode = mode || :internal end def formatted_script @@ -30,8 +30,15 @@ def shfmt_result def custom_formatter_result(command) command = Shellwords.split command if command.is_a? String - output, error, status = Open3.capture3 *command, stdin_data: script - raise DependencyError, "Failed running g`#{command}`:\n\n#{error}" unless status.success? + + begin + output, error, status = Open3.capture3(*command, stdin_data: script) + rescue Errno::ENOENT => e + raise Error, "Command not found: `#{command.join(' ')}`" + end + + raise Error, "Failed running `#{command.join(' ')}`:\n\n#{error}" unless status.success? + output end diff --git a/spec/approvals/formatter/error-failure b/spec/approvals/formatter/error-failure new file mode 100644 index 00000000..94e40cca --- /dev/null +++ b/spec/approvals/formatter/error-failure @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/approvals/formatter/error-not-found b/spec/approvals/formatter/error-not-found new file mode 100644 index 00000000..b8830859 --- /dev/null +++ b/spec/approvals/formatter/error-not-found @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/approvals/formatter/internal b/spec/approvals/formatter/internal new file mode 100644 index 00000000..086b573e --- /dev/null +++ b/spec/approvals/formatter/internal @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +funk() { + cat < Date: Fri, 1 Aug 2025 15:01:09 +0000 Subject: [PATCH 06/10] install shfmt for ci tests --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cd440da1..361db704 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,9 @@ jobs: - name: Install pandoc run: rush get pandoc + - name: Install shfmt + run: rush get shfmt + # libyaml needed for Ruby's YAML library - name: Install OS dependencies run: sudo apt-get -y install libyaml-dev From 6c0bd9aa2ddcfad8c1c9bf95a1000dbdf68129a7 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 1 Aug 2025 15:04:17 +0000 Subject: [PATCH 07/10] rubocop --- lib/bashly/script/formatter.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/bashly/script/formatter.rb b/lib/bashly/script/formatter.rb index 88b94890..7238f09b 100644 --- a/lib/bashly/script/formatter.rb +++ b/lib/bashly/script/formatter.rb @@ -30,16 +30,15 @@ def shfmt_result def custom_formatter_result(command) command = Shellwords.split command if command.is_a? String - + begin output, error, status = Open3.capture3(*command, stdin_data: script) - rescue Errno::ENOENT => e + rescue Errno::ENOENT raise Error, "Command not found: `#{command.join(' ')}`" end raise Error, "Failed running `#{command.join(' ')}`:\n\n#{error}" unless status.success? - output end end From 986c80325273b564c0ffd03214073ce7856feb63 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Fri, 1 Aug 2025 18:30:46 +0000 Subject: [PATCH 08/10] change formatter values from symbols to strings --- lib/bashly/libraries/settings/settings.yml | 15 +++++++++------ lib/bashly/script/formatter.rb | 14 ++++++-------- schemas/settings.json | 6 +++--- spec/approvals/formatter/error-failure | 2 +- spec/approvals/formatter/error-not-found | 2 +- spec/bashly/script/formatter_spec.rb | 10 +++++----- support/schema/settings.yml | 6 +++--- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/bashly/libraries/settings/settings.yml b/lib/bashly/libraries/settings/settings.yml index dc89d23b..2b9e0e31 100644 --- a/lib/bashly/libraries/settings/settings.yml +++ b/lib/bashly/libraries/settings/settings.yml @@ -52,12 +52,15 @@ strict: false tab_indent: false # Choose a post-processor for the generated script: -# formatter: :internal # Use Bashly's internal formatter (compacts newlines) -# formatter: :none # Disable all post-processing -# formatter: :shfmt # Use shfmt if installed -# formatter: shfmt -mn # Use any other string, assuming the command accepts -# # the script as stdin and outputs it to stdout -formatter: :internal +# formatter: internal # Use Bashly's internal formatter (compacts newlines) +# formatter: external # Run the external command `shfmt --case-indent --indent 2` +# formatter: none # Disable formatting entirely +# formatter: # Use a custom shell command to format the script. +# # The command will receive the script via stdin and +# # must output the result to stdout. +# # Example: shfmt --minify +formatter: internal + #------------------------------------------------------------------------------- # INTERFACE OPTIONS diff --git a/lib/bashly/script/formatter.rb b/lib/bashly/script/formatter.rb index 7238f09b..d17c2881 100644 --- a/lib/bashly/script/formatter.rb +++ b/lib/bashly/script/formatter.rb @@ -4,20 +4,18 @@ module Bashly module Script class Formatter - MODES = %i[internal none shfmt] - attr_reader :script, :mode def initialize(script, mode: nil) @script = script - @mode = mode || :internal + @mode = mode&.to_s || 'internal' end def formatted_script case mode - when :internal then script.gsub(/\s+\n/m, "\n\n") - when :shfmt then shfmt_result - when :none then script + when 'internal' then script.gsub(/\s+\n/m, "\n\n") + when 'external' then shfmt_result + when 'none' then script else custom_formatter_result mode end end @@ -34,10 +32,10 @@ def custom_formatter_result(command) begin output, error, status = Open3.capture3(*command, stdin_data: script) rescue Errno::ENOENT - raise Error, "Command not found: `#{command.join(' ')}`" + raise Error, "Command not found: g`#{command.first}`" end - raise Error, "Failed running `#{command.join(' ')}`:\n\n#{error}" unless status.success? + raise Error, "Failed running g`#{Shellwords.join command}`:\n\n#{error}" unless status.success? output end diff --git a/schemas/settings.json b/schemas/settings.json index 32ca2d92..320a8642 100644 --- a/schemas/settings.json +++ b/schemas/settings.json @@ -220,9 +220,9 @@ { "type": "string", "enum": [ - ":internal", - ":none", - ":shfmt" + "internal", + "none", + "external" ] }, { diff --git a/spec/approvals/formatter/error-failure b/spec/approvals/formatter/error-failure index 94e40cca..b350a91b 100644 --- a/spec/approvals/formatter/error-failure +++ b/spec/approvals/formatter/error-failure @@ -1 +1 @@ -# \ No newline at end of file +# \ No newline at end of file diff --git a/spec/approvals/formatter/error-not-found b/spec/approvals/formatter/error-not-found index b8830859..1e1a6ccb 100644 --- a/spec/approvals/formatter/error-not-found +++ b/spec/approvals/formatter/error-not-found @@ -1 +1 @@ -# \ No newline at end of file +# \ No newline at end of file diff --git a/spec/bashly/script/formatter_spec.rb b/spec/bashly/script/formatter_spec.rb index a33f2cfc..efc0be4e 100644 --- a/spec/bashly/script/formatter_spec.rb +++ b/spec/bashly/script/formatter_spec.rb @@ -10,16 +10,16 @@ expect(subject.formatted_script).to match_approval 'formatter/internal' end - context 'with mode: :none' do - let(:mode) { :none } + context 'with mode: none' do + let(:mode) { 'none' } it 'returns the original script' do expect(subject.formatted_script).to eq script end end - context 'with mode: :shfmt' do - let(:mode) { :shfmt } + context 'with mode: external' do + let(:mode) { 'external' } it 'uses shfmt to format the script' do expect(subject.formatted_script).to match_approval 'formatter/shfmt' @@ -35,7 +35,7 @@ end context 'when the external command does not exist' do - let(:mode) { 'my_glorious_formatter' } + let(:mode) { 'my_formatter' } it 'raises a Bashly::Error' do expect { subject.formatted_script }.to raise_approval 'formatter/error-not-found' diff --git a/support/schema/settings.yml b/support/schema/settings.yml index 334264ce..7f31f9eb 100644 --- a/support/schema/settings.yml +++ b/support/schema/settings.yml @@ -189,9 +189,9 @@ properties: anyOf: - type: string enum: - - :internal - - :none - - :shfmt + - internal + - none + - external - type: string minLength: 1 default: :internal From a7b655c2dcc2dbcfd4b198c2f44fae3c0682296b Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sat, 2 Aug 2025 21:50:37 +0300 Subject: [PATCH 09/10] Update spec/bashly/script/formatter_spec.rb Co-authored-by: meleu --- spec/bashly/script/formatter_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/bashly/script/formatter_spec.rb b/spec/bashly/script/formatter_spec.rb index efc0be4e..09e908d5 100644 --- a/spec/bashly/script/formatter_spec.rb +++ b/spec/bashly/script/formatter_spec.rb @@ -45,7 +45,7 @@ context 'when the external command fails' do let(:mode) { 'shfmt --diff' } - it 'raises a a Bashly::Error' do + it 'raises a Bashly::Error' do expect { subject.formatted_script }.to raise_approval 'formatter/error-failure' end end From 1eeb78b75a521701cc740bd6bd3937669c9c5ba9 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sat, 2 Aug 2025 18:56:40 +0000 Subject: [PATCH 10/10] fix settings formatter schema definition --- schemas/settings.json | 6 +++--- support/schema/settings.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/schemas/settings.json b/schemas/settings.json index 320a8642..5cddac76 100644 --- a/schemas/settings.json +++ b/schemas/settings.json @@ -221,8 +221,8 @@ "type": "string", "enum": [ "internal", - "none", - "external" + "external", + "none" ] }, { @@ -230,7 +230,7 @@ "minLength": 1 } ], - "default": ":internal" + "default": "internal" }, "partials_extension": { "title": "partials extension", diff --git a/support/schema/settings.yml b/support/schema/settings.yml index 7f31f9eb..699dbc3b 100644 --- a/support/schema/settings.yml +++ b/support/schema/settings.yml @@ -190,11 +190,11 @@ properties: - type: string enum: - internal - - none - external + - none - type: string minLength: 1 - default: :internal + default: internal partials_extension: title: partials extension description: |-