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

Can't disable a rule with mdx-js/eslint-mdx and remake-lint #205

Closed
DanielFerrariR opened this issue May 21, 2020 · 10 comments
Closed

Can't disable a rule with mdx-js/eslint-mdx and remake-lint #205

DanielFerrariR opened this issue May 21, 2020 · 10 comments
Labels
🙆 yes/confirmed This is confirmed and ready to be worked on

Comments

@DanielFerrariR
Copy link

DanielFerrariR commented May 21, 2020

Can't disable remake-lint rules while using it with mdx-js/eslint-mdx (on a .md file). Tried:

<!--lint disable no-duplicate-headings-->
// eslint-disable-next-line mdx/remark
/ eslint-disable mdx/remark /

I can disable mdx rules in .mdx files just fine, but it doesn't work for .md ones.

Also, seems pretty bad to have to reload my vscode to update disabled rules from .remarkrc file. Is there any better way to use these rules with eslint?

package.json

"eslint": "v7.0.0",
"eslint-plugin-mdx": "^1.6.9",
"remark-preset-lint-consistent": "^3.0.0",
"remark-preset-lint-markdown-style-guide": "^3.0.0",
"remark-preset-lint-recommended": "^4.0.0",
"remark-preset-prettier": "^0.4.0",

.eslintrc

"overrides": [
  {
    "files": "**/*.+(md|mdx)",
    "extends": ["plugin:mdx/recommended"]
   }
]

.remarkrc

module.exports = {
  plugins: [
    'preset-lint-consistent',
    'preset-lint-markdown-style-guide',
    'preset-lint-recommended',
    'preset-prettier'
  ]
}
@DanielFerrariR DanielFerrariR added 🐛 type/bug This is a problem 🙉 open/needs-info This needs some more info labels May 21, 2020
@JounQin
Copy link
Member

JounQin commented May 24, 2020

@DanielFerrariR Please provide a minimal and runnable reproduction like a GitHub repository with https://www.gitpod.io/.

@JounQin
Copy link
Member

JounQin commented May 24, 2020

You’ll need the blank lines between comments and other nodes! (from remark-lint)

Did you try to add a blank line after <!--lint disable no-duplicate-headings-->?

@DanielFerrariR
Copy link
Author

DanielFerrariR commented May 25, 2020

Thanks for your reply!

https://github.com/DanielFerrariR/mdx-eslint-example

Couldn't make eslint work on gitpod.io. Maybe because extensions is on beta phase there.

Install dependencies with yarn and see the readme file warnings. Can't disable them even using it correctly.

@JounQin JounQin added 🙆 yes/confirmed This is confirmed and ready to be worked on and removed 🐛 type/bug This is a problem 🙉 open/needs-info This needs some more info labels May 26, 2020
@JounQin
Copy link
Member

JounQin commented May 26, 2020

@DanielFerrariR Thanks for reporting, and I can reproduce it locally now.

But it seems a bug of remark API itself, because I tried to call the API manually, the warning is always there:

<!-- README.md -->
<!--lint disable no-literal-urls-->

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
const fs = require('fs')

const remark = require('remark')
const remarkMdx = require('remark-mdx')
const remarkLint = require('remark-lint')
const noLiteralUrls = require('remark-lint-no-literal-urls')
const report = require('vfile-reporter')

const file = remark()
  .use(remarkLint)
  .use(noLiteralUrls)
  .use(remarkMdx)
  .processSync(fs.readFileSync('README.md', 'utf8'))

console.log(report(file))
  5:30-5:93  warning  Don’t use literal URLs without angle brackets  no-literal-urls  remark-lint

⚠ 1 warning

But if I use remark-cli directly with yarn remark README.md, there will be no issue anymore.(It's just been replaced silently, the disable comment never works.)

@wooorm Any idea?

Maybe related: remarkjs/remark-lint#47

@JounQin
Copy link
Member

JounQin commented May 26, 2020

OK, I found out that whenever I add remark-mdx into remarkProcessor at https://github.com/mdx-js/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/rules/helper.ts#L81, there will be warnings, if I remove .use(remarkMdx) there, it will just work as expected.

So it should be an issue of remark-mdx? @wooorm

What means disable comments parsed by remark-mdx will stop working.

@wooorm
Copy link
Member

wooorm commented May 26, 2020

Weird. For a quick fix for now, adding this plugin right after remark-mdx should do the trick @JounQin: https://github.com/mdx-js/mdx/blob/master/packages/mdx/md-ast-to-mdx-ast.js

That’s a step MDX takes right before applying remarkPlugins, which it’s doing outside of the unified flow unfortunately.

In the v2 branch, I removed that step: https://github.com/mdx-js/mdx/tree/next/packages/mdx

@JounQin
Copy link
Member

JounQin commented May 26, 2020

@wooorm I don't know whether I understand correctly but I tried like following:

const fs = require('fs')

const toMDXAST = require('@mdx-js/mdx/md-ast-to-mdx-ast')
const remark = require('remark')
const remarkMdx = require('remark-mdx')
const remarkLint = require('remark-lint')
const noLiteralUrls = require('remark-lint-no-literal-urls')
const report = require('vfile-reporter')

const file = remark()
  .use(remarkLint)
  .use(remarkMdx)
  .use(toMDXAST)
  .use(noLiteralUrls)
  .processSync(fs.readFileSync('README.md', 'utf8'))

console.log(report(file))

There will be a fetal error:

Missing compiler for node of type `comment`: `[object Object]`

@wooorm
Copy link
Member

wooorm commented May 26, 2020

Gosh, that’s a pity.

JounQin added a commit that referenced this issue May 30, 2020
so that it could be used to disable the rule
JounQin added a commit that referenced this issue Aug 5, 2020
so that it could be used to disable the rule
@JounQin
Copy link
Member

JounQin commented Aug 5, 2020

@wooorm Please help to publish a new release, it should be fixed.

@JounQin JounQin closed this as completed Aug 5, 2020
@wooorm
Copy link
Member

wooorm commented Aug 5, 2020

Published!

Weird: I have a GH_TOKEN set up (echo $GH_TOKEN had the correct token as output) but yarn deploy didn’t pick up on it 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙆 yes/confirmed This is confirmed and ready to be worked on
Development

No branches or pull requests

3 participants