fprettify
fprettify copied to clipboard
Repeated warnings for long lines
Thanks for the great tool! I'm using it on a few projects, and one thing that's bugging me is the very noisy output when fprettify
encounters a long line:
<snip>
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
WARNING: File time_advance.f90, line 1979
auto indentation failed due to chars limit, line should be split (limit: 150)
<snip>
and a few more pages of this, for each long line encountered. Any ideas what's going on here?
Perhaps line #1979 of your code is, using the (adjustable) default indentation of 3 per level, a length .ge. 150 characters. The limit in the version of fprettify accessible to mine, line #1421 of init.py, is llength=132, however.
Two suggestions:
-
what if you lower the indentation to two characters each time .or. disable indentation altogether; is the warning still seen?
-
user «Steven_L_Intel1» mentions the Intel Fortran is less constraining. To quote: «Intel Fortran accepts up to 2048 characters on a single line.»[1] So perhaps this is an argument to replace the compiler, just this time?
Norwid
[1] https://community.intel.com/t5/Intel-Fortran-Compiler/Max-size-of-a-fortran-procedure-and-max-size-of-a-line-of-code/m-p/956360
Sorry, I set the fprettify option line-length
to 150, but it still appears many times with the default 132.
The code compiles fine, and I'm fine with the warning about auto indentation failing, it's just that the warning is repeated many times.
Dear Peter,
lacking a MWE by your side, I'm unable to replicate your finding. Nor that I recall such a warning when using fprettifify (so far).
I speculate it is not a problem like with the code below -- still accepted /as such/ by gfortran; however yielding the line length warning by fprettify and then no longer accepted by gfortran
program indent_problem
! Still acceptable for gfortran; but yields warning by fprettify and
! then fails compilation by gfortran.
implicit none
integer :: i
do i = 1, 20
if (mod(i, 2) == 0) then
print *, "Since i is an even number, this place holder comment is issued to generate a nonsense message to report this event here."
print *, "A line which shall pass."
end if
end do
end program indent_problem
-- which may be resolved by breaking the long line 10 with the &
into
program indent
! No problem for gfortran prior / after fprettify.
implicit none
integer :: i
do i = 1, 20
if (mod(i, 2) == 0) then
print *, "Since i is an even number, this place holder comment is issued to generate a &
& nonsense message to report this event here."
end if
end do
end program indent
because for the first example (program indent_problem), fprettify is going to state the warning only once and pass on for the next lines without a problem. Maybe your question is resolved quickly on the lively discussion board of fortran-lang.org, which is
https://fortran-lang.discourse.group/
Sorry @nbehrnd, to be clear, my issue is absolutely nothing to do with the compiler -- the code compiles fine, before and after running fprettify. It's purely about the warning fprettify prints.
This seems to be limited to deeply nested expressions that span multiple lines.
Here is an MVWE that demonstrates the issue:
program long_lines_warnings
implicit none
integer :: very_long_variable
very_long_variable = very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable * (very_long_variable &
+ very_long_variable))))))))))))
end program long_lines_warnings
Running fprettify
on this file, and no other options prints the following warnings:
WARNING: File mvwe.f90, line 18
auto indentation failed due to chars limit, line should be split (limit: 132)
WARNING: File mvwe.f90, line 18
auto indentation failed due to chars limit, line should be split (limit: 132)
WARNING: File mvwe.f90, line 18
auto indentation failed due to chars limit, line should be split (limit: 132)
WARNING: File mvwe.f90, line 18
auto indentation failed due to chars limit, line should be split (limit: 132)
WARNING: File mvwe.f90, line 18
auto indentation failed due to chars limit, line should be split (limit: 132)
WARNING: File mvwe.f90, line 18
auto indentation failed due to chars limit, line should be split (limit: 132)
WARNING: File mvwe.f90, line 18
auto indentation failed due to chars limit, line should be split (limit: 132)
WARNING: File mvwe.f90, line 18
auto indentation failed due to chars limit, line should be split (limit: 132)
WARNING: File mvwe.f90, line 18
auto indentation failed due to chars limit, line should be split (limit: 132)
I think this is a bit more understandable now, but the repeated line number in the warning is confusing.
Thanks Peter, I see the issue /much/ clearer now. Apparently,
fprettify does not recognize well enough that 14 physical lines
already «reshaped» by the &
belong to one logical line. And
consequently, leaving the nested design, the individual reports where
exactly one suffices.