typo_checker 0.1.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15d511455e488fe8175d4b8eb85f9d7a55647515d39450d1f627254ee90571a3
4
- data.tar.gz: 3841f4796632094f9e8b17fb3ff9bdd219e5bb2b783ba11e1ec074788185f72e
3
+ metadata.gz: 5c8b3393e0c1ba03a25ec61f84423e6523e6e8b1a72cb6fd9b9fbdd2aaeec3fe
4
+ data.tar.gz: 1b1c5d4867edcafba3fbc9d3dc8128617581e50558ff10746d77476ca36ca133
5
5
  SHA512:
6
- metadata.gz: a42eb16f7838b9e56e39a290d39682c4bb082c643526038d01b168b5f29a1a922fc8dfc6882d205684a906d0155ff96c610e4ccc9f8386b363cd560d781ef292
7
- data.tar.gz: 7c097ec3e93767e28c12c414ec64cc439b06630c3d94983da15f8335ad53077938f3fbbcd240c89c482fd3e15cbeb8cafc077a85e8cd2428c3eba81208d13943
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
@@ -47028,7 +47027,6 @@ frezeang,freezing
47028
47027
  frezeing,freezing
47029
47028
  frezing,freezing
47030
47029
  frezzing,freezing
47031
- fri,fry
47032
47030
  friand,friend
47033
47031
  fribease,firebase
47034
47032
  frictioin,friction
@@ -61982,7 +61980,6 @@ jamiacan,jamaican
61982
61980
  jamine,jasmine
61983
61981
  jammming,jamming
61984
61982
  jamsine,jasmine
61985
- jan,jam
61986
61983
  janacek,janáček
61987
61984
  janaury,january
61988
61985
  janaček,janáček
@@ -69686,7 +69683,6 @@ mommentarily,momentarily
69686
69683
  mommentary,momentary
69687
69684
  momments,moments
69688
69685
  momories,memories
69689
- mon,moon
69690
69686
  monacco,Monaco
69691
69687
  monagomous,monogamous
69692
69688
  monagomy,monogamy
@@ -85517,7 +85513,6 @@ prviously,previously
85517
85513
  pryamid,pyramid
85518
85514
  pryamids,pyramids
85519
85515
  pryor,prior
85520
- ps,rs
85521
85516
  psasword,password
85522
85517
  psblogggers,psbloggers
85523
85518
  pschicology,psychology
@@ -97174,7 +97169,6 @@ seocondary,secondary
97174
97169
  seonc,second
97175
97170
  seond,second
97176
97171
  seonds,seconds
97177
- sep,step
97178
97172
  sepaated,separated
97179
97173
  sepamns,specimens
97180
97174
  sepaphore,semaphore
@@ -107435,7 +107429,6 @@ tfunction,function
107435
107429
  tge,the
107436
107430
  tghe,the
107437
107431
  tghis,this
107438
- th,the
107439
107432
  th9s,this
107440
107433
  thagy,shaggy
107441
107434
  thain,train
@@ -110181,7 +110174,6 @@ tuched,touched
110181
110174
  tucknolgies,tucknologies
110182
110175
  tucowws,tucows
110183
110176
  tudents,students
110184
- tue,true
110185
110177
  tuesdsay,tuesdays
110186
110178
  tuesdsy,tuesdays
110187
110179
  tuitioin,tuition
@@ -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 = nil, skips = nil, stdoutput = true)
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? ? true : stdoutput
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
- "#{colorize_red(word)} -> #{colorize_green(corrected_word)}"
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
- result = {}
13
- Find.find(@repo_path) do |path|
14
- next if exclude_path?(path)
12
+ cops = {}
13
+ paths = @configuration.paths
15
14
 
16
- @file_scanner.scan_file(path, result) if File.file?(path) && text_file?(path)
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
- result.map do |path, data|
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
- private
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) }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TypoChecker
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.8'
5
5
  end
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 = [], skips = [], stdoutput = true)
14
- @configuration = Configuration.new(excludes, skips, stdoutput)
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.6
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-01-08 00:00:00.000000000 Z
10
+ date: 2025-02-20 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thor