lint: Check for missing trailing newline #32477

pull maflcko wants to merge 2 commits into bitcoin:master from maflcko:2505-lint-newline changing 4 files +57 −12
  1. maflcko commented at 10:07 am on May 13, 2025: member

    A missing trailing newline is harmless, but a bit problematic:

    • git shows a warning by default
    • After another line is appended, the diff will be verbose and git blame will be wrong for the “untouched” line.

    Fix the problems by just requiring what is already the default, see also https://github.com/bitcoin/bitcoin/blob/663a9cabf811e2fc53102bc6da00d09fc99d1d81/.editorconfig#L9 and https://github.com/bitcoin/bitcoin/blob/663a9cabf811e2fc53102bc6da00d09fc99d1d81/test/lint/test_runner/src/main.rs#L327

  2. DrahtBot commented at 10:07 am on May 13, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32477.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK l0rinc, fanquake
    Concept ACK laanwj, fjahr

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #32551 (cmake: Remove ENABLE_{SSE41,AVX2,X86_SHANI,ARM_SHANI} from bitcoin-build-config.h by hebasto)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. DrahtBot added the label Tests on May 13, 2025
  4. maflcko commented at 10:33 am on May 13, 2025: member
    This should also catch issues where existing newlines are removed (and make the diff even more verbose): #32404 (review) (cc @l0rinc)
  5. in test/lint/test_runner/src/main.rs:526 in fadec07aec outdated
    521@@ -512,6 +522,44 @@ sourced files to the exclude list.
    522     }
    523 }
    524 
    525+fn lint_trailing_newline() -> LintResult {
    526+    let files = check_output(
    527+        git()
    528+            .args([
    529+                "ls-files", "--", "*.py", "*.cpp", "*.h", "*.md", "*.rs", "*.sh", "*.cmake",
    


    l0rinc commented at 11:25 am on May 13, 2025:

    Should we add any other ones here?

     0$ find . -type f -exec grep -Il . {} + | rev | cut -d. -f1 | rev | sort | uniq -c | sort -nr
     11266 json
     2 721 cpp
     3 704 h
     4 461 d
     5 344 py
     6 275 cmake
     7 228 md
     8 162 ts
     9 145 make
    10  89 cc
    11  73 txt
    12  49 sh
    13  43 mk
    14  32 patch
    15  32 hex
    16  28 c
    17  27 in
    18  26 internal
    19  20 svg
    20  19 ui
    21  16 yml
    22  14 sample
    23  14 gitignore
    24  13 marks
    25  11 m4
    26  10 capnp
    27   9 sage
    28   8 xml
    29   8 1
    30   6 rc
    31   6 ninja
    32   6 include
    33   6 fish
    34   6 bash
    35   5 xpm
    36   4 yaml
    37   4 log
    38   4 ini
    39   4 check_cache
    40   4 bt
    41   3 x
    42   3 toml
    43   3 rs
    44   3 mm
    45   3 lock
    46   3 csv
    47   3 conf
    48   3 clang-format
    49   3 TAG
    50   2 sub
    51   2 s
    52   2 qrc
    53   2 html
    54   2 guess
    55   2 gitattributes
    56   2 clang-tidy
    57   2 am
    58   2 ac
    59   2 Dockerfile
    60   ...
    

    stickies-v commented at 1:27 pm on May 13, 2025:
    You should only be counting files tracked by git: git ls-files | sed -n 's/.*\.//p' | sort | uniq -c | sort -rn

    maflcko commented at 1:50 pm on May 13, 2025:
    Happy to add any, if you see one and a reason to add it and no reason against adding it.

    l0rinc commented at 3:14 pm on May 13, 2025:

    Did a git clean -fxd before running it so I think it should’ve covered only the tracked files.


    Will let you decide of course which ones makes sense to include, just pointing out that we may want to extend this list.

  6. in test/lint/test_runner/src/main.rs:226 in fadec07aec outdated
    227+        list.extend([
    228+            "doc/release-notes/release-notes-*", // archived notes
    229+        ]);
    230+        list
    231+    }
    232+    .iter()
    


    l0rinc commented at 11:28 am on May 13, 2025:

    haven’t tried it, but was wondering it this would also work with chaining the iterators?

    0    get_subtrees()
    1        .into_iter()
    2        .chain(["doc/release-notes/release-notes-*"]) // archived notes
    

    maflcko commented at 1:52 pm on May 13, 2025:
    thx, done
  7. in test/lint/test_runner/src/main.rs:531 in fadec07aec outdated
    529+                "ls-files", "--", "*.py", "*.cpp", "*.h", "*.md", "*.rs", "*.sh", "*.cmake",
    530+            ])
    531+            .args(get_pathspecs_default_excludes()),
    532+    )?;
    533+    let mut missing_newline = false;
    534+    for path in files.lines() {
    


    l0rinc commented at 11:41 am on May 13, 2025:
    would it help if we used .par_iter() here instead (not sure if that would require adding a new lib or not, but seems like a naturally parallelizable task)?

    maflcko commented at 1:52 pm on May 13, 2025:
    Not sure. This will make compile time and runtime slower. I don’t see the point?

    l0rinc commented at 3:17 pm on May 13, 2025:
    I haven’t tested it, if you say it’s fast enough, I believe you
  8. l0rinc approved
  9. l0rinc commented at 11:44 am on May 13, 2025: contributor

    Concept ACK - thanks for automating yet another nit that I hate being brought up during review!

    Should we apply this to a few other file types as well - and take advantage of the naturally independent and parallelizable nature of the problem?

  10. laanwj commented at 12:55 pm on May 13, 2025: member
    Concept ACK it makes sense to be consistent on this, it’s kind of annoying if commit A adds a newline at the end, B removes it again, C adds it again etc. On the other hand i hope we can trust (especially random contributors) to know how their editors work and not have to explain it.
  11. lint: Add archived notes to default excludes
    No need to touch or lint them.
    fa2b2aa27c
  12. lint: Check for missing trailing newline fa9198af55
  13. maflcko force-pushed on May 13, 2025
  14. l0rinc commented at 3:17 pm on May 13, 2025: contributor
    utACK fa9198af55df74b0c19c9125d256ad4df83cf005
  15. DrahtBot requested review from laanwj on May 13, 2025
  16. fjahr commented at 1:09 pm on May 19, 2025: contributor

    Concept ACK

    I agree with the rationale, will test it shortly.

  17. fanquake approved
  18. fanquake commented at 8:23 am on May 20, 2025: member
    ACK fa9198af55df74b0c19c9125d256ad4df83cf005
  19. DrahtBot requested review from fjahr on May 20, 2025
  20. fanquake merged this on May 20, 2025
  21. fanquake closed this on May 20, 2025

  22. maflcko deleted the branch on May 20, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-05-25 21:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me