Skip to content

Commit e90fb2c

Browse files
committed
style: Enforce perlcritic rule ProhibitImplicitNewlines
ValuesAndExpressions::ProhibitImplicitNewlines
1 parent 43f1746 commit e90fb2c

17 files changed

Lines changed: 96 additions & 84 deletions

.perlcriticrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
theme = community + openqa
22
severity = 4
3-
include = strict ValuesAndExpressions::ProhibitInterpolationOfLiterals CodeLayout::ProhibitParensWithBuiltins BuiltinFunctions::RequireBlockMap BuiltinFunctions::ProhibitStringySplit ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions ValuesAndExpressions::RequireQuotedHeredocTerminator Variables::ProhibitUnusedVariables ValuesAndExpressions::RequireNumberSeparators CodeLayout::ProhibitQuotedWordLists RegularExpressions::ProhibitSingleCharAlternation BuiltinFunctions::RequireBlockGrep
3+
include = strict ValuesAndExpressions::ProhibitInterpolationOfLiterals CodeLayout::ProhibitParensWithBuiltins BuiltinFunctions::RequireBlockMap BuiltinFunctions::ProhibitStringySplit ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions ValuesAndExpressions::RequireQuotedHeredocTerminator Variables::ProhibitUnusedVariables ValuesAndExpressions::RequireNumberSeparators CodeLayout::ProhibitQuotedWordLists RegularExpressions::ProhibitSingleCharAlternation BuiltinFunctions::RequireBlockGrep ValuesAndExpressions::ProhibitImplicitNewlines
44

55
# ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions
66
# No operators like < =~ ! allowed in 'unless' or 'until', only simple

lib/OpenQA/Schema/Result/Jobs.pm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,12 +1983,13 @@ sub packages_diff ($self, $prev, $ignore, $filename, $fallback = 'Diff of packag
19831983
sub ancestors ($self, $limit = -1) {
19841984
my $ancestors = $self->{_ancestors};
19851985
return $ancestors if defined $ancestors;
1986-
my $sth = $self->result_source->schema->storage->dbh->prepare('
1986+
my $sth = $self->result_source->schema->storage->dbh->prepare(<<~'EOM');
19871987
with recursive orig_id as (
19881988
select ? as orig_id, 0 as level
19891989
union all
19901990
select id as orig_id, orig_id.level + 1 as level from jobs join orig_id on orig_id.orig_id = jobs.clone_id where (? < 0 or level < ?))
1991-
select level from orig_id order by level desc limit 1;');
1991+
select level from orig_id order by level desc limit 1;
1992+
EOM
19921993
$sth->bind_param(1, $self->id, SQL_BIGINT);
19931994
$sth->bind_param(2, $limit, SQL_BIGINT);
19941995
$sth->bind_param(3, $limit, SQL_BIGINT);
@@ -1999,12 +2000,13 @@ sub ancestors ($self, $limit = -1) {
19992000
sub descendants ($self, $limit = -1) {
20002001
my $descendants = $self->{_descendants};
20012002
return $descendants if defined $descendants;
2002-
my $sth = $self->result_source->schema->storage->dbh->prepare('
2003+
my $sth = $self->result_source->schema->storage->dbh->prepare(<<~'EOM');
20032004
with recursive clone_id as (
20042005
select ? as clone_id, -1 as level
20052006
union all
20062007
select jobs.clone_id as clone_id, clone_id.level + 1 as level from jobs join clone_id on clone_id.clone_id = jobs.id where (? < 0 or level < ?))
2007-
select level from clone_id order by level desc limit 1;');
2008+
select level from clone_id order by level desc limit 1;
2009+
EOM
20082010
$sth->bind_param(1, $self->id, SQL_BIGINT);
20092011
$sth->bind_param(2, $limit, SQL_BIGINT);
20102012
$sth->bind_param(3, $limit, SQL_BIGINT);

lib/OpenQA/Shared/Plugin/Gru.pm

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ sub _find_existing_minion_job ($self, $task, $args, $job_ids) {
132132
$args = [$args] if ref $args eq 'HASH';
133133
my $dtf = $schema->storage->datetime_parser;
134134
my $dbh = $schema->storage->dbh;
135-
my $sql = q{SELECT id, args, created, state, retries, notes, result FROM minion_jobs
136-
WHERE state IN ('inactive', 'active', 'finished')
137-
AND created >= ? AND task = ? AND args = ?
138-
ORDER BY array_position(array['finished'::varchar, 'inactive'::varchar, 'active'::varchar], state::varchar)
139-
LIMIT 1};
135+
my $sql = <<~'EOM';
136+
SELECT id, args, created, state, retries, notes, result FROM minion_jobs
137+
WHERE state IN ('inactive', 'active', 'finished')
138+
AND created >= ? AND task = ? AND args = ?
139+
ORDER BY array_position(array['finished'::varchar, 'inactive'::varchar, 'active'::varchar], state::varchar)
140+
LIMIT 1
141+
EOM
140142
my $sth = $dbh->prepare($sql);
141143
my @args = (
142144
$dtf->format_datetime(DateTime->now()->subtract(minutes => 1)),

lib/OpenQA/WebAPI/Controller/Admin/Influxdb.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ sub minion ($self) {
106106

107107
my $dbh = $self->schema->storage->dbh;
108108
# rc means hook script return code
109-
my $sth = $dbh->prepare(
110-
q{SELECT COUNT(*) AS rc_failed_count FROM minion_jobs
109+
my $sth = $dbh->prepare(<<~'EOM');
110+
SELECT COUNT(*) AS rc_failed_count FROM minion_jobs
111111
WHERE finished >= ? AND finished < ? AND task = 'hook_script' AND
112-
state = 'finished' AND (notes->'hook_rc')::int != 0}
113-
);
112+
state = 'finished' AND (notes->'hook_rc')::int != 0
113+
EOM
114114
$sth->execute("$rc_fail_timespan_start+0", "$rc_fail_timespan_end+0");
115115

116116
my $result = $sth->fetchrow_arrayref;

t/25-cache-client.t

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ BEGIN {
1818
$ENV{OPENQA_CACHE_DIR} = path($basedir, 'cache');
1919
$ENV{OPENQA_BASEDIR} = $basedir;
2020
$ENV{OPENQA_CONFIG} = path($basedir, 'config')->make_path;
21-
path($ENV{OPENQA_CONFIG})->child('workers.ini')->spew('
22-
[global]
23-
CACHEDIRECTORY = ' . $ENV{OPENQA_CACHE_DIR} . '
24-
CACHEWORKERS = 10
25-
CACHELIMIT = 100');
21+
path($ENV{OPENQA_CONFIG})->child('workers.ini')->spew(<<~"EOM");
22+
[global]
23+
CACHEDIRECTORY = $ENV{OPENQA_CACHE_DIR}
24+
CACHEWORKERS = 10
25+
CACHELIMIT = 100
26+
EOM
2627

2728
*CORE::GLOBAL::sleep = sub { $sleep_count++ };
2829
}

t/25-cache-service.t

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ BEGIN {
2626
$ENV{OPENQA_CACHE_DIR} = path($basedir, 'cache');
2727
$ENV{OPENQA_BASEDIR} = $basedir;
2828
$ENV{OPENQA_CONFIG} = path($basedir, 'config')->make_path;
29-
path($ENV{OPENQA_CONFIG})->child('workers.ini')->spew('
30-
[global]
31-
CACHEDIRECTORY = ' . $ENV{OPENQA_CACHE_DIR} . '
32-
CACHEWORKERS = 10
33-
CACHELIMIT = 100');
29+
path($ENV{OPENQA_CONFIG})->child('workers.ini')->spew(<<~"EOM");
30+
[global]
31+
CACHEDIRECTORY = $ENV{OPENQA_CACHE_DIR}
32+
CACHEWORKERS = 10
33+
CACHELIMIT = 100
34+
EOM
3435
}
3536

3637
use FindBin;
@@ -201,10 +202,11 @@ subtest 'Configurable minion workers' => sub {
201202
is_deeply [OpenQA::CacheService::setup_workers(qw(minion daemon))],
202203
[qw(minion daemon)], 'minion worker setup with daemon';
203204

204-
path($ENV{OPENQA_CONFIG})->child('workers.ini')->spew("
205-
[global]
206-
CACHEDIRECTORY = $cachedir
207-
CACHELIMIT = 100");
205+
path($ENV{OPENQA_CONFIG})->child('workers.ini')->spew(<<~"EOM");
206+
[global]
207+
CACHEDIRECTORY = $cachedir
208+
CACHELIMIT = 100
209+
EOM
208210

209211
is_deeply [OpenQA::CacheService::setup_workers(qw(run))], [qw(run -j 5)], 'minion worker setup with parallel jobs';
210212
};

t/25-cache.t

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ BEGIN {
1616
$cachedir->make_path->realpath;
1717
$db_file = $cachedir->child('cache.sqlite');
1818
$ENV{OPENQA_CONFIG} = path($cached, 'config')->make_path;
19-
path($ENV{OPENQA_CONFIG})->child('workers.ini')->spew("
20-
[global]
21-
CACHEDIRECTORY = $cachedir
22-
CACHEWORKERS = 10
23-
CACHELIMIT = 50");
19+
path($ENV{OPENQA_CONFIG})->child('workers.ini')->spew(<<~"EOM");
20+
[global]
21+
CACHEDIRECTORY = $cachedir
22+
CACHEWORKERS = 10
23+
CACHELIMIT = 50
24+
EOM
2425

2526
# make test independent of the journaling setting
2627
delete $ENV{OPENQA_CACHE_SERVICE_SQLITE_JOURNAL_MODE};
@@ -92,17 +93,19 @@ $local_cache_dir->make_path;
9293
for my $i (1 .. 3) {
9394
my $file = $local_cache_dir->child("$i.qcow2")->spew("\0" x 84);
9495
if ($i % 2) {
95-
my $sql = "INSERT INTO assets (filename,size, etag, last_use, pending)
96-
VALUES ( ?, ?, 'Not valid', strftime('\%s','now'), 0);";
96+
my $sql = <<~'EOM';
97+
INSERT INTO assets (filename,size, etag, last_use, pending)
98+
VALUES ( ?, ?, 'Not valid', strftime('\%s','now'), 0);
99+
EOM
97100
$cache->sqlite->db->query($sql, $file->to_string, 84);
98101
}
99102
}
100103
# create pending asset
101104
$local_cache_dir->child('4.qcow2')->touch;
102-
$cache->sqlite->db->query(
103-
"INSERT INTO assets (filename,size, etag, last_use)
104-
VALUES ( '4.qcow2', 42, 'Not valid', strftime('\%s','now'));"
105-
);
105+
$cache->sqlite->db->query(<<'EOM');
106+
INSERT INTO assets (filename,size, etag, last_use)
107+
VALUES ( '4.qcow2', 42, 'Not valid', strftime('\%s','now'));
108+
EOM
106109

107110
# initialize the cache
108111
$cache->downloader->sleep_time(0.01);

t/api/08-jobtemplates.t

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,15 +1094,17 @@ subtest 'References' => sub {
10941094
id => $job_group_id4,
10951095
job_group_id => $job_group_id4,
10961096
ids => [37, 32, 38, 34, 39, 36],
1097-
changes => '@@ -22,7 +22,7 @@
1098-
i586:
1099-
opensuse-13.1-DVD-i586: &2
1100-
- spam
1101-
- - eggs
1102-
+ - foobar
1103-
ppc64:
1104-
opensuse-13.1-DVD-ppc64: *2
1105-
x86_64:'
1097+
changes => <<~'EOM' =~ s/\n\z//r
1098+
@@ -22,7 +22,7 @@
1099+
i586:
1100+
opensuse-13.1-DVD-i586: &2
1101+
- spam
1102+
- - eggs
1103+
+ - foobar
1104+
ppc64:
1105+
opensuse-13.1-DVD-ppc64: *2
1106+
x86_64:
1107+
EOM
11061108
},
11071109
'Diff reflects changes in the YAML';
11081110
};

t/api/13-influxdb.t

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ my $t = Test::Mojo->new('OpenQA::WebAPI');
3333
$t->app->config->{global}->{base_url} = 'http://example.com';
3434

3535

36-
$t->get_ok('/admin/influxdb/jobs')->status_is(200)->content_is(
37-
'openqa_jobs,url=http://example.com blocked=0i,running=2i,scheduled=3i
38-
openqa_jobs_by_group,url=http://example.com,group=No\\ Group scheduled=2i
39-
openqa_jobs_by_group,url=http://example.com,group=opensuse running=1i,scheduled=1i
40-
openqa_jobs_by_group,url=http://example.com,group=opensuse\\ test running=1i
41-
openqa_jobs_by_worker,url=http://example.com,worker=localhost running=1i
42-
openqa_jobs_by_arch,url=http://example.com,arch=i586 scheduled=2i
43-
openqa_jobs_by_arch,url=http://example.com,arch=x86_64 running=2i
44-
'
45-
)->content_unlike(qr/,arch= /);
36+
$t->get_ok('/admin/influxdb/jobs')->status_is(200)->content_is(<<~'EOM')
37+
openqa_jobs,url=http://example.com blocked=0i,running=2i,scheduled=3i
38+
openqa_jobs_by_group,url=http://example.com,group=No\ Group scheduled=2i
39+
openqa_jobs_by_group,url=http://example.com,group=opensuse running=1i,scheduled=1i
40+
openqa_jobs_by_group,url=http://example.com,group=opensuse\ test running=1i
41+
openqa_jobs_by_worker,url=http://example.com,worker=localhost running=1i
42+
openqa_jobs_by_arch,url=http://example.com,arch=i586 scheduled=2i
43+
openqa_jobs_by_arch,url=http://example.com,arch=x86_64 running=2i
44+
EOM
45+
->content_unlike(qr/,arch= /);
4646

4747
$t->get_ok('/admin/influxdb/minion')->status_is(200)
4848
->content_like(qr!openqa_minion_jobs,url=http://example.com active=0i,delayed=0i,failed=0i,inactive=0i!)
@@ -74,10 +74,10 @@ subtest 'openqa_minion_jobs_hook_rc_failed counter' => sub {
7474
my $dbh = $schema->storage->dbh;
7575
my $static_now = DateTime->from_epoch(epoch => 3947); # 1970-01-01T01:05:47
7676
my $rc_fail_finished = DateTime->from_epoch(epoch => 3521); # 1970-01-01T00:46:57
77-
my $sth = $dbh->prepare(
78-
q!INSERT INTO minion_jobs (id, args, created, delayed, finished, priority, result, retried, retries, started, state, task, worker, queue, attempts, parents, notes)
79-
VALUES (7291599, '["/bin/true", 11201356, {"delay": 60, "retries": 1440, "skip_rc": 142, "timeout": "10m", "kill_timeout": "10s"}]', '2023-05-26 17:00:50.542916+02', '2023-05-26 17:00:50.542916+02', ?, 0, null, null, 0, '2023-05-26 17:00:50.565839+02', 'finished', 'hook_script', 1388, 'default', 1, '{}', '{"hook_rc": -1, "hook_cmd": "foobar", "hook_result": "Job is '':investigate:'' already, skipping investigation\n"}')!
80-
);
77+
my $sth = $dbh->prepare(<<~'EOM');
78+
INSERT INTO minion_jobs (id, args, created, delayed, finished, priority, result, retried, retries, started, state, task, worker, queue, attempts, parents, notes)
79+
VALUES (7291599, '["/bin/true", 11201356, {"delay": 60, "retries": 1440, "skip_rc": 142, "timeout": "10m", "kill_timeout": "10s"}]', '2023-05-26 17:00:50.542916+02', '2023-05-26 17:00:50.542916+02', ?, 0, null, null, 0, '2023-05-26 17:00:50.565839+02', 'finished', 'hook_script', 1388, 'default', 1, '{}', '{"hook_rc": -1, "hook_cmd": "foobar", "hook_result": "Job is '':investigate:'' already, skipping investigation\n"}')
80+
EOM
8181
$sth->execute("$rc_fail_finished+0");
8282
my $mock_dt = Test::MockModule->new('DateTime');
8383
$mock_dt->mock(now => sub { $static_now->clone });

t/config.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ subtest 'trim whitespace characters from both ends of openqa.ini value' => sub {
194194
my $t_dir = tempdir;
195195
local $ENV{OPENQA_CONFIG} = $t_dir;
196196
OpenQA::App->set_singleton(my $app = Mojolicious->new(log => $quiet_log));
197-
my $data = '
197+
my $data = <<~'EOM';
198198
[global]
199199
appname = openQA
200200
hide_asset_types = repo iso
201201
recognized_referers = bugzilla.suse.com progress.opensuse.org github.com
202-
';
202+
EOM
203203
$t_dir->child('openqa.ini')->spew($data);
204204
my $global_config = OpenQA::Setup::read_config($app)->{global};
205205
is $global_config->{appname}, 'openQA', 'appname';

0 commit comments

Comments
 (0)