typo_checker 0.1.7 → 0.1.8
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 +0 -3
- data/lib/typo_checker/cli.rb +2 -1
- data/lib/typo_checker/configuration.rb +4 -3
- data/lib/typo_checker/file_scanner.rb +1 -1
- data/lib/typo_checker/repository_scanner.rb +32 -6
- data/lib/typo_checker/version.rb +1 -1
- data/lib/typo_checker.rb +7 -2
- 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: 5c8b3393e0c1ba03a25ec61f84423e6523e6e8b1a72cb6fd9b9fbdd2aaeec3fe
|
4
|
+
data.tar.gz: 1b1c5d4867edcafba3fbc9d3dc8128617581e50558ff10746d77476ca36ca133
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2034fc2e1d590444a857340da4cb62af2ba0866fc8f78f7f8bcca1e9b6fe52bc28b7707348890e0227a1b543d9741c127b5f5785554974b1b2c1f9b890e5d27e
|
7
|
+
data.tar.gz: f5a26daeff90580b1e2f6afd4b9c197ae62b76e420ff092cd15f3445eec448b3293711d9a6c2879a0a7744f981c72e374146174a364dce722782c96a097e8672
|
data/lib/data/typos.csv
CHANGED
@@ -36985,7 +36985,6 @@ duplifaces,duplicates
|
|
36985
36985
|
duplucated,duplicated
|
36986
36986
|
dupplicate,duplicate
|
36987
36987
|
dupplicated,duplicated
|
36988
|
-
dur,due
|
36989
36988
|
durabiblity,durabibility
|
36990
36989
|
durabiity,durability
|
36991
36990
|
durabiliy,durability
|
@@ -85514,7 +85513,6 @@ prviously,previously
|
|
85514
85513
|
pryamid,pyramid
|
85515
85514
|
pryamids,pyramids
|
85516
85515
|
pryor,prior
|
85517
|
-
ps,rs
|
85518
85516
|
psasword,password
|
85519
85517
|
psblogggers,psbloggers
|
85520
85518
|
pschicology,psychology
|
@@ -107431,7 +107429,6 @@ tfunction,function
|
|
107431
107429
|
tge,the
|
107432
107430
|
tghe,the
|
107433
107431
|
tghis,this
|
107434
|
-
th,the
|
107435
107432
|
th9s,this
|
107436
107433
|
thagy,shaggy
|
107437
107434
|
thain,train
|
data/lib/typo_checker/cli.rb
CHANGED
@@ -6,11 +6,12 @@ module TypoChecker
|
|
6
6
|
class CLI < Thor
|
7
7
|
desc 'scan REPO_PATH', 'Scan a repository for typos'
|
8
8
|
|
9
|
+
method_option :paths, type: :array, default: [], aliases: '-p', desc: 'Only scan the specified paths'
|
9
10
|
method_option :excludes, type: :array, default: [], aliases: '-e', desc: 'Skip the directories'
|
10
11
|
method_option :skips, type: :array, default: [], aliases: '-s', desc: 'Skip the typos'
|
11
12
|
|
12
13
|
def scan(repo_path)
|
13
|
-
checker = TypoChecker::Checker.new(options[:excludes], options[:skips])
|
14
|
+
checker = TypoChecker::Checker.new(paths: options[:paths], excludes: options[:excludes], skips: options[:skips])
|
14
15
|
checker.scan_repo(repo_path)
|
15
16
|
end
|
16
17
|
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module TypoChecker
|
2
2
|
class Configuration
|
3
|
-
attr_reader :excludes, :skips, :stdoutput
|
3
|
+
attr_reader :paths, :excludes, :skips, :stdoutput
|
4
4
|
|
5
|
-
def initialize(excludes
|
5
|
+
def initialize(paths: [], excludes: [], skips: [], stdoutput: true)
|
6
|
+
@paths = paths || []
|
6
7
|
@excludes = excludes || []
|
7
8
|
@skips = (skips || []).map(&:downcase)
|
8
|
-
@stdoutput = stdoutput.nil?
|
9
|
+
@stdoutput = stdoutput.nil? || stdoutput
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -63,7 +63,7 @@ module TypoChecker
|
|
63
63
|
return unless @stdoutput
|
64
64
|
|
65
65
|
puts "Typo found in #{colorize_light_blue(typo_path)}: " \
|
66
|
-
|
66
|
+
"#{colorize_red(word)} -> #{colorize_green(corrected_word)}"
|
67
67
|
end
|
68
68
|
|
69
69
|
def colorize_red(text)
|
@@ -9,20 +9,46 @@ module TypoChecker
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def scan
|
12
|
-
|
13
|
-
|
14
|
-
next if exclude_path?(path)
|
12
|
+
cops = {}
|
13
|
+
paths = @configuration.paths
|
15
14
|
|
16
|
-
|
15
|
+
if paths.empty?
|
16
|
+
# Find all files in the repository
|
17
|
+
Find.find(@repo_path) do |path|
|
18
|
+
next if exclude_path?(path)
|
19
|
+
|
20
|
+
find_cops(cops, path)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
paths.each do |pattern|
|
24
|
+
# Find files based on the pattern
|
25
|
+
Dir.glob(File.join(@repo_path, pattern)) do |path|
|
26
|
+
next if exclude_path?(path)
|
27
|
+
|
28
|
+
find_cops(cops, path)
|
29
|
+
end
|
30
|
+
end
|
17
31
|
end
|
18
|
-
|
32
|
+
scan_result(cops)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def scan_result(cops)
|
38
|
+
cops.map do |path, data|
|
19
39
|
data[:typos].map do |entry|
|
20
40
|
{ path: path, line: entry[:line], typos: entry[:typos] }
|
21
41
|
end
|
22
42
|
end.flatten
|
23
43
|
end
|
24
44
|
|
25
|
-
|
45
|
+
def find_cops(cops, path)
|
46
|
+
@file_scanner.scan_file(path, cops) if valid_text_file?(path)
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid_text_file?(path)
|
50
|
+
File.file?(path) && text_file?(path)
|
51
|
+
end
|
26
52
|
|
27
53
|
def exclude_path?(path)
|
28
54
|
exclude_patterns.any? { |pattern| path.match?(pattern) }
|
data/lib/typo_checker/version.rb
CHANGED
data/lib/typo_checker.rb
CHANGED
@@ -10,8 +10,13 @@ require_relative 'typo_checker/repository_scanner'
|
|
10
10
|
|
11
11
|
module TypoChecker
|
12
12
|
class Checker
|
13
|
-
def initialize(excludes
|
14
|
-
|
13
|
+
def initialize(paths: [], excludes: [], skips: [], stdoutput: true)
|
14
|
+
raise ArgumentError, '`paths` must be an Array' unless paths.instance_of?(Array)
|
15
|
+
raise ArgumentError, '`excludes` must be an Array' unless excludes.instance_of?(Array)
|
16
|
+
raise ArgumentError, '`skips` must be an Array' unless skips.instance_of?(Array)
|
17
|
+
raise ArgumentError, '`stdoutput` must be a Boolean' unless [TrueClass, FalseClass].include?(stdoutput.class)
|
18
|
+
|
19
|
+
@configuration = Configuration.new(paths: paths, excludes: excludes, skips: skips, stdoutput: stdoutput)
|
15
20
|
end
|
16
21
|
|
17
22
|
def scan_repo(repo_path = Dir.pwd)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- datpmt
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-20 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: thor
|