@@ -82,9 +82,9 @@ run_reviewdog() {
8282 true > " ${FILE_VIOLATIONS} .formatted"
8383 while read -r violation; do
8484 if echo " $violation " | grep -q ' ||' ; then
85- echo " $violation " | sed ' s/||/::/'
85+ echo " $violation " | sed ' s/||/::/g '
8686 else
87- echo " $violation " | sed ' s/:null:/::/'
87+ echo " $violation " | sed ' s/:null:/::/g '
8888 fi
8989 done < " $FILE_VIOLATIONS " > " ${FILE_VIOLATIONS} .formatted"
9090
@@ -170,6 +170,38 @@ build_changed_lines_cache() {
170170}
171171
172172# ========== FUNÇÕES AUXILIARES ==========
173+ get_rule_priority () {
174+ rule_name=" $1 "
175+
176+ # Busca por property name='RuleName' primeiro (override no XML)
177+ priority=$( echo " $INPUT_RULESETS_CONTENT " | grep -B 2 " name='$rule_name '" | grep -o ' priority" value="[0-9]' | head -1 | cut -d' "' -f3)
178+
179+ # Se não encontrou, busca por class que termina com RuleNameRule (adiciona sufixo Rule)
180+ if [ -z " $priority " ]; then
181+ priority=$( echo " $INPUT_RULESETS_CONTENT " | grep " class='[^']*${rule_name} Rule'" -A 5 | grep -o ' priority" value="[0-9]' | head -1 | cut -d' "' -f3)
182+ fi
183+
184+ # Se ainda não encontrou, tenta sem adicionar Rule (pode já ter o sufixo)
185+ if [ -z " $priority " ]; then
186+ priority=$( echo " $INPUT_RULESETS_CONTENT " | grep " class='[^']*${rule_name} '" -A 5 | grep -o ' priority" value="[0-9]' | head -1 | cut -d' "' -f3)
187+ fi
188+
189+ # Se ainda não encontrou, busca em rule-script com property name
190+ if [ -z " $priority " ]; then
191+ priority=$( echo " $INPUT_RULESETS_CONTENT " | grep -A 3 " path='[^']*${rule_name} " | grep -o ' priority" value="[0-9]' | head -1 | cut -d' "' -f3)
192+ fi
193+
194+ echo " ${priority:- 2} "
195+ }
196+
197+ extract_rule_name () {
198+ violation_line=" $1 "
199+
200+ # Formato: file:line:RuleName Message ou file:null:RuleName Message
201+ # Extrai apenas o RuleName (terceiro campo após os dois pontos)
202+ echo " $violation_line " | sed -E ' s/^[^:]+:[^:]+:([A-Za-z0-9]+).*/\1/'
203+ }
204+
173205get_p1_count () {
174206 p1_count=$( grep -Eo " p1=[0-9]+" " $CODENARC_RESULT " | cut -d' =' -f2 | head -1)
175207 echo " ${p1_count:- 0} "
@@ -219,26 +251,30 @@ check_blocking_rules() {
219251
220252 while IFS=: read -r file line rest; do
221253 [ -z " $file " ] && continue
254+
255+ # Trata file-based violations (formato com ||)
222256 if echo " $file " | grep -q ' ||' ; then
223257 file=$( echo " $file " | cut -d' |' -f1)
224258 line=" "
225259 fi
260+
226261 file_matches_patterns " $file " " $allowed_patterns " || continue
227262
228- priority_marker=$( echo " $rest " | grep -o ' \[P[0-9]\]' | head -1)
263+ # Extrai o nome da regra e busca a priority no XML
264+ rule_name=$( extract_rule_name " $file :$line :$rest " )
265+ priority=$( get_rule_priority " $rule_name " )
229266
230- if [ -n " $priority_marker " ]; then
231- [ " $priority_marker " != " [P1]" ] && continue
232- fi
267+ [ " $priority " != " 1" ] && continue
233268
269+ # Verifica se é file-based ou line-based
234270 if [ -z " $line " ] || [ " $line " = " null" ]; then
235271 if is_file_changed " $file " ; then
236- echo " 📍 Violação P1 file-based em arquivo alterado: $file "
272+ echo " 📍 Violação P1 ( $rule_name ) file-based em arquivo alterado: $file "
237273 echo " 1" > " $VIOLATIONS_FLAG "
238274 break
239275 fi
240276 elif is_line_changed " $line " " $file " ; then
241- echo " 📍 Violação P1 em linha alterada: $file :$line "
277+ echo " 📍 Violação P1 ( $rule_name ) em linha alterada: $file :$line "
242278 echo " 1" > " $VIOLATIONS_FLAG "
243279 break
244280 fi
0 commit comments