syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.56k stars 4.9k forks source link

Passing lintr options to ESS from the configuration. #16375

Open duarteoctavio opened 2 months ago

duarteoctavio commented 2 months ago

Issue

I need to configure some ESS (emacs speaks statistics) variables. My intention is to configure the linter to accept CamelCase variable names. I'm not fluent in Elisp (I intend to ammend that, but now I need to finish some work).

What I know so far

I need to pass the value linters_with_defaults(object_name_linter = "CamelCase") to ESS's ess-r-flymake-linters option. For a similar ssue, in the ESS wiki, they seemingly set a parameter in a non declarative way, which I believe is not how you do it in .spacemacs. What they do is (setq ess-r-flymake-linters '("line_length_linter = line_length_linter(120)")).

My attempt

In .spacemacs.

dotspacemacs-configuration-layers (
  (ess :variables
      ess-r-backend 'lsp
      ess-r-flymake-linters '("object_name_linter("CamelCase")")
    )
)

Result

My CamelCase variables are still highlighted as errors, so I assume ESS is not receiving the parameters I intend to send.

fnussbaum commented 2 months ago

In many cases either way should work: Setting variables in the layer declaration, or using setq or setopt forms in dotspacemacs/user-config.

Some ideas, though I do not use ess regularly myself:

  1. Fix the the value of ess-r-flymake-linters by escaping the inner quotation marks:
    '("object_name_linter(\"CamelCase\")")
  2. If flycheck is enabled in ess-r-mode due to the syntax-checking layer, disable it: (It can also be toggled in a buffer with SPC t s.)
    (setopt flycheck-global-modes (remove 'ess-r-mode flycheck-global-modes))
duarteoctavio commented 2 months ago

I don't know if I'm interpreting 2 correctly, does it imply that I need to take care not two packages are calling for the linter at the same time? Something like a more global one ignoring my config might be taking over?

fnussbaum commented 2 months ago

In this particular case, the main problem I see is that the variable ess-r-flymake-linters only applies to flymake, and flycheck would still use some default (in my case snake_case instead of CamelCase). This means that CamelCase variables would still be highlighted as errors, even though flymake is configured correctly. One could probably also configure flycheck analogously.

However I'm not sure if it ever makes sense to have both flycheck and flymake enabled: I would assume that one of the two packages should suffice for linting a particular buffer at a time and they seem to be alternatives. The ess package will enable flymake by default, which can be configured with the variable ess-use-flymake. If the syntax-checking layer is used (which is always the case if the lsp layer is active), the ess layer will enable flycheck-mode in ess-r-mode-buffers, without disabling flymake. I am not sure whether this is an issue with the ess layer, perhaps someone else actually using it would know.

Have you already tried if the above solves your problem? It seems to work for me.