harper_core/linting/
wordpress_dotcom.rs1use crate::{CharString, CharStringExt, TokenStringExt};
2
3use super::{Lint, LintKind, Linter, Suggestion};
4
5#[derive(Default)]
7pub struct WordPressDotcom;
8
9impl Linter for WordPressDotcom {
10 fn lint(&mut self, document: &crate::Document) -> Vec<Lint> {
11 let correct: CharString = "WordPress.com".chars().collect();
12 let correct_lower = correct.to_lower();
13 let mut lints = Vec::new();
14
15 for hostname in document.iter_hostnames() {
16 let text = document.get_span_content(&hostname.span);
17
18 if correct.as_slice() != text && text.to_lower() == correct_lower {
19 lints.push(Lint {
20 span: hostname.span,
21 lint_kind: LintKind::Style,
22 suggestions: vec![Suggestion::ReplaceWith(correct.to_vec())],
23 message: "The WordPress hosting provider should be stylized as `WordPress.com`"
24 .to_owned(),
25 priority: 31,
26 });
27 }
28 }
29
30 lints
31 }
32
33 fn description(&self) -> &str {
34 "Ensures correct capitalization of WordPress.com. This rule verifies that the official stylization of WordPress.com is used when referring to the hosting provider."
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use crate::linting::tests::assert_suggestion_result;
41
42 use super::WordPressDotcom;
43
44 #[test]
45 fn simple() {
46 assert_suggestion_result("wordpress.com", WordPressDotcom, "WordPress.com");
47 }
48
49 #[test]
50 fn sentence() {
51 assert_suggestion_result(
52 "wordpress.com is a great hosting provider",
53 WordPressDotcom,
54 "WordPress.com is a great hosting provider",
55 );
56 }
57}