From 2f6615bba786e135d22859a284cb40717a487726 Mon Sep 17 00:00:00 2001 From: Anton <1917237+default-anton@users.noreply.github.com> Date: Mon, 22 Sep 2025 11:45:45 -0700 Subject: [PATCH 1/6] feat: Add gem-push.yml --- .github/workflows/gem-push.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/gem-push.yml diff --git a/.github/workflows/gem-push.yml b/.github/workflows/gem-push.yml new file mode 100644 index 0000000..4e822f8 --- /dev/null +++ b/.github/workflows/gem-push.yml @@ -0,0 +1,33 @@ +name: Ruby Gem + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + name: Build + Publish + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: aha-app/checkout@v4 + - name: Set up Ruby + uses: aha-app/setup-ruby@v1 + with: + ruby-version: 3.4.x + + - name: Publish to RubyGems + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + gem build *.gemspec + gem push *.gem + env: + GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" From adffa718035f4d6eb7fa12c2e030663dc368e913 Mon Sep 17 00:00:00 2001 From: Anton Kuzmenko <1917237+default-anton@users.noreply.github.com> Date: Mon, 22 Sep 2025 11:46:35 -0700 Subject: [PATCH 2/6] ci: add GitHub Actions workflow for Ruby testing, linting, and building --- .github/{workflow => workflows}/ci.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/ci.yml (100%) diff --git a/.github/workflow/ci.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/workflow/ci.yml rename to .github/workflows/ci.yml From d10dbc3906ae0f6e63e4d45938503593f7cc6517 Mon Sep 17 00:00:00 2001 From: Anton Kuzmenko <1917237+default-anton@users.noreply.github.com> Date: Mon, 22 Sep 2025 11:49:52 -0700 Subject: [PATCH 3/6] ci: specify exact Ruby version 3.4 in gem-push workflow --- .github/workflows/gem-push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gem-push.yml b/.github/workflows/gem-push.yml index 4e822f8..9a6f4dd 100644 --- a/.github/workflows/gem-push.yml +++ b/.github/workflows/gem-push.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Ruby uses: aha-app/setup-ruby@v1 with: - ruby-version: 3.4.x + ruby-version: 3.4 - name: Publish to RubyGems run: | From c0a9cfd5d870a07b6f5efa335277510e5f22adb1 Mon Sep 17 00:00:00 2001 From: Anton Kuzmenko <1917237+default-anton@users.noreply.github.com> Date: Mon, 22 Sep 2025 12:06:07 -0700 Subject: [PATCH 4/6] style: configure RuboCop and fix code style issues in json_completer.rb --- .rubocop.yml | 44 +++++++++++++++++++++++++++++++++++++++++++ lib/json_completer.rb | 23 +++++++++++----------- 2 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..45437c6 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,44 @@ +AllCops: + Exclude: + - '*.gemspec' + NewCops: enable + SuggestExtensions: false + +Gemspec: + Enabled: false + +Metrics/ClassLength: + Enabled: false + +Metrics/AbcSize: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Metrics/PerceivedComplexity: + Enabled: false + +Layout/LineLength: + Enabled: false + +Metrics/BlockNesting: + Enabled: false + +Metrics/BlockLength: + Enabled: false + +Style/StringConcatenation: + Enabled: false + +Style/StringLiterals: + Enabled: false + +Style/NumericLiterals: + Enabled: false + +Style/IfUnlessModifier: + Enabled: false diff --git a/lib/json_completer.rb b/lib/json_completer.rb index f84909d..a155e32 100644 --- a/lib/json_completer.rb +++ b/lib/json_completer.rb @@ -51,7 +51,7 @@ def complete(partial_json) end return input if input.empty? - return input if is_valid_json_primitive_or_document?(input) + return input if valid_json_primitive_or_document?(input) # If input hasn't grown since last time, just return completed version of existing state if @state.input_length == input.length && !@state.output_tokens.empty? @@ -73,7 +73,7 @@ def complete(partial_json) incomplete_string_buffer = @state.incomplete_string_buffer || StringIO.new('"') incomplete_string_escape_state = @state.incomplete_string_escape_state # Remove the auto-completed string from output_tokens since we'll add the real one - output_tokens.pop if output_tokens.last&.start_with?('"') && output_tokens.last&.end_with?('"') + output_tokens.pop if output_tokens.last&.start_with?('"') && output_tokens.last.end_with?('"') end # Process from the current index @@ -81,7 +81,7 @@ def complete(partial_json) # Special case: continuing an incomplete string if incomplete_string_buffer && index == @state.last_index str_value, new_index, terminated, new_buffer, new_escape_state = continue_parsing_string( - input, incomplete_string_start, incomplete_string_buffer, incomplete_string_escape_state + input, incomplete_string_buffer, incomplete_string_escape_state ) if terminated output_tokens << str_value @@ -227,9 +227,7 @@ def finalize_completion(output_tokens, context_stack, incomplete_string_buffer = # If odd number of trailing backslashes, remove the last one (incomplete escape) # If even number, they're all paired as escaped backslashes, don't remove any - if trailing_backslashes.odd? - buffer_str = buffer_str[0...-1] - end + buffer_str = buffer_str[0...-1] if trailing_backslashes.odd? # Check for incomplete unicode escape after handling backslashes if buffer_str =~ /\\u[0-9a-fA-F]{0,3}\z/ # Incomplete unicode @@ -353,7 +351,7 @@ def parse_string_with_state(input, index) # Continues parsing an incomplete string from saved state # Returns [string_value, new_index, was_terminated, buffer, escape_state] - def continue_parsing_string(input, string_start_index, buffer, escape_state) + def continue_parsing_string(input, buffer, escape_state) # Buffer should not have closing quote - we removed it from parse_string_with_state index = @state.last_index @@ -589,7 +587,8 @@ def parse_number(input, index) else (temp_num_val.include?('.') ? temp_num_val + '0' : temp_num_val) end, - index - start_index] + index - start_index + ] end num_str << input[index] # 'e' or 'E' @@ -631,7 +630,7 @@ def consume_and_complete_keyword(input, index, target_keyword) # Mismatch end # If at least the first char matched, we complete to the target_keyword - return [target_keyword, consumed_count] if consumed_count > 0 + return [target_keyword, consumed_count] if consumed_count.positive? # Fallback (should not be reached if called correctly, i.e., input[index] is t,f, or n) # This indicates the char was not the start of the expected keyword. @@ -702,7 +701,7 @@ def remove_trailing_comma(output_tokens) output_tokens.slice!(last_token_idx) # Also remove any whitespace tokens that were before this comma and are now effectively trailing - while last_token_idx > 0 && output_tokens[last_token_idx - 1].strip.empty? + while last_token_idx.positive? && output_tokens[last_token_idx - 1].strip.empty? output_tokens.slice!(last_token_idx - 1) last_token_idx -= 1 end @@ -710,13 +709,13 @@ def remove_trailing_comma(output_tokens) # Checks if a string is a valid JSON primitive or a complete JSON document. # This is a helper for early exit if input is already fine. - def is_valid_json_primitive_or_document?(str) + def valid_json_primitive_or_document?(str) # Check for simple primitives first return true if VALID_PRIMITIVES.include?(str) # Check for valid number (simplified regex, full JSON number is complex) # Allows integers, floats, but not ending with '.' or 'e'/'E' without digits if str.match?(/\A-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?\z/) && - !str.end_with?('.') && !str.match?(/[eE][+-]?$/) + !str.end_with?('.') && !str.match?(/[eE][+-]?$/) return true end # Check for valid string literal From baea6c77e9dc5fa83da77cce4548c33a7a358b31 Mon Sep 17 00:00:00 2001 From: Anton Kuzmenko <1917237+default-anton@users.noreply.github.com> Date: Mon, 22 Sep 2025 12:08:23 -0700 Subject: [PATCH 5/6] ci: trigger gem push workflow on release published event instead of push or pull_request --- .github/workflows/gem-push.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/gem-push.yml b/.github/workflows/gem-push.yml index 9a6f4dd..144494e 100644 --- a/.github/workflows/gem-push.yml +++ b/.github/workflows/gem-push.yml @@ -1,10 +1,8 @@ name: Ruby Gem on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] + release: + types: [ published ] jobs: build: From dceb95a309a5dee6853064aeefcce180f2e0f439 Mon Sep 17 00:00:00 2001 From: Anton Kuzmenko <1917237+default-anton@users.noreply.github.com> Date: Mon, 22 Sep 2025 12:09:07 -0700 Subject: [PATCH 6/6] ci: remove Ruby 3.0 and 3.1 from CI test matrix --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff940f2..70a8416 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,6 @@ jobs: fail-fast: false matrix: ruby: - - '3.0' - - '3.1' - '3.2' - '3.3' - '3.4'