SonarLint and existing eslint rules

Hey, we’re thinking about migrating our eslint-based code analysis to SonarCloud.

We use several OS, Linux, Mac, Win and different editors (mostly VSCode and IntelliJ, but also Visual Studio sometimes). Currently, we have a pretty extensive eslint configuration to check our JS, TS (including react) code and we’re starting with Stylelint for styles.
It’s automated so that devs see errors live in their editors, it runs before commit and on CI, to make sure no PR can be merged if eslint detects errors. It’s been built by the entire team, so the rules are kind of compromise accepted by all devs.

When reading about Sonar, I came to the conclusion that we will have to integrate on the CI level to ensure our eslint rules are taken into account (not just built in Sonar rules).

But what about code editors? I can’t find any information if SonarLint can use eslint rules?

So far, I think we have these options:

  1. Make sure SonarLint uses eslint rules. Or…
  2. Keep eslint rules locally and on CI + enable Sonar to get additional quality gates, or…
  3. Find a way to migrate all our eslint rules to Sonar.

Do you know if 1 or 3 are possible? Is there a way to automatically migrate eslint rules to Sonar? Does Sonar use eslint under the hood?

Hey, any updates on this question?

Hey @kazag,

let me give you a quick (but not final) answer instead of the assigned personnel.
It is currently not possible to simply add ESLint rules to SonarLint itself, only when using in connected mode with SonarQube or SonarCloud as the rules are loaded via the connection.

I am not aware of the scope of the SonarJS analyzer and if it has a 1-1 replacement of ESLint rules, based on your answer I might forward this topic to the specific analyzer developers.

I’ve seen the option to use ESLint results in your CI build (e.g. THIS article) but in order to fulfill your third option you require something else. The issue is, for SonarCloud there is no possibility yet to add custom rules.

If you decide at one point to switch to SonarQube, there is the possibility to add coding rules. Maybe there is a community plugin with ESLint, but that is out of my scope or you want to write one on your own.

Again, feel free to answer if something is not clear or you have an idea and we can provide you with information on the feasibility.


Hey Tobias, thanks for the response!

Who’s the “assigned personnel” you mentioned? Should I tag someone to get definitive answers?

Hello @kazag,

Before answering, a question first: could you elaborate on why are you considering migrating from eslint to Sonar? Are you unsatisfied with eslint results?

Here are some answers to your questions:

  • there is no way to make Sonar run eslint rules out of the box.
  • as stated here and contrary to what was said it is not possible to define your own custom rules for JavaScript/TypeScript with Sonar
  • as answered previously there is a way to import eslint findings into Sonar. But eslint has to run first separately. This last point should cover the CI part.

Regarding code editors, unfortunately there is also no way to run eslint rules as part of SonarLint. My recommendation would be to go with option 2. In fact Sonar and eslint might not detect exactly the same problems so you can get the best of both worlds. As you did when customizing eslint you can also fine-tune the Quality Profile.

Let us know if you have other questions

1 Like

Hey Damien, thank you for your response!

Well, while the current eslint setup works fine, we’re struggling with managing it. We have shared rules but there is no easy way to make sure all teams use it and do not override :wink: Also, it doesn’t cover other languages we use in the company. So we thought that maybe SonarCloud will be easier to manage, in terms of common standards and a single tool to handle all languages.

Seems that the only option is #2 indeed.

One more question remains - is there a way to map eslint rules to sonar rules (or vice versa)? So we can compare which ones are missing and which ones overlap?

I don’t think such a mapping exists today unfortunately

1 Like