Closed Deckluhm closed 6 months ago
Thanks for the report!
It looks like the problem may be that the plugin has not been loaded. See these instructions on how to load the plugin: https://prettier.io/docs/en/plugins#using-plugins
In older versions of Prettier, plugins would be loaded automatically, but it's explicit from v3 onwards.
It looks like the problem may be that the plugin has not been loaded. See these instructions on how to load the plugin: https://prettier.io/docs/en/plugins#using-plugins
I forgot to import it for CLI but even after adding "plugins": ["prettier-plugin-sort-json"]
to .prettierrc it still doesn't work.
It is correctly imported for programmatic usage: https://github.com/Deckluhm/json-recursive-sort-bug/blob/main/index.js#L14
In that example, you're calling format
without the jsonRecursiveSort
option. This should work:
import { format } from 'prettier'
const formattedJson = await format(
JSON.stringify({
hello: 'world',
nested: {
b: 'Sunt duis ipsum labore tempor exercitation non.',
a: 'Officia sit esse nulla aute esse excepteur ad.',
c: 'Consectetur fugiat ea esse Lorem velit.'
},
another: 'one'
}), {
parser: 'json',
plugins: ['prettier-plugin-sort-json'],
jsonRecursiveSort: true,
}
)
console.log(formattedJson)
When calling format
, it doesn't seem to read from the configuration. You need to specify options manually.
In the repository you shared, the format
npm script does work correctly, but there is no --check
or --write
flag passed in. You need to pass in --check
to get it to fail for unsorted files, or --write
to get it to sort the files for you.
I'll close this for now, as it does seem to work when I've tested it. Let me know if you are still having trouble with this
Thanks for looking into it and sorry!
I was expecting .prettierrc to work with programmatic usage but it doesn't seem to be the case :shrug:
No problem at all! I appreciate the clear reproduction, really helpful report, even if it didn't find a bug
Hello 👋
I'm trying to use this plugin with Prettier 3 and I can't make
jsonRecursiveSort
option work.I'm trying to use it in a programmatic way but I also tried with the CLI and I got the following error:
Here is a minimal reproduction using:
3.2.5
3.1.0
https://github.com/Deckluhm/json-recursive-sort-bug
Thank you!