typo_checker 0.1.1 → 0.1.2
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/README.md +2 -1
- data/lib/typo_checker/version.rb +1 -1
- data/lib/typo_checker.rb +24 -5
- 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: 993172dbd5d6abda8122d79b5b704a3d33c62b070ec992a32a65b88796ee9a89
|
4
|
+
data.tar.gz: fdbf5d4104cdb99b7bd7889cb83173270db123cd171bde3702c0e8687633728b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 664b9a9f3f6123378eaa6560ee3e56753ce4deeea6dd893c45fce5585682d81c8cedf762477dce90af2154da1d6b2b4e2d5a1da91ad6f25e6b3936fb2f5e01f9
|
7
|
+
data.tar.gz: 85b93f37c3b1f1da7bbae9e371a872218b5bddc957c8598a13c9bd5bf23767cafbb9dc6434bb6c3cb22797a4eb135a712326e77d4642d64c7bb255151e6f503b
|
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/typo_checker/version.rb
CHANGED
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
|
@@ -76,8 +80,18 @@ module TypoChecker
|
|
76
80
|
|
77
81
|
corrected_word = corrected_word(word, typos[word.downcase])
|
78
82
|
typo_path = "#{file}:#{line_num + 1}:#{char_index + 1}"
|
79
|
-
|
80
|
-
|
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
|
93
|
+
|
94
|
+
stdout(typo_path, word, corrected_word) if stdoutput
|
81
95
|
end
|
82
96
|
|
83
97
|
def split_function_name(name)
|
@@ -94,6 +108,11 @@ module TypoChecker
|
|
94
108
|
end
|
95
109
|
end
|
96
110
|
|
111
|
+
def stdout(typo_path, word, corrected_word)
|
112
|
+
puts "Typo found in #{colorize_light_blue(typo_path)}: " \
|
113
|
+
"#{colorize_red(word)} -> #{colorize_green(corrected_word)}"
|
114
|
+
end
|
115
|
+
|
97
116
|
def colorize_red(text)
|
98
117
|
"\e[31m#{text}\e[0m"
|
99
118
|
end
|