no-comments
An ordinary comment outside the file's header.
- Group
- Code
- Runs
- Optional: run it with
ur lint --rule no-comments - Level
- warning
- Reads
- Every file
- Fix
- None: what the comment says belongs in a name, a type, or a documentation comment, which the author chooses
Why
Ordinary comments are allowed only in a file's header, its first 10 lines before code begins, and documentation comments only where documentation tooling reads them, such as rustdoc's ///, JSDoc's /**, and Lean's /-- and /-!. Elsewhere a comment restates the code or drifts from it: make the intent clear through names and structure. ur-allow comments are directives, not prose, and are not reported. The rule runs where [lint] no-comments = true turns it on.
The fix, as Ur suggests it: make the intent clear through names and structure, or document an API with a documentation comment.
For agents
Write no ordinary comments after a file's header: make intent clear through names and structure, and document an API with documentation comments.
Example
.ur/ur.toml[lint]
no-comments = true
app/shipping.pydef shipping_cost(weight_kg, express):
# base rate is 5 plus 2 per kilogram
cost = 5 + 2 * weight_kg
if express:
# express doubles the price
cost *= 2
return cost
$ ur lint --rule no-comments
warning[no-comments]: ordinary comment outside the file's header
--> ./app/shipping.py:2:5 comment `# base rate is 5 plus 2 per kilogram`
= hint: make the intent clear through names and structure, or document an API with a documentation comment
= see: Refactoring: Improving the Design of Existing Code, chapter 3, Bad Smells in Code: Comments, Martin Fowler and Kent Beck, second edition (2018-11), https://www.informit.com/articles/article.aspx?p=2952392&seqNum=24
warning[no-comments]: ordinary comment outside the file's header
--> ./app/shipping.py:5:9 comment `# express doubles the price`
= hint: make the intent clear through names and structure, or document an API with a documentation comment
= see: Refactoring: Improving the Design of Existing Code, chapter 3, Bad Smells in Code: Comments, Martin Fowler and Kent Beck, second edition (2018-11), https://www.informit.com/articles/article.aspx?p=2952392&seqNum=24
0 clone classes and 2 ordinary comments in 1 file
Source
Refactoring: Improving the Design of Existing Code, chapter 3, Bad Smells in Code: Comments, Martin Fowler and Kent Beck, second edition (2018-11).