typo_checker 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e1e06748572f803e8d7e9a46765461b1c5780abc659f9a45287df63abf1f5ae
4
- data.tar.gz: d5d762a890491d39e1fef339ce6276cb3b7ede343b278a9e0d29d27aed0ebc59
3
+ metadata.gz: 227145be6c56d2f94d403f2acbd64570413f24d4c5eac9e8aad209a8efbf14d7
4
+ data.tar.gz: f127ac80d6fa9689ffe2b838284bbeb216c2fe0932f17ba7ce06cee26436899e
5
5
  SHA512:
6
- metadata.gz: b96b4c818d693060ef49262b6e8c2eb4177a5be9ae10aae6f6718b3458103dbf1156ae69d0d569de19053e576a3e9462e2d39f55ad246b11a1110e563b39c038
7
- data.tar.gz: b36d80f8c86efe02e3ce38951fdb45e7a17db8c137f056e9baa79733d516506bcb39f601ac30d11251353729a386ea4b61c4174bf05d9ea313de4886f4520a66
6
+ metadata.gz: dde8d82fbc3010b8682589a49608fced1e035857a58d2836027a3237d17ad002ef990f013a0fb9b0e9e115f7e16fc8d03415df50286b6ef9abb9befd7921194e
7
+ data.tar.gz: 5399e74841b109d8b450593f7e061a7ac7a6f96556f7434ddef6a4dc770ade934e97e1623b88baad1394869da0265d6ad7a8a01f27b8a9dcea492b17d901cbb9
data/README.md CHANGED
@@ -30,7 +30,8 @@ Once installed, you can use TypoChecker in your Ruby project to scan a directory
30
30
  ```bash
31
31
  # typo_checker scan /path/repo
32
32
  typo_checker scan . # current repo
33
- typo_checker scan . excludes node_modules .git
33
+ typo_checker scan . --excludes node_modules .git # or typo_checker scan . -e node_modules .git
34
+ typo_checker scan . --excludes node_modules .git --skips rspec defs # or typo_checker scan . -e node_modules .git -s rspec defs
34
35
  ```
35
36
 
36
37
  ### Output
data/lib/data/typos.csv CHANGED
@@ -62986,6 +62986,7 @@ laghtest,latest
62986
62986
  lagre,large
62987
62987
  lagth,laugh
62988
62988
  laguage,language
62989
+ languege,language
62989
62990
  laguages,languages
62990
62991
  lagunage,language
62991
62992
  laiblity,laibility
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TypoChecker
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
  end
data/lib/typo_checker.rb CHANGED
@@ -6,12 +6,14 @@ require 'fileutils'
6
6
 
7
7
  module TypoChecker
8
8
  class Checker
9
- attr_reader :typos, :excludes, :skips
9
+ attr_reader :typos, :excludes, :skips, :found_typos, :stdoutput
10
10
 
11
- def initialize(excludes = [], skips = [])
11
+ def initialize(excludes = [], skips = [], stdoutput = true)
12
12
  @excludes = excludes
13
- @skips = skips
13
+ @skips = skips.map(&:downcase)
14
14
  @typos = load_typos
15
+ @found_typos = []
16
+ @stdoutput = stdoutput
15
17
  end
16
18
 
17
19
  def scan_repo(repo_path = Dir.pwd)
@@ -20,6 +22,8 @@ module TypoChecker
20
22
 
21
23
  scan_file(path) if File.file?(path) && text_file?(path)
22
24
  end
25
+
26
+ @found_typos
23
27
  end
24
28
 
25
29
  private
@@ -42,6 +46,7 @@ module TypoChecker
42
46
  csv_file = File.expand_path('data/typos.csv', __dir__)
43
47
  CSV.foreach(csv_file, headers: false) do |row|
44
48
  next if skips.include?(row[0])
49
+
45
50
  typos[row[0]] = row[1]
46
51
  end
47
52
  typos
@@ -65,8 +70,9 @@ module TypoChecker
65
70
  words = line.split(/[^a-zA-Z0-9']+/)
66
71
  check_words = words.map { |word| split_function_name(word) }.flatten
67
72
  check_words.each do |word|
68
- char_index = line.index(word)
69
- check_word(word, path, line_number, char_index)
73
+ clean_word = word.gsub(/^[^\w]+|[^\w]+$/, '')
74
+ char_index = line.index(clean_word)
75
+ check_word(clean_word, path, line_number, char_index)
70
76
  end
71
77
  end
72
78
  end
@@ -76,8 +82,18 @@ module TypoChecker
76
82
 
77
83
  corrected_word = corrected_word(word, typos[word.downcase])
78
84
  typo_path = "#{file}:#{line_num + 1}:#{char_index + 1}"
79
- puts "Typo found in #{colorize_light_blue(typo_path)}: " \
80
- "#{colorize_red(word)} -> #{colorize_green(corrected_word)}"
85
+ typo_details = {
86
+ path: file,
87
+ line: line_num + 1,
88
+ typos: {
89
+ incorrect_word: word,
90
+ correct_word: corrected_word
91
+ }
92
+ }
93
+
94
+ @found_typos << typo_details
95
+
96
+ stdout(typo_path, word, corrected_word) if stdoutput
81
97
  end
82
98
 
83
99
  def split_function_name(name)
@@ -94,6 +110,11 @@ module TypoChecker
94
110
  end
95
111
  end
96
112
 
113
+ def stdout(typo_path, word, corrected_word)
114
+ puts "Typo found in #{colorize_light_blue(typo_path)}: " \
115
+ "#{colorize_red(word)} -> #{colorize_green(corrected_word)}"
116
+ end
117
+
97
118
  def colorize_red(text)
98
119
  "\e[31m#{text}\e[0m"
99
120
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typo_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - datpmt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-30 00:00:00.000000000 Z
11
+ date: 2024-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor