Code Monkey home page Code Monkey logo

Comments (4)

jose-elias-alvarez avatar jose-elias-alvarez commented on June 13, 2024

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.

ndavd avatar ndavd commented on June 13, 2024

I see. My initial thought is that it might have been a capability of most sources (I have no idea).

from null-ls.nvim.

ndavd avatar ndavd commented on June 13, 2024

As for a PR, I can try it. Just need to improve a bit my lua setup first

from null-ls.nvim.

ndavd avatar ndavd commented on June 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.