Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 671
Ravindra Thorat Avatar asked Aug 24 '16 04:08

Ravindra Thorat


People also ask

How do you change the rule on ESLint?

ESLint comes with a large number of built-in rules and you can add more rules through plugins. You can modify which rules your project uses either using configuration comments or configuration files. To change a rule setting, you must set the rule ID equal to one of these values: "off" or 0 - turn the rule off.

What is Linebreak style?

What is Linebreak style? The linebreaks (new lines) used in windows operating system are usually carriage returns (CR) followed by a line feed (LF) making it a carriage return line feed (CRLF) whereas Linux and Unix use a simple line feed (LF).

What is CRLF vs LF?

Whereas Windows follows the original convention of a carriage return plus a line feed ( CRLF ) for line endings, operating systems like Linux and Mac use only the line feed ( LF ) character. The history of these two control characters dates back to the era of the typewriter.


1 Answers

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   // <----------   } }; 
like image 164
Stu Avatar answered Sep 21 '22 12:09

Stu