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

Add check for ungenerated code #679

Merged
merged 5 commits into from
May 17, 2018

Conversation

DanielMSchmidt
Copy link
Contributor

We had at times updates of the source for code generation not being reflected in the adapters as the code was not generated again. Let's add a check for this here 👍

set -e

if [[ $(git diff) ]]; then
echo "Git shows that there are changes."
Copy link
Member

Choose a reason for hiding this comment

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

Please be more explicit in these logs.

  1. What happened ?
  2. Why did it happen ?
  3. What should the user do now in order to resolve it ?

@DanielMSchmidt DanielMSchmidt force-pushed the danielmschmidt/check-if-generation-needed branch 4 times, most recently from 7ddc373 to a09fa44 Compare April 25, 2018 19:05
@DanielMSchmidt DanielMSchmidt dismissed rotemmiz’s stale review April 25, 2018 19:06

Added meaningful error message

@DanielMSchmidt
Copy link
Contributor Author

@rotemmiz added error message, could you review it again?

@DanielMSchmidt DanielMSchmidt force-pushed the danielmschmidt/check-if-generation-needed branch from a09fa44 to c2e51c4 Compare April 25, 2018 19:32
@@ -19,18 +17,27 @@ GREYCondition::waitWithTimeout:pollInterval:
@param seconds Amount of time to wait for the condition to be met, in seconds.

@return @c YES if the condition was met before the timeout, @c NO otherwise.
*/static waitWithTimeout(element, seconds) {
if (typeof seconds !== "number") throw new Error("seconds should be a number, but got " + (seconds + (" (" + (typeof seconds + ")"))));
*/ static waitWithTimeout(
Copy link
Member

Choose a reason for hiding this comment

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

Is this the crazy working of prettier? This is bad formatting IMO. It's much harder to actually read the function signature like this.

npm run build

if [[ $TRAVIS && $(git diff) ]]; then
printf "\n\n"
Copy link
Member

Choose a reason for hiding this comment

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

Awesome!

@@ -1,4 +1,7 @@
#!/usr/bin/env node
const prettier = require("prettier");
Copy link
Member

Choose a reason for hiding this comment

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

Yep, here it is...

@DanielMSchmidt
Copy link
Contributor Author

@rotemmiz I understood that we wanted to use prettier in our project, so I thought adding it to the generated code too makes sense. I think we are doing a suboptimal job enforcing it, I would offer to help with that. The mockserver I am currently writing enforces it with the help of jest, which I like very much, you can see the config here.

I found this quote on a podcast I listen to (freely quoted as I don't remember when they said it):

Prettier reformats your code to look worse, but at the same time it makes your co-workers code much more readable.

This resonated a lot with me, I think everyone has an opinion on how code should be looking like for whatever (totally) reasons. prettier frees us from having to have conversations about how it should look like, it just always looks the same, freeing up brain cycles for more important tasks 😇

@DanielMSchmidt DanielMSchmidt self-assigned this Apr 25, 2018
@rotemmiz
Copy link
Member

You're right but I still really don't like these formatting choices. It makes the code longer (in lines), and very weirdly formatted.
I would want to explore it there are different "flavors" tho this formatting before running it on the whole project. I do like ESLint's defaults much better.
Sorry for delaying this for too long, but these formatting chocices made by prettier really hurt my eyes.

@DanielMSchmidt
Copy link
Contributor Author

Prettier has a nice playground and at the bottom left corner there is a "Show Options" button where you can play with the options until you like the output ;)

*/static assertWithMatcher(element, matcher) {
if (typeof matcher !== "object" || matcher.type !== "Invocation" || typeof matcher.value !== "object" || typeof matcher.value.target !== "object" || matcher.value.target.value !== "GREYMatchers") {
throw new Error('matcher should be a GREYMatcher, but got ' + JSON.stringify(matcher));
*/ static assertWithMatcher(
Copy link
Member

Choose a reason for hiding this comment

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

Turns out this is not "prettier being prettier".
Prettier doing a really bad job here because of the */ is at the same line as the function deceleration.
If you make sure docs and function declarations are in different lines it will work quite good.

Here's a config I feel ok with.

Copy link
Member

Choose a reason for hiding this comment

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

Hey @DanielMSchmidt , can you please take a look at this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm on it, thank you for pinging 👍

@DanielMSchmidt DanielMSchmidt force-pushed the danielmschmidt/check-if-generation-needed branch 2 times, most recently from 775281b to 5f435e9 Compare May 8, 2018 17:49
@DanielMSchmidt
Copy link
Contributor Author

@rotemmiz I think we are there now, please take another look 🙏

Might make sense to go over it commit by commit as the changeset is quite big due to prettier being unleashed on the generated code

@DanielMSchmidt DanielMSchmidt dismissed rotemmiz’s stale review May 8, 2018 17:56

Not up to date anymore

@rotemmiz
Copy link
Member

rotemmiz commented May 8, 2018

I hate this argument as well, but please use spaces. Tabs make it much harder to read on GitHub, and we spend a lot of time reviewing here

@DanielMSchmidt
Copy link
Contributor Author

@rotemmiz done 👍 Did I copy the rest of your prettier session correctly?

if (typeof point !== "object") throw new Error("point should be a object, but got " + (point + (" (" + (typeof point + ")"))));
if (typeof point.x !== "number") throw new Error("point.x should be a number, but got " + (point.x + (" (" + (typeof point.x + ")"))));
if (typeof point.y !== "number") throw new Error("point.y should be a number, but got " + (point.y + (" (" + (typeof point.y + ")"))));
*/ static actionForMultipleTapsWithCountAtPoint(
Copy link
Member

Choose a reason for hiding this comment

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

still here!
separate */ static actionForMultipleTapsWithCountAtPoint( to

*/ 
static actionForMultipleTapsWithCountAtPoint(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't do much about it, this would be something we would need to do in prettier itself, providing an upstream PR. Do you really want me to spend the time there? Would be fine with that, just wanted to clarify.

Copy link
Member

Choose a reason for hiding this comment

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

It's not related to prettier, it's the code generator

@DanielMSchmidt
Copy link
Contributor Author

DanielMSchmidt commented May 9, 2018

Unfortunately, I can't do much about it. I add a leadingComments entry for the comment in babel, which means "insert the comment before this node", leading to the output you see. So my options are either

  1. Go into babel and "fix" the leadingComments behaviour
  2. Go into prettier and enable it to prettify this situation
  3. Go with a hack solution (String replacement of the final output)
  4. Let it be like this

Which route would you like to take? 😇

@rotemmiz
Copy link
Member

rotemmiz commented May 9, 2018

4

@DanielMSchmidt
Copy link
Contributor Author

Okay :)

@DanielMSchmidt DanielMSchmidt dismissed rotemmiz’s stale review May 12, 2018 10:01

You settled for option 4 - let it be like this, so I dismiss your review

@DanielMSchmidt
Copy link
Contributor Author

@rotemmiz Could you give a final review here? 😇

@@ -126,21 +167,25 @@ to be selected.

@return An interaction (assertion or an action) to be performed on the element at the
specified index in the list of matched elements.
*/static atIndex(element, index) {
if (typeof index !== "number") throw new Error("index should be a number, but got " + (index + (" (" + (typeof index + ")"))));
*/ static atIndex(
Copy link
Member

Choose a reason for hiding this comment

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

Still broken here :/

@rotemmiz
Copy link
Member

The current state where the end of multiline comment is at the beginning of the function declaration fucks up prettier.
Please drop prettier untill there's a solution for these line breaks

@DanielMSchmidt DanielMSchmidt force-pushed the danielmschmidt/check-if-generation-needed branch from 51b8214 to 7ef345f Compare May 12, 2018 12:55
@DanielMSchmidt
Copy link
Contributor Author

@rotemmiz I removed prettier from the generated code (only applied the new style to the code generation). I opened an issue at prettier/prettier#4465 let's see if we can get any help there. I might investigate if there is a quick fix within prettier that doesn't take too long.

.prettierrc Outdated
@@ -0,0 +1,8 @@
{
"useTabs": true,
Copy link
Member

Choose a reason for hiding this comment

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

useTabs:false!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, forgot to squash one of the commits I dropped

DanielMSchmidt and others added 3 commits May 12, 2018 17:20
In this step we also changed the config to standards that match
our code styles better.
This file gets rewritten with an npm install, so it leads to
unnecessary changes
@DanielMSchmidt DanielMSchmidt force-pushed the danielmschmidt/check-if-generation-needed branch from 7ef345f to a27e2f2 Compare May 12, 2018 15:20
@DanielMSchmidt
Copy link
Contributor Author

@rotemmiz Sorry for the typo :/

@rotemmiz
Copy link
Member

@DanielMSchmidt can you please take a look, seems like the build is broken due to this change.
https://travis-ci.org/wix/detox/jobs/378118106#L657

@DanielMSchmidt
Copy link
Contributor Author

Yay, the check works. But damn, need to fix them 😂 will do that asap and ping you :)

@rotemmiz rotemmiz merged commit c6b1b67 into master May 17, 2018
@DanielMSchmidt DanielMSchmidt deleted the danielmschmidt/check-if-generation-needed branch May 17, 2018 11:24
@wix wix locked and limited conversation to collaborators Jul 23, 2018
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.

2 participants