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

Allow formatting ranges of JSON #2298

Merged
merged 9 commits into from
Jun 27, 2017
Merged

Conversation

josephfrazier
Copy link
Collaborator

This fixes #2297

index.js Outdated
@@ -195,6 +202,12 @@ function isSourceElement(node) {
case "TypeAliasDeclaration": // Typescript
case "ExportAssignment": // Typescript
case "ExportDeclaration": // Typescript
case "ObjectExpression": // JSON
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you only do that when you're in a json context? Otherwise it's going to format weird things inside of js.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to have each parser with its own list IMOH

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, fixed in 2963104

We can fix the other parsers separately.

This is so that the AST_COMPARE=1 tests don't try to parse JSON with Flow.
Otherwise JSON formatting would format weird things inside of JS.
See prettier#2298 (comment)
index.js Outdated
@@ -235,12 +236,12 @@ function calculateRange(text, opts, ast) {
const startNodeAndParents = findNodeAtOffset(
ast,
startNonWhitespace,
isSourceElement
isSourceElement.bind(null, opts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use arrow functions, I find them easier to understand

node => isSourceElement(opts, node)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, fixed in e06dc79

index.js Outdated
case "NumericLiteral": // JSON
case "BooleanLiteral": // JSON
case "NullLiteral": // JSON
return opts.parser === "json";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those all the possible node types? Should we just return true if using the json parser?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there's also ObjectProperty and json-identifier. I guess the identifier is technically formattable, so maybe it should be included too.

EDIT: Fixed in 12324ef

@vjeux vjeux merged commit b47c0b4 into prettier:master Jun 27, 2017
@josephfrazier josephfrazier deleted the range-json branch June 27, 2017 23:06
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 19, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Range and json parser throws.
3 participants