question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to set global configuration?

See original GitHub issue

Editor plugins don’t always have ways to pass configuration to the process they call.

For example, in order to set the vim plugin neoformat to tell prettier to use single quotes, I’ve had to fork the plugin.

Other vim plugins for linting, for example, aren’t an issue because we have eslintrc.

I appreciate the complexity involved in having a prettierrc file (the spelling alone is awkward!) and I agree with the spirit of not adding too many options, but is there a way to set a global configuration that prettier could always use?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:46
  • Comments:30 (7 by maintainers)

github_iconTop GitHub Comments

31reactions
lydellcommented, Jan 26, 2017

What about being able to specify options in package.json?

{
  "name": "some-package",
  "prettierConfig": {
    "printWidth": 71,
    "tabWidth": 4,
    "singleQuote": true,
    "trailingComma": true,
    "bracketSpacing": false,
    "parser": "flow"
  },
  "dependencies": {
    "prettier": "0.11.0"
  }
}

It’s easy to read the closest package.json with read-pkg-up;

const readPkgUp = require("read-pkg-up");
let pkg;
try {
  pkg = readPkgUp.sync({normalize: false}).pkg;
} catch (e) {
  console.error(e);
}
const globalOptions = (pkg && pkg.prettierConfig) || {};

Or simply always from ./package.json:

let pkgString;

try {
  pkgString = fs.readFileSync("./package.json", "utf8");
} catch (e) {
  // Ignore no package.json found.
}

let pkg;

if (pkgString) {
  try {
    pkg = JSON.parse(pkgString);
  } catch (e) {
    console.error(e);
  }
}

const globalOptions = (pkg && pkg.prettierConfig) || {};
24reactions
evanliomaincommented, Jan 14, 2017

@jlongster ENV variable is a pain to use unlike a file configuration. Consider a project :

  • which can be run on windows, mac and linux ;
  • which is edited on vscode, vim, textmate, notepad (etc) according developper flavour

Consider you have several project on your laptop, and each one with a different configuration (because of different team)

A prettierrc, tracked in the version control (like git) is the nice way to share the configuration :

  • a new developper have it when he checkout it
  • it’s version controlled, with all benefit (history, PR review …)

ENV variable need a configuration for each team’s developper. It a big break to adopt it in a project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting up and activating global configurations - IBM
Edit the Global Configuration Provider URL property that is located under the Global Configuration SDK set of server properties. The value must be...
Read more >
Using the Global Configuration Object - AWS SDK for JavaScript
There are two ways to configure the SDK: Set the global configuration using AWS.Config . Pass extra configuration information to a service object....
Read more >
How to create global configuration file? - Stack Overflow
Or even lazier, just use include('config.php'); in place of the global $config alias. That way your config script will extract $config as local ......
Read more >
Setting global configuration - Documentation - CloudCannon
Global configuration files are the base level for defining options in the configuration cascade, allowing you to define these options here at a...
Read more >
global() configuration object - Rsyslog - Read the Docs
The global configuration object permits to set global parameters. Note that each parameter can only be set once and cannot be re-set thereafter....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found