prettier-plugin-sort-json icon indicating copy to clipboard operation
prettier-plugin-sort-json copied to clipboard

Add option to ignore specific files

Open ghost opened this issue 3 years ago • 8 comments

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?

ghost avatar May 23 '21 15:05 ghost

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 avatar Jul 07 '21 16:07 Gudahtt

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

Gudahtt avatar Aug 14 '22 12:08 Gudahtt

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

JoshWhite avatar Feb 20 '23 13:02 JoshWhite

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

kunsachdeva avatar Apr 21 '23 18:04 kunsachdeva

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"],
    }
  ]
}

hyperupcall avatar Sep 15 '23 16:09 hyperupcall

^ 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.

Gudahtt avatar Sep 15 '23 16:09 Gudahtt

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'

esetnik avatar Oct 05 '23 14:10 esetnik

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

hesamhoseinkhani avatar Aug 05 '24 11:08 hesamhoseinkhani