Skip to content

Don't format when there are syntax errors #5305

@Chris2011

Description

@Chris2011

Description

Sometimes it happens, when I have a long file, removing lnes and some other stuff and call format the file, it looks weird. This sometimes happens, when you removed an open bracket but not the closed one, or removing a comma but it is needed, etc. Smth like that. That mostly happens in JS, TS, PHP and JSON files.

So here I would suggest to not format the file if we have any syntax issues. VS Code doesn't format if we have problems, WebStorm does and make it as it looks correct.

Take my example snippets and try it by your own.

JSON

{
  "name": "smth",
  "version": "0.0.0"
  "scripts": {
    "dev": "vite",
    "build": "vite build"
    "serve": "vite preview"
  }
}

JavaScript

function tst() {
  le test = 2;

  function () {
    () => {
  }
}

PHP

<?php
class test {
  private tets() {
    echo "";
  }
}

TypeScript

export default class DatabaseConfiguration {
  public a: string;
  public b: string;

  public constructor(configuration: any)
    this.a = configuration.a;
    this.b = configuration.b;
  }
}

Use case/motivation

I don't want this whole formatting, when I'm not finish with developing, but most of the time I hit format to see whether everything is fine or not. And when I know, that there is smth to format it should format but with errors it should not format, so this will be an indicator for me to fix them first. Maybe this should be an option like "Format on syntax errors" but I don't see it, that we need this. So whether we should fix the formatting to do it correct or we should prevent formatting on errors.

Related issues

No response

Are you willing to submit a pull request?

No

Code of Conduct

Yes

Metadata

Metadata

Assignees

Labels

EditorJSONJavaScript[ci] enable web job and extra JavaScript tests (webcommon/javascript2.editor)PHP[ci] enable extra PHP tests (php/php.editor)kind:featureA feature request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions