Skip to content
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
26 changes: 11 additions & 15 deletions crates/biome_html_analyze/src/lint/a11y/use_button_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,20 @@ impl Rule for UseButtonType {
}

fn diagnostic(ctx: &RuleContext<Self>, state: &Self::State) -> Option<RuleDiagnostic> {
let span = ctx.query().range();

let message = if state.missing_prop {
(markup! {
"Provide an explicit "<Emphasis>"type"</Emphasis>" attribute for the "<Emphasis>"button"</Emphasis>" element."
}).to_owned()
} else {
(markup!{
"Provide a valid "<Emphasis>"type"</Emphasis>" attribute for the "<Emphasis>"button"</Emphasis>" element."
}).to_owned()
};

Some(RuleDiagnostic::new(rule_category!(),
span,
message
ctx.query().range(),
if state.missing_prop {
markup! {
"Provide an explicit "<Emphasis>"type"</Emphasis>" attribute for the "<Emphasis>"button"</Emphasis>" element."
}
} else {
markup!{
"Provide a valid "<Emphasis>"type"</Emphasis>" attribute for the "<Emphasis>"button"</Emphasis>" element."
}
}
)
.note(markup! {
"The default "<Emphasis>"type"</Emphasis>" of a button is "<Emphasis>"submit"</Emphasis>", which causes the submission of a form when placed inside a `form` element. "
"The default "<Emphasis>"type"</Emphasis>" of a button is "<Emphasis>"submit"</Emphasis>", which causes the submission of a form when placed inside a `form` element."
})
.note(
markup! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ invalid.html:2:1 lint/a11y/useButtonType ━━━━━━━━━━━━━
3 │ <button type="incorrectType">Do something</button>
4 │ <button type>Do something</button>

i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.
i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.

i Allowed button types are: submit, button or reset

Expand All @@ -47,7 +47,7 @@ invalid.html:3:1 lint/a11y/useButtonType ━━━━━━━━━━━━━
4 │ <button type>Do something</button>
5 │ <button type="">Do something</button>

i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.
i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.

i Allowed button types are: submit, button or reset

Expand All @@ -66,7 +66,7 @@ invalid.html:4:1 lint/a11y/useButtonType ━━━━━━━━━━━━━
5 │ <button type="">Do something</button>
6 │ <button />

i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.
i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.

i Allowed button types are: submit, button or reset

Expand All @@ -85,7 +85,7 @@ invalid.html:5:1 lint/a11y/useButtonType ━━━━━━━━━━━━━
6 │ <button />
7 │ <button type="incorrectType" />

i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.
i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.

i Allowed button types are: submit, button or reset

Expand All @@ -104,7 +104,7 @@ invalid.html:6:1 lint/a11y/useButtonType ━━━━━━━━━━━━━
7 │ <button type="incorrectType" />
8 │ <button type />

i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.
i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.

i Allowed button types are: submit, button or reset

Expand All @@ -123,7 +123,7 @@ invalid.html:7:1 lint/a11y/useButtonType ━━━━━━━━━━━━━
8 │ <button type />
9 │ <button type="" />

i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.
i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.

i Allowed button types are: submit, button or reset

Expand All @@ -142,7 +142,7 @@ invalid.html:8:1 lint/a11y/useButtonType ━━━━━━━━━━━━━
9 │ <button type="" />
10 │

i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.
i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.

i Allowed button types are: submit, button or reset

Expand All @@ -160,7 +160,7 @@ invalid.html:9:1 lint/a11y/useButtonType ━━━━━━━━━━━━━
│ ^^^^^^^^^^^^^^^^^^
10 │

i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.
i The default type of a button is submit, which causes the submission of a form when placed inside a `form` element.

i Allowed button types are: submit, button or reset

Expand Down
3 changes: 3 additions & 0 deletions crates/biome_html_syntax/src/element_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ impl AnyHtmlElement {
}
}

/// Find an attribute by name (case-insensitive) within this element, if it has attributes.
///
/// This will not detect attributes in Svelte attribute shorthand like `<div {foo}>`.
pub fn find_attribute_by_name(&self, name_to_lookup: &str) -> Option<HtmlAttribute> {
match self {
Self::HtmlElement(element) => element.find_attribute_by_name(name_to_lookup),
Expand Down
Loading