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
10 changes: 10 additions & 0 deletions crates/oxc_linter/src/config/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ mod test {
assert!(globals.is_enabled("foo"));
assert!(globals.is_enabled("bar"));
assert!(!globals.is_enabled("baz"));

assert_eq!(globals.get("foo"), Some(&GlobalValue::Readonly));
assert_eq!(globals.get("bar"), Some(&GlobalValue::Writable));
assert_eq!(globals.get("baz"), Some(&GlobalValue::Off));
}

#[test]
Expand All @@ -165,6 +169,9 @@ mod test {
});
assert!(globals.is_enabled("foo"));
assert!(globals.is_enabled("bar"));
// Ensure they map to the correct variants
assert_eq!(globals.get("foo"), Some(&GlobalValue::Readonly));
assert_eq!(globals.get("bar"), Some(&GlobalValue::Writable));
}

#[test]
Expand All @@ -175,6 +182,9 @@ mod test {
});
assert!(globals.is_enabled("foo"));
assert!(globals.is_enabled("bar"));

assert_eq!(globals.get("foo"), Some(&GlobalValue::Writable));
assert_eq!(globals.get("bar"), Some(&GlobalValue::Readonly));
}

#[test]
Expand Down
29 changes: 29 additions & 0 deletions crates/oxc_linter/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,35 @@ mod test {
);
assert_eq!(env.iter().count(), 1);
assert!(globals.is_enabled("foo"));
assert_eq!(globals.get("foo"), Some(&super::GlobalValue::Readonly));
}

#[test]
fn test_deserialize_globals() {
let config = Oxlintrc::deserialize(&serde_json::json!({
"globals": {
"foo": "readable",
"bar": "writeable",
"baz": "off",
"qux": true,
"quux": false,
"corge": "readonly",
"grault": "writable"
}
}));
assert!(config.is_ok());

let Oxlintrc { globals, .. } = config.unwrap();
assert!(globals.is_enabled("foo"));
assert!(globals.is_enabled("bar"));
// Ensure they map to the correct variants
assert_eq!(globals.get("foo"), Some(&super::GlobalValue::Readonly));
assert_eq!(globals.get("bar"), Some(&super::GlobalValue::Writable));
assert_eq!(globals.get("baz"), Some(&super::GlobalValue::Off));
assert_eq!(globals.get("qux"), Some(&super::GlobalValue::Writable));
assert_eq!(globals.get("quux"), Some(&super::GlobalValue::Readonly));
assert_eq!(globals.get("corge"), Some(&super::GlobalValue::Readonly));
assert_eq!(globals.get("grault"), Some(&super::GlobalValue::Writable));
}

#[test]
Expand Down
Loading