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

Lint all JavaScript in markdown files by default #1355

Open
feross opened this issue Aug 13, 2019 · 7 comments
Open

Lint all JavaScript in markdown files by default #1355

feross opened this issue Aug 13, 2019 · 7 comments

Comments

@feross
Copy link
Member

feross commented Aug 13, 2019

ESLint supports the notion of "processors" which allows us to extract JS from markdown files and lint it to ensure it is in standard style. https://eslint.org/docs/user-guide/configuring#specifying-processor

That would let us eliminate this whole section of the readme which describes how to install eslint-plugin-markdown, run standard with the --plugin flag. In the end you need to actually run standard twice if you do this: standard && standard --plugin markdown '**/*.md'

I think we can do better. Let's just do the right thing out of the box.

We should probably do the same for <script> tags in HTML files too, while we're at it.

We can provide a --no-md or --no-html escape hatch for those who need it. But ideally, this just does the right thing 99.9% of the time.

Thoughts?

@feross feross added this to the standard v15 milestone Aug 13, 2019
@mightyiam
Copy link
Member

Brilliant. I'd love that. Would probably break some projects.

Would that be supported merely by extending from eslint-config-standard or would it require the executable? I would prefer the former, if possible.

@feross
Copy link
Member Author

feross commented Aug 13, 2019

We'd put it directly in eslint-config-standard.

@vweevers
Copy link
Contributor

We should probably do the same for <script> tags in HTML files too, while we're at it.

One requirement for this is that generated HTML (like a code coverage report) is excluded. Such HTML is typically git-ignored though, which tells standard to ignore it too, so it's probably fine.

@vweevers
Copy link
Contributor

I've seen and written code examples in READMEs that are not 100% correct, for example to quickly demonstrate two ways to achieve the same thing:

const x = doItOneWay()

// Alternatively:
const x = doItAnotherWay()

I guess standard would implicitly impose a rule to split such snippets? In this case, to not reassign x.

@feross
Copy link
Member Author

feross commented Aug 23, 2019

@vweevers Yeah, we'd certainly need to disable some of the rules for examples, like unused variables for example. I think we can look at what standard-markdown disables as a starting point: https://github.com/zeke/standard-markdown/blob/2f044f48eed5f7162147e7927b65a61387200341/lib/linter.js#L8-L15

@feross feross modified the milestones: standard 15, standard 16 Oct 22, 2020
@feross
Copy link
Member Author

feross commented Oct 29, 2020

I attempted to get this working for standard 16 but ran into issues. Help would be appreciated to figure it out!

Here's what I tried:

eslint-config-standard

  1. Install eslint-plugin-markdown as a peer dep of eslint-config-standard (2.0.0-rc.0 was latest at the time)
  2. Add "extends": ["plugin:markdown/recommended"] to the eslint.json file.

standard

  1. Install eslint-plugin-markdown as a dep of eslint-config-standard
  2. Add extensions: ['.md'] to eslintConfig in options.js:

Screen Shot 2020-10-28 at 3 50 55 PM

observed behavior

  /Users/feross/code/standard/CHANGELOG.md:654:10: 'foo' is defined but never used. (no-unused-vars)

Rules like no-unused-vars are being enforced, which should be ignored for markdown files. From the docs for eslint-plugin-markdown:

Some rules that catch mistakes in regular code are less helpful in documentation. For example, no-undef would flag variables that are declared outside of a code snippet because they aren't relevant to the example. The plugin:markdown/recommended config disables these rules in Markdown files:

https://github.com/eslint/eslint-plugin-markdown#frequently-disabled-rules

Help appreciated!

@jimmywarting
Copy link
Contributor

bump. would like to see this land

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

4 participants