Skip to content

Commit 6e85b6b

Browse files
committed
Add spell checking with codespell as a GitHub Action
`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/
1 parent 3682f11 commit 6e85b6b

File tree

14 files changed

+96
-23
lines changed

14 files changed

+96
-23
lines changed

.github/workflows/lint.yml

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,27 @@ name: Lint
33
on: [pull_request]
44

55
jobs:
6+
codespell:
7+
name: Check spelling all files with codespell
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: [3.8]
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install codespell
22+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
23+
- name: Check spelling with codespell
24+
run: codespell --ignore-words=codespell.txt || exit 1
625
misspell:
7-
name: Check Spelling Misspell
26+
name: Check spelling all files in commit with misspell
827
runs-on: ubuntu-latest
928
steps:
1029
- uses: actions/checkout@v2

actionpack/test/controller/parameters/parameters_permit_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,12 @@ def walk_permitted(params)
253253
assert_not_predicate permitted[:users].last, :permitted?
254254
end
255255

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

261-
test "fetch doesnt raise ParameterMissing exception if there is a default that is nil" do
261+
test "fetch doesn't raise ParameterMissing exception if there is a default that is nil" do
262262
assert_nil @params.fetch(:foo, nil)
263263
assert_nil @params.fetch(:foo) { nil }
264264
end

actionpack/test/controller/rescue_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def test_block_rescue_handler_with_argument_as_string
292292
assert_response :unprocessable_entity
293293
end
294294

295-
test "rescue when cause has handler, but wrapper doesnt" do
295+
test "rescue when cause has handler, but wrapper doesn't" do
296296
get :exception_with_no_handler_for_wrapper
297297
assert_response :unprocessable_entity
298298
end

actionpack/test/dispatch/request_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ class RequestCookie < BaseRequestTest
597597
end
598598

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

611-
test "doesnt interpret request uri as query string when missing" do
611+
test "doesn't interpret request uri as query string when missing" do
612612
request = stub_request("REQUEST_URI" => "foo")
613613
assert_equal({}, request.query_parameters)
614614
end

actionview/test/template/javascript_helper_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def test_escape_javascript
2929
assert_equal "true", escape_javascript(true)
3030
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
3131
assert_equal %(backslash\\\\test), escape_javascript(%(backslash\\test))
32-
assert_equal %(dont <\\/close> tags), escape_javascript(%(dont </close> tags))
32+
assert_equal %(don\\'t <\\/close> tags), escape_javascript(%(don't </close> tags))
3333
assert_equal %(unicode &#x2028; newline), escape_javascript((+%(unicode \342\200\250 newline)).force_encoding(Encoding::UTF_8).encode!)
3434
assert_equal %(unicode &#x2029; newline), escape_javascript((+%(unicode \342\200\251 newline)).force_encoding(Encoding::UTF_8).encode!)
3535

36-
assert_equal %(dont <\\/close> tags), j(%(dont </close> tags))
36+
assert_equal %(don\\'t <\\/close> tags), j(%(don't </close> tags))
3737
end
3838

3939
def test_escape_backtick

actionview/test/template/url_helper_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,12 @@ def test_link_tag_with_javascript_confirm
393393
link_to("Hello", "http://www.example.com", data: { confirm: "Are you sure?" })
394394
)
395395
assert_dom_equal(
396-
%{<a href="http://www.example.com" data-confirm="You cant possibly be sure, can you?">Hello</a>},
397-
link_to("Hello", "http://www.example.com", data: { confirm: "You cant possibly be sure, can you?" })
396+
%{<a href="http://www.example.com" data-confirm="You can't possibly be sure, can you?">Hello</a>},
397+
link_to("Hello", "http://www.example.com", data: { confirm: "You can't possibly be sure, can you?" })
398398
)
399399
assert_dom_equal(
400-
%{<a href="http://www.example.com" data-confirm="You cant possibly be sure,\n can you?">Hello</a>},
401-
link_to("Hello", "http://www.example.com", data: { confirm: "You cant possibly be sure,\n can you?" })
400+
%{<a href="http://www.example.com" data-confirm="You can't possibly be sure,\n can you?">Hello</a>},
401+
link_to("Hello", "http://www.example.com", data: { confirm: "You can't possibly be sure,\n can you?" })
402402
)
403403
end
404404

activemodel/CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
* Cache and re-use generated attibute methods.
1+
* Cache and re-use generated attribute methods.
22

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

66
*Jean Boussier*
77

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def table_alias_for(table_name)
2929
table_name[0...table_alias_length].tr(".", "_")
3030
end
3131

32-
# Returns the relation names useable to back Active Record models.
32+
# Returns the relation names usable to back Active Record models.
3333
# For most adapters this means all #tables and #views.
3434
def data_sources
3535
query_values(data_source_sql, "SCHEMA")

activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ def test_preloaded_associations_size
996996
assert_equal first_project.salaried_developers.size, preloaded_first_project.salaried_developers.size
997997
end
998998

999-
def test_has_and_belongs_to_many_is_useable_with_belongs_to_required_by_default
999+
def test_has_and_belongs_to_many_is_usable_with_belongs_to_required_by_default
10001000
assert_difference "Project.first.developers_required_by_default.size", 1 do
10011001
Project.first.developers_required_by_default.create!(name: "Sean", salary: 50000)
10021002
end

activesupport/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
* Deprecate `ActiveSupport::SafeBuffer`'s incorrect implicit conversion of objects into string.
22

33
Except for a few methods like `String#%`, objects must implement `#to_str`
4-
to be implictly converted to a String in string operations. In some
4+
to be implicitly converted to a String in string operations. In some
55
circumstances `ActiveSupport::SafeBuffer` was incorrectly calling the
66
explicit conversion method (`#to_s`) on them. This behavior is now
77
deprecated.

codespell.txt

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
ake
2+
alls
3+
ba
4+
cookoo
5+
coyp
6+
devels
7+
dum
8+
fase
9+
filetest
10+
fo
11+
fot
12+
froms
13+
frop
14+
hel
15+
inactivate
16+
isnt
17+
iterm
18+
januar
19+
mor
20+
nd
21+
ned
22+
noone
23+
objekt
24+
ot
25+
overthere
26+
reenable
27+
rouge
28+
searchin
29+
serie
30+
splitted
31+
supercalifragilisticexpialidoceous
32+
te
33+
tha
34+
thi
35+
ue
36+
unqiue
37+
upto
38+
varius
39+
vew
40+
vlaue
41+
wil
42+
wth
43+
yau

guides/source/contributing_to_ruby_on_rails.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,12 @@ Inspecting 1 file
275275

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

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

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

294+
We also run [codespell](https://github.com/codespell-project/codespell) with GitHub Actions to check spelling and
295+
[codespell](https://pypi.org/project/codespell/) runs against a [small custom dictionary](../../codespell.txt).
296+
`codespell` is written in [Python](https://www.python.org/) and you can run it with:
297+
298+
```bash
299+
codespell --ignore-words=codespell.txt
300+
```
301+
291302
### Benchmark Your Code
292303

293304
For changes that might have an impact on performance, please benchmark your

railties/test/application/loading_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Post < ApplicationRecord
145145
assert_equal ["ActiveRecord::InternalMetadata", "ActiveRecord::SchemaMigration"], ActiveRecord::Base.descendants.collect(&:to_s).sort.uniq
146146
end
147147

148-
test "initialize cant be called twice" do
148+
test "initialize can't be called twice" do
149149
require "#{app_path}/config/environment"
150150
assert_raise(RuntimeError) { Rails.application.initialize! }
151151
end

railties/test/generators/actions_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,13 @@ def test_environment_with_block_should_include_block_contents_in_environment_ini
276276
run_generator
277277

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

283283
assert_file "config/application.rb" do |content|
284284
assert_match(/# This will be added/, content)
285-
assert_no_match(/# This wont be added/, content)
285+
assert_no_match(/# This won't be added/, content)
286286
end
287287
end
288288

0 commit comments

Comments
 (0)