-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
test(eslint-plugin): assert that ts
/tsx
code blocks in docs are syntactically valid
#8142
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bc9f74f
test(eslint-plugin): assert that `ts`/`tsx` code blocks in docs are s…
auvred ef2b0b7
revert unintended changes in space-before-blocks.md
auvred 4cad96e
chore: shorten examples in consistent-type-assertions.md
auvred e3c374a
refactor: do not parse md file again
auvred 972a903
Merge branch 'main' into test/8134
auvred 58d2607
Merge branch 'main' into test/8134
auvred 7bb200f
Merge branch 'main' into test/8134
auvred 9b7a3f1
docs: more consistent examples for consistent-type-assertions
auvred 7fe7309
docs: convert `js` code blocks to `ts`
auvred 049d172
Update packages/eslint-plugin/tests/docs.test.ts
auvred 63f6775
Merge branch 'main' into test/8134
auvred 90e3409
chore: use regex instead of startsWith
auvred 960e641
chore: fix few codesamples
auvred 72e0b1c
Merge branch 'main' into test/8134
auvred File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ enum Direction { | |
|
||
enum Color { | ||
Red, | ||
Green = 'Green' | ||
Green = 'Green', | ||
Blue = 'Blue', | ||
} | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { parseForESLint } from '@typescript-eslint/parser'; | ||
import fs from 'fs'; | ||
import { marked } from 'marked'; | ||
import path from 'path'; | ||
|
@@ -180,6 +181,32 @@ describe('Validating rule docs', () => { | |
} | ||
}); | ||
} | ||
|
||
test('must include only valid code samples', () => { | ||
for (const token of tokens) { | ||
if (token.type !== 'code') { | ||
continue; | ||
} | ||
|
||
const lang = token.lang?.trim(); | ||
if (!lang || !/^tsx?\b/i.test(lang)) { | ||
continue; | ||
} | ||
|
||
try { | ||
parseForESLint(token.text, { | ||
ecmaFeatures: { | ||
jsx: /^tsx\b/i.test(lang), | ||
}, | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
range: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without |
||
}); | ||
} catch { | ||
throw new Error(`Parsing error:\n\n${token.text}`); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We can't mix angle bracket assertions and jsx syntax