antfu / eslint-config

Anthony's ESLint config preset
https://eslint-config.antfu.me/
MIT License
3.81k stars 426 forks source link

feat: add nvim support for `isInEditor` #507

Closed ryoppippi closed 3 months ago

ryoppippi commented 3 months ago

Description

add nvim support for isInEditor

Linked Issues

Additional context

netlify[bot] commented 3 months ago

Deploy Preview for melodious-froyo-4871f8 ready!

Name Link
Latest commit 2ce103078314f4745cec51436694116d6a2f30ed
Latest deploy log https://app.netlify.com/sites/melodious-froyo-4871f8/deploys/6670a0cf4295690008690f1b
Deploy Preview https://deploy-preview-507--melodious-froyo-4871f8.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

thenbe commented 3 months ago

There's really no harm in merging this either way, but wasn't process.env.VIM already detecting that you were in neovim? (i.e. :lua =vim.env.VIM)

Ref https://github.com/antfu/eslint-config/pull/365

ryoppippi commented 3 months ago

Oh, :=vim.env.VIM works for me! and :=vim.env.NVIM is nil.

But when I launch :terminal, and execute echo $VIM, no variable set, However, executing echo $NVIM shows the Neovim's tmp dir.

So, idk we need this PR anymore, but if you know something, please tell me what is the difference @thenbe

ryoppippi commented 3 months ago

@thenbe you can see :h $NVIM

                                                                     *$NVIM*
                $NVIM is set by |terminal| and |jobstart()|, and is thus
                a hint that the current environment is a subprocess of Nvim.
                Example: >vim
                  if $NVIM
                    echo nvim_get_chan_info(v:parent)
                  endif
<

                Note the contents of $NVIM may change in the future.

So, when running eslint with jobstart, $NVIM variable is set. idk it is good for detecting InEditor

thenbe commented 3 months ago

The main purpose of isInEditor is to prevent some rules from running on save (see here) because they could get annoying. Instead isInEditor was introduced to constrain those rules to only run when eslint is invoked through the cli (either manually by user, or pre-commit hook, etc).

I'm not familiar with the jobstart workflow myself, but if you're using jobstart and feel like those "aggressive" rules should not run during that sort of workflow then we should proceed with this PR and detect process.env.NVIM.