Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upstorysource: Add default parser option. Support prettier v1.13.0 #3660
Conversation
isoppp
requested a review
from
igor-dv
as a
code owner
May 28, 2018
Hypnosphi
added
bug
patch
addon: storysource
labels
May 29, 2018
This comment has been minimized.
This comment has been minimized.
Looks like it doesn't recognize typescript now:
CC @igor-dv |
Hypnosphi
reviewed
May 29, 2018
@@ -5,6 +5,7 @@ const defaultOptions = { | |||
bracketSpacing: true, | |||
trailingComma: 'es5', | |||
singleQuote: true, | |||
parser: 'babylon', |
This comment has been minimized.
This comment has been minimized.
Hypnosphi
May 29, 2018
•
Member
We actually add parser option on call site
So, when parser === 'javascript'
we should add parser: 'babylon'
instead of skipping this part
But I think a more elegant solution would be to pass filepath
option to prettier so that it could infer the correct parser from extension. You can get file path in transform function as this.resourcePath
, add it to options object, and then pass to prettier instead of parser
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
isoppp
May 30, 2018
Author
Contributor
I fixed this.
Pass this.resourcePath
to prettier config.
Thank you for telling me the information.
It was very helpful in fixing it.
isoppp
added some commits
May 30, 2018
This comment has been minimized.
This comment has been minimized.
codecov
bot
commented
May 30, 2018
•
Codecov Report
@@ Coverage Diff @@
## master #3660 +/- ##
==========================================
- Coverage 41.55% 41.54% -0.02%
==========================================
Files 458 458
Lines 5058 5062 +4
Branches 849 851 +2
==========================================
+ Hits 2102 2103 +1
- Misses 2451 2453 +2
- Partials 505 506 +1
Continue to review full report at Codecov.
|
isoppp
added some commits
May 30, 2018
This comment has been minimized.
This comment has been minimized.
I fixed one point with additional. And I did not do the test locally. I'm sorry. However, it seems that errors occur in places which are not touched by CircleCI. |
isoppp
changed the title
storysource: Add default parser option. Support prettier v0.13.0
storysource: Add default parser option. Support prettier v1.13.0
May 30, 2018
Hypnosphi
reviewed
May 30, 2018
@@ -25,7 +25,7 @@ | |||
"babel-runtime": "^6.26.0", | |||
"estraverse": "^4.2.0", | |||
"loader-utils": "^1.1.0", | |||
"prettier": "~1.12.1", | |||
"prettier": "^1.12.1", |
This comment has been minimized.
This comment has been minimized.
Hypnosphi
May 30, 2018
Member
Please update it to latest version: looks like we don't support 1.12
after change in parser imports
This comment has been minimized.
This comment has been minimized.
Hypnosphi
reviewed
May 30, 2018
if (parser) { | ||
config = { | ||
...prettierConfig, | ||
parser: parser === 'javascript' ? 'babylon' : parser, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
isoppp
May 31, 2018
Author
Contributor
I thought the same.
But in this test , if the extension is txt and the contents are something else, prettier does not support to txt file, so it gets an error.
error:
No parser could be inferred for file: (LOCAL_PATH)/addons/storysource/src/loader/__mocks__/inject-decorator.stories.txt
Should i change the test?
I think that probably this is a rare case, so I think that do not have to deal with it unless need it.
This comment has been minimized.
This comment has been minimized.
Hypnosphi
May 31, 2018
Member
After giving it a second thought, we probably should always pass parser to prettier when user specifies it explicitly, which is exactly what we do now. So let's keep it as is
This comment has been minimized.
This comment has been minimized.
Hypnosphi
May 31, 2018
•
Member
But we probably should put else if (filepath)
inside if (!config.parser)
, to cover cases when parser is not passed
This comment has been minimized.
This comment has been minimized.
Hypnosphi
May 31, 2018
Member
Or maybe we should just pass babylon
when parser
isn't set explicitly, because this is what we use by default ourselves. In this case, filepath
will be never needed
This comment has been minimized.
This comment has been minimized.
isoppp
May 31, 2018
•
Author
Contributor
Thank you for review. I tried fixing it.
And, i read Prettier code a little.
Prettier gives priority to parser over filepath.
If both are empty we gave babylon as Prettier will output errors in the future.
May 31, 2018
This was referenced
Hypnosphi
reviewed
May 31, 2018
if (parser) { | ||
config = { | ||
...prettierConfig, | ||
parser: parser === 'javascript' ? 'babylon' : parser, |
This comment has been minimized.
This comment has been minimized.
Hypnosphi
May 31, 2018
•
Member
let's put ...prettierConfig
after this line, so that it wouldn't override explicitly passed prettierConfig.parser
This is why there was !config.parser
check before
This comment has been minimized.
This comment has been minimized.
isoppp
May 31, 2018
Author
Contributor
I made a slight change to the beginning of this function.
When prettierConfig.parser
is explicitly set return
will be done at this point
if (prettierConfig.parser) return prettier.format(source, prettierConfig);
After this processing, shoud not set prettierConfig.parser.
So I do not think it is necessary to change it
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hypnosphi
Jun 1, 2018
Member
I don't feel really good about this double prettier.format
call in different logical branches. Let's maybe revert it to how it was, with if (!prettier config.parser)
check?
This comment has been minimized.
This comment has been minimized.
isoppp
Jun 2, 2018
Author
Contributor
OK, I understood.
Many thanks for having you review it over and over. And, sorry...
I reverted before commit.
After, modified to make parser or filepath always specified
If the parser and file path are empty, set the parser babylon
isoppp commentedMay 28, 2018
•
edited
Issue: #3657
What I did
Add default parser option for prettier v1.13.0 in storysource
How to test
Probably can't.
No.
No.
Note
I try to make a PR of this comment on the ticket