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

Commit

Permalink
feat(rome_analyzer): ARIA query
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Nov 28, 2022
1 parent 8fe7aee commit 7e8d0a0
Show file tree
Hide file tree
Showing 32 changed files with 1,762 additions and 25 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ codegen = "run -p xtask_codegen --"
codegen-configuration = "run -p xtask_codegen --features configuration -- configuration"
codegen-schema = "run -p xtask_codegen --features schema -- schema"
codegen-bindings = "run -p xtask_codegen --features schema -- bindings"
codegen-aria = "run -p xtask_codegen --features aria -- aria"
lintdoc = "run -p xtask_lintdoc --"
documentation = """
doc \
Expand Down
13 changes: 11 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/rome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ use crate::signals::DiagnosticSignal;
pub use crate::signals::{AnalyzerAction, AnalyzerSignal};
pub use crate::syntax::SyntaxVisitor;
pub use crate::visitor::{NodeVisitor, Visitor, VisitorContext, VisitorFinishContext};

use rome_console::markup;
use rome_diagnostics::{category, Applicability, DiagnosticTags, FileId};
use rome_rowan::{
Expand Down
3 changes: 2 additions & 1 deletion crates/rome_analyze/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::{borrow, collections::BTreeSet};
pub enum Phases {
Syntax = 0,
Semantic = 1,
Accessibility = 2,
}

/// Defines which phase a rule will run. This will be defined
Expand Down Expand Up @@ -98,7 +99,7 @@ impl<L: Language> RegistryVisitor<L> for MetadataRegistry {
/// after the "SemanticModel" is ready, which demands a whole transverse of the parsed tree.
pub struct RuleRegistry<L: Language> {
/// Holds a collection of rules for each phase.
phase_rules: [PhaseRules<L>; 2],
phase_rules: [PhaseRules<L>; 3],
}

impl<L: Language + Default> RuleRegistry<L> {
Expand Down
36 changes: 36 additions & 0 deletions crates/rome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,17 @@ pub struct RuleDiagnostic {
pub struct RuleAdvice {
pub(crate) details: Vec<Detail>,
pub(crate) notes: Vec<(LogCategory, MarkupBuf)>,
pub(crate) suggestion_list: Option<SuggestionList>,
pub(crate) code_suggestion_list: Vec<CodeSuggestionAdvice<MarkupBuf>>,
}

#[derive(Debug, Default)]
pub struct SuggestionList {
pub(crate) message: MarkupBuf,
pub(crate) list: Vec<MarkupBuf>,
}

// TODO: this code will be hit once https://github.com/rome/tools/issues/3829 is closed. Make sure it works as expected.
impl Advices for RuleAdvice {
fn record(&self, visitor: &mut dyn Visit) -> std::io::Result<()> {
for detail in &self.details {
Expand All @@ -402,6 +410,19 @@ impl Advices for RuleAdvice {
visitor.record_log(*log_category, &markup! { {note} }.to_owned())?;
}

if let Some(suggestion_list) = &self.suggestion_list {
visitor.record_log(
LogCategory::Info,
&markup! { {suggestion_list.message} }.to_owned(),
)?;
let list: Vec<_> = suggestion_list
.list
.iter()
.map(|suggestion| suggestion as &dyn Display)
.collect();
visitor.record_list(&list)?;
}

// finally, we print possible code suggestions on how to fix the issue
for suggestion in &self.code_suggestion_list {
suggestion.record(visitor)?;
Expand Down Expand Up @@ -486,6 +507,21 @@ impl RuleDiagnostic {
self.footer(LogCategory::Info, msg)
}

///
pub fn note_list(mut self, message: impl Display, list: &[impl Display]) -> Self {
if !list.is_empty() {
self.rule_advice.suggestion_list = Some(SuggestionList {
message: markup! { {message} }.to_owned(),
list: list
.iter()
.map(|msg| markup! { {msg} }.to_owned())
.collect(),
});
}

self
}

/// Adds a footer to this [`RuleDiagnostic`], with the `Warn` severity.
pub fn warning(self, msg: impl Display) -> Self {
self.footer(LogCategory::Warn, msg)
Expand Down
12 changes: 12 additions & 0 deletions crates/rome_aria/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "rome_aria"
version = "0.0.0"
edition = "2021"
authors = ["Rome Tools Developers and Contributors"]
repository = "https://github.com/rome/tools"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rustc-hash = "1.1.0"
143 changes: 143 additions & 0 deletions crates/rome_aria/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//! Metadata of:
//! - ARIA properties
//! - ARIA property types
//! - ARIA roles
//!
//! **Note**: the crate relies on `binary_search`, which means that the
//! entries of all these constants must be ordered!

pub const ARIA_PROPERTIES: [&str; 48] = [
"aria-activedescendant",
"aria-atomic",
"aria-autocomplete",
"aria-busy",
"aria-checked",
"aria-colcount",
"aria-colindex",
"aria-colspan",
"aria-controls",
"aria-current",
"aria-describedby",
"aria-details",
"aria-disabled",
"aria-dropeffect",
"aria-errormessage",
"aria-expanded",
"aria-flowto",
"aria-grabbed",
"aria-haspopup",
"aria-hidden",
"aria-invalid",
"aria-keyshortcuts",
"aria-label",
"aria-labelledby",
"aria-level",
"aria-live",
"aria-modal",
"aria-multiline",
"aria-multiselectable",
"aria-orientation",
"aria-owns",
"aria-placeholder",
"aria-posinset",
"aria-pressed",
"aria-readonly",
"aria-relevant",
"aria-required",
"aria-roledescription",
"aria-rowcount",
"aria-rowindex",
"aria-rowspan",
"aria-selected",
"aria-setsize",
"aria-sort",
"aria-valuemax",
"aria-valuemin",
"aria-valuenow",
"aria-valuetext",
];

pub const ARIA_PROPERTY_TYPE: [&str; 9] = [
"boolean",
"id",
"idlist",
"integer",
"number",
"string",
"token",
"tokenlist",
"tristate",
];

pub const ARIA_WIDGET_ROLES: [&str; 27] = [
"alert",
"alertdialog",
"button",
"checkbox",
"dialog",
"gridcell",
"link",
"log",
"marquee",
"menuitem",
"menuitemcheckbox",
"menuitemradio",
"option",
"progressbar",
"radio",
"scrollbar",
"searchbox",
"slider",
"spinbutton",
"status",
"switch",
"tab",
"tabpanel",
"textbox",
"timer",
"tooltip",
"treeitem",
];

pub const ARIA_ABSTRACT_ROLES: [&str; 12] = [
"command",
"composite",
"input",
"landmark",
"range",
"roletype",
"section",
"sectionhead",
"select",
"structure",
"widget",
"window",
];

pub const ARIA_DOCUMENT_STRUCTURE_ROLES: [&str; 25] = [
"article",
"cell",
"columnheader",
"definition",
"directory",
"document",
"feed",
"figure",
"group",
"heading",
"img",
"list",
"listitem",
"math",
"none",
"note",
"presentation",
"region",
"row",
"rowgroup",
"rowheader",
"separator",
"table",
"term",
"toolbar",
];
Loading

0 comments on commit 7e8d0a0

Please sign in to comment.