Codacy configuration file#
Codacy supports configuring certain advanced features through a configuration file, such as:
Ignoring files globally, for duplication, or a specific tool
Configuring a specific repository directory on which to start the analysis
Adding custom file extensions to languages, keeping in mind that some tools might not work out of the box with those extensions
Adjusting tool-specific configurations
- If a Codacy configuration file exists in your repository, the Ignored files settings defined on the Codacy UI don't apply and you must ignore files using the configuration file instead.
- To disable a tool you must use the Code patterns page instead.
- To exclude files from coverage analysis only, you must ignore them directly in the tool you're using to generate coverage reports and ensure that the reports you upload to Codacy don't include coverage information for those files.
To use a Codacy configuration file:
Create a text file with the name
.codacy.yamlon the root of your repository.
Add your settings to the configuration file based on the example template below.
The configuration file must start with a line containing a triple dash (
--- engines: rubocop: exclude_paths: - "config/test.yml" base_sub_dir: "test/baseDir" duplication: exclude_paths: - "config/test.yml" config: languages: - "ruby" languages: css: extensions: - ".scss" exclude_paths: - ".bundle/**" - "spec/**/*" - "benchmarks/**/*" - "**.min.js" - "**/tests/**"
Optionally, validate the syntax of your configuration file with the Codacy Analysis CLI by running the following command in the same folder as the Codacy configuration file:
codacy-analysis-cli validate-configuration --directory `pwd`
Syntax for ignoring files#
To ignore files, you must use the Java glob syntax to define one or more
exclude_paths patterns. For example:
|Example pattern||Ignored files|
||All files in the root of test|
||All files and directories inside test|
||All files inside sub-directories of test|
Which tools can be configured and which name should I use?#
You can use the Codacy configuration file to configure all tools supported by Codacy except the client-side tools.
The following are the tool names that must be used in the Codacy configuration file:
ameba bandit brakeman bundleraudit checkov checkstyle codacy-scalameta-pro codenarc coffeelint cppcheck credo csslint dartanalyzer detekt eslint flawfinder hadolint jacksonlinter jshint markdownlint phpcs phpmd pmd prospector psscriptanalyzer pylint pylintpython3 remark-lint revive rubocop roslyn scalastyle shellcheck sonarscharp sonarvb SQLint spectral stylelint swiftlint tailor tslint tsqllint
By default, Codacy tries to detect which language is used on each source code file, and uses a set of default options for identifying duplicate blocks of code. However, some false positives may occur.
The tools below support specifying the language or language version used in the source code files that you're analyzing, or tuning the duplication detection.
If you're using Cppcheck to analyze C or C++ source code files, add the following configuration to your Codacy configuration file to define the programming language you're using. The supported languages are
--- engines: cppcheck: language: c++
If you're using the PHP Compatibility coding standard for PHP_CodeSniffer, add the following configuration to your Codacy configuration file to define the PHP version you're using:
--- engines: phpcs: php_version: 5.5
Legacy Pylint 1.9.*#
If you're using the legacy Pylint 1.9.* to analyze Python source code files, add the following configuration to your Codacy configuration file to define the Python language version you're using. The supported versions are
--- engines: pylint: python_version: 2
If you're using Python 3.4.* or later as your programming language, disable the tool Pylint (legacy) and enable the tool Pylint on your repository Code patterns page instead. For more information, see What's New in Pylint 2.0.
PMD CPD (Duplication)#
Codacy uses PMD's Copy/Paste Detector (CPD) to identify duplicated blocks of code on the supported languages.
By default, Codacy only reports duplicate code blocks that have the following minimum token length, depending on the language:
|Language||Default minimum token length|
Besides this, Codacy runs PMD CPD with the following options enabled by default:
- Skip lexical errors: Skip files which can't be tokenized due to invalid characters instead of aborting CPD
- Ignore literals: Ignore number values and string contents when comparing text
- Ignore annotations: Ignore language annotations when comparing text
- Ignore usings: Ignore
usingdirectives in C# when comparing text
To use a different minimum token length or change any of the default options, add your settings to the Codacy configuration file based on the example template below.
If you configure
minTokenMatch on the Codacy configuration file, Codacy will use that value for all languages.
--- engines: duplication: minTokenMatch: 20 skipLexicalErrors: false ignoreLiterals: false ignoreIdentifiers: true ignoreAnnotations: false ignoreUsings: false
Share your feedback 📢
Did this page help you?
Thanks for the feedback! Is there anything else you'd like to tell us about this page?
255 characters left
We're sorry to hear that. Please let us know what we can improve:
255 characters left
Alternatively, you can create a more detailed issue on our GitHub repository.
Thanks for helping improve the Codacy documentation.
Edit this page on GitHub if you notice something wrong or missing.
If you have a question or need help please contact firstname.lastname@example.org.