4 ms·
Is anyone else seeing the code samples getting cut off? Seems to happen to me in Chrome on both OS X and Ubuntu. The page shows: export const sum = (a, b)
by alxlu 10y ago
Is anyone else seeing the code samples getting cut off? Seems to happen to me in Chrome on both OS X and Ubuntu. The page shows:
export const sum = (a, b) => { re
And when I copy and paste the line the rest of it is copied to the clipboard.
- throwanem 10y agoI think everybody is; it looks like whatever CMS they're using eats newlines out of content pasted into <pre>s, because there aren't any in the source. Maybe it's a cavil, but I'm not overjoyed at the thought of doing global search and destroy on my codebases with a tool I heard about on a website that messes up something that basic. On the other hand, apparently jscodeshift itself comes from Facebook [1], and they tend to do good work (on a technical level, at least); perhaps it'd be worthwhile to change the HN link to point to that repo, not least because the code samples aren't munged to unintelligibility there. [1] https://github.com/facebook/jscodeshift https://github.com/facebook/jscodeshift
- 15155 10y ago> I'm not overjoyed at the thought of doing global search and destroy on my codebases with a tool I heard about on a website that messes up something that basic. When I am writing jscodeshift scripts, it's a constant cycle of git checkout -> run codemod -> git checkout. Nobody is saying you need to commit the changes: review them by hand if you will. I've never had a problem with jscodeshift itself. Publicly available transform scripts though are quite hit or miss.
- throwawaysocks 10y agoCould you share links to buggy ones? I'm interested in seeing how they go wrong.
- 15155 10y agoI can't name any specific situations, but it will generally come down to the fact that your project is different from whatever the script writer was anticipating. For instance: import statements vs. require expressions - these need to be handled with different AST matchers. Import statements themselves have 3 different varieties of specifiers (default, named, "all") which must be accounted for. A require expression may or may not involve destructuring, it may or may not use const or let over var (each of which need to be handled explicitly, etc.) As far as failure mode: scripts generally just won't match or work, or they might replace all of your consts with vars, etc - they can be very codebase specific depending on the complexity of the script.
- Kerrick 10y agoThis seems to be because the DataScienceCentral site stole the content from the original source [1], Toptal. It looks like their copy-paste job messed things up. [1]: https://www.toptal.com/javascript/write-code-to-rewrite-your-code https://www.toptal.com/javascript/write-code-to-rewrite-your...
- reergymerej 10y agoYou can find the accompanying code for the article at https://github.com/reergymerej/jscodeshift-article https://github.com/reergymerej/jscodeshift-article