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
40 changes: 20 additions & 20 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ workshop-rs = "=0.3.11"
libc = "0.2"
serde = "1"
serde_json = "1"
serde_yaml = "0.9"
yaml_serde = "0.10"
sha2 = "0.10"
flate2 = "1"
tar = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion crates/wright-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ workspace = true
[dependencies]
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
serde_yaml.workspace = true
yaml_serde.workspace = true
# Single pinned reference: `[workspace.dependencies]` in the root Cargo.toml.
workshop-rs.workspace = true
4 changes: 2 additions & 2 deletions crates/wright-analyzer/src/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ enum CanonicalValuePattern {

impl RuleDefinition {
pub fn from_yaml_str(input: &str) -> Result<Self, RuleError> {
serde_yaml::from_str(input).map_err(RuleError::Yaml)
yaml_serde::from_str(input).map_err(RuleError::Yaml)
}
}

Expand Down Expand Up @@ -959,7 +959,7 @@ fn default_true() -> bool {

#[derive(Debug)]
pub enum RuleError {
Yaml(serde_yaml::Error),
Yaml(yaml_serde::Error),
InvalidIdentity(String),
UnsupportedLocale(String),
UnknownSpelling {
Expand Down
6 changes: 3 additions & 3 deletions crates/wright-analyzer/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ pub struct LintConfig {

impl LintConfig {
/// Parse a project lint configuration from the stable YAML surface.
pub fn from_yaml_str(input: &str) -> Result<Self, serde_yaml::Error> {
serde_yaml::from_str(input)
pub fn from_yaml_str(input: &str) -> Result<Self, yaml_serde::Error> {
yaml_serde::from_str(input)
}

/// Read and parse a project lint configuration from YAML.
pub fn from_yaml_path(path: &Path) -> Result<Self, std::io::Error> {
let input = std::fs::read_to_string(path)?;
serde_yaml::from_str(&input).map_err(std::io::Error::other)
yaml_serde::from_str(&input).map_err(std::io::Error::other)
}

/// Disable a rule by its stable ID.
Expand Down
35 changes: 35 additions & 0 deletions crates/wright-analyzer/tests/yaml_contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use wright_analyzer::declarative::RuleDefinition;
use wright_analyzer::registry::LintConfig;

#[test]
fn lint_config_yaml_round_trips_through_yaml_serialization() {
let config = LintConfig::from_yaml_str(
r#"
rules:
community/minimum-wait:
enabled: false
severity: warn
options:
max-matches: 2
"#,
)
.expect("lint config YAML parses");

let serialized = yaml_serde::to_string(&config).expect("lint config serializes");
let round_tripped =
LintConfig::from_yaml_str(&serialized).expect("serialized lint config parses");

assert!(!round_tripped.is_enabled("community/minimum-wait"));
assert_eq!(
round_tripped.options("community/minimum-wait").max_matches,
Some(2)
);
}

#[test]
fn invalid_rule_yaml_remains_an_explicit_error() {
let error = RuleDefinition::from_yaml_str("id: community/broken\nmetadata: []\nmatcher: {}\n")
.expect_err("invalid rule YAML must be rejected");

assert!(error.to_string().starts_with("invalid rule YAML:"));
}
Loading