Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get my projects to use a global .eslintrc file by default?

I use atom text editor. Here are the steps I took to get my linter working with React and ES6:

  • install atom-react package
  • when I start a new project, I run npm install --save eslint
  • create an .eslintrc file in my project folder (this can be done either manually or running command eslint --init, which helps create the file with a series of questions that I answer on the command line)

I don't want to have to create the .eslintrc everytime I start coding a new project. I want to use the global .eslintrc file, which I found when I:

  • Go to Atom > Preferences
  • Click on Open Config Folder
  • Click on .atom > packages > linter > .eslintrc

How can I make it so that when I fire up a new file and start coding I already get the options defined in this global file?

In particular, this is the setup I am using in individual projects:

{
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "sourceType": "module"
  },
  "env": {
    "es6": true
  },
  "plugins": [
    "eslint-plugin-react"
  ]
}

And I want this to be the default.

like image 780
evianpring Avatar asked Sep 01 '16 15:09

evianpring


People also ask

Should I install ESLint globally?

It is also possible to install ESLint globally rather than locally (using npm install eslint --global ). However, this is not recommended, and any plugins or shareable configs that you use must be installed locally in either case.


2 Answers

Go to settings --> packages --> linter-eslint settings. On that menu, look for the .eslintrc Path option. For your particular preference, you would put ~/.atom/packages/linter/.eslintrc in that field. Your .eslintrc is now being used globally across all of your projects.

like image 116
Matt Schuchard Avatar answered Oct 19 '22 00:10

Matt Schuchard


You could use the configuration cascading to your advantage : http://eslint.org/docs/user-guide/configuring#configuration-cascading-and-hierarchy

workspace
     |
     |_ .eslintrc (global, root = true)
     |
     |_ project-1
           |       
           |_ .eslintrc (project specific, if you need to overwrite some rules)


From the eslint documentation:

enter image description here

like image 33
Fab313 Avatar answered Oct 19 '22 00:10

Fab313