@@ -2560,3 +2560,117 @@ def test_commit_type_rule_still_fails_for_other_authors(self):
25602560 patch ("commit_check.engine.get_commit_info" , return_value = "Ada Lovelace" ),
25612561 ):
25622562 assert validator .validate (context ) == ValidationResult .FAIL
2563+
2564+
2565+ class TestImperativeMorphology :
2566+ """The rule decides on form, not on vocabulary. See #526.
2567+
2568+ A word list can only approximate "is this an English imperative", and the
2569+ cost of every gap falls on someone who wrote the subject correctly. These
2570+ pin the three things that replace it: inflected first words are rejected,
2571+ everything else is not, and the few words whose spelling trips the test
2572+ are named rather than guessed at.
2573+ """
2574+
2575+ def _verdict (self , subject ):
2576+ validator = SubjectImperativeValidator (
2577+ ValidationRule (check = "subject_imperative" )
2578+ )
2579+ return validator .validate (ValidationContext (stdin_text = subject ))
2580+
2581+ @pytest .mark .benchmark
2582+ @pytest .mark .parametrize (
2583+ "subject" ,
2584+ [
2585+ "fix: fixed the parser" , # past tense
2586+ "fix: updated the docs" ,
2587+ "fix: removed the flag" ,
2588+ "feat: adding a retry" , # gerund
2589+ "feat: implementing the cache" ,
2590+ "fix: fixes the parser" , # third person
2591+ "fix: removes the flag" ,
2592+ "docs: documents the API" ,
2593+ "fix: tries the fallback" , # -ies, so the stem is "try"
2594+ "fix: applies the patch" ,
2595+ ],
2596+ )
2597+ def test_inflected_first_words_are_rejected (self , subject ):
2598+ """The failure the rule exists for, and now the only one it reports."""
2599+ assert self ._verdict (subject ) == ValidationResult .FAIL
2600+
2601+ @pytest .mark .benchmark
2602+ @pytest .mark .parametrize (
2603+ "subject" ,
2604+ [
2605+ # Correct imperatives that no list contained, or ever would.
2606+ "feat: reword the report format" ,
2607+ "refactor: dedupe the helper" ,
2608+ "chore: decommission the legacy path" ,
2609+ "fix: loosen the guard" ,
2610+ "fix: backfill an absent value" ,
2611+ # Adverb-led subjects, which a list of *verbs* cannot represent
2612+ # without becoming a list of not-verbs.
2613+ "feat: optionally skip the hook" ,
2614+ "fix: explicitly close the handle" ,
2615+ # British spelling, which is not a mistake.
2616+ "refactor: normalise the path separators" ,
2617+ ],
2618+ )
2619+ def test_uninflected_first_words_pass_without_being_listed (self , subject ):
2620+ assert self ._verdict (subject ) == ValidationResult .PASS
2621+
2622+ @pytest .mark .benchmark
2623+ @pytest .mark .parametrize (
2624+ "subject" ,
2625+ [
2626+ "fix: embed the token" , # -ed, not a past tense
2627+ "fix: need a newer pip" ,
2628+ "fix: proceed without the cache" ,
2629+ "chore: spread the load" ,
2630+ "feat: bring back the flag" , # -ing, not a gerund
2631+ "fix: string the parts together" ,
2632+ "fix: ping the endpoint" ,
2633+ "chore: weed out the dead code" ,
2634+ "fix: heed the configured timeout" ,
2635+ "feat: sling the payload over the wire" ,
2636+ ],
2637+ )
2638+ def test_lookalikes_are_not_mistaken_for_inflection (self , subject ):
2639+ """The words a suffix rule gets wrong, enumerated rather than guessed."""
2640+ assert self ._verdict (subject ) == ValidationResult .PASS
2641+
2642+ @pytest .mark .benchmark
2643+ @pytest .mark .parametrize (
2644+ "subject" ,
2645+ [
2646+ "fix: address the warning" , # -ss, never third person
2647+ "fix: process the queue" ,
2648+ "fix: guess the encoding" ,
2649+ "fix: focus the search" , # -s, but the stem is not a verb
2650+ "fix: status report is empty" , # noun-led
2651+ "chore: deps bump" ,
2652+ # Stems that are not verbs at all, so their plurals are nouns.
2653+ "fix: partials are rendered twice" ,
2654+ "chore: setups differ between CI and local" ,
2655+ "fix: always quote the path" , # adverb-led
2656+ "fix: sometimes the cache is stale" ,
2657+ ],
2658+ )
2659+ def test_single_s_words_are_not_assumed_third_person (self , subject ):
2660+ """A trailing -s only counts when the stem is a verb we know."""
2661+ assert self ._verdict (subject ) == ValidationResult .PASS
2662+
2663+ @pytest .mark .benchmark
2664+ def test_a_noun_led_subject_now_passes (self ):
2665+ """Documents the deliberate loosening, so a change to it is a choice.
2666+
2667+ The old list rejected this by accident of vocabulary, not because it
2668+ detected the mood. Naming it here means anyone tightening it later
2669+ does so on purpose.
2670+ """
2671+ assert self ._verdict ("fix: parser improvements" ) == ValidationResult .PASS
2672+
2673+ @pytest .mark .benchmark
2674+ def test_merge_and_fixup_subjects_still_bypass_the_rule (self ):
2675+ assert self ._verdict ("Merge branch 'main' into topic" ) == ValidationResult .PASS
2676+ assert self ._verdict ("fixup! fixed the parser" ) == ValidationResult .PASS
0 commit comments