apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.63k stars 843 forks source link

Don't format when there are syntax errors #5305

Open Chris2011 opened 1 year ago

Chris2011 commented 1 year ago

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

Chris2011 commented 1 year ago

Just copy the examples into each file type and hit format