eslint-plugin-markdown: New: ability to only lint for certain parts of the code block

Ref https://github.com/airbnb/javascript/issues/685

Not sure how this would work but an example would be in airbnb’s style guide.

3.1 Use the literal syntax for object creation. eslint rules: no-new-object.

// bad
const item = new Object();

// good
const item = {};

So in this case you would want to check the // good part is linted correctly while the // bad snippet is incorrect.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 35 (25 by maintainers)

Commits related to this issue

Most upvoted comments

I just added HTML comments preceding code blocks in the ESLint rule docs, and our new renderer is preserving the comments correctly! I also ran a test with the parser in this plugin. As long as there’s still a blank line preceding the code block (this is required by spec anyway), it correctly picks up the raw HTML and the code block separately.

  • <!--eslint-plugin-markdown ignore-->
  • <!--eslint-disable-block-->
  • <!--eslint-disable--> / <!--eslint-enable-->
  • <!--eslint-plugin-markdown-disable--> / <!--eslint-plugin-markdown-enable-->

Brainstorming a few different options there. Any preferences/other ideas?

Below, I’ve borrowed from ESLint’s eqeqeq docs and inserted comments to demonstrate what this should look like given the latest proposal. Any objections to implementing this as described?

When disabling a specific rule <!--eslint-disable-next-block eqeqeq-->, the plugin will alert for syntax errors and other rules but ignore errors from eqeqeq:

### always

The `"always"` option (default) enforces the use of `===` and `!==` in every situation.

Examples of **incorrect** code for the `"always"` option:

<!--eslint-disable-next-block eqeqeq-->

```js
/*eslint eqeqeq: ["error", "always"]*/

a == b
foo == true
bananas != 1
```

Without any comments, the plugin will report all errors as received from ESLint:

Examples of **correct** code for the `"always"` option:

```js
/*eslint eqeqeq: ["error", "always"]*/

a === b
foo === true
bananas !== 1
```

When disabled for the entire block, the plugin won’t even bother sending the code to ESLint:

Examples of **syntax errors**:

<!--eslint-disable-next-block-->

```js
!@#$%^&*()
```

@ljharb the implementation for configuring rules in comments will be different than it will be for this, so I’ve opened #54 to track that separately. Since we still have inline config comments, I’d say #54 can build on top of this rather than blocking it.

For https://github.com/airbnb/javascript, it would be all of those. Some blocks should be skipped entirely, some blocks will have modified configs, and some blocks will be intentionally failing