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 code in documentation code blocks #507

Closed
sindresorhus opened this issue May 10, 2019 · 4 comments
Closed

Lint code in documentation code blocks #507

sindresorhus opened this issue May 10, 2019 · 4 comments
Labels
enhancement New feature or request package: parser Issues related to @typescript-eslint/parser package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@sindresorhus
Copy link

I often include code examples in my documentation comments and it would be useful if TypeScript ESLint could lint that code too. I always try to make sure that the code examples are fully runnable by themselves, so would be nice to be able to ensure that's true with linting.

For example:

/**
 * @example
 * ```
 * import foo from 'foo';
 * 
 * foo(bar: string);
 * //=> '✨'
 * ```
 */
function foo() {}
@sindresorhus sindresorhus added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels May 10, 2019
@bradzacher bradzacher added enhancement New feature or request package: parser Issues related to @typescript-eslint/parser package: typescript-estree Issues related to @typescript-eslint/typescript-estree and removed package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels May 10, 2019
@bradzacher
Copy link
Member

bradzacher commented May 10, 2019

My only issue with this is that typescript doesn't run on the code in comments, which means it's easy to provide us with code that is syntactically valid, but not semantically valid, and potentially break assumptions that rules make.

Note that typescript-estree purposely doesn't throw if the semantics of the code are bad during its parse because it's not intended to be a replacement for tsc

@sindresorhus
Copy link
Author

@bradzacher True, but it's still better than nothing.

@mysticatea
Copy link
Member

Named processors may fit this request: eslint/eslint#11552
For example, it defines the named processor that extracts @example code.

@bradzacher
Copy link
Member

Just like how we don't parse code in markdown files - I don't think parsing code in JSDoc comments is within the purview of this project.

This is something that is better suited to a pre-processor - similar to how markdown code fences can be pre-processed for linting by eslint-plugin-markdown.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request package: parser Issues related to @typescript-eslint/parser package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

No branches or pull requests

3 participants