nrwl / precise-commits

:sparkles: Painlessly apply Prettier by only formatting lines you have modified anyway!
MIT License
471 stars 20 forks source link

class method formatted incorrectly due to missing context(?) #15

Open cmcaine opened 6 years ago

cmcaine commented 6 years ago
diff --git a/src/keyseq.ts b/src/keyseq.ts
index 5caa81a..d5dccbc 100644
--- a/src/keyseq.ts
+++ b/src/keyseq.ts
@@ -35,12 +35,12 @@ export class MinimalKey {

     /** Does this key match a given MinimalKey extending object? */
     match(keyevent) {
-        // 'in' doesn't include prototypes, so it's safe for this object.
-        for (let attr in this) {
-            if (this[attr] !== keyevent[attr]) return false
-        }
-        return true
-    }
+                        // 'in' doesn't include prototypes, so it's safe for this object.
+                        for (let attr in this) {
+                            if (this[attr] !== keyevent[attr]) return false
+                        }
+                        return true
+                    }
 }

Prettier handles it correctly.

JamesHenry commented 6 years ago

@cmcaine Can I please check what you mean by prettier handles it correctly?

I am guessing you mean, when you run prettier on the whole file, and not just the range?

You can now reproduce ranges issues using the prettier playground.

E.g. Here is a range I am selecting from a separate, unrelated issue: https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBLAtgBwgJxgAgBtUAjfAMxwnXwB0RiT6BuWqNjqSKAZwIEN8AXnxkhAPnzceEQnAB0hCAHMAFCQCUrdjs6N5M9HBgALVFDVaQAGhARMMVNB7JQ-HFQDuABXcIXKPwAbhCoACY2ICQ4-GAA1sYAypix5srIMDgArnC25jxweN4xyuj8yOT8hAW2AFY8AB4AQjHxSfxGADLmcBVVNSApOAU4yFH8JACeSlCRmDjmMADq4abIABwADLbzEAVLMZhj83AjQb22OHAAjlmoV8X8peVIldW5IAXoqBnZHzxpOQARSyEHgfXethgExWYTWSAATFCYqhiBYAMLUMpjKDQC4gLIFAAqEwCbwGMQscES0LwyARSJAlOUcAAolAIkgAGybAC+vKAA

My guess is you will be able to reproduce the issue there if you apply the same range to your source that matches your git diff (i.e. what precise-commits is doing for you behind the scenes)

Please could you try and build that reproduction in the playground to confirm?

cmcaine commented 6 years ago

Yes, I am comparing with running the whole file through prettier.

This issue should maybe be on prettier rather than here. Depends what prettier --range-* is intended to do. Obviously in the precise-commits use this is wrong. Maybe if you just want to format some js in another document --range is fine, though what it's doing here is still pretty weird.

Reproduction.