From 5b22342c81282091d87d7c86d2268edd5fb1d698 Mon Sep 17 00:00:00 2001 From: Datpmt Date: Fri, 17 Jan 2025 14:13:37 +0700 Subject: [PATCH 1/3] Upgrade gem typo_checker v0.1.8 --- .github/typocop/setting.yml | 11 +++++++++++ .gitignore | 1 + Gemfile.lock | 37 ------------------------------------- lib/typocop.rb | 16 ++++++++++------ lib/typocop/settings.rb | 10 ++++------ 5 files changed, 26 insertions(+), 49 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.github/typocop/setting.yml b/.github/typocop/setting.yml index adcd61a6..2c87f13f 100644 --- a/.github/typocop/setting.yml +++ b/.github/typocop/setting.yml @@ -1,5 +1,16 @@ # Configuration for Typocop - a GitHub Action for checking typos in pull requests +# 'paths' section allows you to specify which files or directories to scan. +# Only the specified paths will be checked for typos. You can use glob patterns to include directories. + +paths: # Files and directories to scan + # Example: Scan only the 'src' folder + - src/* + # Example: Scan a specific file (e.g., 'README.md') + - README.md + # Example: Scan all Ruby files in the 'lib' directory + - lib/**/*.rb + # 'excludes' section allows you to specify files and folders to exclude # from the typo-checking process. You can list specific files or use glob # patterns to exclude entire directories. diff --git a/.gitignore b/.gitignore index 100c07a0..837b0a57 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,4 @@ build-iPhoneSimulator/ # Used by RuboCop. Remote config files pulled in from inherit_from directive. # .rubocop-https?--* .DS_Store +Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index d404d153..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,37 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - addressable (2.8.7) - public_suffix (>= 2.0.2, < 7.0) - cli (1.4.0) - faraday (2.12.1) - faraday-net_http (>= 2.0, < 3.5) - json - logger - faraday-net_http (3.4.0) - net-http (>= 0.5.0) - json (2.9.0) - logger (1.6.2) - net-http (0.6.0) - uri - octokit (9.2.0) - faraday (>= 1, < 3) - sawyer (~> 0.9) - public_suffix (6.0.1) - rugged (1.6.3) - sawyer (0.9.2) - addressable (>= 2.3.5) - faraday (>= 0.17.3, < 3) - uri (1.0.2) - -PLATFORMS - arm64-darwin-22 - x86_64-darwin-22 - -DEPENDENCIES - cli - octokit (>= 9.2.0) - rugged (= 1.6.3) - -BUNDLED WITH - 2.3.5 diff --git a/lib/typocop.rb b/lib/typocop.rb index 91870dbf..c3855f60 100644 --- a/lib/typocop.rb +++ b/lib/typocop.rb @@ -11,23 +11,27 @@ require 'typocop/repo' require 'typo_checker' -GITHUB_TOKEN = ENV['GITHUB_TOKEN'] || '' -PULL_ID = ENV['PULL_REQUEST_ID'] -GITHUB_BASE_REF = ENV['GITHUB_BASE_REF'] || 'main' +GITHUB_TOKEN = ENV.fetch('GITHUB_TOKEN') { raise 'GITHUB_TOKEN is required' } +PULL_ID = ENV.fetch('PULL_REQUEST_ID') { raise 'PULL_REQUEST_ID is required' } +GITHUB_BASE_REF = ENV.fetch('GITHUB_BASE_REF') { raise 'GITHUB_BASE_REF is required' } BASE_BRANCH = GITHUB_BASE_REF.start_with?('origin/') ? GITHUB_BASE_REF : "origin/#{GITHUB_BASE_REF}" module Typocop def self.execute(settings) + repo = Repo.new + paths = repo.patch_additions.map(&:path) + + return unless paths.any? + excludes = settings.excludes skips = settings.skips - typo_checker = TypoChecker::Checker.new(excludes, skips, stdoutput = false) + typo_checker = TypoChecker::Checker.new(paths: paths, excludes: excludes, skips: skips, stdoutput: false) found_typos = typo_checker.scan_repo('.') if found_typos.empty? - puts 'No typos.' + puts 'No typos found' else cops = Cops.new(found_typos) - repo = Repo.new client = Client.new(repo) client.execute(cops.cops) end diff --git a/lib/typocop/settings.rb b/lib/typocop/settings.rb index f700c20b..e51f13b0 100644 --- a/lib/typocop/settings.rb +++ b/lib/typocop/settings.rb @@ -13,12 +13,10 @@ def initialize(setting_path) private def load_settings(setting_path) - begin - YAML.load_file(setting_path) - rescue StandardError => e - puts "Error loading YAML file: #{e.message}" - return {} - end + YAML.load_file(setting_path) + rescue StandardError => e + puts "Error loading YAML file: #{e.message}" + {} end end end From e1b188e462c962ea725ab48019d28de2228db6ab Mon Sep 17 00:00:00 2001 From: Datpmt Date: Fri, 17 Jan 2025 14:18:22 +0700 Subject: [PATCH 2/3] revert settings.yml --- .github/typocop/setting.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/typocop/setting.yml b/.github/typocop/setting.yml index 2c87f13f..adcd61a6 100644 --- a/.github/typocop/setting.yml +++ b/.github/typocop/setting.yml @@ -1,16 +1,5 @@ # Configuration for Typocop - a GitHub Action for checking typos in pull requests -# 'paths' section allows you to specify which files or directories to scan. -# Only the specified paths will be checked for typos. You can use glob patterns to include directories. - -paths: # Files and directories to scan - # Example: Scan only the 'src' folder - - src/* - # Example: Scan a specific file (e.g., 'README.md') - - README.md - # Example: Scan all Ruby files in the 'lib' directory - - lib/**/*.rb - # 'excludes' section allows you to specify files and folders to exclude # from the typo-checking process. You can list specific files or use glob # patterns to exclude entire directories. From 2bc247420db9432a3b585834c92578b74dda0583 Mon Sep 17 00:00:00 2001 From: Datpmt Date: Fri, 17 Jan 2025 15:55:27 +0700 Subject: [PATCH 3/3] fix rubocop --- lib/typocop/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/typocop/client.rb b/lib/typocop/client.rb index 0a5d1f76..6e4a9c0b 100644 --- a/lib/typocop/client.rb +++ b/lib/typocop/client.rb @@ -99,7 +99,7 @@ def suggestion_comment(typos) end def line_content(cop) - patch = @repo.patch_additions.find { |patch| patch.path == cop.path } + patch = @repo.patch_additions.find { |p| p.path == cop.path } patch.added_lines.find { |line| line.new_lineno == cop.line }.content end