-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Conversation
e5a69c5
to
3ff1cc9
Compare
path => | ||
path.endsWith('/eslint/lib/linter/linter.js') || | ||
path.endsWith('\\eslint\\lib\\linter\\linter.js'), | ||
) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, it's based on https://github.com/sveltejs/eslint-plugin-svelte3/blob/master/src/processor_options.js
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
3ff1cc9
to
9a3a99b
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
3304055
to
e0d6ed4
Compare
@wooorm Ready for review and merge! I just copied |
There was a problem hiding this 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?
const LANGUAGES_MAPPER: Record<string, string> = { | ||
javascript: 'js', | ||
javascriptreact: 'jsx', | ||
typescript: 'ts', | ||
typescriptreact: 'tsx', | ||
markdown: 'md', | ||
mdown: 'md', | ||
mkdn: 'md', | ||
} |
There was a problem hiding this comment.
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, '')
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wooorm See also eslint/markdown#176
It's just temporarily, I've mentioned that
|
My second point talks about after it’s temporary |
I'm not sure to understand correctly. |
Ok, so you are only using it to check codeblocks in MDX files, correct? Put another way, it’s NOT that |
With help of
|
I’m all for that!
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). From a users perspective: there are markdown users that don’t use MDX; they might want to check their markdown too, so they find |
See https://github.com/mdx-js/eslint-mdx/blob/master/packages/eslint-mdx/src/parser.ts#L170
Well, If we want to lint markdown syntaxes in |
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.
Yep, might be something to upstream to them, if they’re interested! |
I don't know, maybe another discussion in rasied eslint/markdown#179 |
@wooorm Can we merge and release then? |
4414ac0
to
50251ff
Compare
79fc2c2
to
9269549
Compare
9269549
to
2934abf
Compare
@wooorm Please help to review last once. I'll focus on |
6b4e8b4
to
ea32dac
Compare
@wooorm Any time to release? |
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! |
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 witheslint-plugin-mdx
better, close #282.