Skip to content

Commit

Permalink
Recursively find learned_words.txt files
Browse files Browse the repository at this point in the history
  • Loading branch information
mdb1 committed Aug 31, 2023
1 parent 59cc9cb commit 6dd73ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

An easy to install, easy to use, swift typo detector for your console.

[BlogPost](https://www.manu.show/2023-08-30-swift-typo-detector/)

## Installation

* Run the setup script: `./setup.sh`
Expand All @@ -27,7 +29,9 @@ Aside from checking against the US dictionary, the script will also check agains

If you want to provide a set of custom words:

1. Create a file named `learned_words.txt` in the root of the project you want to find typos on.
1. Create a file named `learned_words.txt` inside the project you want to find typos on.
* _Note 1_: It won't matter if it's in the root or not.
* _Note 2_: You could even have multiple `learned_words.txt` and the script will combine them all.
2. Populate the `.txt` file with one learned word per line (lowercased).
* The script will lowercase the words before matching them to the ones in the `.txt` file.

Expand All @@ -40,4 +44,4 @@ You could copy and paste the [one in this project](./learned_words.txt):
If you want to sort the sections of the `learned_word` file:

* Run the sort script: `./sort_txt_sections.sh path/to/your-project/learned_words.txt`
* Replace `path/to/your-project/` with the real path of your project.
* Replace `path/to/your-project/learned_words.txt` with the real path of your `txt` file.
14 changes: 8 additions & 6 deletions find_typos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
# Initialize Aspell and dictionary
speller = FFI::Aspell::Speller.new('en_US')

# Learn new words from config file
project_path = ARGV[0]
learned_words_path = File.join(project_path, 'learned_words.txt')
# Learn new words from all the `learned_words.txt` files inside the path
learned_words = []
if File.exists?(learned_words_path)
File.readlines(learned_words_path).each do |line|
learned_words << line.strip
project_path = ARGV[0]
# Given your project path variable 'project_path'
Dir.glob(File.join(project_path, '**', 'learned_words.txt')) do |path|
if File.exists?(path)
File.readlines(path).each do |line|
learned_words << line.strip
end
end
end

Expand Down

0 comments on commit 6dd73ec

Please sign in to comment.