Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at "deno fmt" config #11857

Closed
bartlomieju opened this issue Aug 27, 2021 · 6 comments · Fixed by #11944
Closed

First pass at "deno fmt" config #11857

bartlomieju opened this issue Aug 27, 2021 · 6 comments · Fixed by #11944
Labels
deno fmt Related to the "deno fmt" subcommand or dprint feat new feature (which has been agreed to/accepted)

Comments

@bartlomieju
Copy link
Member

bartlomieju commented Aug 27, 2021

Ref #11686
Ref #11855

Analogous to adding configuration for deno lint I propose to allow configuring
deno fmt via a configuration file (and also using CLI flags as we don't want to have
options in config file that are not available via CLI). I propose to start
with minimal set of options; concretely allow only useTabs (that will help
with the accessibility #3695), tabWidth and singleQuote

{
  "compilerOptions": {
    "jsxFactory": "h"
  },

  "lint": {
    "files": {
      "include": ["testdata/"],
      "exclude": []
    },
    "rules": {
      "tags": ["recommended"],
      "include": [
        "ban-untagged-todo"
      ]
    }
  },

  "fmt": {
    "files": {
      "include": ["testdata/"],
      "exclude": []
    },
    "rules": {
      "useTabs": true,
      "indentWidth": 2,
      "singleQuote": true,
    }
  }
}

To keep the same configurability in CLI I suggest to add --rules-use-tabs, --rules-indent-width and --rules-single-quote flags to deno fmt subcommand.

Similar to linter specifying CLI flags takes precedence over configuration in config file.

Alternatives:

  • allow to configure only fmt.files and don't allow configuring rules,
    this would imply that we should switch default setting to use tabs instead
    of spaces to address deno fmt accessibility #3695
@grian32
Copy link
Contributor

grian32 commented Aug 27, 2021

I've put many of my thoughts on this issue in: #11553(although its only on spaces it should still apply here). But in extension to that I'd like to add that Prettier pretty much works for everyone even though it only has like 4 or 5 config options, if anyone complains about the config options we can more or less redirect them to Prettier(as also noted in the discussion minutes). I believe allowing tabs while keeping whats currently there as defaults will make more or less everyone happy. (Single quotes rule is also very nice for all the touch typers out there).

This becoming a thing would likely allow me to adapt deno fmt for all my deno projects as not being able to use 4 spaces/tabs has been stopping me from doing that.

I feel like this is enough to keep deno fmt opinionated ish while not hindering acessibility and adoption. If this becomes a thing I think it'd be fair to point people in the direction of other formatters for more granular configuration.

@wojpawlik
Copy link

Not every option is equally valuable. Prettier seems to regret adding some of them:

other options are harder to motivate in hindsight: --arrow-parens, --jsx-single-quote, --jsx-bracket-same-line and --no-bracket-spacing are not the type of options we’re happy to have.

I'd advocate for initially allowing only useTabs, for accessibility.

If you want tabWidth different than 2, just useTabs.

Single quotes rule is also very nice for all the touch typers out there

I disagree. You can still type single quotes and let the formatter normalize them to double quotes. So it's purely aesthetic preference.

@wojpawlik
Copy link

Deno 2 could default to "useTabs": true

@grian32
Copy link
Contributor

grian32 commented Aug 28, 2021

Not every option is equally valuable. Prettier seems to regret adding some of them:

Doesn't really change the fact that prettier's current options(by that i refer to the 4 or so that are in the config file: trailing commas, tab/space width, semis and single qeuotes) work for pretty much everyone and satisfy pretty much everyone.

I disagree. You can still type single quotes and let the formatter normalize them to double quotes. So it's purely aesthetic preference.

You are right, I had not thought of that at the time of writing that comment as I personally use " anyway 😆

@Skillz4Killz
Copy link

Is there any chance of convincing you not to support this config option at all?

@David-Else
Copy link

It would be great to get an option for Markdown that turns off the the hard wrapping at 80 characters: #9191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deno fmt Related to the "deno fmt" subcommand or dprint feat new feature (which has been agreed to/accepted)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants