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

feat: use eslint-plugin-markdown as processor! #283

Merged
merged 8 commits into from
Mar 14, 2021

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Mar 12, 2021

close #259 and #278

This PR uses a different way to lint code blocks: use eslint-plugin-markdown as processor directly!

What means we do not need to maintain related codes by ourselves, I raised another PR eslint/markdown#178 for eslint-plugin-markdown to integrate with eslint-plugin-mdx better, close #282.

Comment on lines 11 to 12
path =>
path.endsWith('/eslint/lib/linter/linter.js') ||
path.endsWith('\\eslint\\lib\\linter\\linter.js'),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems a bit fragile?
Would it make sense to use something like require.resolve?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use require.resolve, it will always be added into require.cache, so I don't know is that correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried:

let resolvedLinterPath: string

// find Linter instance
const linterPath = Object.keys(require.cache).find(
  path =>
    path === resolvedLinterPath ||
    (resolvedLinterPath = require.resolve('eslint/lib/linter/linter')),
)

And there are an error:

(node:46681) Warning: Accessing non-existent property 'Linter' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)

Oops! Something went wrong! :(

ESLint: 7.21.0

TypeError: Cannot read config file: /Users/JounQin/Workspaces/GitHub/eslint-mdx/node_modules/@1stg/eslint-config/base.js
Error: Cannot read property 'prototype' of undefined
Referenced from: /Users/JounQin/Workspaces/GitHub/eslint-mdx/node_modules/@1stg/eslint-config/index.js
    at Object.<anonymous> (/Users/JounQin/Workspaces/GitHub/eslint-mdx/packages/eslint-plugin-mdx/src/processors/options.ts:33:27)
    at Module._compile (/Users/JounQin/Workspaces/GitHub/eslint-mdx/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Module.m._compile (/Users/JounQin/Workspaces/GitHub/eslint-mdx/node_modules/ts-node/src/index.ts:1056:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/JounQin/Workspaces/GitHub/eslint-mdx/node_modules/ts-node/src/index.ts:1059:12)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (/Users/JounQin/Workspaces/GitHub/eslint-mdx/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/Users/JounQin/Workspaces/GitHub/eslint-mdx/packages/eslint-plugin-mdx/src/processors/remark.ts:6:1)

@JounQin JounQin force-pushed the feat/eslint-plugin-markdown branch from 3ff1cc9 to 9a3a99b Compare March 13, 2021 04:04
@codecov-io
Copy link

codecov-io commented Mar 13, 2021

Codecov Report

Merging #283 (ea32dac) into master (5052eb8) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #283   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        22    +1     
  Lines          464       538   +74     
  Branches        90       111   +21     
=========================================
+ Hits           464       538   +74     
Impacted Files Coverage Δ
.eslintrc.js 100.00% <ø> (ø)
packages/eslint-plugin-mdx/src/configs/base.ts 100.00% <ø> (ø)
packages/eslint-plugin-mdx/src/configs/helpers.ts 100.00% <ø> (ø)
...kages/eslint-plugin-mdx/src/configs/recommended.ts 100.00% <ø> (ø)
...lint-plugin-mdx/src/rules/no-unescaped-entities.ts 100.00% <ø> (ø)
...lint-plugin-mdx/src/rules/no-unused-expressions.ts 100.00% <ø> (ø)
test/helpers.ts 100.00% <ø> (ø)
packages/eslint-mdx/src/helpers.ts 100.00% <100.00%> (ø)
packages/eslint-mdx/src/index.ts 100.00% <100.00%> (ø)
packages/eslint-mdx/src/parser.ts 100.00% <100.00%> (ø)
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5052eb8...ea32dac. Read the comment docs.

@JounQin JounQin self-assigned this Mar 13, 2021
@JounQin JounQin added 🦋 type/enhancement This is great to have 🧒 semver/minor This is backwards-compatible change labels Mar 13, 2021
@JounQin JounQin force-pushed the feat/eslint-plugin-markdown branch from 3304055 to e0d6ed4 Compare March 13, 2021 04:42
@JounQin JounQin requested a review from wooorm March 13, 2021 04:50
@JounQin
Copy link
Member Author

JounQin commented Mar 13, 2021

@wooorm Ready for review and merge!

I just copied eslint-plugin-markdown codes temporarily, will use it as dependency once eslint/markdown#178 merged.

Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • What’s the benefit of copy-pasting eslint-plugin-markdown into this project?
  • Assuming you could use it here as a depenedncy and not copy-paste, still: what’s the benefit of supporting both markdown and MDX here?

Comment on lines +230 to +238
const LANGUAGES_MAPPER: Record<string, string> = {
javascript: 'js',
javascriptreact: 'jsx',
typescript: 'ts',
typescriptreact: 'tsx',
markdown: 'md',
mdown: 'md',
mkdn: 'md',
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you basic JS + React, and TS + React off? They don’t work:

```text/javascript
console.log(1)
```

```javascript/react
console.log(1)
```

```javascript
console.log(1)
```

```js
console.log(1)
```

```.js
console.log(1)
```

```JS
console.log(1)
```
console.log(1)
console.log(1)
console.log(1)
console.log(1)
console.log(1)
console.log(1)

I think the get short language functionality seems more complex that needed? This seems closer: (node.lang || '').toLowerCase().replace(/\./g, '')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will generate a virtual filename for code blocks. What means:

javascript -> 0_0.javascript

So I add this mapper so that the virtual files will be linted correctly by ESLint again.

When I try javascript/react or text/javascript, etc in VSCode, there will be no syntax highlighting, so I don't think this is a standard usage.

Of course, I can add support for it, maybe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, I can add support for it, maybe.

No, I don’t think you should!

But where did you get getShortLang from?

It seems to do much more than needed

Copy link
Member Author

@JounQin JounQin Mar 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But where did you get getShortLang from?

I wrote it by myself.

It seems to do much more than needed

Why? Writing JavaScript or typescript as lang for code blocks is common, and we need to support linting them by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JounQin
Copy link
Member Author

JounQin commented Mar 13, 2021

  • What’s the benefit of copy-pasting eslint-plugin-markdown into this project?
  • Assuming you could use it here as a depenedncy and not copy-paste, still: what’s the benefit of supporting both markdown and MDX here?

It's just temporarily, I've mentioned that

will use it as dependency once eslint/markdown#178 merged.

@wooorm
Copy link
Member

wooorm commented Mar 13, 2021

My second point talks about after it’s temporary

@JounQin
Copy link
Member Author

JounQin commented Mar 13, 2021

My second point talks about after it’s temporary

I'm not sure to understand correctly. eslint-plugin-markdown aims to lint code blocks both in md or mdx files.

@wooorm
Copy link
Member

wooorm commented Mar 13, 2021

Ok, so you are only using it to check codeblocks in MDX files, correct?

Put another way, it’s NOT that eslint-mdx now supports .md files?

@JounQin
Copy link
Member Author

JounQin commented Mar 13, 2021

Ok, so you are only using it to check codeblocks in MDX files, correct?

Put another way, it’s NOT that eslint-mdx now supports .md files?

eslint-mdx supports md files for a long time with remark-lint!

With help of eslint-plugin-markdown, we support codeblocks too now.


eslint-plugin-markdown can only lint code blocks while eslint-plugin-mdx can lint markdown content + ES syntaxes.

@wooorm
Copy link
Member

wooorm commented Mar 13, 2021

With help of eslint-plugin-markdown, we support codeblocks too now.

I’m all for that!

eslint-mdx supports md files for a long time with remark-lint!

I’m all for supporting remark lint rules here, but I’m not for supporting markdown files here: MDX !== MD (https://github.com/wooorm/xdm#caveats).
I think markdown belongs in eslint-plugin-markdown and MDX belongs here. If there’s overlap internally (such as what you’re doing here with code blocks), that‘s fine.

From a users perspective: there are markdown users that don’t use MDX; they might want to check their markdown too, so they find eslint-plugin-markdown. They shouldn’t have to install eslint-mdx.

@JounQin
Copy link
Member Author

JounQin commented Mar 13, 2021

I’m all for supporting remark lint rules here, but I’m not for supporting markdown files here: MDX !== MD

remark-mdx is not enabled for md files, so that's OK.

See https://github.com/mdx-js/eslint-mdx/blob/master/packages/eslint-mdx/src/parser.ts#L170

I think markdown belongs in eslint-plugin-markdown and MDX belongs here.

Well, eslint-plugin-markdown does not support remark-lint at all right now.

If we want to lint markdown syntaxes in mdx files, it should be done in eslint-plugin-mdx, so the md files support is incidental result.

@wooorm
Copy link
Member

wooorm commented Mar 13, 2021

remark-mdx is not enabled for md files, so that's OK.

Great! I was worried about that, and your “eslint-mdx supports md files for a long time with remark-lint!” seemed to indicate that, hence my asking.

Well, eslint-plugin-markdown does not support remark-lint at all right now.

Yep, might be something to upstream to them, if they’re interested!

@JounQin
Copy link
Member Author

JounQin commented Mar 13, 2021

Yep, might be something to upstream to them, if they’re interested!

I don't know, maybe another discussion in eslint-plugin-markdown will help.


rasied eslint/markdown#179

@JounQin
Copy link
Member Author

JounQin commented Mar 13, 2021

@wooorm Can we merge and release then?

@JounQin JounQin force-pushed the feat/eslint-plugin-markdown branch from 4414ac0 to 50251ff Compare March 13, 2021 10:39
@JounQin JounQin force-pushed the feat/eslint-plugin-markdown branch 2 times, most recently from 79fc2c2 to 9269549 Compare March 13, 2021 11:45
@JounQin JounQin force-pushed the feat/eslint-plugin-markdown branch from 9269549 to 2934abf Compare March 13, 2021 11:48
@JounQin
Copy link
Member Author

JounQin commented Mar 13, 2021

@wooorm Please help to review last once. I'll focus on remark-mdx@next after this PR been merged and released!

@JounQin JounQin force-pushed the feat/eslint-plugin-markdown branch from 6b4e8b4 to ea32dac Compare March 14, 2021 14:11
@JounQin
Copy link
Member Author

JounQin commented Mar 14, 2021

I'm going to merge first, @wooorm please help to release.

This PR and #281 are both great to have.

@JounQin JounQin merged commit abe30cb into master Mar 14, 2021
@JounQin JounQin deleted the feat/eslint-plugin-markdown branch March 14, 2021 14:18
@JounQin
Copy link
Member Author

JounQin commented Mar 15, 2021

@wooorm Any time to release?

@wooorm
Copy link
Member

wooorm commented Mar 16, 2021

Done!

P.S. I get a ton of issues and notifications, and some days I try and focus on other things. So, you don’t have to ping me every day. I’ll get to it! If I forget for several days, then of course feel free to ping me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

eslint-plugin-mdx won't work along with eslint-plugin-markdown
4 participants