typo_checker 0.1.0 → 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 +8 -1
- data/lib/typo_checker/cli.rb +8 -1
- data/lib/typo_checker/version.rb +1 -1
- data/lib/typo_checker.rb +48 -7
- 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: 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
@@ -2,11 +2,16 @@
|
|
2
2
|
|
3
3
|
TypoChecker is a tool for scanning source code files for common typographical errors. The tool checks through text-based files in a given repository to identify and suggest corrections for any matches found.
|
4
4
|
|
5
|
+
<p align="center" width="100%">
|
6
|
+
<img src="typo_checker.png" alt="TypoChecker Image">
|
7
|
+
</p>
|
8
|
+
|
5
9
|
## Features
|
6
10
|
|
7
11
|
- **Automatic typo detection**: Scan through files in a repository for known typos.
|
8
12
|
- **Support for multiple file types**: It checks various source code and text file extensions.
|
9
13
|
- **Colorized output**: Provides color-coded feedback for easier identification of typos.
|
14
|
+
- **Customization**: Allows you to exclude certain files or skip specific typos.
|
10
15
|
|
11
16
|
## Installation
|
12
17
|
|
@@ -25,6 +30,8 @@ Once installed, you can use TypoChecker in your Ruby project to scan a directory
|
|
25
30
|
```bash
|
26
31
|
# typo_checker scan /path/repo
|
27
32
|
typo_checker scan . # current repo
|
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
|
28
35
|
```
|
29
36
|
|
30
37
|
### Output
|
@@ -37,7 +44,7 @@ When a typo is found, the tool prints out the following information in a coloriz
|
|
37
44
|
Example output:
|
38
45
|
|
39
46
|
```bash
|
40
|
-
Typo found in /path/to/file.rb:10:15: myFuncton
|
47
|
+
Typo found in /path/to/file.rb:10:15: myFuncton -> myFunction
|
41
48
|
```
|
42
49
|
|
43
50
|
## File Types Supported
|
data/lib/typo_checker/cli.rb
CHANGED
@@ -6,9 +6,16 @@ module TypoChecker
|
|
6
6
|
class CLI < Thor
|
7
7
|
desc 'scan REPO_PATH', 'Scan a repository for typos'
|
8
8
|
|
9
|
+
method_option :excludes, type: :array, default: [], aliases: '-e', desc: 'Skip the directories'
|
10
|
+
method_option :skips, type: :array, default: [], aliases: '-s', desc: 'Skip the typos'
|
11
|
+
|
9
12
|
def scan(repo_path)
|
10
|
-
checker = TypoChecker::Checker.new
|
13
|
+
checker = TypoChecker::Checker.new(options[:excludes], options[:skips])
|
11
14
|
checker.scan_repo(repo_path)
|
12
15
|
end
|
16
|
+
|
17
|
+
def self.exit_on_failure?
|
18
|
+
true
|
19
|
+
end
|
13
20
|
end
|
14
21
|
end
|
data/lib/typo_checker/version.rb
CHANGED
data/lib/typo_checker.rb
CHANGED
@@ -6,30 +6,56 @@ require 'fileutils'
|
|
6
6
|
|
7
7
|
module TypoChecker
|
8
8
|
class Checker
|
9
|
-
attr_reader :typos
|
9
|
+
attr_reader :typos, :excludes, :skips, :found_typos, :stdoutput
|
10
10
|
|
11
|
-
def initialize
|
12
|
-
|
13
|
-
@
|
11
|
+
def initialize(excludes = [], skips = [], stdoutput = true)
|
12
|
+
@excludes = excludes
|
13
|
+
@skips = skips.map(&:downcase)
|
14
|
+
@typos = load_typos
|
15
|
+
@found_typos = []
|
16
|
+
@stdoutput = stdoutput
|
14
17
|
end
|
15
18
|
|
16
19
|
def scan_repo(repo_path = Dir.pwd)
|
17
20
|
Find.find(repo_path) do |path|
|
21
|
+
next if exclude_path?(path)
|
22
|
+
|
18
23
|
scan_file(path) if File.file?(path) && text_file?(path)
|
19
24
|
end
|
25
|
+
|
26
|
+
@found_typos
|
20
27
|
end
|
21
28
|
|
22
29
|
private
|
23
30
|
|
24
|
-
def
|
31
|
+
def exclude_path?(path)
|
32
|
+
exclude_patterns.any? { |pattern| path.match?(pattern) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def exclude_patterns
|
36
|
+
@exclude_patterns ||= excludes + [
|
37
|
+
%r{\.git/.*}, # Skip all files and directories inside .git
|
38
|
+
%r{node_modules/.*}, # Skip all files and directories inside node_modules
|
39
|
+
%r{vendor/.*}, # Skip all files and directories inside vendor
|
40
|
+
%r{tmp/.*} # Skip all files and directories inside tmp
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_typos
|
25
45
|
typos = {}
|
46
|
+
csv_file = File.expand_path('data/typos.csv', __dir__)
|
26
47
|
CSV.foreach(csv_file, headers: false) do |row|
|
48
|
+
next if skips.include?(row[0])
|
27
49
|
typos[row[0]] = row[1]
|
28
50
|
end
|
29
51
|
typos
|
30
52
|
end
|
31
53
|
|
32
54
|
def text_file?(path)
|
55
|
+
excluded_extensions = %w[.log]
|
56
|
+
|
57
|
+
return false if excluded_extensions.include?(File.extname(path))
|
58
|
+
|
33
59
|
%w[
|
34
60
|
.rb .txt .md .html .css .js .py .java .php .go .swift .ts .scala .c .cpp .csharp .h .lua .pl .rs .kt
|
35
61
|
.d .r .m .sh .bash .bat .json .yaml .xml .scss .tsv .vb .ps1 .clj .elixir .f# .vhdl .verilog
|
@@ -54,8 +80,18 @@ module TypoChecker
|
|
54
80
|
|
55
81
|
corrected_word = corrected_word(word, typos[word.downcase])
|
56
82
|
typo_path = "#{file}:#{line_num + 1}:#{char_index + 1}"
|
57
|
-
|
58
|
-
|
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
|
59
95
|
end
|
60
96
|
|
61
97
|
def split_function_name(name)
|
@@ -72,6 +108,11 @@ module TypoChecker
|
|
72
108
|
end
|
73
109
|
end
|
74
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
|
+
|
75
116
|
def colorize_red(text)
|
76
117
|
"\e[31m#{text}\e[0m"
|
77
118
|
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.2
|
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-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|