ale icon indicating copy to clipboard operation
ale copied to clipboard

Disable linting for select files

Open mark-westerhof opened this issue 9 years ago • 18 comments

I currently have some files that i don't want to lint within a project due to how massive they are. Is it possible to have linting disabled for filepaths that match a regex?

mark-westerhof avatar Feb 28 '17 23:02 mark-westerhof

There isn't a feature for that currently. For most tools, I recommend configuring whatever configuration files to exclude certain files if possible. Not many tools support that kind of behaviour.

I wonder if perhaps a feature should be added for excluding files above a set file size from being checked, maybe files with lines that are so long.

A filename regex option might make sense. You could include matches like '.*\.min\.js' and so on.

w0rp avatar Mar 01 '17 23:03 w0rp

Unfortunately the tool doesn't support that behaviour in my example.

The filename regex solution is ideal. I used to rely on that behaviour in syntastic before switching over to ale, for example, in my ~/.vimrc:

let g:syntastic_ignore_files = ['.*\.json', '.*some/folder/.*\.js']

mark-westerhof avatar Mar 03 '17 19:03 mark-westerhof

If someone else wants to implement this, go for it. I recommend doing it in the function which queues a lint cycle. If no one else implements this, I will implement it eventually.

w0rp avatar Mar 03 '17 20:03 w0rp

You can achieve this with a simple autocommand:

autocmd BufEnter *.min.js ALEDisable

But that isn't ideal since:

  1. You will have to enable ALE again with a BufLeave autocommand.
  2. You may want to disable a specific linter, not all linters.

I think buffer-local variables could be a better solution.

adriaanzon avatar Apr 14 '17 00:04 adriaanzon

I'll implement an ignore list like above, eventually, if nobody else creates a pull request for it first.

w0rp avatar Apr 15 '17 10:04 w0rp

I have now accomplished this through slightly different means, which will solve this problem, and some configuration issues. You can now use let b:ale_enabled = 0 to disable ALE for a particular buffer. This will be respected by the cursor echoing function and the function for running linters. For configuring files based on patterns, I have created g:ale_pattern_options, for automatically setting buffer variables based on filename patterns. See :help g:ale_pattern_options

These options should make it possible to not only disable ALE for particular files, but also to set different linter options for different files, etc.

w0rp avatar May 26 '17 15:05 w0rp

@mark-westerhof You should now be able to disable linting for files like so.

let g:ale_pattern_options = {
\   '.*\.json$': {'ale_enabled': 0},
\   '.*some/folder/.*\.js$': {'ale_enabled': 0},
\}

w0rp avatar May 26 '17 15:05 w0rp

Works great. Thanks alot!

mark-westerhof avatar May 26 '17 17:05 mark-westerhof

@w0rp I really appreciate the presence of this feature. I often have many buffers open in a vim but one of them is a poorly written javascript file that i have to maintain without having prioritized the refactoring that it sorely needs. The 410 warnings and 75 errors cause ALE & Vim to slow to a crawl...

Once I set b:ale_enabled=0, ALE immediately stops updating signs, but the presence of the signs themselves still slow Vim down, not to mention that this is still also an assault upon the senses. I have to run sign unplace * and save the file to bring the signify and other signs back.

I'm just after having a single button i can press to toggle the activity of ALE and to clear signs if it's getting switched off.

What make that wonderfully simple would be if I can run sign unplace ALE* but this does not work!

Edit: I've also noticed an additional issue which is that once ALE's been disabled, the line column background highlight indicators are staying put. That's actually a bigger problem than having to flush all signs to clear them out. I don't know how to clear these out.

For the time being, I really have to manually specify for this file to disable ALE from the get-go.

unphased avatar Jul 27 '17 21:07 unphased

If you set ale_enabled to 0 with g:ale_pattern_options, linting will be disabled before any linting is done.

w0rp avatar Jul 28 '17 20:07 w0rp

See :help ALEDisable for disabling ALE and removing all of the errors and everything else.

w0rp avatar Jul 28 '17 20:07 w0rp

If someone wants to take the time to do it, they could write different commands which enable, disable, or toggle ALE just for one specific buffer.

w0rp avatar Jul 28 '17 20:07 w0rp

@w0rp Yes! So I think we may have some components we can use to fix things. e.g. let b:ale_enabled=0 followed by ALEDisable and ALEEnable

unphased avatar Aug 01 '17 20:08 unphased

I'm now tracking that enhancement here: #817.

w0rp avatar Aug 01 '17 21:08 w0rp

Thanks for this. Ale was automatically folding my folds within my vimrc file, when editing, until I added let b:ale_enabled = 0.

olimorris avatar Oct 24 '17 07:10 olimorris

This works for me, but not only this disables linting in the file with the matching name, but also in the current file where I included the excluded files. Is there a way around it? Screen Shot 2022-07-03 at 10 06 51 Screen Shot 2022-07-03 at 10 06 59 Screen Shot 2022-07-03 at 10 07 08

bezlant avatar Jul 03 '22 07:07 bezlant

UPD: I have found out another issue that if I create a compile_commands.json with bear -- make command ALE doesn't lint until I remove the #include "imgui/imgui.h". I'm confused. Here is my compile_commands.json below. Screen Shot 2022-07-03 at 11 19 14

bezlant avatar Jul 03 '22 08:07 bezlant

very helpful, thanks for implementing this!

jm3 avatar Mar 06 '25 03:03 jm3