Skip to content

Commit

Permalink
Add spell checking with codespell as a GitHub Action
Browse files Browse the repository at this point in the history
`codespell` works with a small custom dictionary and seems to find perhaps more spelling mistakes than `misspell` which really only fixes commonly misspelled English words.

Not all spell checkers can check all file types and most spell checkers can't find all the errors.

https://github.com/codespell-project/codespell
https://pypi.org/project/codespell/
  • Loading branch information
jbampton committed May 4, 2021
1 parent 3682f11 commit 6e85b6b
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 23 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@ name: Lint
on: [pull_request]

jobs:
codespell:
name: Check spelling all files with codespell
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install codespell
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Check spelling with codespell
run: codespell --ignore-words=codespell.txt || exit 1
misspell:
name: Check Spelling Misspell
name: Check spelling all files in commit with misspell
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ def walk_permitted(params)
assert_not_predicate permitted[:users].last, :permitted?
end

test "fetch doesnt raise ParameterMissing exception if there is a default" do
test "fetch doesn't raise ParameterMissing exception if there is a default" do
assert_equal "monkey", @params.fetch(:foo, "monkey")
assert_equal "monkey", @params.fetch(:foo) { "monkey" }
end

test "fetch doesnt raise ParameterMissing exception if there is a default that is nil" do
test "fetch doesn't raise ParameterMissing exception if there is a default that is nil" do
assert_nil @params.fetch(:foo, nil)
assert_nil @params.fetch(:foo) { nil }
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/rescue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def test_block_rescue_handler_with_argument_as_string
assert_response :unprocessable_entity
end

test "rescue when cause has handler, but wrapper doesnt" do
test "rescue when cause has handler, but wrapper doesn't" do
get :exception_with_no_handler_for_wrapper
assert_response :unprocessable_entity
end
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/dispatch/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class RequestCookie < BaseRequestTest
end

class RequestParamsParsing < BaseRequestTest
test "doesnt break when content type has charset" do
test "doesn't break when content type has charset" do
request = stub_request(
"REQUEST_METHOD" => "POST",
"CONTENT_LENGTH" => "flamenco=love".length,
Expand All @@ -608,7 +608,7 @@ class RequestParamsParsing < BaseRequestTest
assert_equal({ "flamenco" => "love" }, request.request_parameters)
end

test "doesnt interpret request uri as query string when missing" do
test "doesn't interpret request uri as query string when missing" do
request = stub_request("REQUEST_URI" => "foo")
assert_equal({}, request.query_parameters)
end
Expand Down
4 changes: 2 additions & 2 deletions actionview/test/template/javascript_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def test_escape_javascript
assert_equal "true", escape_javascript(true)
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
assert_equal %(backslash\\\\test), escape_javascript(%(backslash\\test))
assert_equal %(dont <\\/close> tags), escape_javascript(%(dont </close> tags))
assert_equal %(don\\'t <\\/close> tags), escape_javascript(%(don't </close> tags))
assert_equal %(unicode &#x2028; newline), escape_javascript((+%(unicode \342\200\250 newline)).force_encoding(Encoding::UTF_8).encode!)
assert_equal %(unicode &#x2029; newline), escape_javascript((+%(unicode \342\200\251 newline)).force_encoding(Encoding::UTF_8).encode!)

assert_equal %(dont <\\/close> tags), j(%(dont </close> tags))
assert_equal %(don\\'t <\\/close> tags), j(%(don't </close> tags))
end

def test_escape_backtick
Expand Down
8 changes: 4 additions & 4 deletions actionview/test/template/url_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ def test_link_tag_with_javascript_confirm
link_to("Hello", "http://www.example.com", data: { confirm: "Are you sure?" })
)
assert_dom_equal(
%{<a href="http://www.example.com" data-confirm="You cant possibly be sure, can you?">Hello</a>},
link_to("Hello", "http://www.example.com", data: { confirm: "You cant possibly be sure, can you?" })
%{<a href="http://www.example.com" data-confirm="You can't possibly be sure, can you?">Hello</a>},
link_to("Hello", "http://www.example.com", data: { confirm: "You can't possibly be sure, can you?" })
)
assert_dom_equal(
%{<a href="http://www.example.com" data-confirm="You cant possibly be sure,\n can you?">Hello</a>},
link_to("Hello", "http://www.example.com", data: { confirm: "You cant possibly be sure,\n can you?" })
%{<a href="http://www.example.com" data-confirm="You can't possibly be sure,\n can you?">Hello</a>},
link_to("Hello", "http://www.example.com", data: { confirm: "You can't possibly be sure,\n can you?" })
)
end

Expand Down
4 changes: 2 additions & 2 deletions activemodel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
* Cache and re-use generated attibute methods.
* Cache and re-use generated attribute methods.

Generated methods with identical implementations will now share their instruction sequences
leading to reduced memory retention, and sligtly faster load time.
leading to reduced memory retention, and slightly faster load time.

*Jean Boussier*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def table_alias_for(table_name)
table_name[0...table_alias_length].tr(".", "_")
end

# Returns the relation names useable to back Active Record models.
# Returns the relation names usable to back Active Record models.
# For most adapters this means all #tables and #views.
def data_sources
query_values(data_source_sql, "SCHEMA")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ def test_preloaded_associations_size
assert_equal first_project.salaried_developers.size, preloaded_first_project.salaried_developers.size
end

def test_has_and_belongs_to_many_is_useable_with_belongs_to_required_by_default
def test_has_and_belongs_to_many_is_usable_with_belongs_to_required_by_default
assert_difference "Project.first.developers_required_by_default.size", 1 do
Project.first.developers_required_by_default.create!(name: "Sean", salary: 50000)
end
Expand Down
2 changes: 1 addition & 1 deletion activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
* Deprecate `ActiveSupport::SafeBuffer`'s incorrect implicit conversion of objects into string.

Except for a few methods like `String#%`, objects must implement `#to_str`
to be implictly converted to a String in string operations. In some
to be implicitly converted to a String in string operations. In some
circumstances `ActiveSupport::SafeBuffer` was incorrectly calling the
explicit conversion method (`#to_s`) on them. This behavior is now
deprecated.
Expand Down
43 changes: 43 additions & 0 deletions codespell.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
ake
alls
ba
cookoo
coyp
devels
dum
fase
filetest
fo
fot
froms
frop
hel
inactivate
isnt
iterm
januar
mor
nd
ned
noone
objekt
ot
overthere
reenable
rouge
searchin
serie
splitted
supercalifragilisticexpialidoceous
te
tha
thi
ue
unqiue
upto
varius
vew
vlaue
wil
wth
yau
17 changes: 14 additions & 3 deletions guides/source/contributing_to_ruby_on_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,12 @@ Inspecting 1 file

For `rails-ujs` CoffeeScript and JavaScript files, you can run `npm run lint` in `actionview` folder.

We are also running [misspell](https://github.com/client9/misspell) which is mainly written in Golang to check
spelling with [GitHub Actions](../../.github/workflows/lint.yml). Correct commonly misspelled English words quickly
with `misspell`. You can run `misspell` locally against all files with:
#### Spell Checking

We are running [misspell](https://github.com/client9/misspell) which is mainly written in
[Golang](https://golang.org/) to check spelling with [GitHub Actions](../../.github/workflows/lint.yml). Correct
commonly misspelled English words quickly with `misspell`. `misspell` is different from most other spell checkers
because it doesn't use a custom dictionary. You can run `misspell` locally against all files with:

```bash
find . -type f | xargs ./misspell -i 'aircrafts,devels,invertions' -error
Expand All @@ -288,6 +291,14 @@ Notable `misspell` help options or flags are:
- `-i` string: ignore the following corrections, comma separated
- `-w`: Overwrite file with corrections (default is just to display)

We also run [codespell](https://github.com/codespell-project/codespell) with GitHub Actions to check spelling and
[codespell](https://pypi.org/project/codespell/) runs against a [small custom dictionary](../../codespell.txt).
`codespell` is written in [Python](https://www.python.org/) and you can run it with:

```bash
codespell --ignore-words=codespell.txt
```

### Benchmark Your Code

For changes that might have an impact on performance, please benchmark your
Expand Down
2 changes: 1 addition & 1 deletion railties/test/application/loading_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Post < ApplicationRecord
assert_equal ["ActiveRecord::InternalMetadata", "ActiveRecord::SchemaMigration"], ActiveRecord::Base.descendants.collect(&:to_s).sort.uniq
end

test "initialize cant be called twice" do
test "initialize can't be called twice" do
require "#{app_path}/config/environment"
assert_raise(RuntimeError) { Rails.application.initialize! }
end
Expand Down
4 changes: 2 additions & 2 deletions railties/test/generators/actions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ def test_environment_with_block_should_include_block_contents_in_environment_ini
run_generator

action :environment do
_ = "# This wont be added" # assignment to silence parse-time warning "unused literal ignored"
_ = "# This won't be added" # assignment to silence parse-time warning "unused literal ignored"
"# This will be added"
end

assert_file "config/application.rb" do |content|
assert_match(/# This will be added/, content)
assert_no_match(/# This wont be added/, content)
assert_no_match(/# This won't be added/, content)
end
end

Expand Down

0 comments on commit 6e85b6b

Please sign in to comment.