standard / ts-standard

Typescript style guide, linter, and formatter using StandardJS
https://www.npmjs.com/package/ts-standard
MIT License
464 stars 36 forks source link

Doesn't format JSX like standard does #157

Closed hutch120 closed 3 years ago

hutch120 commented 3 years ago

What version of this package are you using? ^10.0.0

What operating system, Node.js, and npm version? 14.16.0

What happened? When I go to VSCode settings and set "standard.engine":"standard" it formats JSX with jsx-indent-props rule When I set "standard.engine":"ts-standard" it doesn't format JSX

What did you expect to happen? When I set "standard.engine":"ts-standard", it should format JSX just like standard does

Are you willing to submit a pull request to fix this bug? Sure, if you can point me in the right direction... does it need a rule added?

FYI this is my settings.json file in VSCode that works great for Standard and JS files. But clearly doesn't work for TSX files.

{
  "editor.formatOnSave": true,
  "[javascript]": {
    "editor.formatOnSave": false
  },
  "javascript.validate.enable": false,
  "standard.autoFixOnSave": true
}

TBH, I'm struggling to find much info on how to configure this correctly. Every guide I can find assume you are either 100% TSX or 100% JS files.

theoludwig commented 3 years ago

Hey! @hutch120 :wave:

It seems that it is more an issue with the VSCode extension than ts-standard. But I can't reproduce:

2021-08-12_11-32

The react/jsx-indent-props rule is working fine for both jsx and tsx files. Here are my settings.json :

{
  "standard.enable": true,
  "standard.usePackageJson": true,
  "standard.engine": "ts-standard",
  "standard.treatErrorsAsWarnings": true,
  "standard.autoFixOnSave": true
}

Thanks for your report! Closing, as it is a non-issue and not opened in the right place. Please reopen if you think it is wrong, or open a new issue for the VSCode extension if the problem persist in VSCode: https://github.com/standard/vscode-standard/issues

hutch120 commented 3 years ago

@Divlo Legend! I see the issue now.. I didn't have "standard.usePackageJson": true (but I only have standard installed locally) I'm not sure why it half worked.

Couple of follow up questions:

1) Do you have any additional config in package.json, or is the flag just indicating standard is installed in the local package?

2) Can you confirm you have Standard VS Code extension installed? And is it the new one or the old one ?

3) Wondering if this could this be clearer in the doco? Shouldn't the default be local version? Maybe a settings example for those installing Standard locally?

So, for reference, this ended up being my settings.json, to allow formatting on save for other types like .json files.

{
    "editor.formatOnSave": true,
    "[javascript]": {
        "editor.formatOnSave": false
    },
    "[javascriptreact]": {
        "editor.formatOnSave": false
    },
    "[typescript]": {
        "editor.formatOnSave": false
    },
    "[typescriptreact]": {
        "editor.formatOnSave": false,
    },
    "standard.enable": true,
    "standard.engine": "ts-standard",
    "standard.usePackageJson": true,
    "standard.treatErrorsAsWarnings": true,
    "standard.autoFixOnSave": true
}

Thanks again!

theoludwig commented 3 years ago

@hutch120

  1. Do you have any additional config in package.json, or is it just indicating it is installed by the package?

I don't have any extras configs in package.json, I only have ts-standard in my devDependencies.

"standard.usePackageJson": true tells the VSCode extension to use the version of ts-standard installed locally in the project (strongly recommended, avoid the usage of global installation).

  1. Can you confirm you have Standard VS Code extension installed? And is it the new one or the old one ?

I'm using the new one. We should not use the old one as it is now deprecated and not anymore maintained/supported.

  1. Wondering if this could this be clearer in the doco? Shouldn't the default be local version? Maybe a settings example for those installing Standard locally?

Great suggestions! I also think that the default should be the local version instead of global one. :+1: I created a new issue for vscode-standard to have better config defaults and improve the documentation for the "How to use" part of the README. https://github.com/standard/vscode-standard/issues/261