typo_checker 0.1.3 → 0.1.4

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: 227145be6c56d2f94d403f2acbd64570413f24d4c5eac9e8aad209a8efbf14d7
4
- data.tar.gz: f127ac80d6fa9689ffe2b838284bbeb216c2fe0932f17ba7ce06cee26436899e
3
+ metadata.gz: 05a50b54ca97d02ac7e6f082201ac84e7b2f10609efc163cdbc8bb52a70689b5
4
+ data.tar.gz: e3ab87a0fbf6b462c0598997480573046abea5543e62003b48e126303387c0d6
5
5
  SHA512:
6
- metadata.gz: dde8d82fbc3010b8682589a49608fced1e035857a58d2836027a3237d17ad002ef990f013a0fb9b0e9e115f7e16fc8d03415df50286b6ef9abb9befd7921194e
7
- data.tar.gz: 5399e74841b109d8b450593f7e061a7ac7a6f96556f7434ddef6a4dc770ade934e97e1623b88baad1394869da0265d6ad7a8a01f27b8a9dcea492b17d901cbb9
6
+ metadata.gz: a28ea83ca84d3b27076923a8c8ad6ee68ed789653f9f0bb5710989e32b3754a916f87823335da50e4b134337e72593ff07ea16ed26597b2ae6f4908d4080b6c7
7
+ data.tar.gz: afc715bcbe853fd07dedf36917fa4792f2ea7aa9f7f036e9a58652124a9dddd4e4f4c0b2b77ece448aef0347faee965933609d717fde0c69335ba8eae02a8ef1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TypoChecker
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
data/lib/typo_checker.rb CHANGED
@@ -6,24 +6,28 @@ require 'fileutils'
6
6
 
7
7
  module TypoChecker
8
8
  class Checker
9
- attr_reader :typos, :excludes, :skips, :found_typos, :stdoutput
9
+ attr_reader :typos, :excludes, :skips, :stdoutput
10
10
 
11
11
  def initialize(excludes = [], skips = [], stdoutput = true)
12
12
  @excludes = excludes
13
13
  @skips = skips.map(&:downcase)
14
14
  @typos = load_typos
15
- @found_typos = []
16
15
  @stdoutput = stdoutput
17
16
  end
18
17
 
19
18
  def scan_repo(repo_path = Dir.pwd)
19
+ result = {}
20
20
  Find.find(repo_path) do |path|
21
21
  next if exclude_path?(path)
22
22
 
23
- scan_file(path) if File.file?(path) && text_file?(path)
23
+ scan_file(path, result) if File.file?(path) && text_file?(path)
24
24
  end
25
25
 
26
- @found_typos
26
+ result.map do |path, data|
27
+ data[:typos].map do |entry|
28
+ { path: path, line: entry[:line], typos: entry[:typos] }
29
+ end
30
+ end.flatten
27
31
  end
28
32
 
29
33
  private
@@ -65,33 +69,35 @@ module TypoChecker
65
69
  ].include? File.extname(path)
66
70
  end
67
71
 
68
- def scan_file(path)
72
+ def scan_file(path, result)
69
73
  File.foreach(path).with_index do |line, line_number|
70
74
  words = line.split(/[^a-zA-Z0-9']+/)
71
75
  check_words = words.map { |word| split_function_name(word) }.flatten
72
76
  check_words.each do |word|
73
77
  clean_word = word.gsub(/^[^\w]+|[^\w]+$/, '')
74
78
  char_index = line.index(clean_word)
75
- check_word(clean_word, path, line_number, char_index)
79
+ check_word(clean_word, path, line_number, char_index, result)
76
80
  end
77
81
  end
78
82
  end
79
83
 
80
- def check_word(word, file, line_num, char_index)
84
+ def check_word(word, file, line_num, char_index, result)
81
85
  return unless typos.key?(word.downcase)
82
86
 
83
87
  corrected_word = corrected_word(word, typos[word.downcase])
88
+ typo_details = { incorrect_word: word, correct_word: corrected_word }
84
89
  typo_path = "#{file}:#{line_num + 1}:#{char_index + 1}"
85
- typo_details = {
86
- path: file,
87
- line: line_num + 1,
88
- typos: {
89
- incorrect_word: word,
90
- correct_word: corrected_word
91
- }
92
- }
93
-
94
- @found_typos << typo_details
90
+ path = file.sub(%r{^./}, '')
91
+
92
+ result[path] ||= {}
93
+ result[path][:typos] ||= []
94
+ line_entry = result[path][:typos].find { |entry| entry[:line] == line_num + 1 }
95
+
96
+ if line_entry
97
+ line_entry[:typos] << typo_details
98
+ else
99
+ result[path][:typos] << { line: line_num + 1, typos: [typo_details] }
100
+ end
95
101
 
96
102
  stdout(typo_path, word, corrected_word) if stdoutput
97
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typo_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - datpmt