Skip to content

Commit dcbef5f

Browse files
authored
Merge pull request #47 from github/kh-add-about-disable
Update README.md to describe how to disable rules
2 parents 1b33916 + 517c8a0 commit dcbef5f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,34 @@ linters:
6767
- [GitHub::Accessibility::NoTitleAttributeCounter](./docs/rules/accessibility/no-title-attribute-counter.md)
6868
- [GitHub::Accessibility::SvgHasAccessibleTextCounter](./docs/rules/accessibility/svg-has-accessible-text-counter.md)
6969
70+
## Disabling a rule (experimental)
71+
72+
_This is an experimental feature which should ideally be upstreamed to erblint_
73+
74+
`erblint` does not natively support rule disables. At GitHub, we've implemented these rules in a way to allow rules to be disabled at an offense-level via counters or disabled at a file-level because often times, we want to enable a rule but aren't able to address all offenses at once. We achieve this in one of two ways.
75+
76+
Rules that are marked as `Counter` can be disabled by adding a comment with the offense count that matches the number of offenses within the file like:
77+
78+
```.html.erb
79+
<%# erblint:counter GitHub::Accessibility::LinkHasHrefCounter 1 %>
80+
```
81+
82+
In this comment example, when a new `LinkHasHrefCounter` offense has been added, the counter will need to be bumped up to 2. More recent rules use a `Counter` format.
83+
84+
If you are enabling a rule for the first time and your codebase has a lot of offenses, you can use the `-a` command to automatically add these counter comments in the appropriate places.
85+
86+
```
87+
bundle exec erblint app/views app/components -a
88+
```
89+
90+
Rules that are not marked as `Counter` like `NoRedundantImageAlt` are considered to be legacy format. We are in the process of migrating these to counters. These rules can still be disabled at the file-level by adding this comment at the top of the file:
91+
92+
```.html.erb
93+
<%# erblint:disable GitHub::Accessibility::NoRedundantImageAlt %>
94+
```
95+
96+
However, unlike a counter, any subsequent offenses introduced to the file will not raise.
97+
7098
## Testing
7199

72100
```

0 commit comments

Comments
 (0)