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

Breaks with eslint-plugin-markdown #22

Closed
heygrady opened this issue Aug 30, 2019 · 6 comments · Fixed by eslint/eslint-plugin-markdown#119
Closed

Breaks with eslint-plugin-markdown #22

heygrady opened this issue Aug 30, 2019 · 6 comments · Fixed by eslint/eslint-plugin-markdown#119
Labels
bug Something isn't working

Comments

@heygrady
Copy link

heygrady commented Aug 30, 2019

https://github.com/eslint/eslint-plugin-markdown

Parsed some markdown files and totally mangled them. Easy to turn off the rule for markdown but other rules (like import/order) seemed to manage the individual code blocks well.

@lydell
Copy link
Owner

lydell commented Aug 30, 2019

Hi! I've never used eslint-plugin-markdown before. Can you show me how you set things up? The best thing would be a small reproduction repo.

@heygrady
Copy link
Author

heygrady commented Sep 5, 2019

module.exports = {
  extends: [],
  plugins: [
    'simple-import-sort',
    'markdown',
  ],
  rules: {
    'simple-import-sort/sort': 'error',
  },
  overrides: [
    {
      files: ['**/*.md'],
      parserOptions: {
        ecmaFeatures: {
          impliedStrict: true,
        },
      },
      rules: {
        'simple-import-sort/sort': 'error',
      },
    },
  ],
}
Some text

\\```js
import b from 'b'
import a from 'a'
\\```

@lydell
Copy link
Owner

lydell commented Sep 6, 2019

Couldn’t you have bothered to post something that actually works? 😢

Anyway, after fighting ESLint’s configuration for a while I finally made it work and could reproduce the issue. But now I lost my steam for working on the bug.

Some text

```js
import b from 'b'
import a from 'a'
```

is autofixed to:

import a from 'a'
import b from 'b'
```

In other words, everything before the first import seems to be removed.

@lydell lydell added the bug Something isn't working label Sep 6, 2019
@lydell
Copy link
Owner

lydell commented Sep 7, 2019

Discovery: The issue only seems to occur when the autofix applies from the very beginning of the code block (index 0).

For example:

Some text

```js
;import b from 'b'
import a from 'a'
```

successfully autofixes to:

Some text

```js
;import a from 'a'
import b from 'b'
```

Feels like a bug in eslint-plugin-markdown. I need to investigate further.

lydell added a commit to lydell/eslint-plugin-markdown that referenced this issue Sep 7, 2019
Previously, if a rule added an autofix at index 0 of a code block, all
code from the start of the markdown file until the start of that code
block would be removed. Now, the autofix is applied as expected.

Fixes lydell/eslint-plugin-simple-import-sort#22
lydell added a commit to lydell/eslint-plugin-markdown that referenced this issue Sep 7, 2019
Previously, if a rule added an autofix at index 0 of a code block, all
code from the start of the markdown file until the start of that code
block would be removed. Now, the autofix is applied as expected.

Fixes lydell/eslint-plugin-simple-import-sort#22
lydell added a commit to lydell/eslint-plugin-markdown that referenced this issue Sep 7, 2019
If the replacement text of an autofix contains newlines, all lines but
the first in the replacement text will unexpectedly have 0 indentation
if a code block is indented. I guess not only the _range_ of fixes but
also the _text_ of fixes need to be adjusted.

If the code block is placed within a blockquote, a `>` character also
needs to be inserted.

This issue was found while investigating
lydell/eslint-plugin-simple-import-sort#22.  That plugin several lines
of imports in one go. This means that most of the imports will have too
little indentation after autofix if the code block is indented (such as
when placed in a list).
btmills pushed a commit to eslint/eslint-plugin-markdown that referenced this issue Oct 8, 2019
Previously, if a rule added an autofix at index 0 of a code block, all
code from the start of the markdown file until the start of that code
block would be removed. Now, the autofix is applied as expected.

Fixes lydell/eslint-plugin-simple-import-sort#22
@lydell
Copy link
Owner

lydell commented Oct 8, 2019

eslint/eslint-plugin-markdown#119 has been merged, so the next version of eslint-plugin-markdown should not cause removals of markdown above imports anymore.

You might still run into eslint/eslint-plugin-markdown#120, though.

btmills added a commit to eslint/eslint-plugin-markdown that referenced this issue Oct 22, 2019
* Chore: Add failing test case for indent of multiline fixes

If the replacement text of an autofix contains newlines, all lines but
the first in the replacement text will unexpectedly have 0 indentation
if a code block is indented. I guess not only the _range_ of fixes but
also the _text_ of fixes need to be adjusted.

If the code block is placed within a blockquote, a `>` character also
needs to be inserted.

This issue was found while investigating
lydell/eslint-plugin-simple-import-sort#22.  That plugin several lines
of imports in one go. This means that most of the imports will have too
little indentation after autofix if the code block is indented (such as
when placed in a list).

* Fix: Indent multiline fixes (fixes #120)

* Add test for underindented multiline autofix

* Add test for nested blockquote multiline autofix

* Add comment explaining underintented line shift
@lydell
Copy link
Owner

lydell commented Oct 22, 2019

v1.0.1 of eslint-plugin-markdown has been released! All the above issues should be fixed.

I have some uncommitted test that I need to finish up, then we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants