How can I write a ESLint rule for "linebreak-style", changing depending on Windows or Unix?

Ravindra Thorat picture Ravindra Thorat · Aug 24, 2016 · Viewed 42.2k times · Source

As we all know, the linebreaks (new line) used in Windows are usually carriage returns (CR) followed by a line feed (LF) i.e. (CRLF) whereas, Linux and Unix use a simple line feed (LF)

Now, in my case, my build server uses supports Linux and Unix format so, below rule is working perfectly on build server:

linebreak-style: ["error", "unix"]

But I am doing development on Windows and I need to update rule on each git pull/git push as below,

linebreak-style: ["error", "windows"]

So, is there any way to write a generic linebreak-style rule to support both environments, Linux/Unix and Windows?

Note: I am using ECMAScript6[js], WebStorm[ide] for development

Any solutions/suggestions would be highly appreciated. Thanks!

Answer

Stu picture Stu · Mar 24, 2017

I spent time trying to find how to shut off the linkbreak-style and lost it due to reverting some of my code I thought others my like to have this as well.

In the .eslintrc file you can also set linebreak-style to 0 which shuts off the linebreak feature:

module.exports = {
  extends: 'google',
  quotes: [2, 'single'],
  globals: {
    SwaggerEditor: false
  },
  env: {
    browser: true
  },
  rules:{
    "linebreak-style": 0   // <----------
  }
};