xstate-tools icon indicating copy to clipboard operation
xstate-tools copied to clipboard

Optional automatic formatting with prettier

Open Silverwolf90 opened this issue 3 years ago • 5 comments

When you open a machine with the visual editor, it automatically formats the machine using prettier and there is no way to opt out of this behavior. I don't use prettier so it would be better to make this optional.

Silverwolf90 avatar Jun 14 '22 21:06 Silverwolf90

What kind of formatting would you like to have by default? Are you using any other formatter?

Andarist avatar Jun 15 '22 07:06 Andarist

The way we have it set up now, we need to use some kind of default formatting - otherwise it'll just present as JSON.stringify(config, null, 2).

I.e. any time you have generated code, the thing that generates the code needs to make choices about how that code displays.

mattpocock avatar Jun 15 '22 08:06 mattpocock

There are various ways to achieve the result though. A simple formatter could just work similarly to JSON.stringify (we probably can't use it directly because we might need to handle things that are not fully serializable, especially in the future) with indentation detected based on the file and the position in the file.

Andarist avatar Jun 15 '22 09:06 Andarist

Yeah I don't use an auto-formatter at all (except for eslint which is pretty limited), but I see the problems here.

Perhaps what feels most problematic is that the machine is formatted before I've made any material changes via the visual editor -- so even if I just want alter the layout in the editor, I incur formatting changes that I don't want.

Moving from there, it seems that ideally the only parts that should be formatted are parts that have been introduced via the visual editor, and avoid formatting parts that haven't. I realize the complexity of that makes it very difficult to build 😅

I guess these kind of problems are what makes building this bidirectional code<->visual editing pretty difficult (I remember Dreamweaver pretty fondly though 😂)

Silverwolf90 avatar Jun 15 '22 09:06 Silverwolf90

Moving from there, it seems that ideally the only parts that should be formatted are parts that have been introduced via the visual editor, and avoid formatting parts that haven't. I realize the complexity of that makes it very difficult to build 😅

Ye - this isn't impossible but definitely more complex than the current solution. Given our small team right now and the relatively low priority of this, I wouldn't expect this to happen any time soon. A good thing though is that this is an open-source repository - so... sky's the limit 😉

Andarist avatar Jun 15 '22 09:06 Andarist

The dependency on Prettier is being removed (for the most part) in this PR: https://github.com/statelyai/xstate-tools/pull/229

Andarist avatar Nov 08 '22 16:11 Andarist