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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c08c05d34a0569f214adc5a2f01416f2ce6302aadca2dabd597bc3581ff5d8b1
4
- data.tar.gz: d54006052dfbc69df8998d0c5012935c42fe14240643a058eaa0584fae829db9
3
+ metadata.gz: 5c8b3393e0c1ba03a25ec61f84423e6523e6e8b1a72cb6fd9b9fbdd2aaeec3fe
4
+ data.tar.gz: 1b1c5d4867edcafba3fbc9d3dc8128617581e50558ff10746d77476ca36ca133
5
5
  SHA512:
6
- metadata.gz: 7dd706b82d00f6f3c40bc8bc9c5ae42b04f2dc8c01b7a33732207008c39aa97a481430bb1cf76ec519cdca86e8da312eef5d278496be5a462f5b935010533050
7
- data.tar.gz: bb49fd0e16e06c9fb08a396d39f4ee80ae1ba64124e336f1e2da3f957de69c8ff4ce2ccd10ec902cf590f88fdd4d2af9df7b6a5c1acd2d9963bae696131f96ee
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
@@ -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.7'
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.7
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-17 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