0

I'm using synatastic with flake8 in neovim for python development. I want to name variables in upper case occasionally but I don't want to turn the warning off completely. However I get bored of adding the comments to the end of lines to silence the flake8 warnings/errors (like the following one):

R = E_pi_sqroot.T @ A @ E_pi_sqroot  # noqa: N806

In general I would like to silence any flake8 warning in the location list with a mapping so it would not always be N806 but should be acquired from the location window line:

experimental/one_shot/rkda.py|108 col 26 warning| argument name 'X' should be lowercase [N803]
experimental/one_shot/rkda.py|119 col 10 warning| variable 'K' in function should be lowercase [N806]

Is there an easy way to create a mapping that would just add the correct noqa end of line comment if I am on the line in the code buffer or location window? I don't know where to start with this one.

2
  • So, is it always N806, or could it be different numbers? Please edit to clarify. (And if it could be other numbers, can we see some examples of where those come from?)
    – D. Ben Knoble
    Nov 4 '20 at 13:34
  • @D.BenKnoble thx for the comment. Edited.
    – Epimetheus
    Nov 4 '20 at 18:45
1

I guess one answer would be a mapping to (untested)

$yi[<CR>A # noqa: <esc>p

(I think $yi[<CR>put =' # noqa: '.@@<CR>J is equivalent.)

You would want to map this in the quickfix (loclist) buffer (using nnoremap <buffer>, probably in an ftplugin or autocommand), but I'm not sure how to do so only for the right quickfix (loclist) buffer.

Another option would be to have the mapping in python files, and then prepend :lopen<CR> or :copen<CR> to the mapping, depending on where you have the results.

3
  • Thx @d-ben-knoble! I'll give it a try.
    – Epimetheus
    Nov 5 '20 at 18:59
  • That pretty much worked out of the box. I ended up with: nnoremap <LocalLeader>f8i $yi[<CR>A # noqa: <esc>p
    – Epimetheus
    Nov 5 '20 at 20:29
  • 1
    Just a quick note for the version to be called from the python file it should be :lopen not :copen, for example: nnoremap <LocalLeader>f8i :lopen<CR>$yi[<CR>A # noqa: <esc>p
    – Epimetheus
    Nov 5 '20 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.