typo_checker 0.1.3 → 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/typo_checker/version.rb +1 -1
- data/lib/typo_checker.rb +23 -17
- metadata +1 -1
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/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
|
@@ -65,33 +69,35 @@ module TypoChecker
|
|
65
69
|
].include? File.extname(path)
|
66
70
|
end
|
67
71
|
|
68
|
-
def scan_file(path)
|
72
|
+
def scan_file(path, result)
|
69
73
|
File.foreach(path).with_index do |line, line_number|
|
70
74
|
words = line.split(/[^a-zA-Z0-9']+/)
|
71
75
|
check_words = words.map { |word| split_function_name(word) }.flatten
|
72
76
|
check_words.each do |word|
|
73
77
|
clean_word = word.gsub(/^[^\w]+|[^\w]+$/, '')
|
74
78
|
char_index = line.index(clean_word)
|
75
|
-
check_word(clean_word, path, line_number, char_index)
|
79
|
+
check_word(clean_word, path, line_number, char_index, result)
|
76
80
|
end
|
77
81
|
end
|
78
82
|
end
|
79
83
|
|
80
|
-
def check_word(word, file, line_num, char_index)
|
84
|
+
def check_word(word, file, line_num, char_index, result)
|
81
85
|
return unless typos.key?(word.downcase)
|
82
86
|
|
83
87
|
corrected_word = corrected_word(word, typos[word.downcase])
|
88
|
+
typo_details = { incorrect_word: word, correct_word: corrected_word }
|
84
89
|
typo_path = "#{file}:#{line_num + 1}:#{char_index + 1}"
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
95
101
|
|
96
102
|
stdout(typo_path, word, corrected_word) if stdoutput
|
97
103
|
end
|