patternjavascriptMinor
Tool for automatically correcting indentation and formatting of CR & SO code
Viewed 0 times
formattingcorrectingautomaticallyindentationcodeforandtool
Problem
This is my tentative solution to:
How can I prepare my code so that I can paste it formatted?
If you need to copy and paste code into the question or answer textarea when solving someone's problem, describing your own, or fixing someone else's formatting, this tool will correct the indentation of the code and prepare it as a code block as understood by the Stack Exchange formatter. Pending CR's improvements, it will some day hatch into a bookmarklet, and none of us will hit the space bar repeatedly or alt-tab between browser and IDE ever again.
In the interest of having a great thing that can make all of our CRing easier, I invite you to review this without mercy. Readability, usefulness, you prefer
The following were my concerns while writing this, upon which I would specifically request comment:
There are also some features which are just not going to fit into what I've got right now, so I would like input on how you think their absence impacts the effectiveness of the tool and how you might go about implementing them without a total re-write and/or moving on to a grammar-based solution. These are:
How can I prepare my code so that I can paste it formatted?
If you need to copy and paste code into the question or answer textarea when solving someone's problem, describing your own, or fixing someone else's formatting, this tool will correct the indentation of the code and prepare it as a code block as understood by the Stack Exchange formatter. Pending CR's improvements, it will some day hatch into a bookmarklet, and none of us will hit the space bar repeatedly or alt-tab between browser and IDE ever again.
In the interest of having a great thing that can make all of our CRing easier, I invite you to review this without mercy. Readability, usefulness, you prefer
.concat to +, you just stubbed your toe - you have a gripe, let's hear it.The following were my concerns while writing this, upon which I would specifically request comment:
- I'm pretty sure the way I'm counting delimiters is not the most obvious route, but it works in what I think is linear time. Is it difficult to follow? I kept tossing out comments thinking I wasn't getting the whole strategy across right.
- Am I overdoing
map,filter,reduce, etc? To me, it's easier to see the intent of an iterative process and to analyze its performance characteristics when I use those methods than usingwhileandforfor everything. But I don't see a lot of code that uses them as much as I do.
- Clearly there was some iterative factoring going on, and not all methods have been neatly bundled into classes, so I invite comment on a more organized set of abstractions, or just how you would have factored it differently.
There are also some features which are just not going to fit into what I've got right now, so I would like input on how you think their absence impacts the effectiveness of the tool and how you might go about implementing them without a total re-write and/or moving on to a grammar-based solution. These are:
- Can't enforce token parity (e
Solution
It was originally going to have a "just turn the tabs into spaces" mode, which is why you see it messing with tab/space alignment. Is this a feature that would be useful? It would take trivial effort to implement.
That feature might be useful on this site (Code Review):
That feature might be useful on this site (Code Review):
- Reviewing the format of the code in the OP is on-topic; if the format is bad we should review that in an answer, not correct it in the OP's question.
- Occasionally, however, the formatting is messed up because the OP pasted-in code which contains tabs. In that case (formatting was messed up by the process of converting to markdown) it would be appropriate for someone else to edit the question to fix only that (tabs to spaces).
Context
StackExchange Code Review Q#40422, answer score: 5
Revisions (0)
No revisions yet.