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

feat: Add prettier for formatting #79

Closed
wants to merge 2 commits into from
Closed

Conversation

pksjce
Copy link

@pksjce pksjce commented Mar 2, 2017

What kind of change does this PR introduce?
Changing formatting to use prettier for #70

Did you add tests for your changes?
Existing tests are modified

If relevant, did you update the documentation?

Summary
By formatting with prettier, we can use recast as is without worrying about benjamn/recast#242.
Also due to this, we can add yarn support to our project!

Does this PR introduce a breaking change?

Yes, formatting changes in all snapshots.

Other information

@pksjce pksjce requested review from okonet and TheLarkInn March 2, 2017 16:18
Copy link
Contributor

@okonet okonet left a comment

Choose a reason for hiding this comment

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

Please also add test case with tabs since the last time I tried prettier on a project with tabs it blew the whole file up.

@@ -38,7 +38,8 @@ function transform(source, transforms, options) {
}, options);
transforms = transforms || Object.keys(transformations).map(k => transformations[k]);
transforms.forEach(f => f(jscodeshift, ast));
return ast.toSource(recastOptions);
const astStr = ast.toSource(recastOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't call it astStr since. Let's call it transformedSource?

Copy link
Member

Choose a reason for hiding this comment

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

+1 Yes DAMP (Descriptive and Meaningful Phrases) ftw.

@@ -38,7 +38,8 @@ function transform(source, transforms, options) {
}, options);
transforms = transforms || Object.keys(transformations).map(k => transformations[k]);
transforms.forEach(f => f(jscodeshift, ast));
return ast.toSource(recastOptions);
const astStr = ast.toSource(recastOptions);
return prettier.format(astStr, {singleQuote: true, tabWidth: 2});
Copy link
Contributor

Choose a reason for hiding this comment

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

Users should be able to pass prettier options. Also, some options like singleQuote and tabWidth might overlap recast options. We need to respect both or remove recast options completely.

Copy link
Author

Choose a reason for hiding this comment

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

Lets drop recast options. Recast pretty print is not reliable. I'll add prettier options instead

@@ -31,7 +31,8 @@ module.exports = {
`;

describe('transform', () => {
it('should not transform if no transformations defined', () => {
// WIll not be equal unless input is also from prettier
xit('should not transform if no transformations defined', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Right, that's pretty much an issue to me. We only should apply prettier if we have transformed something.

Copy link
Author

Choose a reason for hiding this comment

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

Shall we applly prettier after showing diff to user? I'm not sure how to check if a transformation happened.. can AST's be compared?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it can be done by checking the return value. Check out jscodeshift docs since I'm on mobile now

@@ -166,9 +166,11 @@ if(argv.init) {
if (!filePaths.length) {
throw new Error('Please specify a path to your webpack config');
}
const outputConfigName = filePaths[1] || `${filePaths[0]}v2.js`;
Copy link
Contributor

Choose a reason for hiding this comment

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

This will make git diff impossible and it will require an extra step from users to remove the old config and rename the new. IMO it defeats the purpose of using this tool. Why would someone like to keep the old config?

Copy link
Author

Choose a reason for hiding this comment

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

Yes you are right. But can we keep this until testing is done?

Copy link
Member

Choose a reason for hiding this comment

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

@okonet I could see a benefit of being able to have the old one left around especially while still a [WIP]. There were cases on initial trials of migrate where I had wished I specified outputConfigName beacuse I had lost the original, etc.

Copy link
Member

Choose a reason for hiding this comment

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

At the least we should store it somewhere, but only as a temp trial for now, or if user specifies.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay but in this case I'd suggest renaming the original config to something with webpack.config.orig.js in order to be able to run webpack without specifying the path to the new one in case of the default name. Either way, I guess for most people the next operation after transforming would be to try run the build and see if everything works. With a different name it's not possible.

Copy link
Member

@TheLarkInn TheLarkInn left a comment

Choose a reason for hiding this comment

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

Looks like @okonet has all my thoughts covered in his suggested changes. This looks great overall.

@@ -38,7 +38,8 @@ function transform(source, transforms, options) {
}, options);
transforms = transforms || Object.keys(transformations).map(k => transformations[k]);
transforms.forEach(f => f(jscodeshift, ast));
return ast.toSource(recastOptions);
const astStr = ast.toSource(recastOptions);
Copy link
Member

Choose a reason for hiding this comment

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

+1 Yes DAMP (Descriptive and Meaningful Phrases) ftw.

@@ -166,9 +166,11 @@ if(argv.init) {
if (!filePaths.length) {
throw new Error('Please specify a path to your webpack config');
}
const outputConfigName = filePaths[1] || `${filePaths[0]}v2.js`;
Copy link
Member

Choose a reason for hiding this comment

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

At the least we should store it somewhere, but only as a temp trial for now, or if user specifies.

@pksjce
Copy link
Author

pksjce commented Mar 21, 2017

Better to do this after #92

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants