Skip to content

Commit 442d4b8

Browse files
authored
Merge pull request rails#50595 from p8/guides/api-docs-wording-examples
Add "GOOD" and "BAD" examples to API wording guide [ci-skip]
2 parents a8e59f1 + 34629a9 commit 442d4b8

File tree

1 file changed

+80
-11
lines changed

1 file changed

+80
-11
lines changed

guides/source/api_documentation_guidelines.md

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,44 +46,113 @@ Wording
4646

4747
Write simple, declarative sentences. Brevity is a plus. Get to the point.
4848

49-
Write in present tense: "Returns a hash that...", rather than "Returned a hash that..." or "Will return a hash that...".
49+
```ruby
50+
# BAD
51+
# Caching may interfere with being able to see the results
52+
# of code changes.
53+
54+
# GOOD
55+
# Caching interferes with seeing the results of code changes.
56+
```
57+
58+
Use present tense:
59+
60+
```ruby
61+
# BAD
62+
# Returned a hash that...
63+
# Will return a hash that...
64+
# Return a hash that...
65+
66+
# GOOD
67+
# Returns a hash that...
68+
```
5069

5170
Start comments in upper case. Follow regular punctuation rules:
5271

5372
```ruby
73+
# BAD
74+
# declares an attribute reader backed by an internally-named
75+
# instance variable
76+
77+
# GOOD
5478
# Declares an attribute reader backed by an internally-named
5579
# instance variable.
56-
def attr_internal_reader(*attrs)
57-
# ...
58-
end
5980
```
6081

6182
Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.
6283

84+
```ruby
85+
# BAD
86+
# Book.where('name = ?', "Where the Wild Things Are")
87+
# Book.where('year_published < ?', 50.years.ago)
88+
89+
# GOOD
90+
# Book.where(name: "Where the Wild Things Are")
91+
# Book.where(year_published: ...50.years.ago)
92+
```
93+
6394
Documentation has to be brief but comprehensive. Explore and document edge cases. What happens if a module is anonymous? What if a collection is empty? What if an argument is nil?
6495

6596
### Naming
6697

6798
The proper names of Rails components have a space in between the words, like "Active Support". `ActiveRecord` is a Ruby module, whereas Active Record is an ORM. All Rails documentation should consistently refer to Rails components by their proper names.
6899

100+
```ruby
101+
# GOOD
102+
# Active Record classes can be created by inheriting from
103+
# ActiveRecord::Base.
104+
```
105+
69106
When referencing a "Rails application", as opposed to an "engine" or "plugin", always use "application". Rails apps are not "services", unless specifically discussing about service-oriented architecture.
70107

71-
Spell names correctly: Arel, minitest, RSpec, HTML, MySQL, JavaScript, ERB, Hotwire. When in doubt, please have a look at some authoritative source like their official documentation.
108+
```ruby
109+
# BAD
110+
# Production services can report their status upstream.
111+
# Devise is a Rails authentication application.
112+
113+
# GOOD
114+
# Production applications can report their status upstream.
115+
# Devise is a Rails authentication enging.
116+
```
72117

73-
Use the article "an" for "SQL", as in "an SQL statement". Also "an SQLite database".
118+
Spell software names correctly. When in doubt, please have a look at some authoritative source like their official documentation.
74119

75-
### Pronouns
120+
```ruby
121+
# GOOD
122+
# Arel
123+
# ERB
124+
# Hotwire
125+
# HTML
126+
# JavaScript
127+
# minitest
128+
# MySQL
129+
# npm
130+
# PostgreSQL
131+
# RSpec
132+
```
76133

77-
Prefer wordings that avoid "you"s and "your"s. For example, instead of
134+
Use the article "an" for "SQL":
78135

79136
```ruby
80-
# If you need to use +return+ statements in your callbacks, it is
81-
# recommended that you explicitly define them as methods.
137+
# BAD
138+
# Creates a SQL statement.
139+
# Starts a SQLite database.
140+
141+
# GOOD
142+
# Creates an SQL statement.
143+
# Starts an SQLite database.
82144
```
83145

84-
use this style:
146+
### Pronouns
147+
148+
Prefer wordings that avoid "you"s and "your"s.
85149

86150
```ruby
151+
# BAD
152+
# If you need to use +return+ statements in your callbacks, it is
153+
# recommended that you explicitly define them as methods.
154+
155+
# GOOD
87156
# If +return+ is needed, it is recommended to explicitly define a
88157
# method.
89158
```

0 commit comments

Comments
 (0)