this post was submitted on 09 Nov 2023
4 points (100.0% liked)

Emacs

305 readers
1 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

It's a feature that I miss from Clion, my current workflow is by using a 3rd party linter after my coding session outside of Emacs. I know that I can use the linter with an after-save-hook, but is there any other solutions with flycheck or lsp integrations? (I tried flycheck-clang-tidy but I didn't get any warrings or indicators, not sure if clang-tidy can detect them though)

top 5 comments
sorted by: hot top controversial new old
[–] thblt@alien.top 2 points 10 months ago

clangd and probably other linters can warn about this. False positives are possible, though: an include may very well be unused in a given build configuration, but enabled in another.

[–] lmarcantonio@alien.top 1 points 10 months ago (1 children)

Never heard of such thing. I don't think that could be done correctly either. How do you detect is an include is used? Looking if it defines something? what about a conditional that can exclude the whole file unless a define is set?

[–] john_bergmann@alien.top 1 points 10 months ago

usually the compiler can help here, as it knows what was needed in the code and where the definition came from, including macros. Not sure there is an open-source tol for that though, if clang-tidy does not do it.

as it was said elsewhere, when there are several configurations at play, one needs to be careful.

[–] filippoargiolas@alien.top 1 points 10 months ago

Eglot does this out of the box with clangd. Also no need for extra packages for clang-tidy, it's integrated with within clangd so you get both linter warnings and build errors in the flymake window.

You may have to enable more checks as it is quiet enough by default. You may also have to enable clangd-tidy integration in clangd command line as I'm not sure it is out of the box. Something like this should work:

(with-eval-after-load 'eglot
        (add-to-list 'eglot-server-programs
            '((c-mode c++-mode c-ts-mode c++-ts-mode c-or-c++-ts-mode)
              . ("clangd"
                 "--clang-tidy"))))
[–] GeekoftheWild@alien.top 0 points 10 months ago

RemindMe! 24 hours