Project

General

Profile

Actions

action #48605

closed

coordination #44075: [functional][y][epic] Use more static code style checks to make life for test developers such a pain that nobody dares to add new tests which we would not be able to maintain anyway ;)

[functional][y] Reduce code nesting level to a limit of 4

Added by okurz about 5 years ago. Updated almost 5 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
Enhancement to existing tests
Target version:
SUSE QA - Milestone 25
Start date:
2019-03-02
Due date:
2019-06-04
% Done:

0%

Estimated time:
2.00 h
Difficulty:

Description

Motivation

See parent ticket #44075

Acceptance criteria

  • AC1: .perlcriticrc has a nesting limit of 4
  • AC2: All code positions that exceed the limit have been fixed or explicitly whitelisted together with specific tickets, e.g. to other teams

Suggestions

Currently based on a limit of 4 the following code positions are reporting too deep nesting.

lib/bootloader_setup.pm: Code structure is deeply nested at line 486, column 21.  Consider refactoring.  (Severity: 5)
lib/registration.pm: Code structure is deeply nested at line 280, column 21.  Consider refactoring.  (Severity: 5)
lib/registration.pm: Code structure is deeply nested at line 334, column 21.  Consider refactoring.  (Severity: 5)
lib/registration.pm: Code structure is deeply nested at line 339, column 21.  Consider refactoring.  (Severity: 5)
lib/registration.pm: Code structure is deeply nested at line 343, column 21.  Consider refactoring.  (Severity: 5)
tests/migration/sle12_online_migration/yast2_migration.pm: Code structure is deeply nested at line 159, column 21.  Consider refactoring.  (Severity: 5)
tests/slenkins/slenkins_control.pm: Code structure is deeply nested at line 84, column 21.  Consider refactoring.  (Severity: 5)

I suggest to either fix these code positions directly or explicitly whitelist the positions, e.g. with some "nocritic" pragmas together with tickets that can be assigned to other teams to fix it.

Actions #1

Updated by JERiveraMoya almost 5 years ago

  • Estimated time set to 2.00 h

Run make perlcritic and ensure that nested level are ok according to ticket description (it might be fixed already). Simulate that problem to see if current applied policy is in place.

Actions #2

Updated by JERiveraMoya almost 5 years ago

  • Status changed from New to Workable
Actions #3

Updated by JERiveraMoya almost 5 years ago

Perlcritic freenode already applied, so we can proceed with this ticket without problem to overlapping.

Actions #4

Updated by ybonatakis almost 5 years ago

  • Status changed from Workable to In Progress
  • Assignee set to ybonatakis
Actions #5

Updated by JERiveraMoya almost 5 years ago

@ybonatakis, once you have installed perl-Perl-Critic-Freenode system-wise in your system, according to THEME-RULES it is possible to create themes combination.
Therefore we can modify .perlcriticrc as follows:

theme = freenode or complexity
severity = 4
...
[Perl::Critic::Policy::ControlStructures::ProhibitDeepNests]
severity = 4
max_nests = 4

So basically we can combine both themes and override ProhibitDeepNests with the severity that we are applying at the level of them plus max nests that we want. For instance if you include this test code:

my %my_hash = ('a' => b );
    my @bases_i;
    my @bases_j;
    my @bases_k;
    my @bases_l;
    my @bases_m;
    my @bases_n;
    my @bases_o;
    my @bases_p;
    my @bases_q;
    my @bases_r;
    foreach my $i (@bases_i) {
        foreach my $j (@bases_j) {
            foreach my $k (@bases_k) {
                foreach my $l (@bases_l) {
                    foreach my $m (@bases_m) {
                       my aa = 1;
                    }
                }
            }
        }
    }

You will see errors coming from both themes:
tests/path/to/module/you/decide/to/include/test/code.pm: Hash key with quotes at line 40, column 20. Avoid useless quotes. (Severity: 5)
tests/path/to/module/you/decide/to/include/test/code.pm: Code structure is deeply nested at line 60, column 41. Consider refactoring. (Severity: 4)

We have a couple of policies that we include as parameters in https://github.com/os-autoinst/os-autoinst-distri-opensuse/blob/master/Makefile#L104, I don't know the historic reasons for that, but they look like custom and in fact I can find the files for them in directory under tools. We could also add there another include for the policy of nested loop and it would work as well, but we should focus on make it work using perlcriticrc.
I hope it helps, you just need to play around with it and check that we don't miss anything.

Actions #6

Updated by JERiveraMoya almost 5 years ago

  • Due date changed from 2019-05-21 to 2019-06-04
Actions #7

Updated by ybonatakis almost 5 years ago

  • Due date changed from 2019-06-04 to 2019-05-21

modules which report to has nested loops > 4 and belong to other teams:

  • tests/migration/sle12_online_migration/yast2_migration.pm at line 159
  • tests/slenkins/slenkins_control.pm at line 84
Actions #8

Updated by riafarov almost 5 years ago

  • Due date changed from 2019-05-21 to 2019-06-04
Actions #9

Updated by ybonatakis almost 5 years ago

  • Due date changed from 2019-06-04 to 2019-05-21
  • Status changed from In Progress to Feedback
Actions #10

Updated by JERiveraMoya almost 5 years ago

  • Due date changed from 2019-05-21 to 2019-06-04

I probably missed to move this ticket to current sprint.

Actions #11

Updated by ybonatakis almost 5 years ago

  • Status changed from Feedback to Resolved
Actions

Also available in: Atom PDF