Home Developer Monorepo with Static Code Analysis

Monorepo with Static Code Analysis

Author

Date

Category

Monorepo is short for monorepository. With it, code for many projects is stored in the same repository. I like to use monorepo for NodeJS and React projects but sometimes it’s difficult to use monorepo when performing static code analysis (SCA), particularly when it comes to code coverage and code patterns. However, Codacy’s tool helps with this. Let me show you how below:

Code Coverage

Because many projects are stored in the same repository, many coding languages co-exist. Therefore, code coverage (checking code for errors) becomes complicated.  

A tool that enables reports in multiple programming languages is helpful to address these concerns. With Codacy, I receive backend and frontend reports for each language in each repo.  The weight is also calculated.  

You can see the documentation here and an excerpt below:

Code Patterns

I also worry about code patterns when using monorepos with static code analysis. Linting tools detect code patterns. However, these tend to be specific to coding languages. With multiple projects in multiple coding languages things can get tricky.

Example with ESLint

We’ll focus on ESLint in our example as it is a top linting tool for JavaScript developers with many useful plugins.  Although ESLint alone doesn’t solve for issues of having two different projects in the same repository, there is a work around:

Solution

In the src folder of the project create a client and server folder.  This is where it makes sense to have the .eslintrs.js file. In this, common rules can be set (or left empty).  

monorepo

Then, inside each client or server folder, an additional .eslintr.js, extending the src file can be added. This overrides the previously defined rules.

Locally seems to be going as expected. Now, to Codacy. Under the “Code Patterns” tab, I chose “Configuration File” instead of the Rules from the UI.

We get the same, expected results:

As you can see, with these techniques (and some help from Codacy) monorepo should no longer be an obstacle with static code analysis.

Want more from Helio, a Solutions Engineer at Codacy? Follow him on twitter.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Subscribe to our newsletter

To be updated with all the latest news, offers and special announcements.

Recent posts

New Public Product Roadmap – See What's In Store For Q1

We’re excited to release a public product roadmap for 2020.  Now, those outside Codacy can see what our team is working on...

4 Trends To Boost Software Quality in 2020

Today’s abundance of technology has created an increased demand for higher software quality. With companies aware of this, spending on IT worldwide...

7 Reasons Dev Teams Choose Codacy Over Other Automated Code Review Tools

Today more than 100,000 developers at leading global organizations like PayPal and Adobe across industries use Codacy (read customer case studies). ...

Introducing GitHub Sync For Seamless User Management

Announcing GitHub Sync: Synced Organizations For GitHub We are thrilled to announce "GitHub Sync" -- automatic user and repository...

Ringing In 2020 With Codacy

It’s been an exciting 2019 at Codacy and we expect more excitement in 2020. Over the last 12 months we’ve built out...