You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/source/api_documentation_guidelines.md
+80-11Lines changed: 80 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,44 +46,113 @@ Wording
46
46
47
47
Write simple, declarative sentences. Brevity is a plus. Get to the point.
48
48
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
+
```
50
69
51
70
Start comments in upper case. Follow regular punctuation rules:
52
71
53
72
```ruby
73
+
# BAD
74
+
# declares an attribute reader backed by an internally-named
75
+
# instance variable
76
+
77
+
# GOOD
54
78
# Declares an attribute reader backed by an internally-named
55
79
# instance variable.
56
-
defattr_internal_reader(*attrs)
57
-
# ...
58
-
end
59
80
```
60
81
61
82
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.
62
83
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
+
63
94
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?
64
95
65
96
### Naming
66
97
67
98
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.
68
99
100
+
```ruby
101
+
# GOOD
102
+
# Active Record classes can be created by inheriting from
103
+
# ActiveRecord::Base.
104
+
```
105
+
69
106
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.
70
107
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
+
```
72
117
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.
74
119
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
+
```
76
133
77
-
Prefer wordings that avoid "you"s and "your"s. For example, instead of
134
+
Use the article "an" for "SQL":
78
135
79
136
```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.
82
144
```
83
145
84
-
use this style:
146
+
### Pronouns
147
+
148
+
Prefer wordings that avoid "you"s and "your"s.
85
149
86
150
```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
87
156
# If +return+ is needed, it is recommended to explicitly define a
0 commit comments