Skip to content
This repository was archived by the owner on Oct 1, 2019. It is now read-only.

Upgrade Prettier version, fix comment discovery #25

Merged
merged 2 commits into from
Feb 21, 2018

Conversation

FuegoFro
Copy link
Collaborator

Bump the dependency on the main Prettier repo to the latest commit. This allows us to specify additional options (such as pythonVersion). Note that the Python version defaults to Python3, which I believe matches the behavior from before.

The plugin API in the newer version requires plugins to provide a locStart and locEnd function. From what I've seen, this is to allow customization, which is something we want and will help with things like better comment rendering. However, I'm not totally sure what customizations we want/need in these functions, so for now this just copies in the old versions of those functions. This shouldn't actually be a functional change from before the upgrade, and still allows us to modify/customize that functionality in the future as needed.

I also noticed a bug in how comments are detected within Python. There was a check that hard-coded the COMMENT token type as 57, but it's actually different in different versions of Python. This fixes that check to use the proper value for the given version of Python and updates a test that mistakenly did not have comments in the expected output.

@taion
Copy link
Contributor

taion commented Feb 13, 2018

@FuegoFro See also #15 which deals with a lot of those issues and adds checks that things are consistent between Python 2 and 3.

@FuegoFro
Copy link
Collaborator Author

Oh nice! I like a lot of the Python stuff done in that diff! It seems like the overlap with this (using the tokenizer.COMMENT constant and modifying the pythonVersions) are small enough that these two can be considered mostly independent? Specifically the tokenizer.COMMENT change is just one line, and the options object I added can be removed or modified and necessary once your more complete Python2/3 handling lands. Given that it seems that we wouldn't necessarily need to block this PR on that one. Does that seem like a reasonable/accurate description?

@taion
Copy link
Contributor

taion commented Feb 14, 2018

Yeah, that sounds totally reasonable. I haven't had much time to think about much of this – just wanted to point you at another attempt to handle some of the same issues.

@FuegoFro
Copy link
Collaborator Author

Looks like CI might have had a flake. Closing and re-opening to try to force Travis to rebuild. (Is there a better way to do that?)

@FuegoFro FuegoFro closed this Feb 14, 2018
@FuegoFro FuegoFro reopened this Feb 14, 2018
@@ -1,5 +1,6 @@
"use strict";

const utilShared = require("prettier").util;
const util = require("./_util-from-prettier");
Copy link
Member

Choose a reason for hiding this comment

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

Can we delete this file now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yeah, good call! It's gone!

src/index.js Outdated
@@ -47,7 +133,6 @@ function clean(ast, newObj) {
const printers = {
python: {
print,
hasPrettierIgnore: util.hasIgnoreComment,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that this wasn't actually being passed in, as far as I can tell (the value was undefined, even on master).

@patrick91
Copy link
Member

@FuegoFro what's the state of this?

Danny Weinberg added 2 commits February 20, 2018 18:49
Bump the dependency on the main Prettier repo to the latest commit. This allows us to specify additional options (such as `pythonVersion`). Note that the version is defaulting to Python3, which I believe matches the behavior from before.

The plugin API in the newer version requires plugins to provide a `locStart` and `locEnd` function. From what I've seen, this is to allow customization, which is something we want and will help with things like better comment rendering. However, I'm not totally sure what customizations we want/need in these functions, so for now this just copies in the old versions of those functions. This shouldn't actually be a functional change from before the upgrade, and still allows us to modify/customize that functionality in the future as needed.

I also noticed a bug in how comments are detected within Python. There was a check that hard-coded the `COMMENT` token type as `57`, but it's actually different on different versions of Python. This fixes that check to use the proper value for the given version of Python and updates a test that mistakenly did not have comments in the expected output.
@FuegoFro
Copy link
Collaborator Author

Just rebased and fixed up conflicts and failing tests!

@patrick91 patrick91 merged commit 88a6dd1 into prettier:master Feb 21, 2018
@FuegoFro FuegoFro deleted the upgrade_prettier branch March 2, 2018 19:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants