Comments (9)
To be honest, the very fact that the code contains a string of 80 characters is a sign itself that you need to fix it. Is it an error message? Sure, place those in a single file where you disable the "max characters per lines" rule. Is it a variable name? Chop that down.
I just think the source of the problem lies elsewhere and should be addressed before trying to patch it up quick and dirty.
@lazarljubenovic it is nice for it to be able to handle these edge cases well so it's good to discuss them :)
Agree though that if it's too complicated then the code should just be changed and this is not a big deal. I'm not sure what the expected output is though.
from dprint-plugin-typescript.
@dsherret Thanks for looking into this. Since it wasn't clear to some people, the first one does not contain a string or even a line of more than 80 chars. :) Prettier would leave it the way it is. First one is source and expected, second is actual. Using options:
ConfigurationBuilder::new()
.line_width(80)
.indent_width(2)
.next_control_flow_position(NextControlFlowPosition::SameLine)
.force_multi_line_parameters(true)
.force_multi_line_arguments(true)
.binary_expression_operator_position(OperatorPosition::SameLine)
.build()
Neither of the examples looks good
A highly subjective thing to predicate your argument on. Judging by your first paragraph, I'd say you're distracted by that specific example I gave. That was intended to minimally represent the structure while achieving +80 for the whole statement. Here's a more realistic one:
walk("path/to/subdir", {
followSymlinks: true,
includeFiles: false,
skip: excludePatterns
});
Is it ugly? Would you suggest I pull the object out as a variable, betraying the meaning of the options object pattern? Is this an edge case? People are calling this a complex statement, but it objectively isn't. It just happens to be a long one. That's exactly what automatic line wrapping is for.
from dprint-plugin-typescript.
To be honest, the very fact that the code contains a string of 80 characters is a sign itself that you need to fix it. Is it an error message? Sure, place those in a single file where you disable the "max characters per lines" rule. Is it a variable name? Chop that down.
While I appreciate tools being strictly defined and predictable, the point of a formatter is no get rid of:
- thinking too much about it;
- everyone formatting code differently;
- everyone automatically re-formatting the code differently, making noise in the diff.
Neither of the examples looks good, and instead of fixing the printer, I think it's a sign that the code itself needs fixing. This will help with reason (1). Or -- just let it format one way, and leave it like that, and you'll avoid issues related to the reasons (2) and (3).
I don't mean that this shouldn't be decided or thought through, or that you shouldn't have opened the issue. I just think the source of the problem lies elsewhere and should be addressed before trying to patch it up quick and dirty.
from dprint-plugin-typescript.
@nayeemrmn Is that the expected output you'd like? I think this does what you'd like when forceMultiLineArguments
is on:
Ryan turned that on in deno in the recent PR, so I think that should be good. Let me know if I'm misunderstanding.
from dprint-plugin-typescript.
@nayeemrmn wait... actually I think I am misunderstanding. Could you provide the expected output and what the current output is? Right now the output is the same as prettier unless forceMultiLineArguments
is off.
from dprint-plugin-typescript.
Oh, this is a bug that only occurs with forceMultilineArguments
. I see that now. Thanks! Will fix this soon (probably tonight).
Playground link:
from dprint-plugin-typescript.
@nayeemrmn How do you think this should format?
call({
prop
}, "testing");
call({
prop
}, {
prop
});
It seems prettier splits them up and makes them multiline. Wouldn't be hard to keep them as-is though...
I'm thinking we could have an argument list meet either of these requirements in order to be considered "multi-line":
- A collection of arguments exceeds the line width.
- OR, an argument start position is the first token on that line.
So the above would format as-is. Does that sound good?
from dprint-plugin-typescript.
I've discovered various issues while making forceMultiLineArguments
the default. Currently fixing them and making this more robust.
from dprint-plugin-typescript.
Thanks so much for reporting @nayeemrmn! I have fixed this bug and it's a pretty bad bug IMO.
Additionally I updated the config to the following:
forceMultiLineParameters
-> Replaced bypreferHangingParameters
with a default offalse
.forceMultiLineArguments
-> Replaced bypreferHangingArguments
with a default offalse
.
I should be able to catch bugs for this more often now that I've made it the default behaviour.
from dprint-plugin-typescript.
Related Issues (20)
- Option `jsxExpressionContainer.spaceSurroundingExpression` adds spaces between multiple braces
- Q: Plugin Location HOT 2
- Consider renaming `arrowFunction.useParentheses: "always"` HOT 1
- Interpretation of trailing comments with ASI formatting
- bracePosition: nextLine does not work when passing objects as arguments
- Allow multi-line, multi-argument function calls to maintain formatting
- Duplicate imports do not have a consistent ordering HOT 1
- Break interfaces/types onto multiple lines
- Wrapping of arrow functions in the second argument of functions
- `semiColons` should be spelled `semicolons` because it's a single word. HOT 3
- Allow brackets to be put on the same link as case statement (and potentially allow "break" to be on the same link as the closing bracket)
- Alphabetical ordering of interfaces, classes, properties and methods
- Option to disable the removing of trailing spaces
- dprint moves `else` to the wrong `if` HOT 1
- Incorrect indentation of inner expression in template literal
- Don't trailing generic comma when format tsx file when `trailingComma: never` HOT 3
- cannot format associated files
- Support for Formatting Vue and Svelte Code with `dprint_plugin_typescript::format_text`
- Array of objects is not formatted nicely
- Missing space for `export default function doX()` with `spaceBeforeParentheses`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dprint-plugin-typescript.