3 ms·
And autoformatters have cemented my preference for non-white spaced languages. As you say, just write whatever and let it format it. When I then switch to our p
by matsemann 3y ago
And autoformatters have cemented my preference for non-white spaced languages. As you say, just write whatever and let it format it. When I then switch to our python backend this strategy no longer works. Like, it can fix something, but it needs a much cleaner state to do so. For instance if my loops are indented wrong, black can't solve that as the decision it makes has a semantic meaning.
- resters 3y agoA team I'm doing some work with uses eslint and has not configured prettier, so instead of simply having everything get formatted correctly, I get red squiggly lines under blocks of code because of an omitted meaningless whitespace character. There are a few linting rules that can help identify semantic errors or dead code, but only a small number of rules are needed to get all of the benefits. Autoformatting (prettier, gofmt, etc.) is the way to go.
- kitschpatrol 3y agoYou can mellow the squiggles for stylistic errors in VS Code. Take a look at the “eslint.rules.customizations” key in this file: https://github.com/antfu/eslint-config/blob/main/.vscode/settings.json https://github.com/antfu/eslint-config/blob/main/.vscode/set...
- resters 3y agoThank you! I had been wondering if that was possible. Do you know if it can be done only for a single project / directory?
- WorldMaker 3y agoYou can set workspace settings in the top-level .vscode/settings.json file of your project: https://code.visualstudio.com/docs/getstarted/settings#_workspace-settings https://code.visualstudio.com/docs/getstarted/settings#_work...
- mcpeepants 3y agomany (most?) red squiggles are autofixable with eslint. I use eslint exactly like prettier, in that I never think about formatting and everything gets fixed/formatted on save.
- resters 3y agoMany are, but some of the "errors" are not helpful while code is in progress. Why do I need to see them while typing if they can be easily auto-fixed later? It's just more useless visual clutter to worry about.
- globular-toast 3y agoI'm amazed people are using editors that require manually tweaking indentation. I mean, apart from making sure the code is in the right block.
- samatman 3y agoIn languages which don't use indentation semantically, I always end up catching a bug, sooner or later, by running code through a formatter. It's usually in a complex tree of nested if statements, some code I thought was part of one group gets moved to be in another group, making it obvious where the mistake was. Python can't do that. It's one of a few things about the language which is "nice" when using it for simple tasks, but which makes more complex programming pointlessly error-prone.
- stavros 3y agoConversely, my strategy is "press shift+tab to close the block and not have to screw around with matching {} everywhere".
- tux1968 3y agoBut that leaves you having to manually adjust entire blocks, when indentation levels change. With {}, prettier can readjust everything properly for you, even after mutilating changes such as copying an entire block from a different file into a new one, and at a different indentation level.
- stavros 3y agoPython formatters do that too, they don't care about the indentation, as long as it's consistent. All I need to do is indent the block far enough to the right that it's not more left than the previous one, and that's it. This also happens rarely enough that it's never been an issue for me.
- wongarsu 3y agoI find selecting a block of code and hitting tab/shift+tab much simpler and faster than hunting down matching parenthesis, especially when adjusting longer sections or complex situations. Of course this is mostly a tooling issue, since there is a shortcut for adjusting indentation but not for adjusting parenthesis. Or maybe there is and I just haven't discovered it yet.
- eddd-ddde 3y agoPerhaps is because jetbrains make better structural editing than vscode, but I practically never have to type closing brackets. Copying, moving, reordering, newlines, pretty much anything will keep correct pairing of brackets.
- stavros 3y agoSure, and I never have to type any opening indentation either, only closing. Regardless, to me, this is such a minor issue that I don't consider it at all when choosing a language.
- WorldMaker 3y agoSomething of a tangent: with Automatic Semicolon Insertion (ASI), JS is a white-space influenced language. Some of prettier's defaults are directly related to ASI, such as the way it often wraps things in extra ("unnecessary") parentheses, especially JSX but also anything complicated and multi-line especially after keywords like `return`. (`return` is the trickiest under ASI, so prettier's defaults seem that conservative in large part because of `return`.) As someone who appreciates `{ "semi": false }` in my prettierrc, I take a lot of advantage of JS' ASI and find prettier's behavior interesting and conservative, but useful.