Home Education Tutorials Configure Codacy: Use Your Own Conventions

Configure Codacy: Use Your Own Conventions

Author

Date

Category

We show you how to Configure Codacy in this blog post originally written by Saptak Sengupta. Saptak is a full stack developer in FOSSASIA and a participant in Google Summer of Code 2016 under FOSSASIA doing the project Open Event Organizer Server. He is an Information Technology grad from the Indian Institute of Information Technology, Allahabad.

Saptak is an open source enthusiast, a freelancer, and loves web app and chrome extension development.

Configure Codacy: Use Your Own Conventions

configure codacy

All the developers agree on at least one thing — writing clean code is necessary. Because as someone anonymous said, always write a code as if the developer who comes after you is a homicidal maniac who knows your address. So, yeah, writing clean code is very important. Codacy helps in code reviewing and code quality monitoring. You can set codacy in any of your github project. It automatically identifies new static analysis issues, code coverage, code duplication and code complexity evolution in every commit and pull request.

To maintain a clean code, codacy is really helpful as it reviews all the pull requests, commits and the entire code for you based on code style, code coverage and other metrics..

But as we all know, a perfect code style is very difficult to determine. What is more important is readability and maintainability of the code rather than following a strict code style rules. There are various lint guides such as csslint, jslint, pylint, PEP-8 which give you a good idea about clean code style but they are guidelines rather than rules. So what is important is whatever convention you follow, you follow throughout the code..

So you may need to make some changes in the codacy configuration to check the codebase according to your organisation’s coding conventions rather than a standard lint issue. Unfortunately, there is not very good documentation about this. So, I will share a few common changes I found out myself.

Enable / Disable Checks

Firstly you need to have access for the repository to set up proper checks. Otherwise you can only view the reports. If you have proper write access to the repository in github, you will see 2 additional options in the sidebar –

Screenshot from 2016-07-23 01:26:03
  • Code Pattern — List of all the checks available on codacy to review your code
  • Settings — Settings involving github repository url, codacy badge, repository name, etc.

To enable or disable a check, you need to click on code patterns options on sidebar. On clicking you will find a page like this:

Screenshot from 2016-07-23 01:33:36

Now to add or remove a check, you just need to click the checkbox and the configuration is automatically updated.

To see the checks based on language or category, you can click the dropdowns above to select a particular language or category to get checks related to that. For example, there is a javascript lint issue which says “Enforce ===”.

Screenshot from 2016-07-23 01:37:15

This might not be suitable for your project or maybe your team doesn’t follow this convention, so you can ignore this check by clicking on the checkbox.

Modify Checks

Now the biggest confusion or controversial point that we all have while talking about clean code is Naming Conventions. There is always an argument whether to use snake_case or camelCase or PascalCase. Different lints consider different naming conventions to be correct. However it is believed that an entire codebase should follow a single naming convention. So, what to do?

Well there is a way to configure this and all other checks. For example, to change naming convention for python codes, you can filter according to python and code style. The you would find a check “Enforces naming convention”. To modify the check, click on the “show details” button which you get on hovering over the rule. On clicking the button, you will see something like this:

Screenshot from 2016-07-23 01:44:14

As you can see, there are certain regular expressions present corresponding to various identifier names. Now if you know about regular expressions, you can figure out what this regular expressions. Right now, for our project, the regular expression set for variable type is “[a-z_][a-z0–9_]{0,30}$”. This regular expression basically means it allows any variable name in snake_case which has a length between 1 and 29. Now you might feel like you want the variable names to be of at least 5 letters. So you can modify it as “[a-z_][a-z0–9_]{4,30}$”. Or suppose you want the variable names to start with uppercase letter. So your regular expression should be something like “[A-Z_][a-z0–9_]{0,30}$”. You can check your regular expression our with some example names in regexr.com.

After you have modified the regular expression, click on save parameters. This enforces the new regex to be followed the next time codacy reviews your code.

Re-analyze

After modifying the checks, you might want to re-analyze certain pull requests or commits. This won’t be done automatically in an old pull request at that very instance. But you can again enforce this. Click on “Pull Requests” in the sidebar. Select the pull request you want to re-analyze. It would look something like this.

Screenshot from 2016-07-23 01:55:14

Beside the “CURRENT STATUS: Analysed” you can find a recycle button

Screenshot from 2016-07-23 01:55:14

. Click on this button, and it will start analyzing the pull request according to the new configurations.


P.S. We just published an ebook: “The Ultimate Guide to Code Review” based on a survey of 680+ developers. Enjoy!


About Codacy

Codacy is used by thousands of developers to analyze billions of lines of code every day!

Getting started is easy – and free! Just use your  GitHub, Bitbucket or Google account to sign up.

GET STARTED

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

Free Codacy Pro account to fight COVID-19

Our hearts go out to everyone who has been directly or indirectly impacted by the global coronavirus (COVID-19) pandemic. We are committed...

Introducing GitHub Apps for improved user access control

We are very excited to announce our recent migration to GitHub Apps to improve the experience of GitHub Cloud users. Now, you...

How Agile & Container Technology led to the rise of enterprise DevSecOps

New development processes and open-source technologies have shifted the technology security landscape for enterprises. Previously a separate security department often dealt with...

Spring tech events with Codacy: Coverage & what's next

Although many Spring tech events are being canceled or turning virtual due to coronavirus we are fortunate to have already participated in...

Top 6 items for your code review checklist

At Codacy we set high standards, and care about the quality of the code we produce. In order to provide optimal experiences...