@@ -68,43 +68,23 @@ def matchtask(
6868 name , lintable = file , linenumber = task [LINE_NUMBER_KEY ]
6969 )
7070 )
71- task_name = name .split ("|" )
72- if len (task_name ) > 1 :
73- name = task_name [1 ].strip ()
74- results .extend (
75- self ._check_name (name , lintable = file , linenumber = task [LINE_NUMBER_KEY ])
76- )
7771 return results
7872
7973 def _prefix_check (
8074 self , name : str , lintable : Lintable | None , linenumber : int
8175 ) -> list [MatchError ]:
8276
8377 results : list [MatchError ] = []
78+ effective_name = name
8479 if lintable is None :
8580 return []
8681
87- if self ._collection :
88- prefix = self ._collection .options .task_name_prefix .format (
89- stem = lintable .path .stem
82+ if not results :
83+ results .extend (
84+ self ._check_name (
85+ effective_name , lintable = lintable , linenumber = linenumber
86+ )
9087 )
91- if (
92- lintable .kind == "tasks"
93- and lintable .path .stem != "main"
94- and not name .startswith (prefix )
95- ):
96- # For the moment in order to raise errors this rule needs to be
97- # enabled manually. Still, we do allow use of prefixes even without
98- # having to enable the rule.
99- if "name[prefix]" in self ._collection .options .enable_list :
100- results .append (
101- self .create_matcherror (
102- message = f"Task name should start with '{ prefix } '." ,
103- linenumber = linenumber ,
104- tag = "name[prefix]" ,
105- filename = lintable ,
106- )
107- )
10888 return results
10989
11090 def _check_name (
@@ -114,7 +94,37 @@ def _check_name(
11494 # lowercase letter, so we ignore anything else. On Unicode isupper()
11595 # is not necessarily the opposite of islower()
11696 results = []
117- if name [0 ].isalpha () and name [0 ].islower () and not name [0 ].isupper ():
97+ # stage one check prefix
98+ effective_name = name
99+ if self ._collection and lintable :
100+ prefix = self ._collection .options .task_name_prefix .format (
101+ stem = lintable .path .stem
102+ )
103+ if lintable .kind == "tasks" and lintable .path .stem != "main" :
104+ if not name .startswith (prefix ):
105+ # For the moment in order to raise errors this rule needs to be
106+ # enabled manually. Still, we do allow use of prefixes even without
107+ # having to enable the rule.
108+ if "name[prefix]" in self ._collection .options .enable_list :
109+ results .append (
110+ self .create_matcherror (
111+ message = f"Task name should start with '{ prefix } '." ,
112+ linenumber = linenumber ,
113+ tag = "name[prefix]" ,
114+ filename = lintable ,
115+ )
116+ )
117+ return results
118+ else :
119+ effective_name = name [len (prefix ) :]
120+ # breakpoint()
121+
122+ if (
123+ effective_name [0 ].isalpha ()
124+ and effective_name [0 ].islower ()
125+ and not effective_name [0 ].isupper ()
126+ ):
127+ # breakpoint()
118128 results .append (
119129 self .create_matcherror (
120130 message = "All names should start with an uppercase letter." ,
@@ -171,6 +181,7 @@ def test_name_prefix_negative() -> None:
171181 bad_runner = Runner (failure , rules = collection )
172182 results = bad_runner .run ()
173183 assert len (results ) == 3
184+ # , "\n".join(results)
174185 assert results [0 ].tag == "name[casing]"
175186 assert results [1 ].tag == "name[prefix]"
176187 assert results [2 ].tag == "name[prefix]"
0 commit comments