.NAME Files with more than X% of similar code are forbiden 

.DESCRIPTION
Files with more than X% of similar code are forbiden

Parameters for the rule: conf degree [percent]
if percent is omitted, it defaults to 90

.SEVERITY Advisory

.COMMAND reducer

.CODE

proc compute {mnemo prj params} {
    if {![llength $params]} {
        error "Rule $mnemo can not be used without parameters."
    }
    set cfg [red_obj::get_config_from_param $prj $params]
    if {![string length $cfg]} {
        error "Rule $mnemo: Can not find a built configuration for parameter : $params."
    }
    
    set max [lindex $params 2]
    if {![string length $max]} {
        set max 90
    }

    foreach diff [red_obj::get_config_differences $cfg] {
        set dl1 [lindex [red_obj::get_difference_locs $diff] 0]
        set dl2 [lindex [red_obj::get_difference_locs $diff] 1]

        set path1 [red_obj::get_file_path [red_obj::get_diff_loc_file $dl1]]
        set percent1 [red_obj::get_diff_loc_percent $dl1]
        set path2 [red_obj::get_file_path [red_obj::get_diff_loc_file $dl2]]
        set percent2 [red_obj::get_diff_loc_percent $dl2]
        if {$percent1 >= $max} {
            api::add_rule_violation $path1 1 "[red_obj::get_config_acronym $cfg] - $percent1% of file similar to $path2"
        }
        if {$percent2 >= $max} {
            api::add_rule_violation $path2 1 "[red_obj::get_config_acronym $cfg] - $percent2% of file similar to $path1"
        }
    }
}

