Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for formatting json files when prettier is used #676

Closed
joseDaKing opened this issue Jul 31, 2022 · 4 comments
Closed

Add support for formatting json files when prettier is used #676

joseDaKing opened this issue Jul 31, 2022 · 4 comments

Comments

@joseDaKing
Copy link

joseDaKing commented Jul 31, 2022

Add support formatting json files when prettier is used (prettier option set to true). My suggestion is to add an config option formatJson which is a boolean and default value is false. If this implemented xo-vscode extension should also be updated to reflect the change. I could do all these be myself but would be nice if this library supports it

example

{
    "prettier": true,
    "formatJson": true,
    "envs": [
        "es2015",
        "node"
    ],
    "rules": {
        "import/extensions": "off",
        "n/file-extension-in-import": "off"
    }
}
@acalvino4
Copy link

acalvino4 commented Aug 25, 2022

Just came here to log the exact same issue.

To add to the original post, I think this functionality would ideally be used to format all types of files that prettier supports - sass, md, css, jsonc, etc.

I can of course still use prettier's formatting directly for these other files, but it complicated my config (and the point of xo is of course to simplify things). I need an additional extension enabled for prettier in my IDE, and need additional IDE settings:

{
  "xo.format.enable": true,
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "[javascript]": {
    "editor.defaultFormatter": "samverschueren.linter-xo"
  },
  "[javascriptreact]": {
    "editor.defaultFormatter": "samverschueren.linter-xo"
  },
  "[typescript]": {
    "editor.defaultFormatter": "samverschueren.linter-xo"
  },
  "[typescriptreact]": {
    "editor.defaultFormatter": "samverschueren.linter-xo"
  }
}

@acalvino4
Copy link

I noticed the extensions config option, described as

Allow more extensions to be linted besides .js, .jsx, .mjs, and .cjs. Make sure they're supported by ESLint or an ESLint plugin.

but when I add json, css, etc. to that list, they don't seem to be auto-fixed. I thought I'd give a try at a PR, but as far as I can tell, this should be enough. I'm probably looking at the wrong place, but if I could be pointed in the right direction, I'd be happy to put some more effort toward it.

@spence-s
Copy link
Contributor

spence-s commented Oct 6, 2022

Just a note: xo is an eslint wrapper. Prettier is not used directly, it is just a convenience option where we internally add the prettier eslint plugin to work with eslint. -- You can add eslint plugins for json and css. There is nothing stopping you from configuring this yourself anytime without any changes to the xo library.

@fregante
Copy link
Member

This seems to be possible but it requires extra plugins which don't seem to be otherwise useful in XO

Closing for now

@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants