Prettier-atom: Using editor preferences

Created on 13 Feb 2018  路  15Comments  路  Source: prettier/prettier-atom

Updating to [email protected] I've noticed my editor preference for single quotes isn't being respected. It's formatting everything to be double quotes.

I'm only using prettier, and have the eslint integration disabled. I do have an eslint config, but that also is set to use single quotes.

I'm guessing this may be a result of #374?

Atom version: 1.23.3
prettier-atom version: 0.50.0
prettier version: 1.10.2
prettier-eslint version: 8.8.1
prettier-atom configuration: {
  "formatOnSaveOptions": {
    "enabled": true,
    "excludedGlobs": [
      "package.json"
    ],
    "respectEslintignore": true,
    "showInStatusBar": false,
    "javascriptScopes": [
      "source.js",
      "source.jsx",
      "source.js.jsx",
      "source.babel",
      "source.js-semantic",
      "text.html.basic",
      "text.html.vue"
    ],
    "typescriptScopes": [
      "source.ts",
      "source.tsx",
      "source.ts.tsx"
    ],
    "cssScopes": [
      "source.css",
      "source.less",
      "source.css.less",
      "source.scss",
      "source.css.scss",
      "source.css.postcss"
    ],
    "jsonScopes": [
      "source.json"
    ],
    "graphQlScopes": [
      "source.graphql"
    ],
    "markdownScopes": [
      "source.md",
      "source.gfm",
      "text.md"
    ],
    "vueScopes": [
      "text.html.vue"
    ],
    "whitelistedGlobs": [],
    "isDisabledIfNotInPackageJson": false,
    "isDisabledIfNoConfigFile": false
  },
  "prettierOptions": {
    "arrowParens": "always",
    "singleQuote": true,
    "trailingComma": "all",
    "bracketSpacing": true,
    "semi": true,
    "useTabs": false,
    "jsxBracketSameLine": false,
    "printWidth": 80,
    "tabWidth": "auto",
    "parser": "babylon"
  },
  "silenceErrors": false,
  "useEslint": false,
  "useStylelint": false,
  "useEditorConfig": true,
  "prettierEslintOptions": {
    "prettierLast": false
  }
}
bug

Most helpful comment

I'm mainly referring to eslint sharable config.

Ah gotcha.

Is there anything that atom would keep in it's settings, hanging around from a previous version, that could be impacting this?

I don't know what's causing it yet. The good news is I can reproduce which is always the hardest part haha. I'll let you know what I find.

All 15 comments

I'm assuming it's finding a .prettierrc, prettier property within your package.json or some other prettier configuration found via cosmiconfig.

374 made it so your editor preferences are ignored in the event a prettier configuration is found. This is to make sure teams can share styling preferences in a project without people's editors overriding them (in this case prettier-atom).

If you're still confused, please post a sample repo on github that reproduces your issue. I will figure out what's going on if you do that.

I don't have any of those things, specifically because prettier config isn't shareable. Without a shareable config I can't assume prettier will work in all my projects, at least without manually copying the config from one project to another. I specifically rely on my editor settings as a result.

I just tried in https://github.com/BarryThePenguin/barrythepenguin.github.io

There is no prettier config in that repository, but my editor still formats with double quotes.

I even checked for ~/.prettierrc, but no luck

Thanks for the info.

because prettier config isn't shareable

Mind explaining what you mean by this? The most common scenario is for a prettier configuration to live in a repository and be shared by anyone who works off of it. Even if it's just yourself, as long as the prettier configuration travels with the repo, you should get common formatting whether you're working on a windows pc, a mac, etc. The editor-specific configurations should generally be used for one-off files which aren't a part of a repository. If you have a different use-case then I'm interested in what it is so I can better understand how people use this tool.

https://github.com/BarryThePenguin/barrythepenguin.github.io

Thanks. I'm testing this now and will post back soon.

I even checked for ~/.prettierrc, but no luck

fyi it should stop at the repository root (checks for common version control directories like .git)

Mind explaining what you mean by this?

Sure. I'm mainly referring to eslint sharable config. Other tools have similar support eg: nyc, stylelint, and remark

I understand this might not fit in with the goals of prettier having as little configuration as possible, but at the moment there is no way to share a single prettier configuration across multiple projects.

Kind of a different issue though! 馃惓

Is there anything that atom would keep in it's settings, hanging around from a previous version, that could be impacting this?

I'm mainly referring to eslint sharable config.

Ah gotcha.

Is there anything that atom would keep in it's settings, hanging around from a previous version, that could be impacting this?

I don't know what's causing it yet. The good news is I can reproduce which is always the hardest part haha. I'll let you know what I find.

So before I explain what's going on (seems to be a bug that I will create a PR to fix tomorrow) - can you say whether you're expecting the editorconfig's indent_style = tab or prettier's Use Tabs: false to take precedence?

but at the moment there is no way to share a single prettier configuration across multiple projects.

This isn't true. Prettier will traverse the entire file tree upward until it finds a configuration. So, if you're source code is in something like ~/source/prettier-atom, and you have a .prettierrc in the root of your home directory ~/.prettierrc, it will find it and use it.

However, at this time prettier-atom doesn't fully support this functionality. It will get better in the future when I have time to work on it again after some crunch time at work. :D

I'd expect prettier to use the editorconfig setting, if there is no prettier config

Long answer... I'd expect the order to be

  1. project settings

    • including .editorconfig, .prettierrc and .eslintrc, if there's any discrepancies here I'd expect the user/team to make sure each tool align

  2. user settings

    • including editor settings, global machine config, or anything else the user can change outside the project settings

This isn't true. Prettier will traverse the entire file tree upward...

This works for the individual, however doesn't work for multiple machines, or multiple people on a team.

It'd be great if prettier core added an option for shareable config...

Prettier will traverse the entire file tree upward until it finds a configuration

Yeah at first I thought it used find-project-root to stop at vcs directories, but I guess that's only used for editorconfig's configuration file. cosmiconfig stops at the user's home directory. I wonder why differing directories would be used between editorconfig and prettier

Sorry for the misinformation, I was too confident in my memory ><

It'd be great if prettier core added an option for shareable config

I see the benefits of that structure. Though I also agree with your statement how it conflicts with their zero-config culture.

I'd expect the order to be

Good - thanks for clarifying. I asked because I don't use editorconfig and I have a biased view over how the order should be.

So the bug in my PR is the following:

  • Prettier allows us to resolve a configuration optionally including those derived from the .editorconfig. I implemented the logic:
if a prettier configuration is resolved in the project, then use that
otherwise use the settings found in the plugin

So because you had the editorconfig integration checked, that logic was skipping the plugin settings as configuration was resolved. Instead the logic should be

if a prettier configuration exists, then resolve the project's configuration
otherwise use the settings found in the plugin (merged with editorconfig)

I'm sorry for the hassle @BarryThePenguin - and thanks for reporting 馃憤

In order to maintain consistency with expectations from the Prettier documentation we follow this logic. We only want to rely on editor settings when we have no other option as it lead to confusing results in the first place.

global machine config, or anything else the user can change outside the project settings

This will be supported in the future, once I finish fixing up some of Prettier's internals that happen to be broken. It is certainly on the roadmap!

It'd be great if prettier core added an option for shareable config...

While I totally agree, this isn't something Prettier can easily add support for due to their use of cosmiconfig. You could always look into moving packages into monorepos using something like lerna, as that is a popular option, assuming that will fit your needs. It may be something I look into in the future.

I wonder why differing directories would be used between editorconfig and prettier

Prettier reluctantly added minimal support for .editorconfig as it's not _really_ relevant to what Prettier specifically does.

if a prettier configuration exists, then resolve the project's configuration...

That's the plan I outlined above, @olsonpm 馃槢 EDIT: I guess the .editorconfig support wasn't explicit in my comment. Sorry!

That's the plan I outlined above, @olsonpm 馃槢

It will be really confusing when resolveConfigWithFilePath resolves a config with no file path 馃槢

It's not done!!! haha. I've been busy.

Thanks all for the detailed information. Glad I could help 鈽猴笍

really though - I was thinking about resolveConfig entirely incorrectly. Because it's also meant to be used as a cli with no explicit configuration, it's just resolving the configuration to be passed to prettier for formatting. I kept thinking of it as something that resolved the actual .prettierrc. Lesson learned!

Was this page helpful?
0 / 5 - 0 ratings