forked from os-autoinst/os-autoinst-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Introducing `tools/tidyall` an improved wrapper over perl's `tidyall`. It does version detection directly in perl and exposes the underlying `tidyall` CLI. - Adds a complementary GitHub Action to run `tools/tidyall` automatically on Pull Requests & Master. - Brings bare minimum dependencies.yaml for running `tools/tidyall`. Adjusted `tools/update-deps` to produce a `cpanfile` alone (without needing an `.spec` file first). - Applied tidy rules. Branched off os-autoinst#30.
- Loading branch information
1 parent
0cfcdb3
commit c752b24
Showing
9 changed files
with
186 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
name: 'Perl static checks' | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- 'master' | ||
|
||
jobs: | ||
perl-lint-checks: | ||
runs-on: ubuntu-latest | ||
name: "Perltidy" | ||
container: | ||
image: perldocker/perl-tester | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: GITHUB_ACTIONS=1 ./tools/tidyall --check-only --all --quiet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.tidyall.d/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Workaround needed for handling non-ASCII in files. | ||
# # See <https://github.com/houseabsolute/perl-code-tidyall/issues/84>. | ||
--character-encoding=none | ||
--no-valign | ||
-l=160 | ||
-fbl # don't change blank lines | ||
-fnl # don't remove new lines | ||
-nsfs # no spaces before semicolons | ||
-baao # space after operators | ||
-bbao # space before operators | ||
-pt=2 # no spaces around () | ||
-bt=2 # no spaces around [] | ||
-sbt=2 # no spaces around {} | ||
-sct # stack closing tokens )} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[PerlTidy] | ||
select = **/*.{pl,pm,t} tools/tidyall tools/perlcritic tools/update-deps | ||
argv = --profile=$ROOT/.perltidyrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
################################################## | ||
# WARNING | ||
# This file is autogenerated by tools/update-deps | ||
# from dependencies.yaml | ||
################################################## | ||
|
||
requires 'Module::CPANfile'; | ||
requires 'Storable', '>= 3.06'; | ||
|
||
on 'test' => sub { | ||
requires 'Test::Most'; | ||
requires 'Test::Warnings'; | ||
|
||
}; | ||
|
||
on 'develop' => sub { | ||
requires 'Code::TidyAll'; | ||
requires 'Perl::Critic'; | ||
requires 'Perl::Critic::Community'; | ||
requires 'Perl::Tidy', '== 20230912'; | ||
|
||
}; | ||
|
||
feature 'coverage', 'coverage for CI' => sub { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
# % is placeholder for section. | ||
# e.g.: | ||
# % => develop | ||
# %_requires => develop_requires | ||
targets: | ||
# List all %_requires into a cpanfile | ||
cpanfile: [main, develop, test] | ||
cpanfile-targets: | ||
# save %_require into cpanfile section | ||
develop: develop | ||
test: test | ||
|
||
main_requires: | ||
# Needed until preaction/Log-Any#105 is solved. | ||
perl(Storable): '>= 3.06' | ||
perl(Module::CPANfile): | ||
perl(version): | ||
|
||
develop_requires: | ||
perl(Perl::Tidy): '== 20230912' | ||
perl(Code::TidyAll): | ||
perl(Perl::Critic): | ||
perl(Perl::Critic::Community): | ||
|
||
cover_requires: | ||
perl(Devel::Cover): | ||
perl(Devel::Cover::Report::Codecov): | ||
|
||
test_requires: | ||
perl(Test::Most): | ||
perl(Test::Warnings): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env perl | ||
# Copyright SUSE LLC | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
# | ||
# Tidyall command with perltidy version constraint. | ||
use strict; | ||
use warnings; | ||
use version; | ||
use Perl::Tidy; | ||
use Module::CPANfile; | ||
use FindBin '$Bin'; | ||
|
||
=item perltidy_version() | ||
Grabs the perltidy version from cpanfile using Module::CPANfile. | ||
=cut | ||
|
||
sub perltidy_version() { | ||
my $cpanfile_location; | ||
# Try searching for a cpanfile in: | ||
# - the current working directory | ||
# - a directory above this command | ||
# - the catch-all location in external/os-autoinst-common | ||
my @locations = ('.', "$Bin/..", "$Bin/../external/os-autoinst-common"); | ||
|
||
foreach my $path (@locations) { | ||
next unless -e "$path/cpanfile"; | ||
$cpanfile_location = "$path/cpanfile" and last; | ||
} | ||
|
||
my $version = Module::CPANfile->load($cpanfile_location) | ||
->prereq_for_module('Perl::Tidy') | ||
->requirement | ||
->version; | ||
# Version requirements may contain qualifiers >=, ==, <, etc. The convention | ||
# is to separate the qualifier from the actual version with a space. | ||
# | ||
# It's safe enough to assume that the last item is really the version. | ||
# | ||
# Additionally version will take care of 1.2.0 being equal to 1.2 | ||
return version->new((split ' ', $version)[-1]); | ||
} | ||
|
||
sub is_force_flag() { $_ eq '--force' } | ||
|
||
my $required_version = perltidy_version(); | ||
my $detected_version = version->new($Perl::Tidy::VERSION); | ||
my @tidyall_argv = @ARGV; | ||
|
||
unless ($detected_version eq $required_version) { | ||
print STDERR "Incorrect version of perltidy.\n"; | ||
printf STDERR "- Detected: %s\n+ Required: %s\n\n", $detected_version, $required_version; | ||
|
||
my $force_run = grep { is_force_flag } @ARGV; | ||
|
||
unless ($force_run) { | ||
printf STDERR "Please install the appropriate version of perltidy.\n"; | ||
printf STDERR "If you want to proceed anyways, re run with --force flag.\n"; | ||
exit 1; | ||
} | ||
|
||
# tidyall does not know about the --force flag. | ||
@tidyall_argv = grep { !is_force_flag } @tidyall_argv; | ||
|
||
print STDERR 'Proceeding to run with incorrect version of perltidy. '; | ||
print STDERR "Results might not be consistent.\n"; | ||
print STDERR "==================\n"; | ||
} | ||
|
||
exec 'tidyall', @tidyall_argv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters