Skip to content

Commit aea6491

Browse files
committed
Add lint rule for checkbox character style
1 parent 67209d0 commit aea6491

9 files changed

Lines changed: 1332 additions & 0 deletions

File tree

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# Checkbox Character Style
22+
23+
> [ESLint rule][eslint-rules] to enforce that Markdown checkboxes follow a specified style in JSDoc descriptions.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-checkbox-character-style' );
37+
```
38+
39+
#### rule
40+
41+
[ESLint rule][eslint-rules] to enforce that Markdown checkboxes follow a specified style in JSDoc descriptions.
42+
43+
**Bad**:
44+
45+
<!-- eslint-disable stdlib/jsdoc-checkbox-character-style, stdlib/jsdoc-no-paragraph-character-style, stdlib/jsdoc-markdown-remark -->
46+
47+
```javascript
48+
/**
49+
* Beep.
50+
*
51+
* - [x] Item 1
52+
* - [X] Item 2
53+
* - [ ] Item 3
54+
*
55+
* @returns {string} a value
56+
*
57+
* @example
58+
* var str = beep();
59+
* // returns 'boop'
60+
*/
61+
function beep() {
62+
return 'boop';
63+
}
64+
```
65+
66+
**Good**:
67+
68+
```javascript
69+
/**
70+
* Beep.
71+
*
72+
* - [x] Item 1
73+
* - [x] Item 2
74+
* - [ ] Item 3
75+
*
76+
* @returns {string} a value
77+
*
78+
* @example
79+
* var str = beep();
80+
* // returns 'boop'
81+
*/
82+
function beep() {
83+
return 'boop';
84+
}
85+
```
86+
87+
The [rule][eslint-rules] may be configured using the same options as supported by [remark][remark-lint-emphasis-marker].
88+
89+
</section>
90+
91+
<!-- /.usage -->
92+
93+
<section class="examples">
94+
95+
## Examples
96+
97+
<!-- lint disable no-tabs -->
98+
99+
<!-- eslint no-undef: "error" -->
100+
101+
<!-- eslint-disable no-tabs -->
102+
103+
```javascript
104+
var Linter = require( 'eslint' ).Linter;
105+
var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-checkbox-character-style' );
106+
107+
var linter = new Linter();
108+
var result;
109+
var code;
110+
111+
// Generate our source code:
112+
code = [
113+
'/**',
114+
'* Beep boop.',
115+
'*',
116+
'* - [X] First Item',
117+
'* - [ ] Second Item',
118+
'*',
119+
'*',
120+
'* @param {string} str - input value',
121+
'* @returns {string} output value',
122+
'*',
123+
'* @example',
124+
'* var out = beep( "boop" );',
125+
'* // returns "beepboop"',
126+
'*/',
127+
'function beep( str ) {',
128+
'\treturn "beep" + str;',
129+
'}'
130+
].join( '\n' );
131+
132+
// Register the ESLint rule:
133+
linter.defineRule( 'jsdoc-checkbox-character-style', rule );
134+
135+
// Lint the code:
136+
result = linter.verify( code, {
137+
'rules': {
138+
'jsdoc-checkbox-character-style': [
139+
'error',
140+
{
141+
'checked': 'x',
142+
'unchecked': ' '
143+
}
144+
]
145+
}
146+
});
147+
console.log( result );
148+
/* =>
149+
[
150+
{
151+
'ruleId': 'jsdoc-checkbox-character-style',
152+
'severity': 2,
153+
'message': 'Checked checkboxes should use `x` as a marker',
154+
'line': 4,
155+
'column': 6,
156+
'nodeType': null,
157+
'source': '* - [X] Second Item',
158+
'endLine': 14,
159+
'endColumn': 3
160+
},
161+
{
162+
'ruleId': 'jsdoc-checkbox-character-style',
163+
'severity': 2,
164+
'message': 'Unchecked checkboxes should use `\t` as a marker',
165+
'line': 5,
166+
'column': 6,
167+
'nodeType': null,
168+
'source': '* - [ ] Third Item',
169+
'endLine': 14,
170+
'endColumn': 3
171+
}
172+
]
173+
*/
174+
```
175+
176+
</section>
177+
178+
<!-- /.examples -->
179+
180+
<section class="links">
181+
182+
[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules
183+
184+
[remark-lint-emphasis-marker]: https://github.com/remarkjs/remark-lint/tree/19150d94f89f7a0d94d083417890236d11839641/packages/remark-lint-checkbox-character-style
185+
186+
</section>
187+
188+
<!-- /.links -->
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var Linter = require( 'eslint' ).Linter;
22+
var rule = require( './../lib' );
23+
24+
var linter = new Linter();
25+
var result;
26+
var code;
27+
28+
// Generate our source code:
29+
code = [
30+
'/**',
31+
'* Beep boop.',
32+
'*',
33+
'* - [X] First Item',
34+
'* - [ ] Second Item',
35+
'*',
36+
'*',
37+
'* @param {string} str - input value',
38+
'* @returns {string} output value',
39+
'*',
40+
'* @example',
41+
'* var out = beep( "boop" );',
42+
'* // returns "beepboop"',
43+
'*/',
44+
'function beep( str ) {',
45+
'\treturn "beep" + str;',
46+
'}'
47+
].join( '\n' );
48+
49+
// Register the ESLint rule:
50+
linter.defineRule( 'jsdoc-checkbox-character-style', rule );
51+
52+
// Lint the code:
53+
result = linter.verify( code, {
54+
'rules': {
55+
'jsdoc-checkbox-character-style': [
56+
'error',
57+
{
58+
'checked': 'x',
59+
'unchecked': ' '
60+
}
61+
]
62+
}
63+
});
64+
console.log( result );
65+
/* =>
66+
[
67+
{
68+
'ruleId': 'jsdoc-checkbox-character-style',
69+
'severity': 2,
70+
'message': 'Checked checkboxes should use `x` as a marker',
71+
'line': 4,
72+
'column': 6,
73+
'nodeType': null,
74+
'source': '* - [X] Second Item',
75+
'endLine': 14,
76+
'endColumn': 3
77+
},
78+
{
79+
'ruleId': 'jsdoc-checkbox-character-style',
80+
'severity': 2,
81+
'message': 'Unchecked checkboxes should use `\t` as a marker',
82+
'line': 5,
83+
'column': 6,
84+
'nodeType': null,
85+
'source': '* - [ ] Third Item',
86+
'endLine': 14,
87+
'endColumn': 3
88+
}
89+
]
90+
*/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* ESLint rule to enforce that Markdown checkboxes follow a specified style in JSDoc descriptions.
23+
*
24+
* @module @stdlib/_tools/eslint/rules/jsdoc-checkbox-character-style
25+
*
26+
* @example
27+
* var rule = require( '@stdlib/_tools/eslint/rules/jsdoc-checkbox-character-style' );
28+
*
29+
* console.log( rule );
30+
*/
31+
32+
// MODULES //
33+
34+
var main = require( './main.js' );
35+
36+
37+
// EXPORTS //
38+
39+
module.exports = main;

0 commit comments

Comments
 (0)