Gudahtt / prettier-plugin-sort-json

A plugin for Prettier that sorts JSON files by property name.
MIT License
103 stars 12 forks source link

Add option to ignore specific files #35

Open ghost opened 3 years ago

ghost commented 3 years ago

I'm already using prettier-plugin-package to sort my package.json file, but its custom sort would conflict with this plugin. Would it be possible to add an option to the .prettierrc configuration to ignore certain files?

Gudahtt commented 3 years ago

This will not conflict with prettier-plugin-package because it doesn't get applied to package.json. Prettier recognizes package.json as its own format, so it doesn't get included by JSON parsers such as this plugin.

Still a good suggestion though! We should update the README to clarify how this works with prettier-plugin-package, and I can still see an ignore configuration being useful sometimes.

Gudahtt commented 2 years ago

The README was updated in #96 to explain that package.json files are not sorted.

JoshWhite commented 1 year ago

I came across this, as I wanted a way to only sort my locale files. Would it be possible to add a glob matcher?

kunsachdeva commented 1 year ago

@JoshWhite were you able to find a way around this?

hyperupcall commented 1 year ago

Should this be closed because prettier supports an override format in their configuration, which can be used by any plugin?

{
  "semi": false,
  "overrides": [
    {
      "plugins": ["prettier-plugin-OTHER"],
      "files": "*.test.js",
      "excludeFiles": ["my.test.js"],
    },
    {
      "plugins": ["prettier-plugin-sort-json"],
      "files": ["my.test.js"],
    }
  ]
}
Gudahtt commented 1 year ago

^ Amazing! I'll leave this issue open until adding a brief note to the README about this, but that looks like the perfect solution to me.

esetnik commented 1 year ago

I had a similar issue with tsconfig.json files that I didn't want sorted. I used the below which worked well:

plugins:
  - prettier-plugin-organize-imports
singleQuote: true
trailingComma: es5
overrides:
  - options:
      plugins:
        - prettier-plugin-sort-json
      jsonRecursiveSort: true
    files: '*.json'
    excludeFiles:
      - '**/tsconfig.json'
hesamhoseinkhani commented 3 months ago

Should this be closed because prettier supports an override format in their configuration, which can be used by any plugin?

{
  "semi": false,
  "overrides": [
    {
      "plugins": ["prettier-plugin-OTHER"],
      "files": "*.test.js",
      "excludeFiles": ["my.test.js"],
    },
    {
      "plugins": ["prettier-plugin-sort-json"],
      "files": ["my.test.js"],
    }
  ]
}

this doesn't work