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

Plugin doesn't respect configured linting style #117

Closed
frederikheld opened this issue Jul 17, 2019 · 10 comments
Closed

Plugin doesn't respect configured linting style #117

frederikheld opened this issue Jul 17, 2019 · 10 comments

Comments

@frederikheld
Copy link

I'm using eslint-plugin-standard to lint my JS files. I would see this style reflected in my markdown files as well but eslint-plugin-markdown doesn't respect this but uses it's own linting style instead. I haven't found any documentation about how to configure the plugin to lint standard style.

Is it possible to configure the linting style for eslint-plugin-markdown? If so: How? If not: I would like to see this feature :-)

@platinumazure
Copy link
Member

Hi @frederikheld, thanks for the issue.

All the plugin does is find the JS blocks and send them off to ESLint for linting. It should use your own configuration.

Could you please share your ESLint configuration?

@frederikheld
Copy link
Author

Thanks for the quick answer :-) You can find my configuration here: https://github.com/frederikheld/usm.io/blob/master/.eslintrc

I have to admit that I'm fairly new to eslint, so if the plugin should use my eslint config, then I've most probably configured eslint wrong :-P I would really appreciate your help with that.

@platinumazure
Copy link
Member

@frederikheld Thanks. Could you also please share an example (code, actual ESLint output, expected output) where you believe the linter is working incorrectly?

@frederikheld
Copy link
Author

frederikheld commented Jul 17, 2019

The main issue I have is that standard uses no semicolons, which is correctly linted for all js files.

Since I have installed eslint-plugin-markdown, semicolons are automatically added on save (I have configured VSCode to format on save) for all javascript blocks in markdown files :-P

So

```javascript
const foo = 'bar'
\```

becomes

```javascript
const foo = "bar";
\```
  • I had to add the backslash in order to make to closing of the md block visible. They aren't there in my real md file

after saving.

For js files it still works correctly, it's just how markdown is linted.

@frederikheld
Copy link
Author

frederikheld commented Jul 17, 2019

Ah. What I haven't seen before: It also changes the single quotes to double quotes :-P

I don't understand where it takes those rules from. May this be an interference with VSCode? Sometimes I get the feeling that VSCode is doing shenanigans even though I have an eslint config in my project. Like when I hit enter, the new line is indented with 4 spaces. After saving, eslint changes this to 2 following the standard rules.

How can I make sure that VSCode is actually using my eslint config for everything in my project?

@platinumazure
Copy link
Member

@frederikheld Could you try running ESLint from the command line to see if semicolons are correctly left off in the Markdown blocks? If so, this proves that VS Code must have some other configuration that is in conflict with ESLint.

@frederikheld
Copy link
Author

frederikheld commented Jul 17, 2019

Ok, now it gets weird :-P

This is my markdown file:

Lorem ipsum dolor sit amet ...

```javascript
let foo = 'bar'
console.log(foo)
\```

Lorem ipsum dolor sit amet ...

(minus the backslash)

If I run eslint on it I get this, which is expected if standard is applied correctly:

$ ./node_modules/.bin/eslint eslint_markdown_test.md
/home/frederik/eslint_markdown_test/eslint_markdown_test.md
  2:5  error  'foo' is never reassigned. Use 'const' instead  prefer-const

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

So no complaint about semicolons or single quotes.

But if I run

$ ./node_modules/.bin/eslint --fix eslint_markdown_test.md

on it, this is how my markdown file looks after the procedure o_0

const foo = 'bar'
console.log(foo)
\```

Lorem ipsum dolor sit amet ...

So it completely removes parts of the markdown ??

@frederikheld
Copy link
Author

frederikheld commented Jul 20, 2019

I figured out why markdown was linted with the wrong style: I had VSCode plugin prettier running as well. This was originally intended to lint according to eslint rules but seemed to be configured wrong. I disabled it and am only using ESlint plugin now. Linting works as expected on JS files now but not at all on markdown (which is kind of an improvement though :-P). My .eslintrc is configured as the README suggests.

Linting files directly still works, but --fix will chew up everything that comes before the first ```javascript (same for ```js) block including this line.

Do you have any suggestions how to fix this? Looks like a bug to me :-P

frederikheld added a commit to frederikheld/usm.io that referenced this issue Jul 20, 2019
- also removes eslint-plugin-markdown because of buggy behavior. See: eslint/eslint-plugin-markdown#117
- fixes linting in generator as well
@alex996
Copy link

alex996 commented Aug 3, 2019

Same issue here. The plugin is not respected by prettier-vscode even though I have "markdown" under "eslint.validate" as well.

@btmills
Copy link
Member

btmills commented Oct 8, 2019

@frederikheld thanks for the report and for diagnosing what was going on with VSCode. If you figure out a good way to get this working in VSCode, I'd be happy to merge a PR adding that as documentation.

As for deleting the beginning of your Markdown, yeah, not exactly intended behavior! I just verified that #119 fixes the very same bug, so I'll get that merged and released shortly.

@btmills btmills closed this as completed in dc90961 Oct 8, 2019
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

4 participants