Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint --report-unused-disable-directives does not work with this plugin #115

Open
ehmicky opened this issue Apr 30, 2019 · 2 comments
Open

Comments

@ehmicky
Copy link

ehmicky commented Apr 30, 2019

eslint --report-unused-disable-directives is not reported when a <-- eslint-disable --> is defined in Markdown but is unused (i.e. could be removed).

.eslintrc.yml:

plugins: [markdown]
rules:
  no-inline-comments: 2

README.md:

<!-- eslint-disable no-inline-comments -->

```js
var aa = true
```

index.js:

/* eslint-disable no-inline-comments */
var aa = true

package.json:

{
  "name": "eslint-comments-bug",
  "version": "1.0.0",
  "license": "ISC",
  "dependencies": {
    "eslint": "^5.16.0",
    "eslint-plugin-markdown": "^1.0.0"
  }
}

In the terminal:

$ eslint --report-unused-disable-directives README.md
$ eslint --report-unused-disable-directives index.js

/home/ehmicky/eslint-comments-bug/index.js
  1:1  error  Unused eslint-disable directive (no problems were reported from 'no-inline-comments')

✖ 1 problem (1 error, 0 warnings)

--report-unused-disable-directives works for the JavaScript file, but not for the Markdown (where nothing is reported).

@ehmicky ehmicky changed the title This does not work with eslint --report-unused-disable-directives eslint --report-unused-disable-directives does not work with this plugin Apr 30, 2019
@btmills
Copy link
Member

btmills commented May 1, 2019

I suspect the cause here is the same as in #75.

Before linting, the processor looks for HTML comments preceding a code block and inserts them as /* ... */ comments at the beginning of the code. When it gets back a report from ESLint, it tries to map error locations in the linted code back to locations in the Markdown code block. Since the leading HTML comments aren't in the code block, if ESLint reports any errors on them, the plugin ignores those messages.

A fix would replace the bail-out check for HTML comments and instead map error locations back to their original location above the code block. That would require tracking original location information for comments, which it doesn't do right now. A fix for either this or #75 should fix both. I'd welcome a contribution if you're interested in taking a stab at it, @ehmicky!

@ehmicky
Copy link
Author

ehmicky commented May 1, 2019

Thanks for your explanation!

I would gladly help but I am not familiar with writing ESLint plugins. It's on my to-do list but not yet unfortunately :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants