mirror of
https://github.com/Automattic/harper.git
synced 2025-08-04 18:48:02 +00:00
fix: appease precommit and add a unit test to ensure the changed code behaves correctly
(also sort lint kinds alphabetically)
This commit is contained in:
parent
d2b9fdfcb5
commit
17ff00006c
3 changed files with 18 additions and 12 deletions
|
@ -427,22 +427,20 @@ impl WordMetadata {
|
|||
// Singular is default if number is not marked in the dictionary.
|
||||
pub fn is_singular_noun(&self) -> bool {
|
||||
if let Some(noun) = self.noun {
|
||||
match (noun.is_singular, noun.is_plural) {
|
||||
(Some(true), _) => true,
|
||||
(None | Some(false), None | Some(false)) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
(noun.is_singular, noun.is_plural),
|
||||
(Some(true), _) | (None | Some(false), None | Some(false))
|
||||
)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
pub fn is_non_singular_noun(&self) -> bool {
|
||||
if let Some(noun) = self.noun {
|
||||
match (noun.is_singular, noun.is_plural) {
|
||||
(Some(true), _) => false,
|
||||
(None | Some(false), None | Some(false)) => false,
|
||||
_ => true,
|
||||
}
|
||||
!matches!(
|
||||
(noun.is_singular, noun.is_plural),
|
||||
(Some(true), _) | (None | Some(false), None | Some(false))
|
||||
)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -921,6 +919,14 @@ mod tests {
|
|||
assert!(md("pooches").is_non_singular_noun());
|
||||
}
|
||||
|
||||
// Make sure is_non_xxx_noun methods don't behave like is_not_xxx_noun.
|
||||
// In other words, make sure they don't return true for words that are not nouns.
|
||||
// They must only pass for words that are nouns but not singular etc.
|
||||
#[test]
|
||||
fn loyal_doesnt_pass_is_non_singular_noun() {
|
||||
assert!(!md("loyal").is_non_singular_noun());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hounds_is_plural_noun() {
|
||||
assert!(md("hounds").is_plural_noun());
|
||||
|
|
|
@ -10,8 +10,8 @@ const LINT_KIND_COLORS = {
|
|||
Repetition: '#00A67C', // Green-cyan
|
||||
Spelling: '#EE4266', // Pink-red
|
||||
Style: '#FFD23F', // Yellow
|
||||
WordChoice: '#228B22', // Forest green
|
||||
Typo: '#FF6B35', // Vibrant orange-red
|
||||
WordChoice: '#228B22', // Forest green
|
||||
} as const;
|
||||
|
||||
// Export the type for the lint kind keys
|
||||
|
|
|
@ -10,8 +10,8 @@ const LINT_KIND_COLORS = {
|
|||
Repetition: '#00A67C', // Green-cyan
|
||||
Spelling: '#EE4266', // Pink-red
|
||||
Style: '#FFD23F', // Yellow
|
||||
WordChoice: '#228B22', // Forest green
|
||||
Typo: '#FF6B35', // Vibrant orange-red
|
||||
WordChoice: '#228B22', // Forest green
|
||||
} as const;
|
||||
|
||||
// Export the type for the lint kind keys
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue