Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

12.2 KB
Raw Blame
use super::merge_linters::merge_linters;

mod general;
mod proper_noun;

use general::General;
use proper_noun::ProperNoun;

merge_linters!(
    ItsContraction => General, ProperNoun =>
    "Detects places where the possessive `its` should be the contraction `it's`, including before verbs/clauses and before proper nouns after opinion verbs."
);

#[cfg(test)]
mod tests {
    use super::ItsContraction;
    use crate::linting::pooled_linter::for_tests::create_test_pool;
    use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};

    create_test_pool!(ItsContraction, ItsContraction, ItsContraction::default());

    #[test]
    fn fix_had() {
        assert_suggestion_result(
            "Its had an enormous effect.",
            test_linter(),
            "It's had an enormous effect.",
        );
    }

    #[test]
    fn fix_been() {
        assert_suggestion_result(
            "Its been months since we spoke.",
            test_linter(),
            "It's been months since we spoke.",
        );
    }

    #[test]
    fn fix_got() {
        assert_suggestion_result(
            "I think its got nothing to do with us.",
            test_linter(),
            "I think it's got nothing to do with us.",
        );
    }

    #[test]
    fn fixes_its_common() {
        assert_suggestion_result(
            "Its common for users to get frustrated.",
            test_linter(),
            "It's common for users to get frustrated.",
        );
    }

    #[test]
    fn ignore_correct_contraction() {
        assert_lint_count("It's been a long year for everyone.", test_linter(), 0);
    }

    #[test]
    fn ignore_possessive() {
        assert_lint_count(
            "The company revised its policies last week.",
            test_linter(),
            0,
        );
    }

    #[test]
    fn ignore_coroutine() {
        assert_lint_count(
            "Launch each task within its own child coroutine.",
            test_linter(),
            0,
        );
    }

    #[test]
    fn issue_381() {
        assert_suggestion_result("Its a nice day.", test_linter(), "It's a nice day.");
    }

    #[test]
    fn ignore_nominal_progressive() {
        assert_lint_count(
            "The class preserves its existing properties.",
            test_linter(),
            0,
        );
    }

    #[test]
    #[ignore = "past participles are not always adjectives ('cared' for instance)"]
    fn ignore_nominal_perfect() {
        assert_lint_count(
            "The robot followed its predetermined route.",
            test_linter(),
            0,
        );
    }

    #[test]
    fn ignore_nominal_long() {
        assert_lint_count(
            "I think of its exploding marvelous spectacular output.",
            test_linter(),
            0,
        );
    }

    #[test]
    fn corrects_because() {
        assert_suggestion_result(
            "Its because they don't want to.",
            test_linter(),
            "It's because they don't want to.",
        );
    }

    #[test]
    fn corrects_its_hard() {
        assert_suggestion_result(
            "Its hard to believe that.",
            test_linter(),
            "It's hard to believe that.",
        );
    }

    #[test]
    fn corrects_its_easy() {
        assert_suggestion_result(
            "Its easy if you try.",
            test_linter(),
            "It's easy if you try.",
        );
    }

    #[test]
    fn corrects_its_a_picnic() {
        assert_suggestion_result(
            "Its a beautiful day for a picnic",
            test_linter(),
            "It's a beautiful day for a picnic",
        );
    }

    #[test]
    fn corrects_its_my() {
        assert_suggestion_result(
            "Its my favorite song.",
            test_linter(),
            "It's my favorite song.",
        );
    }

    #[test]
    fn allows_its_new() {
        assert_no_lints(
            "The company announced its new product line. ",
            test_linter(),
        );
    }

    #[test]
    fn allows_its_own_charm() {
        assert_no_lints("The house has its own charm. ", test_linter());
    }

    #[test]
    fn allows_its_victory() {
        assert_no_lints("The team celebrated its victory. ", test_linter());
    }

    #[test]
    fn allows_its_history() {
        assert_no_lints("The country is proud of its history. ", test_linter());
    }

    #[test]
    fn allows_its_secrets() {
        assert_no_lints("The book contains its own secrets. ", test_linter());
    }

    #[test]
    fn corrects_think_google() {
        assert_suggestion_result(
            "I think its Google, not Microsoft.",
            test_linter(),
            "I think it's Google, not Microsoft.",
        );
    }

    #[test]
    fn corrects_hope_katie() {
        assert_suggestion_result("I hope its Katie.", test_linter(), "I hope it's Katie.");
    }

    #[test]
    fn corrects_guess_date() {
        assert_suggestion_result(
            "I guess its March 6.",
            test_linter(),
            "I guess it's March 6.",
        );
    }

    #[test]
    fn corrects_assume_john() {
        assert_suggestion_result("We assume its John.", test_linter(), "We assume it's John.");
    }

    #[test]
    fn corrects_doubt_tesla() {
        assert_suggestion_result(
            "They doubt its Tesla this year.",
            test_linter(),
            "They doubt it's Tesla this year.",
        );
    }

    #[test]
    fn handles_two_word_name() {
        assert_suggestion_result(
            "She thinks its New York.",
            test_linter(),
            "She thinks it's New York.",
        );
    }

    #[test]
    fn ignores_existing_contraction() {
        assert_lint_count("I think it's Google.", test_linter(), 0);
    }

    #[test]
    fn ignores_possessive_noun_after_name() {
        assert_lint_count("I think its Google product launch.", test_linter(), 0);
    }

    #[test]
    fn ignores_without_opinion_verb() {
        assert_lint_count("Its Google Pixel lineup is impressive.", test_linter(), 0);
    }

    #[test]
    fn ignores_common_noun_target() {
        assert_lint_count("We hope its accuracy improves.", test_linter(), 0);
    }

    #[test]
    fn issue_2547() {
        assert_no_lints(
            "using the foo feature and its associated parameter",
            test_linter(),
        );
    }

    #[test]
    fn issue_2609() {
        assert_no_lints(
            "One such aspect is how the standard library takes great care to make working with its built-in collections as efficient as possible.",
            ItsContraction::default(),
        );
    }

    #[test]
    fn ignore_past_participle_noun_phrase() {
        assert_no_lints(
            "using the foo feature and its abetted parameter",
            test_linter(),
        );
    }

    #[test]
    fn corrects_predicative_called() {
        assert_suggestion_result(
            "Its called recursion.",
            test_linter(),
            "It's called recursion.",
        );
    }

    #[test]
    fn corrects_predicative_named() {
        assert_suggestion_result(
            "Its named Manhattan.",
            test_linter(),
            "It's named Manhattan.",
        );
    }

    #[test]
    fn allows_possessive_generated_code() {
        assert_no_lints("The compiler emits its generated code.", test_linter());
    }

    #[test]
    fn corrects_its_anybody() {
        assert_suggestion_result(
            "Its anybody who volunteers should speak up.",
            test_linter(),
            "It's anybody who volunteers should speak up.",
        );
    }

    #[test]
    fn corrects_its_anyone() {
        assert_suggestion_result(
            "Its anyone you ping will be looped in automatically.",
            test_linter(),
            "It's anyone you ping will be looped in automatically.",
        );
    }

    #[test]
    fn corrects_its_everyone() {
        assert_suggestion_result(
            "Its everyone on the thread noticed the spike.",
            test_linter(),
            "It's everyone on the thread noticed the spike.",
        );
    }

    #[test]
    fn corrects_its_everything() {
        assert_suggestion_result(
            "Its everything we collect ends up in the archive.",
            test_linter(),
            "It's everything we collect ends up in the archive.",
        );
    }

    #[test]
    fn corrects_its_somebody() {
        assert_suggestion_result(
            "Its somebody on call right now.",
            test_linter(),
            "It's somebody on call right now.",
        );
    }

    #[test]
    fn corrects_its_somewhere() {
        assert_suggestion_result(
            "Its somewhere safe to stash the nightly dump.",
            test_linter(),
            "It's somewhere safe to stash the nightly dump.",
        );
    }

    #[test]
    fn corrects_its_nobody() {
        assert_suggestion_result(
            "Its nobody left who can approve this.",
            test_linter(),
            "It's nobody left who can approve this.",
        );
    }

    #[test]
    fn corrects_its_anywhere() {
        assert_suggestion_result(
            "Its anywhere the monitors blink red.",
            test_linter(),
            "It's anywhere the monitors blink red.",
        );
    }

    #[test]
    fn corrects_its_anything() {
        assert_suggestion_result(
            "Its anything worth keeping should be archived.",
            test_linter(),
            "It's anything worth keeping should be archived.",
        );
    }

    #[test]
    fn corrects_its_something() {
        assert_suggestion_result(
            "Its something that keeps restarting the job.",
            test_linter(),
            "It's something that keeps restarting the job.",
        );
    }

    #[test]
    fn allows_its_tail() {
        assert_no_lints("Its tail twitches every time I call it.", test_linter());
    }

    #[test]
    fn allows_its_release_pipeline() {
        assert_no_lints(
            "Its release pipeline is stable in production.",
            test_linter(),
        );
    }

    #[test]
    fn allows_its_nodes() {
        assert_no_lints("The cluster updates its nodes nightly.", test_linter());
    }

    #[test]
    fn allows_its_cover_page() {
        assert_no_lints("Its cover page mentions all contributors.", test_linter());
    }

    #[test]
    fn allows_its_not_anybody() {
        assert_no_lints(
            "Its not anybody to blame despite the outage.",
            test_linter(),
        );
    }

    #[test]
    fn allows_its_never_anywhere() {
        assert_no_lints(
            "Its never anywhere near the ideal timing we hoped for.",
            test_linter(),
        );
    }

    #[test]
    fn allows_at_its_highest() {
        assert_no_lints(
            "Curiosity about Gatsby was at its highest that night.",
            test_linter(),
        );
    }

    #[test]
    fn allows_its_pull_is() {
        assert_no_lints(
            "The Earth is huge, so its pull is super strong.",
            test_linter(),
        );
    }

    #[test]
    fn allows_its_unforeseen_consequences() {
        assert_no_lints(
            "The experiment continued despite its unforeseen consequences.",
            test_linter(),
        );
    }

    #[test]
    fn allows_its_potential_to_benefit() {
        assert_no_lints(
            "The proposal emphasized its potential to benefit local businesses.",
            test_linter(),
        );
    }

    #[test]
    fn allows_its_cover_was() {
        assert_no_lints(
            "Its cover was intricately engraved with floral patterns.",
            test_linter(),
        );
    }

    #[test]
    fn allows_its_starting_level() {
        assert_no_lints("Reduce the tracker to its starting level.", test_linter());
    }

    #[test]
    fn issue_4435() {
        assert_no_lints(
            "I spent more effort in its reading than he did in its creation.",
            test_linter(),
        );
    }

    #[test]
    fn allows_its_gerund_after_preposition() {
        assert_no_lints(
            "The value comes from its measuring of the output.",
            test_linter(),
        );
    }

    #[test]
    fn allows_its_gerund_after_unlisted_preposition() {
        assert_no_lints(
            "I spent more effort during its reading than he did during its creation.",
            test_linter(),
        );
    }
}