-
Notifications
You must be signed in to change notification settings - Fork 797
Add an option to activate source only if a configuration is found in the project #1614
Comments
Neovim has various methods of reading files which you can use to read I wouldn't be opposed to a PR adding another helper to the |
I see. My initial thought is that it might have been a capability of most sources (I have no idea). |
As for a PR, I can try it. Just need to improve a bit my lua setup first |
Modified a bit my config to achieve the desired result: local should_load_prettier = function(condition_utils)
-- Check for config files
if
condition_utils.root_has_file({
'.prettierrc',
'.prettierrc.json',
'.prettierrc.yml',
'.prettierrc.yaml',
'.prettierrc.json5',
'.prettierrc.js',
'.prettierrc.cjs',
'.prettierrc.toml',
'prettier.config.js',
'prettier.config.cjs',
})
then
return true
end
-- Check for package.json config entry
if condition_utils.root_has_file({ 'package.json' }) then
local package_json_path = utils.get_root() .. '/package.json'
local package_json = vim.json.decode(table.concat(vim.fn.readfile(package_json_path)))
return package_json['prettier'] ~= nil
end
return false
end Thanks for the help. I don't know how common this use case would be, I personally found it pretty useful. Would you consider adding it to the docs? Or accept a PR doing so |
Issues
Feature description
My current use case would be the
prettier
linter. I am usingeslint
in a project and prettier is overriding it.So I tried doing
only_local
, but prettier is actually being installed in node_modules by a dependency of my project.As a workaround I tried adding a condition:
And this works 99% of the cases. Thing is that prettier also recognizes an entry inside package.json...
So I feel like this would be a common thing to happen, maybe there should be an option to let the source decide whether it finds a configuration and activate it accordingly. Perhaps that's not possible, if that's the case then it would be nice to have a condition that allows me to check inside package.json for prettier (some util that let's us check inside files perhaps)
The text was updated successfully, but these errors were encountered: