Formatting seems to use non-standard Prettier options by default
I'm seeing an issue where the formatting doesn't follow the standard Prettier rules, in this instance regarding line length.
I have an enum that looks something like this, as part of a larger schema:
"state": {
"type": "string",
"enum": [
"processing",
"success",
"error",
"cancelled",
"failure",
"skipped"
]
},
Everything builds fine, but the output is changed when we run Prettier. This is mildly annoying, because it means when you generate the types, they aren't correct-by-default.
The output here is something like:
state: 'processing' | 'success' | 'error' | 'cancelled' | 'failure' | 'skipped';
In context, that goes over 80 characters (as its indented as part of the object), but isn't wrapped by json-schema-to-typescript. It does get wrapped when using Prettier from the CLI.
The call site for json-schema-to-typescript looks like:
const style = await loadJSON(
path.join(__dirname, '..', '.prettierrc.json'),
);
const typedef = await compile(schema, typeFileName, {
bannerComment,
style,
cwd: schemaDir,
enableConstEnums: false,
});
Where loadJSON is some trivial utility to read a file and parse it. I edited our prettier config to have printWidth: 80, and that fixed the issue, causing the output to be formatted correctly.
This makes me think that something else is setting the default Prettier width, as it appears that when manually overriding it from the callsite, it went back to 80 as expected.
My suspicion is, because you are publishing your prettierrc as part of the package (https://unpkg.com/browse/[email protected]/) those options are getting picked up as the default.
Hey @bcherny, any thoughts on this?
Contributions welcome! I’d suggest starting with a good repro case.
The Prettier default options can be used by providing --style '{ bracketSpacing: true, printWidth: 80, trailingComma: "es5" }' on the command line. It would indeed be nice if these were the default in this package as well 👍