Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint: Using recommended default rules with angularjs applications

I have recently added ESLint-ing into my angular application and soon realised I needed the eslint-plugin-angular plugin in order to get my application to be linted correctly.

Prior to this, I was using the extends property in my .eslintrc file and setting to eslint:recommended to make use of the eslint recommended rule set.

{
  "extends": "eslint:recommended"
}

I tested this worked by adding a trailing comma to an object definition in my code to make sure I saw an error appear from eslint.

Now, following the guides for the eslint-plugin-angular, I have also installed eslint-config-angular and I see that the quickest way to get started is using the shareable config.

If I use the extends angular config option in place of my current:

{
  "extends": "angular"
}

I no longer get my error thrown for an unexpected trailing comma.

So, is there a way I can use both angular and eslint:recommended in the extends config option? E.g:

{
  "extends": ["angular", "eslint:recommended"]
}

(which I know does not work)

If not, does this mean I have to create a rules config object in my .eslintrc to mimic the recommended ones from eslint?

{
  "extends": "angular",
  "rules" : {
    ...
  }
}
like image 582
mindparse Avatar asked Oct 05 '15 13:10

mindparse


People also ask

Can I use ESLint with angular?

We can use a property, defined in the ESLint configuration file, in order to know which version is used : Angular 1 or Angular 2. based on this property, you can create rules for each version.

How do you set rules in 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.

Does ESLint work with JavaScript?

ESLint is an open source project that helps you find and fix problems with your JavaScript code. It doesn't matter if you're writing JavaScript in the browser or on the server, with or without a framework, ESLint can help your code live its best life.

How many ESLint rules are there?

Keep in mind that we have over 200 rules, and that is daunting both for end users and the ESLint team (who has to maintain them). As such, any new rules must be deemed of high importance to be considered for inclusion in ESLint.


1 Answers

I can't speak to whether or not there was a code change between the time this SO article was entered but I am using "extends": ["eslint:recommended", "angular"] in my .eslintrc file and it is working fine. I have it at the same level as the "env" property.

My package.json file has eslint and eslint-plugin-angular versions 2.3.0 and 0.5.0, respectively.

like image 99
icfantv Avatar answered Oct 22 '22 15:10

icfantv