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

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

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

    <!--021abf342d371248e50ceaed478a90ca-->

    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.

    <!--174a7506f384e20aa4161008e828411d-->

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  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?

    $ find . -type f -exec grep -Il . {} + | rev | cut -d. -f1 | rev | sort | uniq -c | sort -nr
    1266 json
     721 cpp
     704 h
     461 d
     344 py
     275 cmake
     228 md
     162 ts
     145 make
      89 cc
      73 txt
      49 sh
      43 mk
      32 patch
      32 hex
      28 c
      27 in
      26 internal
      20 svg
      19 ui
      16 yml
      14 sample
      14 gitignore
      13 marks
      11 m4
      10 capnp
       9 sage
       8 xml
       8 1
       6 rc
       6 ninja
       6 include
       6 fish
       6 bash
       5 xpm
       4 yaml
       4 log
       4 ini
       4 check_cache
       4 bt
       3 x
       3 toml
       3 rs
       3 mm
       3 lock
       3 csv
       3 conf
       3 clang-format
       3 TAG
       2 sub
       2 s
       2 qrc
       2 html
       2 guess
       2 gitattributes
       2 clang-tidy
       2 am
       2 ac
       2 Dockerfile
       ...
    

    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?

        get_subtrees()
            .into_iter()
            .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: 2026-04-24 09:13 UTC

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