typo_checker 0.1.2 → 0.1.4

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: 993172dbd5d6abda8122d79b5b704a3d33c62b070ec992a32a65b88796ee9a89
4
- data.tar.gz: fdbf5d4104cdb99b7bd7889cb83173270db123cd171bde3702c0e8687633728b
3
+ metadata.gz: 05a50b54ca97d02ac7e6f082201ac84e7b2f10609efc163cdbc8bb52a70689b5
4
+ data.tar.gz: e3ab87a0fbf6b462c0598997480573046abea5543e62003b48e126303387c0d6
5
5
  SHA512:
6
- metadata.gz: 664b9a9f3f6123378eaa6560ee3e56753ce4deeea6dd893c45fce5585682d81c8cedf762477dce90af2154da1d6b2b4e2d5a1da91ad6f25e6b3936fb2f5e01f9
7
- data.tar.gz: 85b93f37c3b1f1da7bbae9e371a872218b5bddc957c8598a13c9bd5bf23767cafbb9dc6434bb6c3cb22797a4eb135a712326e77d4642d64c7bb255151e6f503b
6
+ metadata.gz: a28ea83ca84d3b27076923a8c8ad6ee68ed789653f9f0bb5710989e32b3754a916f87823335da50e4b134337e72593ff07ea16ed26597b2ae6f4908d4080b6c7
7
+ data.tar.gz: afc715bcbe853fd07dedf36917fa4792f2ea7aa9f7f036e9a58652124a9dddd4e4f4c0b2b77ece448aef0347faee965933609d717fde0c69335ba8eae02a8ef1
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.2'
4
+ VERSION = '0.1.4'
5
5
  end
data/lib/typo_checker.rb CHANGED
@@ -6,24 +6,28 @@ require 'fileutils'
6
6
 
7
7
  module TypoChecker
8
8
  class Checker
9
- attr_reader :typos, :excludes, :skips, :found_typos, :stdoutput
9
+ attr_reader :typos, :excludes, :skips, :stdoutput
10
10
 
11
11
  def initialize(excludes = [], skips = [], stdoutput = true)
12
12
  @excludes = excludes
13
13
  @skips = skips.map(&:downcase)
14
14
  @typos = load_typos
15
- @found_typos = []
16
15
  @stdoutput = stdoutput
17
16
  end
18
17
 
19
18
  def scan_repo(repo_path = Dir.pwd)
19
+ result = {}
20
20
  Find.find(repo_path) do |path|
21
21
  next if exclude_path?(path)
22
22
 
23
- scan_file(path) if File.file?(path) && text_file?(path)
23
+ scan_file(path, result) if File.file?(path) && text_file?(path)
24
24
  end
25
25
 
26
- @found_typos
26
+ result.map do |path, data|
27
+ data[:typos].map do |entry|
28
+ { path: path, line: entry[:line], typos: entry[:typos] }
29
+ end
30
+ end.flatten
27
31
  end
28
32
 
29
33
  private
@@ -46,6 +50,7 @@ module TypoChecker
46
50
  csv_file = File.expand_path('data/typos.csv', __dir__)
47
51
  CSV.foreach(csv_file, headers: false) do |row|
48
52
  next if skips.include?(row[0])
53
+
49
54
  typos[row[0]] = row[1]
50
55
  end
51
56
  typos
@@ -64,32 +69,35 @@ module TypoChecker
64
69
  ].include? File.extname(path)
65
70
  end
66
71
 
67
- def scan_file(path)
72
+ def scan_file(path, result)
68
73
  File.foreach(path).with_index do |line, line_number|
69
74
  words = line.split(/[^a-zA-Z0-9']+/)
70
75
  check_words = words.map { |word| split_function_name(word) }.flatten
71
76
  check_words.each do |word|
72
- char_index = line.index(word)
73
- check_word(word, path, line_number, char_index)
77
+ clean_word = word.gsub(/^[^\w]+|[^\w]+$/, '')
78
+ char_index = line.index(clean_word)
79
+ check_word(clean_word, path, line_number, char_index, result)
74
80
  end
75
81
  end
76
82
  end
77
83
 
78
- def check_word(word, file, line_num, char_index)
84
+ def check_word(word, file, line_num, char_index, result)
79
85
  return unless typos.key?(word.downcase)
80
86
 
81
87
  corrected_word = corrected_word(word, typos[word.downcase])
88
+ typo_details = { incorrect_word: word, correct_word: corrected_word }
82
89
  typo_path = "#{file}:#{line_num + 1}:#{char_index + 1}"
83
- typo_details = {
84
- path: file,
85
- line: line_num + 1,
86
- typos: {
87
- incorrect_word: word,
88
- correct_word: corrected_word
89
- }
90
- }
91
-
92
- @found_typos << typo_details
90
+ path = file.sub(%r{^./}, '')
91
+
92
+ result[path] ||= {}
93
+ result[path][:typos] ||= []
94
+ line_entry = result[path][:typos].find { |entry| entry[:line] == line_num + 1 }
95
+
96
+ if line_entry
97
+ line_entry[:typos] << typo_details
98
+ else
99
+ result[path][:typos] << { line: line_num + 1, typos: [typo_details] }
100
+ end
93
101
 
94
102
  stdout(typo_path, word, corrected_word) if stdoutput
95
103
  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.2
4
+ version: 0.1.4
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