-
-
Notifications
You must be signed in to change notification settings - Fork 777
feat(website): auto-generate rule docs pages #4640
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
graphite-app
merged 1 commit into
main
from
don/08-04-feat_website_auto-generate_rule_docs_pages
Aug 10, 2024
Merged
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //! Create documentation pages for each rule. Pages are printed as Markdown and | ||
| //! get added to the website. | ||
|
|
||
| use oxc_linter::{table::RuleTableRow, RuleFixMeta}; | ||
| use std::fmt::{self, Write}; | ||
|
|
||
| use crate::linter::rules::html::HtmlWriter; | ||
|
|
||
| pub fn render_rule_docs_page(rule: &RuleTableRow) -> Result<String, fmt::Error> { | ||
| const APPROX_FIX_CATEGORY_AND_PLUGIN_LEN: usize = 512; | ||
| let RuleTableRow { name, documentation, plugin, turned_on_by_default, autofix, .. } = rule; | ||
|
|
||
| let mut page = HtmlWriter::with_capacity( | ||
| documentation.map_or(0, str::len) + name.len() + APPROX_FIX_CATEGORY_AND_PLUGIN_LEN, | ||
| ); | ||
|
|
||
| writeln!( | ||
| page, | ||
| "<!-- This file is auto-generated by {}. Do not edit it manually. -->\n", | ||
| file!() | ||
| )?; | ||
| writeln!(page, "# {plugin}/{name}\n")?; | ||
|
|
||
| // rule metadata | ||
| page.div(r#"class="rule-meta""#, |p| { | ||
| if *turned_on_by_default { | ||
| p.span(r#"class="default-on""#, |p| { | ||
| p.writeln("✅ This rule is turned on by default.") | ||
| })?; | ||
| } | ||
|
|
||
| if let Some(emoji) = fix_emoji(*autofix) { | ||
| p.span(r#"class="fix""#, |p| { | ||
| p.writeln(format!("{} {}", emoji, autofix.description())) | ||
| })?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| })?; | ||
|
|
||
| // rule documentation | ||
| if let Some(docs) = documentation { | ||
| writeln!(page, "\n{}", *docs)?; | ||
| } | ||
|
|
||
| // TODO: link to rule source | ||
|
|
||
| Ok(page.into()) | ||
| } | ||
|
|
||
| fn fix_emoji(fix: RuleFixMeta) -> Option<&'static str> { | ||
| match fix { | ||
| RuleFixMeta::None => None, | ||
| RuleFixMeta::FixPending => Some("🚧"), | ||
| RuleFixMeta::Conditional(_) | RuleFixMeta::Fixable(_) => Some("🛠️"), | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.