Repository navigation
Description
Describe the bug
Investigating #9798, I wanted to find the number of single line project files. In doing this I found some were reported as having 0 lines.
On review, @geekosaur is catching the mistake I'm often making of dropping or forgetting these newlines.
Therefore, “lines” not ending in a newline character aren't considered actual lines. That's why some programs have problems processing the last line of a file if it isn't newline terminated.
The advantage of following this convention is that all POSIX tools expect and use it.
SOURCE: Why should text files end with a newline?
I have a script to add newlines when missing and can use it to fix up some files that don't conform, for instance *.hs and *.project files. I didn't find any non-conforming *.cabal files. There are only two legitimate zero line (empty) projects;
./cabal-install/tests/fixtures/project-root/cabal.project./cabal-install/tests/fixtures/project-root/nix/cabal.project
To Reproduce
$ find -name '*.project' -exec wc -l {} \; | sort -k 1
0 ./cabal-install/tests/fixtures/project-root/cabal.project
0 ./cabal-install/tests/fixtures/project-root/nix/cabal.project
0 ./cabal-testsuite/PackageTests/ExtraProgPath/cabal.project
0 ./cabal-testsuite/PackageTests/HaddockArgs/cabal.project
0 ./cabal-testsuite/PackageTests/HaddockWarn/cabal.project
0 ./cabal-testsuite/PackageTests/NewBuild/CmdRun/Script/cabal.project
0 ./cabal-testsuite/PackageTests/NewBuild/CmdRun/ScriptLiterate/cabal.project
0 ./cabal-testsuite/PackageTests/NewHaddock/Fails/cabal.project
0 ./cabal-testsuite/PackageTests/NewSdist/DeterministicTrivial/cabal.project
0 ./cabal-testsuite/PackageTests/PkgConfigParse/cabal.project
0 ./cabal-testsuite/PackageTests/Regression/T5782Diamond/cabal.project
0 ./cabal-testsuite/PackageTests/SDist/Respect-Project-File/cabal.project
0 ./cabal-testsuite/PackageTests/SDist/T5195and5349/cabal.project
0 ./cabal-testsuite/PackageTests/WarnEarlyOverwrite/cabal.project
...
$ cat ./cabal-testsuite/PackageTests/WarnEarlyOverwrite/cabal.project
packages: .⏎
Expected behavior
We add the missing newlines (I have a script for this).
#!/bin/bash
# SEE: https://unix.stackexchange.com/questions/31947/how-to-add-a-newline-to-the-end-of-a-file
for f in $(git grep -Il '' -- "$1"); do
echo "$f";
tail -c1 < "$f" | read -r _ || echo >> "$f";
doneStretch goal: We stop relying on @geekosaur spotting these mistakes and add a check for this in CI.
Activity
ffaf1 commentedon Mar 13, 2024
Mhhh I thought we already did it re: automating this bit of geekosaur
cabal/fix-whitespace.yaml
Lines 1 to 6 in 74b1f21
philderbeast commentedon Mar 14, 2024
Looking at the blame for
fix-whitespace.yaml, I see it was added along with .github/workflows/whitespace.yml in #8320. That workflow no longer exists and I can't find another one that still runs this check, that runsfix-whitespace --check.philderbeast commentedon Mar 14, 2024
With
fix-whitespacewe have these violations;philderbeast commentedon Mar 14, 2024
The configuration doesn't include
cabal.projectfiles;cabal/fix-whitespace.yaml
Line 43 in aaf16c4
philderbeast commentedon Mar 14, 2024
I find our naming for project files odd in that it doesn't have a consistent file extension,
.project. Elsewhere I've usedcabal.something.projectrather than what we use here,cabal.project.something.philderbeast commentedon Mar 14, 2024
@Kleidukos was there some bad interaction between
fourmoluandfix-whitespace? The former doesn't cover all the file types of the later so perhaps we could revive some offix-whitespace, deleted in 827ee18.ulysses4ever commentedon Mar 14, 2024
I think we should put back the action running fix-whitespace and revise the tool's config to include more files and to print explanation for violations (it's a new flag in fix-whitespace), and maybe something else.