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 +4 -4
- data/lib/data/typos.csv +1 -0
- data/lib/typo_checker/version.rb +1 -1
- data/lib/typo_checker.rb +26 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05a50b54ca97d02ac7e6f082201ac84e7b2f10609efc163cdbc8bb52a70689b5
|
4
|
+
data.tar.gz: e3ab87a0fbf6b462c0598997480573046abea5543e62003b48e126303387c0d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/typo_checker/version.rb
CHANGED
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, :
|
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
|
-
|
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
|
-
|
73
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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.
|
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-
|
11
|
+
date: 2024-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|