Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(xtask_lintdoc): add more markdown syntax support #2764

Merged
merged 6 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use rome_rowan::{AstNode, AstSeparatedList};

declare_rule! {
/// Disallows using an async function as a Promise executor.
IWANABETHATGUY marked this conversation as resolved.
Show resolved Hide resolved
///
/// The executor function can also be an async function. However, this is usually a mistake, for a few reasons:
/// If an async executor function throws an error, the error will be lost and won't cause the newly-constructed `Promise` to reject. This could make it difficult to debug and handle some errors.
/// If a Promise executor function is using `await`, this is usually a sign that it is not actually necessary to use the `new Promise` constructor, or the scope of the `new Promise` constructor can be reduced.
/// 1. If an async executor function throws an error, the error will be lost and won't cause the newly-constructed `Promise` to reject. This could make it difficult to debug and handle some errors.
/// 2. If a Promise executor function is using `await`, this is usually a sign that it is not actually necessary to use the `new Promise` constructor, or the scope of the `new Promise` constructor can be reduced.
///
/// ## Examples
/// ### Valid
Expand Down
3 changes: 0 additions & 3 deletions website/src/docs/lint/rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ eleventyNavigation:
<a class="header-anchor" href="#noAsyncPromiseExecutor"></a>
</h3>
Disallows using an async function as a Promise executor.
The executor function can also be an async function. However, this is usually a mistake, for a few reasons:
If an async executor function throws an error, the error will be lost and won't cause the newly-constructed <code>Promise</code> to reject. This could make it difficult to debug and handle some errors.
If a Promise executor function is using <code>await</code>, this is usually a sign that it is not actually necessary to use the <code>new Promise</code> constructor, or the scope of the <code>new Promise</code> constructor can be reduced.
</div>
<div class="rule">
<h3 data-toc-exclude id="noCompareNegZero">
Expand Down
5 changes: 3 additions & 2 deletions website/src/docs/lint/rules/noAsyncPromiseExecutor.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ layout: layouts/rule.liquid
# noAsyncPromiseExecutor

Disallows using an async function as a Promise executor.

The executor function can also be an async function. However, this is usually a mistake, for a few reasons:
If an async executor function throws an error, the error will be lost and won't cause the newly-constructed `Promise` to reject. This could make it difficult to debug and handle some errors.
If a Promise executor function is using `await`, this is usually a sign that it is not actually necessary to use the `new Promise` constructor, or the scope of the `new Promise` constructor can be reduced.

1. If an async executor function throws an error, the error will be lost and won't cause the newly-constructed `Promise` to reject. This could make it difficult to debug and handle some errors.
2. If a Promise executor function is using `await`, this is usually a sign that it is not actually necessary to use the `new Promise` constructor, or the scope of the `new Promise` constructor can be reduced.
## Examples

### Valid
Expand Down
24 changes: 23 additions & 1 deletion xtask/lintdoc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn parse_documentation(
// Tracks the content of the current code block if it's using a
// language supported for analysis
let mut language = None;

let mut list_order = None;
for event in parser {
if is_summary {
if matches!(event, Event::End(Tag::Paragraph)) {
Expand Down Expand Up @@ -245,6 +245,28 @@ fn parse_documentation(
writeln!(content)?;
}

Event::Start(Tag::List(num)) => {
if let Some(num) = num {
list_order = Some(num);
}
}

Event::End(Tag::List(_)) => {
list_order = None;
}
Event::Start(Tag::Item) => {
if let Some(num) = list_order {
write!(content, "{num}. ")?;
} else {
write!(content, "- ")?;
}
}

Event::End(Tag::Item) => {
list_order = list_order.map(|item| item + 1);
writeln!(content)?;
}

_ => {
// TODO: Implement remaining events as required
bail!("unimplemented event {event:?}")
Expand Down