Skip to content

Commit

Permalink
Fix checkbox lists starting with links
Browse files Browse the repository at this point in the history
Closes GH-68.
  • Loading branch information
wooorm committed Jun 6, 2016
1 parent 27d3444 commit 019ff36
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 99 deletions.
194 changes: 97 additions & 97 deletions doc/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ be null or undefined in order to be ignored.
### external

````md
<!-- Load more rules -->
```json
{
"external": ["foo", "bar", "baz"]
}
```
<!-- Load more rules -->
```json
{
"external": ["foo", "bar", "baz"]
}
```
````

External contains a list of extra rules to load.
Expand All @@ -99,13 +99,13 @@ rules are also loaded.
### reset

````md
<!-- Explicitly activate rules: -->
```json
{
"reset": true,
"final-newline": true
}
```
<!-- Explicitly activate rules: -->
```json
{
"reset": true,
"final-newline": true
}
```
````

By default, all rules are turned on unless explicitly set to `false`.
Expand Down Expand Up @@ -204,28 +204,28 @@ Options: `boolean`, default: `false`.
### code-block-style

````md
<!-- Valid, when set to `indented` or `consistent`, invalid when set to `fenced` -->
Hello
<!-- Valid, when set to `indented` or `consistent`, invalid when set to `fenced` -->
Hello

...
...

World
World

<!-- Valid, when set to `fenced` or `consistent`, invalid when set to `indented` -->
```
<!-- Valid, when set to `fenced` or `consistent`, invalid when set to `indented` -->
```
Hello
```
...
```bar
World
```

<!-- Always invalid -->
Hello
```
...
```bar
World
```

<!-- Always invalid -->
Hello
...
```
World
```
...
```
World
```
````

Warn when code-blocks do not adhere to a given style.
Expand Down Expand Up @@ -285,28 +285,28 @@ Options: `boolean`, default: `false`.
### fenced-code-flag

````md
<!-- Valid: -->
```hello
world();
```

<!-- Valid: -->
Hello

<!-- Invalid: -->
```
world();
```

<!-- Valid when given `{allowEmpty: true}`: -->
```
world();
```

<!-- Invalid when given `["world"]`: -->
```hello
world();
```
<!-- Valid: -->
```hello
world();
```

<!-- Valid: -->
Hello

<!-- Invalid: -->
```
world();
```

<!-- Valid when given `{allowEmpty: true}`: -->
```
world();
```

<!-- Invalid when given `["world"]`: -->
```hello
world();
```
````

Warn when fenced code blocks occur without language flag.
Expand All @@ -324,32 +324,32 @@ Options: `boolean`, default: `false`.
### fenced-code-marker

````md
<!-- Valid by default and `` '`' ``: -->
```foo
bar();
```

```
baz();
```

<!-- Valid by default and `'~'`: -->
~~~foo
bar();
~~~

~~~
baz();
~~~

<!-- Always invalid: -->
~~~foo
bar();
~~~

```
baz();
```
<!-- Valid by default and `` '`' ``: -->
```foo
bar();
```

```
baz();
```

<!-- Valid by default and `'~'`: -->
~~~foo
bar();
~~~

~~~
baz();
~~~

<!-- Always invalid: -->
~~~foo
bar();
~~~

```
baz();
```
````

Warn for violating fenced code markers.
Expand Down Expand Up @@ -970,24 +970,24 @@ Options: `boolean`, default: `false`.
### no-shell-dollars

````md
<!-- Invalid: -->
```bash
$ echo a
$ echo a > file
```

<!-- Valid: -->
```sh
echo a
echo a > file
```

<!-- Also valid: -->
```zsh
$ echo a
a
$ echo a > file
```
<!-- Invalid: -->
```bash
$ echo a
$ echo a > file
```

<!-- Valid: -->
```sh
echo a
echo a > file
```

<!-- Also valid: -->
```zsh
$ echo a
a
$ echo a > file
```
````

Warn when shell code is prefixed by dollar-characters.
Expand Down
8 changes: 7 additions & 1 deletion lib/rules/list-item-content-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ function listItemContentIndent(ast, file, preferred, done) {
*/

if (index === 0) {
/*
* If there’s a checkbox before the content,
* look backwards to find the start of that
* checkbox.
*/

if (Boolean(node.checked) === node.checked) {
char = begin.offset;
char = begin.offset - 1;

while (contents.charAt(char) !== '[') {
char--;
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/list-item-content-indent-invalid.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@

1. Foo
1. Bar

<!-- Checkboxes can be used incorrectly -->

1. [x] Foo
1. Bar
6 changes: 6 additions & 0 deletions test/fixtures/list-item-content-indent-valid.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@

1. Foo
1. Bar

<!-- Checkboxes (and links) work OK -->

* [ ] [alpha](http://bravo.com)
* [ ] charlie
* [ ] delta
3 changes: 2 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,8 @@ describe('Rules', function () {
describeRule('list-item-content-indent', function () {
describeSetting(true, function () {
assertFile('list-item-content-indent-invalid.md', [
'list-item-content-indent-invalid.md:14:5: Don’t use mixed indentation for children, remove 1 space'
'list-item-content-indent-invalid.md:14:5: Don’t use mixed indentation for children, remove 1 space',
'list-item-content-indent-invalid.md:19:5: Don’t use mixed indentation for children, remove 1 space'
]);

assertFile('list-item-content-indent-valid.md', []);
Expand Down

0 comments on commit 019ff36

Please sign in to comment.