typo_checker 0.1.0 → 0.1.1

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: a70148af1265992e4ad1912242058765ec6b16079e7ec928b97ea9eef03b7c1e
4
- data.tar.gz: 4577201281037b384f51b07ad7b20506ea1a2aa7e486e57cf06823448dff99f5
3
+ metadata.gz: 3e1e06748572f803e8d7e9a46765461b1c5780abc659f9a45287df63abf1f5ae
4
+ data.tar.gz: d5d762a890491d39e1fef339ce6276cb3b7ede343b278a9e0d29d27aed0ebc59
5
5
  SHA512:
6
- metadata.gz: 9b71c09497ee8dd367e99dc63e69faa599b9c9c61579d108544e066b5a6839e7fd967989d588bfeef3983c38a7c4786ef50595bf306f4cea168f1e7aba301832
7
- data.tar.gz: 86f01baf7fe9e3147503f1ebbec821d9b25c78c79a3469d7288400bf95d374e97e8217d545a1a058d114aee3757c946c40ba65e6676740b1624086ba9d8b3a00
6
+ metadata.gz: b96b4c818d693060ef49262b6e8c2eb4177a5be9ae10aae6f6718b3458103dbf1156ae69d0d569de19053e576a3e9462e2d39f55ad246b11a1110e563b39c038
7
+ data.tar.gz: b36d80f8c86efe02e3ce38951fdb45e7a17db8c137f056e9baa79733d516506bcb39f601ac30d11251353729a386ea4b61c4174bf05d9ea313de4886f4520a66
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,7 @@ 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
28
34
  ```
29
35
 
30
36
  ### Output
@@ -37,7 +43,7 @@ When a typo is found, the tool prints out the following information in a coloriz
37
43
  Example output:
38
44
 
39
45
  ```bash
40
- Typo found in /path/to/file.rb:10:15: myFuncton() -> myFunction()
46
+ Typo found in /path/to/file.rb:10:15: myFuncton -> myFunction
41
47
  ```
42
48
 
43
49
  ## File Types Supported
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TypoChecker
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/lib/typo_checker.rb CHANGED
@@ -6,30 +6,52 @@ require 'fileutils'
6
6
 
7
7
  module TypoChecker
8
8
  class Checker
9
- attr_reader :typos
9
+ attr_reader :typos, :excludes, :skips
10
10
 
11
- def initialize
12
- csv_file = File.expand_path('data/typos.csv', __dir__)
13
- @typos = load_typos(csv_file)
11
+ def initialize(excludes = [], skips = [])
12
+ @excludes = excludes
13
+ @skips = skips
14
+ @typos = load_typos
14
15
  end
15
16
 
16
17
  def scan_repo(repo_path = Dir.pwd)
17
18
  Find.find(repo_path) do |path|
19
+ next if exclude_path?(path)
20
+
18
21
  scan_file(path) if File.file?(path) && text_file?(path)
19
22
  end
20
23
  end
21
24
 
22
25
  private
23
26
 
24
- def load_typos(csv_file)
27
+ def exclude_path?(path)
28
+ exclude_patterns.any? { |pattern| path.match?(pattern) }
29
+ end
30
+
31
+ def exclude_patterns
32
+ @exclude_patterns ||= excludes + [
33
+ %r{\.git/.*}, # Skip all files and directories inside .git
34
+ %r{node_modules/.*}, # Skip all files and directories inside node_modules
35
+ %r{vendor/.*}, # Skip all files and directories inside vendor
36
+ %r{tmp/.*} # Skip all files and directories inside tmp
37
+ ]
38
+ end
39
+
40
+ def load_typos
25
41
  typos = {}
42
+ csv_file = File.expand_path('data/typos.csv', __dir__)
26
43
  CSV.foreach(csv_file, headers: false) do |row|
44
+ next if skips.include?(row[0])
27
45
  typos[row[0]] = row[1]
28
46
  end
29
47
  typos
30
48
  end
31
49
 
32
50
  def text_file?(path)
51
+ excluded_extensions = %w[.log]
52
+
53
+ return false if excluded_extensions.include?(File.extname(path))
54
+
33
55
  %w[
34
56
  .rb .txt .md .html .css .js .py .java .php .go .swift .ts .scala .c .cpp .csharp .h .lua .pl .rs .kt
35
57
  .d .r .m .sh .bash .bat .json .yaml .xml .scss .tsv .vb .ps1 .clj .elixir .f# .vhdl .verilog
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.0
4
+ version: 0.1.1
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-27 00:00:00.000000000 Z
11
+ date: 2024-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor