From cf946e70ca2cbfa5c4526d2730cf6c1dd6b9da5d Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Mon, 22 Jul 2024 09:57:25 +0800 Subject: [PATCH] chore: rubocop --- .github/workflows/rake.yml | 6 +----- .github/workflows/release.yml | 7 +++---- lib/poepod/cli.rb | 5 ++++- lib/poepod/file_processor.rb | 26 ++++++++++++++------------ lib/poepod/gem_processor.rb | 16 +++++++++------- lib/poepod/processor.rb | 2 ++ poepod.gemspec | 4 ++-- spec/poepod/cli_spec.rb | 16 +++++++++++++--- spec/poepod/file_processor_spec.rb | 2 ++ spec/poepod/gem_processor_spec.rb | 4 +++- 10 files changed, 53 insertions(+), 35 deletions(-) diff --git a/.github/workflows/rake.yml b/.github/workflows/rake.yml index 61bae9a..23c496f 100644 --- a/.github/workflows/rake.yml +++ b/.github/workflows/rake.yml @@ -1,5 +1,3 @@ -# Auto-generated by Cimas: Do not edit it manually! -# See https://github.com/metanorma/cimas name: rake on: @@ -11,6 +9,4 @@ on: jobs: rake: - uses: metanorma/ci/.github/workflows/generic-rake.yml@main - secrets: - pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }} + uses: metanorma/ci/.github/workflows/graphviz-rake.yml@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 029dc6f..aa6ca31 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,3 @@ -# Auto-generated by Cimas: Do not edit it manually! -# See https://github.com/metanorma/cimas name: release on: @@ -19,5 +17,6 @@ jobs: with: next_version: ${{ github.event.inputs.next_version }} secrets: - rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }} - pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }} + rubygems-api-key: ${{ secrets.LUTAML_CI_RUBYGEMS_API_KEY }} + pat_token: ${{ secrets.LUTAML_CI_PAT_TOKEN }} + diff --git a/lib/poepod/cli.rb b/lib/poepod/cli.rb index 678517d..00fad6a 100644 --- a/lib/poepod/cli.rb +++ b/lib/poepod/cli.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # lib/poepod/cli.rb require "thor" require_relative "file_processor" @@ -27,7 +29,8 @@ def concat(*files, output_file: nil) end desc "wrap GEMSPEC_PATH", "Wrap a gem based on its gemspec file" - option :include_unstaged, type: :boolean, default: false, desc: "Include unstaged files from lib, spec, and test directories" + option :include_unstaged, type: :boolean, default: false, + desc: "Include unstaged files from lib, spec, and test directories" def wrap(gemspec_path) processor = Poepod::GemProcessor.new(gemspec_path, nil, options[:include_unstaged]) diff --git a/lib/poepod/file_processor.rb b/lib/poepod/file_processor.rb index bb0d4ec..36763f0 100644 --- a/lib/poepod/file_processor.rb +++ b/lib/poepod/file_processor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "processor" require "yaml" require "tqdm" @@ -9,7 +11,7 @@ module Poepod class FileProcessor < Processor EXCLUDE_DEFAULT = [ - /node_modules\//, /.git\//, /.gitignore$/, /.DS_Store$/, + %r{node_modules/}, %r{.git/}, /.gitignore$/, /.DS_Store$/ ].freeze def initialize(files, output_file, config_file = nil, include_binary = false) @@ -27,17 +29,17 @@ def process File.open(@output_file, "w", encoding: "utf-8") do |output| @files.each do |file| Dir.glob(file).each do |matched_file| - if File.file?(matched_file) - total_files += 1 - file_path, content, error = process_file(matched_file) - if content - output.puts "--- START FILE: #{file_path} ---" - output.puts content - output.puts "--- END FILE: #{file_path} ---" - copied_files += 1 - elsif error - output.puts "#{file_path}\n#{error}" - end + next unless File.file?(matched_file) + + total_files += 1 + file_path, content, error = process_file(matched_file) + if content + output.puts "--- START FILE: #{file_path} ---" + output.puts content + output.puts "--- END FILE: #{file_path} ---" + copied_files += 1 + elsif error + output.puts "#{file_path}\n#{error}" end end end diff --git a/lib/poepod/gem_processor.rb b/lib/poepod/gem_processor.rb index d33b2ca..c65a387 100644 --- a/lib/poepod/gem_processor.rb +++ b/lib/poepod/gem_processor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # lib/poepod/gem_processor.rb require_relative "processor" require "rubygems/specification" @@ -18,7 +20,7 @@ def process begin spec = Gem::Specification.load(@gemspec_path) - rescue => e + rescue StandardError => e return [false, "Error loading gemspec: #{e.message}"] end @@ -43,11 +45,11 @@ def process files_to_include.uniq.each do |relative_path| full_path = File.join(File.dirname(@gemspec_path), relative_path) - if File.file?(full_path) - file.puts "--- START FILE: #{relative_path} ---" - file.puts File.read(full_path) - file.puts "--- END FILE: #{relative_path} ---\n\n" - end + next unless File.file?(full_path) + + file.puts "--- START FILE: #{relative_path} ---" + file.puts File.read(full_path) + file.puts "--- END FILE: #{relative_path} ---\n\n" end end @@ -58,7 +60,7 @@ def process def find_readme_files Dir.glob(File.join(File.dirname(@gemspec_path), "README*")) - .map { |path| Pathname.new(path).relative_path_from(Pathname.new(File.dirname(@gemspec_path))).to_s } + .map { |path| Pathname.new(path).relative_path_from(Pathname.new(File.dirname(@gemspec_path))).to_s } end def check_unstaged_files diff --git a/lib/poepod/processor.rb b/lib/poepod/processor.rb index 599bc3f..719bcd3 100644 --- a/lib/poepod/processor.rb +++ b/lib/poepod/processor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # lib/poepod/processor.rb module Poepod class Processor diff --git a/poepod.gemspec b/poepod.gemspec index 9f65d8f..694f68a 100644 --- a/poepod.gemspec +++ b/poepod.gemspec @@ -30,11 +30,11 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.test_files = `git ls-files -- spec/*`.split("\n") + spec.add_runtime_dependency "git", "~> 1.11" + spec.add_runtime_dependency "mime-types", "~> 3.3" spec.add_runtime_dependency "parallel", "~> 1.20" spec.add_runtime_dependency "thor", "~> 1.0" spec.add_runtime_dependency "tqdm" - spec.add_runtime_dependency "mime-types", "~> 3.3" - spec.add_runtime_dependency "git", "~> 1.11" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" diff --git a/spec/poepod/cli_spec.rb b/spec/poepod/cli_spec.rb index f88101b..bf38b03 100644 --- a/spec/poepod/cli_spec.rb +++ b/spec/poepod/cli_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" require "poepod/cli" @@ -27,12 +29,18 @@ it "excludes binary files by default" do output_file = File.join(temp_dir, "output.txt") - expect { cli.concat(text_file, binary_file, output_file: output_file) }.to output(/-> 2 files detected\.\n=> 1 files have been concatenated into.*\.txt/).to_stdout + expect do + cli.concat(text_file, binary_file, + output_file: output_file) + end.to output(/-> 2 files detected\.\n=> 1 files have been concatenated into.*\.txt/).to_stdout end it "includes binary files when specified" do output_file = File.join(temp_dir, "output.txt") - expect { cli.invoke(:concat, [text_file, binary_file], output_file: output_file, include_binary: true) }.to output(/-> 2 files detected\.\n=> 2 files have been concatenated into.*\.txt/).to_stdout + expect do + cli.invoke(:concat, [text_file, binary_file], output_file: output_file, + include_binary: true) + end.to output(/-> 2 files detected\.\n=> 2 files have been concatenated into.*\.txt/).to_stdout end end @@ -74,7 +82,9 @@ end it "handles non-existent gemspec" do - expect { cli.wrap("non_existent.gemspec") }.to output(/Error: The specified gemspec file/).to_stdout.and raise_error(SystemExit) + expect do + cli.wrap("non_existent.gemspec") + end.to output(/Error: The specified gemspec file/).to_stdout.and raise_error(SystemExit) end end end diff --git a/spec/poepod/file_processor_spec.rb b/spec/poepod/file_processor_spec.rb index 19f8fc4..f75dd57 100644 --- a/spec/poepod/file_processor_spec.rb +++ b/spec/poepod/file_processor_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # spec/poepod/file_processor_spec.rb require "spec_helper" require "poepod/file_processor" diff --git a/spec/poepod/gem_processor_spec.rb b/spec/poepod/gem_processor_spec.rb index bd3d4dd..72fe240 100644 --- a/spec/poepod/gem_processor_spec.rb +++ b/spec/poepod/gem_processor_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # spec/poepod/gem_processor_spec.rb require "spec_helper" require "poepod/gem_processor" @@ -103,7 +105,7 @@ "spec/test_gem_spec.rb" => "RSpec.describe TestGem do\nend", "README.md" => "# Test Gem\n\nThis is a test gem.", "README.txt" => "Test Gem\n\nThis is a test gem in plain text.", - "lib/unstaged_file.rb" => "Unstaged content", + "lib/unstaged_file.rb" => "Unstaged content" } # Mock File.read