Skip to content

Commit

Permalink
Reinstate lost style checks (alire-project#1591)
Browse files Browse the repository at this point in the history
* Reinstate lost style checks

* Explicit style checks and corresponding fixes
  • Loading branch information
mosteo authored Feb 27, 2024
1 parent cfc6152 commit d6c2572
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 46 deletions.
32 changes: 24 additions & 8 deletions alire_common.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,30 @@ abstract project Alire_Common is
Style_Check_Switches := ();
case Style_Check_Mode is
when "enabled" => Style_Check_Switches :=
("-gnatwe", -- Warnings as errors
"-gnatyd", -- no DOS line terminators
"-gnatyI", -- no IN mode
"-gnatyO", -- all overrides
"-gnatyS", -- separate lines after THEN/ELSE
"-gnatyu", -- no unnecessary blank lines
"-gnatyx", -- no extra parens around conditionals
"-gnaty-s"); -- relax fwd decl
( "-gnatwe" -- Warnings as errors
,"-gnaty3" -- Specify indentation level of 3
,"-gnatya" -- Check attribute casing
,"-gnatyA" -- Use of array index numbers in array attributes
,"-gnatyB" -- Check Boolean operators
,"-gnatyb" -- Blanks not allowed at statement end
,"-gnatyc" -- Check comments
,"-gnatye" -- Check end/exit labels
,"-gnatyf" -- No form feeds or vertical tabs
,"-gnatyh" -- No horizontal tabs
,"-gnatyi" -- Check if-then layout
,"-gnatyI" -- check mode IN keywords
,"-gnatyk" -- Check keyword casing
,"-gnatyl" -- Check layout
,"-gnatym" -- Check maximum line length
,"-gnatyn" -- Check casing of entities in Standard
,"-gnatyO" -- Check all overriding subprograms explicitly marked
,"-gnatyp" -- Check pragma casing
,"-gnatyr" -- Check identifier references casing
,"-gnatyS" -- Check no statements after THEN/ELSE
,"-gnatyt" -- Check token spacing
,"-gnatyu" -- Check unnecessary blank lines
,"-gnatyx" -- Check extra parentheses
);
when "disabled" => Style_Check_Switches := ();
end case;

Expand Down
6 changes: 4 additions & 2 deletions src/alire/alire-conditional.adb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ package body Alire.Conditional is
return Result : Boolean := True do
for Child of T loop
case T.Conjunction is
when Anded => Result := Result and Eval_Children (Child);
when Ored => Result := Result or Eval_Children (Child);
when Anded =>
Result := Result and then Eval_Children (Child);
when Ored =>
Result := Result or else Eval_Children (Child);
end case;
end loop;
end return;
Expand Down
4 changes: 2 additions & 2 deletions src/alire/alire-config.ads
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ package Alire.Config is
Public : Boolean := True;
Check : CLIC.Config.Check_Import := null)
return Builtin_Option
with Pre => Help /= "" or not Public;
with Pre => Help /= "" or else not Public;

function New_Builtin (Key : CLIC.Config.Config_Key;
Def : Boolean;
Help : String := "";
Public : Boolean := True;
Check : CLIC.Config.Check_Import := null)
return Builtin_Option
with Pre => Help /= "" or not Public;
with Pre => Help /= "" or else not Public;

private

Expand Down
4 changes: 2 additions & 2 deletions src/alire/alire-errors.adb
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ package body Alire.Errors is
if Line /= "" then
Trace.Error
((if I > Lines.First_Index then " " else "")
-- Indentation
-- Indentation

& (if I < Lines.Last_Index and Line (Line'Last) = '.'
& (if I < Lines.Last_Index and then Line (Line'Last) = '.'
then Line (Line'First .. Line'Last - 1)
else Line)
-- The error proper, trimming unwanted final '.'
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-index_on_disk-git.ads
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package Alire.Index_On_Disk.Git is
function New_Handler (Origin : URL;
Name : Restricted_Name;
Parent : Any_Path) return Index with
Pre => AAA.Strings.Has_Prefix (Origin, "git+") or
Pre => AAA.Strings.Has_Prefix (Origin, "git+") or else
AAA.Strings.Has_Prefix (Origin, "git@");

overriding
Expand Down
5 changes: 2 additions & 3 deletions src/alire/alire-index_on_disk.adb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ package body Alire.Index_On_Disk is
return Outcome_Success;
exception
when E : others =>
return Outcome_From_Exception
(E, "Could not delete index directory: " & This.Metadata_Directory);
return Outcome_From_Exception (E, "Could not delete index directory");
end Delete;

----------
Expand Down Expand Up @@ -219,7 +218,7 @@ package body Alire.Index_On_Disk is
(Origin (Origin'First + File_Prefix'Length .. Origin'Last));
elsif Origin (Origin'First) = '/'
or else not (AAA.Strings.Contains (Origin, "@")
or AAA.Strings.Contains (Origin, "+"))
or else AAA.Strings.Contains (Origin, "+"))
then
return Process_Local_Index (Origin);
end if;
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-index_on_disk.ads
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ package Alire.Index_On_Disk is
Result : out Outcome;
Priority : Priorities := Default_Priority)
return Index'Class
with Post => Name in Restricted_Name or not Result.Success;
with Post => Name in Restricted_Name or else not Result.Success;
pragma Warnings (On);
-- Factory function.
-- Name is a user given name used to denote the index (like a git origin).
Expand Down
11 changes: 6 additions & 5 deletions src/alire/alire-publish.adb
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ package body Alire.Publish is
-- Safeguard to avoid tests creating a live pull request, unless
-- explicitly desired
if OS_Lib.Getenv (Environment.Testsuite, "unset") /= "unset"
and then OS_Lib.Getenv (Environment.Testsuite_Allow, "unset") = "unset"
and then
OS_Lib.Getenv (Environment.Testsuite_Allow, "unset") = "unset"
then
raise Program_Error
with "Attempting to go online to create a PR during tests";
Expand Down Expand Up @@ -631,9 +632,9 @@ package body Alire.Publish is
Git : constant VCSs.Git.VCS := VCSs.Git.Handler;
Is_Repo : constant Boolean := Git.Is_Repository (Base_Path (Context));
Archive : constant Relative_Path := Target_Dir / (Milestone & ".tgz");
-- We used to use tbz2 for locally tar'ed files, but that has an implicit
-- dependency on bzip2 that we are not managing yet, so for now we err on
-- the safe side of built-in tar gzip capabilities.
-- We used to use tbz2 for locally tar'ed files, but that has an
-- implicit dependency on bzip2 that we are not managing yet, so for
-- now we err on the safe side of built-in tar gzip capabilities.

-----------------
-- Git_Archive --
Expand Down Expand Up @@ -1111,7 +1112,7 @@ package body Alire.Publish is
-- already. No matter what, it will be checked again on the
-- deployed sources step.

if Revision = "" or Revision = "HEAD" then
if Revision = "" or else Revision = "HEAD" then
declare
Tmp_Context : Data := (Options => Options, others => <>);
begin
Expand Down
6 changes: 3 additions & 3 deletions src/alire/alire-roots.adb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ package body Alire.Roots is

function Stop_Build (Wanted, Actual : Builds.Stop_Points) return Boolean
is
use type Builds.Stop_Points;
use type Builds.Stop_Points;
begin
if Wanted <= Actual then
Trace.Debug ("Stopping build as requested at stage: " & Wanted'Image);
Expand Down Expand Up @@ -269,7 +269,7 @@ package body Alire.Roots is
begin
This.Build_Prepare (Saved_Profiles => Saved_Profiles,
Force_Regen => False,
Stop_After => stop_after);
Stop_After => Stop_After);

if Stop_Build (Stop_After, Actual => Generation) then
return True;
Expand Down Expand Up @@ -443,7 +443,7 @@ package body Alire.Roots is
Prefix => Prefix,
Recursive => False,
Quiet => True,
Force => (Force or
Force => (Force or else
Action in Reinstall | Replace));

-- Say something if after installing a crate it
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-solutions-diffs.adb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ package body Alire.Solutions.Diffs is
if Has_Latter and then Latter.Is_Provided
and then
(not Has_Former or else
(Former.Has_Release and Then
(Former.Has_Release and then
Former.Release.Name_Str /= Latter.Release.Name_Str))
then
Add_Change (Chg, "", TTY.Italic (Latter.Release.Name.As_String));
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-solutions.ads
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ package Alire.Solutions is
-- exact versions. NOTE that the original dependency is thus lost in this
-- info.

function Pins (This : Solution) return dependency_Map;
function Pins (This : Solution) return Dependency_Map;
-- return all version-pinned dependencies as plain dependencies for a exact
-- version. NOTE that the original dependency is thus lost.

Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-solver.adb
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ package body Alire.Solver is
and then
not Unavailable_Direct_Deps.Contains
(Solution.Dependency (Crate))
-- Because no release fulfills it, so "complete"
-- Because no release fulfills it, so "complete"
then
return False;
end if;
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-toml_adapters.ads
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ package Alire.TOML_Adapters with Preelaborate is
function "+" (Vect : AAA.Strings.Vector) return TOML.TOML_Value;

function To_Array (V : TOML.TOML_Value) return TOML.TOML_Value with
Pre => V.Kind in TOML.Atom_Value_Kind or V.Kind = TOML.TOML_Array,
Pre => V.Kind in TOML.Atom_Value_Kind or else V.Kind = TOML.TOML_Array,
Post => To_Array'Result.Kind = TOML.TOML_Array;
-- Take an atom value and return an array of a single element
-- If already an array, do nothing
Expand Down
4 changes: 2 additions & 2 deletions src/alire/alire-utils-regex.adb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package body Alire.Utils.Regex is

function Escape (Literal : String) return String is
Targets : constant String := "\()[].*+?^";
Result : Ustring;
use Ustrings;
Result : UString;
use UStrings;
begin
for Char of Literal loop
if (for some Nono of Targets => Char = Nono) then
Expand Down
3 changes: 2 additions & 1 deletion src/alire/alire-utils-tools.adb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ package body Alire.Utils.Tools is
when Easy_Graph =>
(if Distribution in Centos | Fedora | Rhel | Suse
then "perl-Graph-Easy"
elsif Distribution /= Msys2 and Distribution /= Arch
elsif Distribution /= Msys2 and then
Distribution /= Arch
then "libgraph-easy-perl"
else ""),
when Git | Tar | Unzip | Curl =>
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-vcss.adb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ package body Alire.VCSs is
----------

function Kind (Origin : URL) return Kinds is
(if Has_Prefix (Origin, "git+") or Has_Prefix (Origin, "git@")
(if Has_Prefix (Origin, "git+") or else Has_Prefix (Origin, "git@")
then VCS_Git
else VCS_Unknown);

Expand Down
4 changes: 2 additions & 2 deletions src/alr/alr-commands-edit.adb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ package body Alr.Commands.Edit is
Put_Info ("The editor command has been unset.");
end if;

Put_Info ("You can change this setting by running the following command:");
Put_Info ("You can change editors by running the following command:");
Put_Info ("`alr edit " & Switch_Select & "`");
end Set_Config_Cmd;

Expand Down Expand Up @@ -62,7 +62,7 @@ package body Alr.Commands.Edit is

procedure Query_Editor is
use AAA.Strings;
use Clic.User_Input;
use CLIC.User_Input;

package Builtins renames Alire.Config.Builtins;

Expand Down
2 changes: 1 addition & 1 deletion src/alr/alr-commands-edit.ads
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ private

type Command is new Commands.Command with record
Prj : aliased GNAT.Strings.String_Access;
Set : aliased Boolean; --select-editor
Set : aliased Boolean; -- --select-editor
end record;
end Alr.Commands.Edit;
4 changes: 2 additions & 2 deletions src/alr/alr-commands-get.adb
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@ package body Alr.Commands.Get is
Allowed : constant Alire.Dependencies.Dependency :=
Alire.Dependencies.From_String (Args (1));
begin
if Cmd.Build and Cmd.Only then
if Cmd.Build and then Cmd.Only then
Reportaise_Wrong_Arguments
("--only is incompatible with --build");
end if;

if Cmd.Dirname and (Cmd.Build or else Cmd.Only) then
if Cmd.Dirname and then (Cmd.Build or else Cmd.Only) then
Reportaise_Wrong_Arguments
("--dirname is incompatible with other switches");
end if;
Expand Down
2 changes: 1 addition & 1 deletion src/alr/alr-commands-printenv.adb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ package body Alr.Commands.Printenv is
& "because running " & TTY.Terminal ("alr printenv") & " after "
& "manifest editions may trigger an automatic synchronization that "
& "could produce extra output not intended as environment variables.")
.New_line
.New_Line
.Append ("Examples:")
.Append (" - eval $(alr -n -q printenv --unix)")
.Append (" - alr -n -q printenv --powershell | Invoke-Expression")
Expand Down
6 changes: 3 additions & 3 deletions src/alr/alr-commands-show.adb
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ package body Alr.Commands.Show is
end if;

if Args.Count = 0 then
if Alire.Root.Current.Outside and not Cmd.Nested then
if Alire.Root.Current.Outside and then not Cmd.Nested then
Reportaise_Wrong_Arguments
("Cannot proceed without a crate name");
elsif not Cmd.Nested then
Expand All @@ -450,8 +450,8 @@ package body Alr.Commands.Show is

if Cmd.External and then
(Cmd.Dependents.all /= "unset"
or Cmd.Detect or Cmd.Jekyll or Cmd.Graph or Cmd.Solve
or Cmd.Tree)
or else Cmd.Detect or else Cmd.Jekyll or else Cmd.Graph
or else Cmd.Solve or else Cmd.Tree)
then
Reportaise_Wrong_Arguments
("Switch --external can only be combined with --system");
Expand Down
4 changes: 2 additions & 2 deletions src/alr/alr-commands-toolchain.adb
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,12 @@ package body Alr.Commands.Toolchain is
("The provided switches cannot be used simultaneously");
end if;

if (Cmd.Install or Cmd.Uninstall) and then Args.Is_Empty then
if (Cmd.Install or else Cmd.Uninstall) and then Args.Is_Empty then
Reportaise_Wrong_Arguments ("No release specified");
end if;

if not Args.Is_Empty and then
not (Cmd.Install or Cmd.Uninstall or Cmd.S_Select)
not (Cmd.Install or else Cmd.Uninstall or else Cmd.S_Select)
then
Reportaise_Wrong_Arguments
("Specify the action to perform with the crate");
Expand Down

0 comments on commit d6c2572

Please sign in to comment.