Comments (4)
Neovim has various methods of reading files which you can use to read package.json
and determine if the Prettier config key exists. Off the top of my head, you can use vim.fn.readfile()
+ vim.fn.json_decode()
or luv
+ vim.json.decode()
.
I wouldn't be opposed to a PR adding another helper to the utils
object to facilitate this process, but I don't think I'd want to do anything beyond that as a default.
from null-ls.nvim.
I see. My initial thought is that it might have been a capability of most sources (I have no idea).
from null-ls.nvim.
As for a PR, I can try it. Just need to improve a bit my lua setup first
from null-ls.nvim.
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
from null-ls.nvim.
Related Issues (20)
- Support fbinfer static analysis tool
- Support for pmd/cpd static analysis tool HOT 2
- Support for NASA's Ikos static analyzer
- Add support for typst HOT 2
- Support for PMD 7.x HOT 2
- latex: chktex and proselint cause delay in `gq` formatting HOT 2
- null-ls trying to use user folder as command name on windows HOT 1
- It is very inconvenient that I cannot see the documentation with the help command HOT 1
- Feature request: Only show diagnostics on modified lines HOT 2
- [eslint] failed to decode json: Expected value but found invalid token at character 2() HOT 3
- Code Actions not working (tested on gitsigns) HOT 3
- PrismaFmt built-in replaces the content of schema.prisma file
- Full restart of null-ls HOT 4
- goimports-reviser with `-rm-unused` removes the module that not in go.mod
- Mypy fails when buffer is not yet saved
- IMPORTANT: Archiving null-ls HOT 110
- Null-ls is not registering any sources HOT 1
- When registering a source, condition should recursively from current file dir to root
- UTF-8 characters break diagnostics' underline position
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from null-ls.nvim.