Skip to content

Commit fe139d8

Browse files
Support ignoring blocks by special comments (#78)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent 6108552 commit fe139d8

27 files changed

+215
-93
lines changed

readme.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,59 @@ $ npm install --global awesome-lint
3838
3 errors
3939
```
4040

41+
### Special comments
42+
43+
You can enable, disable, and ignore rules using special comments. This is based on [remark-message-control](https://github.com/remarkjs/remark-message-control#markers).
44+
45+
By default, all rules are turned on. For example, 4 errors (2 of `no-dead-urls` and 2 of `awesome-list-item`) will be generated for following code snippets.
46+
47+
```md
48+
- [foo](https://foo.com) - an invalid description.
49+
- [foo](https://foo.com) - invalid description.
50+
```
51+
52+
###### `disable`
53+
54+
The `disable` keyword turns off all messages of the given rule identifiers. If no identifiers are specified, all messages are turned off.
55+
56+
**Don't leave spaces after the last rule identifier.**
57+
58+
For example, only the 2 `no-dead-urls` errors are left:
59+
60+
```md
61+
<!--lint disable awesome-list-item-->
62+
- [foo](https://foo.com) - an invalid description.
63+
- [foo](https://foo.com) - invalid description.
64+
```
65+
66+
###### `enable`
67+
68+
The `enable` keyword turns on all messages of the given rule identifiers. If no identifiers are specified, all messages are turned on.
69+
70+
For example, only the second line reports a `awesome-list-item` rule violation:
71+
72+
```md
73+
<!--lint disable awesome-list-item-->
74+
- [foo](https://foo.com) - an invalid description.
75+
<!--lint enable awesome-list-item-->
76+
- [foo](https://foo.com) - invalid description.
77+
```
78+
79+
###### `ignore`
80+
81+
The `ignore` keyword turns off all messages of the given rule identifiers occurring in the following node. If no identifiers are specified, all messages are turned ignored. After the end of the following node, messages are turned on again. This is the main difference with `disable`.
82+
83+
For example, to turn off certain messages for the next node:
84+
85+
```md
86+
<!--lint ignore awesome-list-item-->
87+
- [foo](https://foo.com) - an invalid description.
88+
89+
List items share the same parent node. So let's create a new list.
90+
91+
- [foo](https://foo.com) - invalid description.
92+
```
93+
4194
### Tip
4295

4396
Add it as a `test` script in package.json and activate Travis CI to lint on new commits and pull requests.

rules/badge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const badgeSrcUrlWhitelist = new Set([
1616
const isValidBadgeUrl = url => badgeUrlWhitelist.has(url);
1717
const isValidBadgeSrcUrl = url => badgeSrcUrlWhitelist.has(url);
1818

19-
module.exports = rule('remark-lint:awesome/badge', (ast, file) => {
19+
module.exports = rule('remark-lint:awesome-badge', (ast, file) => {
2020
visit(ast, 'heading', (node, index) => {
2121
if (index > 0) {
2222
return;

rules/code-of-conduct.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const findAuthorName = require('../lib/find-author-name');
66
const authorName = 'sindresorhus';
77
const authorEmail = '[email protected]';
88

9-
module.exports = rule('remark-lint:awesome/code-of-conduct', (ast, file) => {
9+
module.exports = rule('remark-lint:awesome-code-of-conduct', (ast, file) => {
1010
if (ast.children.length === 0) {
1111
file.message('code-of-conduct.md file must not be empty');
1212
return;

rules/contributing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const path = require('path');
44
const globby = require('globby');
55
const rule = require('unified-lint-rule');
66

7-
module.exports = rule('remark-lint:awesome/contributing', (ast, file) => {
7+
module.exports = rule('remark-lint:awesome-contributing', (ast, file) => {
88
const {dirname} = file;
99

1010
const contributingFile = globby.sync(['contributing.md', 'CONTRIBUTING.md'], {cwd: dirname})[0];

rules/git-repo-age.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const oneDay = 24 * 60 * 60 * 1000;
77
const minGitRepoAgeDays = 30;
88
const minGitRepoAgeMs = minGitRepoAgeDays * oneDay;
99

10-
module.exports = rule('remark-lint:awesome/git-repo-age', async (ast, file) => {
10+
module.exports = rule('remark-lint:awesome-git-repo-age', async (ast, file) => {
1111
const {dirname} = file;
1212

1313
try {

rules/github.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const got = require('got');
44
const gh = require('github-url-to-object');
55
const rule = require('unified-lint-rule');
66

7-
module.exports = rule('remark-lint:awesome/github', async (ast, file) => {
7+
module.exports = rule('remark-lint:awesome-github', async (ast, file) => {
88
const {dirname} = file;
99

1010
try {

rules/heading.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const listHeadingCaseWhitelist = new Set([
88
'capital'
99
]);
1010

11-
module.exports = rule('remark-lint:awesome/heading', (ast, file) => {
11+
module.exports = rule('remark-lint:awesome-heading', (ast, file) => {
1212
let headings = 0;
1313

1414
visit(ast, (node, index) => {

rules/license.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const rule = require('unified-lint-rule');
55
const toString = require('mdast-util-to-string');
66
const visit = require('unist-util-visit');
77

8-
module.exports = rule('remark-lint:awesome/license', (ast, file) => {
8+
module.exports = rule('remark-lint:awesome-license', (ast, file) => {
99
const license = find(ast, node => (
1010
node.type === 'heading' &&
1111
(toString(node) === 'Licence' || toString(node) === 'License')

rules/list-item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const listItemDescriptionSuffixNodeWhitelist = new Set([
4747
'text'
4848
]);
4949

50-
module.exports = rule('remark-lint:awesome/list-item', (ast, file) => {
50+
module.exports = rule('remark-lint:awesome-list-item', (ast, file) => {
5151
let lists = findAllLists(ast);
5252

5353
const toc = find(ast, node => (

rules/no-ci-badge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const rule = require('unified-lint-rule');
33
const visit = require('unist-util-visit');
44

5-
module.exports = rule('remark-lint:awesome/no-ci-badge', (ast, file) => {
5+
module.exports = rule('remark-lint:awesome-no-ci-badge', (ast, file) => {
66
visit(ast, 'image', node => {
77
if (/build status|travis|circleci/i.test(node.title)) {
88
file.message('Readme must not contain CI badge', node);

0 commit comments

Comments
 (0)