Code Patterns

As a wise man once said, "You can't please everyone", and that is true for code patterns. But don't you worry! You can choose from a range of patterns to fit your needs.

 

1. Pattern details and filters


 

Each pattern has a title and a short description. To see a detailed explanation you can click on Show Details in the top right corner (mouse over the pattern and the Show Details option will appear):

 


 

The pattern explanation shows more detail about the issues it can detect and how to fix them.

You can filter the patterns by category using the side menu:

 


The issues detected by Codacy belong to one of the following categories:

Code Style - Code formatting and syntax problems. Ex: variable name style, enforce the use of brackets and quotation marks

Error Prone - Code that may hide bugs and language keywords that should be used with caution. Ex: == in Javascript or Option.get in Scala

Code Complexity - Highly complex methods and classes that should be refactored

Performance - Code that could have performance problems

Compatibility - Used mainly for frontend code, detects compatibility problems across different browser versions

Unused Code - Unused variables and methods, code that can't be reached

Security - All security problems

Documentation - Detects methods and classes that do not have the correct comment annotations

 

2. Configure your project patterns


 

To configure the patterns used to analyse your project simply click on the checkbox on the left of the title:

 


 

When you change the enabled patterns you can reanalyse your project. To do that, just enter the latest commit from your list on the Commit view and click to reanalyse

 

 

3. Account vs Project Patterns


 Account Patterns

Here you can change the default selection of patterns by enabling/disabling them for all future projects added by you. Just go to Account Settings -> Default Patterns:

Screen_Shot_2018-01-12_at_11.21.22.png
Account Patterns

Project Patterns

Here you can specify the patterns you want to use for each project. When you change your account patterns it doesn't affect pattern selection for projects already added. You can go to Code patterns:

Screen_Shot_2019-06-18_at_17.57.58.pngScreen_Shot_2019-06-18_at_17.57.58.png
Project Patterns

  

4. I have my own tool configuration file


If you have configuration files for your static analysis tool of choice, just add it to the root of your repository and Codacy will pick it up automatically.

Supported Configuration files

Codacy currently supports configuration files for several tools. To have results accordingly to your configuration file, you need to go to the Code Patterns view and select "Configuration file" for the respective tool and select the option as shown in the example below.

Screen_Shot_2017-10-09_at_18.54.12.png

The known file names for each tool are the following:

 

Tool name Language Files detected Other info
CSSLint CSS .csslintrc  
Checkstyle Java checkstyle.xml Supports config file in other dirs than root and can search up to 5 dirs into the project. 
detekt Kotlin

default-detekt-config.yml, detekt.yml

Supports config file in other dirs than root and can search up to 5 dirs into the project. 
Findbugs Java findbugs.xml, findbugs-includes.xml, findbugs-excludes.xml Supports config file in other dirs than root and can search up to 5 dirs into the project. 
Findbugs Security Java findbugs.xml, findbugs-includes.xml, findbugs-excludes.xml  Supports config file in other dirs than root and can search up to 5 dirs into the project.
PMD Apex, Java, Javascript, JSP, XML, Velocity and Visualforce ruleset.xml, apex-ruleset.xml Supports config file in other dirs than root and can search up to 5 dirs into the project. 
ESLint JavaScript, JSON

.eslintrc.js, .eslintrc.yaml,.eslintrc.yml, .eslintrc.json,
.eslintrc

Plugins 
JSHint JavaScript .jshintrc  
PHP CodeSniffer PHP  phpcs.xml, phpcs.xml.dist  
PHPMD PHP  codesize.xml  
Bandit  Python  bandit.yml, .bandit

To solve flagged valid Python "assert" statements, create a bandit.yml in the root of the repo containing: skips: ['B101']

 
Pylint Python pylintrc, .pylintrc  Plugins 
Prospector Python .landscape.yml, .landscape.yaml, landscape.yml, landscape.yaml,
.prospector.yml, .prospector.yaml, prospector.yml ,prospector.yaml
 
Brakeman Ruby  config/brakeman.yml  
Rubocop Ruby  .rubocop.yml  
ScalaStyle Scala  scalastyle_config.xml, scalastyle-config.xml   
SCSSLint SASS  .scss-lint.yml   
Tailor Swift   .tailor.yml  
SwiftLint Swift .swiftlint.yml  
TSLint TypeScript   tslint.json  
Hadolint Docker .hadolint.yaml  
Stylelint LESS, SASS, CSS .stylelintrc, stylelint.config.js, .stylelintrc.json, .stylelintrc.yaml, .stylelintrc.js, stylelintrc.yml  Supports config file in other dirs than root and can search up to 5 dirs into the project.
Remark-Lint Markdown .remarkrc, .remarkrc.json, .remarkrc.yaml, .remarkrc.yml, .remarkrc.js  

 

5. Configuring the project root directory for analysis

By default, Codacy starts the analysis on the repository's root. However, you can set up a different project folder on which to start the analysis using a Codacy configuration file. This file needs to be named ".codacy.yaml" or ".codacy.yml" and must be placed in the project's root.

See example below:

---
engines:
rubocop:
enabled: true
exclude_paths:
- config/engines.yml
base_sub_dir: test/baseDir
 
Have more questions? Submit a request

0 Comments

Article is closed for comments.