eslint / markdown

Lint JavaScript code blocks in Markdown documents
MIT License
406 stars 63 forks source link

feat!: map known code block languages to respective file extensions #246

Closed DMartens closed 6 months ago

DMartens commented 7 months ago

Fixes #245. I researched common language codes for javascript and markdown which are not the same as the file extension. There may be additional ones. The current tests had test cases for the language codes javascript and node already, so I adjusted them and added a case to make sure the mapping from code block language to file extension is done after the code block language normalization. This may be a breaking change as additional code blocks may be linted.

DMartens commented 7 months ago

The lint task was failing as one of the mappings also enabled linting the nested code blocks nested in markdown. As I thought all the detected lint errors are irrelevant for demonstrating the plugin, I added them to the existing rule ignores.

DMartens commented 7 months ago

I removed the code block language mapping from node to js as mentioned in the issue. Should I add documentation for this case such as setting parserOptions: { sourceType: 'commonjs' }?

nzakas commented 7 months ago

I think at this point we don't need to do anything to cater to CommonJS, specifically. I'm not sure what node is meant to indicate in Markdown anyway.

nzakas commented 7 months ago

The lint task was failing as one of the mappings also enabled linting the nested code blocks nested in markdown. As I thought all the detected lint errors are irrelevant for demonstrating the plugin, I added them to the existing rule ignores.

Can you explain this a bit more? I'm not quite sure I follow what happened here. On HEAD linting passes as-is, so I don't just want to disable rules without understanding what changed.

DMartens commented 7 months ago

One of the added mappings from code block language was from markdown to md. This is also the case in the README.md section "What gets linted").. As such the processor is called recursively which was not the case before (just forgot to run the linter on all files). I ignored the rules such as the console.log (no-console) or function without jsdoc (jsdoc/require-jsdoc) in the nested code blocks are for what I think are demonstration purposes. The same reason as why no-var for markdown code block was disabled before this PR.