Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type LanguagesConfig struct {
Name string `yaml:"name" json:"name"`
Languages []string `yaml:"languages" json:"languages"`
Extensions []string `yaml:"extensions" json:"extensions"`
Files []string `yaml:"files" json:"files"`
} `yaml:"tools" json:"tools"`
}

Expand Down Expand Up @@ -90,19 +91,22 @@ func GetFileExtension(filePath string) string {
return strings.ToLower(filepath.Ext(filePath))
}

// IsToolSupportedForFile checks if a tool supports a given file based on its extension
// IsToolSupportedForFile checks if a tool supports a given file based on its extension or filename
func IsToolSupportedForFile(toolName string, filePath string, langConfig *LanguagesConfig) bool {
if langConfig == nil {
// If no language config is available, assume all tools are supported
return true
}

fileExt := GetFileExtension(filePath)

if fileExt == "" {
// If file has no extension, assume tool is supported
return true
}

fileName := filepath.Base(filePath)

for _, tool := range langConfig.Tools {
if tool.Name == toolName {
// If tool has no extensions defined, assume it supports all files
Expand All @@ -117,6 +121,13 @@ func IsToolSupportedForFile(toolName string, filePath string, langConfig *Langua
}
}

// Check if filename is supported by this tool (exact match)
for _, file := range tool.Files {
if strings.EqualFold(file, fileName) {
return true
}
}

// Extension not found in tool's supported extensions
return false
}
Expand Down
21 changes: 19 additions & 2 deletions cmd/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,31 @@ func TestIsToolSupportedForFile(t *testing.T) {
Name string `yaml:"name" json:"name"`
Languages []string `yaml:"languages" json:"languages"`
Extensions []string `yaml:"extensions" json:"extensions"`
Files []string `yaml:"files" json:"files"`
}{
{
Name: "pylint",
Languages: []string{"Python"},
Extensions: []string{".py"},
Files: []string{},
},
{
Name: "eslint",
Languages: []string{"JavaScript", "TypeScript"},
Extensions: []string{},
Files: []string{},
},
{
Name: "cppcheck",
Languages: []string{"C", "CPP"},
Extensions: []string{".c", ".cpp", ".h", ".hpp"},
Files: []string{},
},
{
Name: "trivy",
Languages: []string{"Multiple"},
Extensions: []string{},
Extensions: []string{".yaml", ".yml"},
Files: []string{"requirements.txt"},
},
},
}
Expand Down Expand Up @@ -111,7 +121,7 @@ func TestIsToolSupportedForFile(t *testing.T) {
},
{
name: "Tool with no extensions specified",
toolName: "trivy",
toolName: "eslint",
filePath: "any.file",
config: langConfig,
want: true,
Expand All @@ -130,6 +140,13 @@ func TestIsToolSupportedForFile(t *testing.T) {
config: nil,
want: true,
},
{
name: "Trivy with requirements.txt",
toolName: "trivy",
filePath: "requirements.txt",
config: langConfig,
want: true,
},
}

for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion codacy-client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func GetToolsVersions() ([]domain.Tool, error) {
}

// GetRepositoryLanguages fetches the languages for a repository
func GetRepositoryLanguages(initFlags domain.InitFlags) ([]domain.Language, error) {
func GetRepositoryLanguages(initFlags domain.InitFlags) ([]domain.RepositoryLanguage, error) {
baseURL := fmt.Sprintf("%s/api/v3/organizations/%s/%s/repositories/%s/settings/languages",
CodacyApiBase,
initFlags.Provider,
Expand Down
16 changes: 13 additions & 3 deletions domain/language.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
package domain

// Language represents a language in the Codacy API
type Language struct {
// RepositoryLanguage represents a language in the Codacy API
type RepositoryLanguage struct {
Name string `json:"name"`
CodacyDefaults []string `json:"codacyDefaults"`
Extensions []string `json:"extensions"`
DefaultFiles []string `json:"defaultFiles"`
Enabled bool `json:"enabled"`
Detected bool `json:"detected"`
}

// LanguagesResponse represents the structure of the languages response
type LanguagesResponse struct {
Languages []Language `json:"languages"`
Languages []RepositoryLanguage `json:"languages"`
}

// Language represents a processed language with combined extensions and files
type Language struct {
Name string
Extensions []string
Files []string
}

// LanguageTool represents a language tool with its file extensions from the API
type LanguageTool struct {
Name string `json:"name"`
FileExtensions []string `json:"fileExtensions"`
Files []string `json:"files"`
}

// LanguageToolsResponse represents the structure of the language tools API response
Expand All @@ -30,6 +39,7 @@ type ToolLanguageInfo struct {
Name string `yaml:"name"`
Languages []string `yaml:"languages,flow"`
Extensions []string `yaml:"extensions,flow"`
Files []string `yaml:"files,flow"`
}

// LanguagesConfig represents the structure of the languages configuration file
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/config-discover/expected/codacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ tools:
- pmd@7.11.0
- pylint@3.3.6
- semgrep@1.78.0
- trivy@0.59.1
- trivy@0.59.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ tools:
- name: dartanalyzer
languages: [Dart]
extensions: [.dart]
files: []
- name: eslint
languages: [Javascript, TypeScript]
extensions: [.js, .jsm, .jsx, .mjs, .ts, .tsx, .vue]
files: []
- name: lizard
languages: [C, CPP, CSharp, Erlang, Fortran, Go, Java, Javascript, Kotlin, Lua, Objective C, PHP, Python, Ruby, Rust, Scala, Solidity, Swift, TypeScript]
extensions: [.c, .cc, .cpp, .cs, .cxx, .gemspec, .go, .h, .hpp, .ino, .java, .jbuilder, .js, .jsm, .jsx, .kt, .kts, .m, .mjs, .opal, .php, .podspec, .py, .rake, .rb, .rlib, .rs, .scala, .swift, .ts, .tsx, .vue]
files: []
- name: pmd
languages: [Apex, JSP, Java, Javascript, PLSQL, SQL, Velocity, VisualForce, XML]
extensions: [.cls, .component, .fnc, .java, .js, .jsm, .jsp, .jsx, .mjs, .page, .pck, .pkb, .pkh, .pks, .plb, .pld, .plh, .pls, .pom, .prc, .sql, .tpb, .tps, .trg, .trigger, .tyb, .typ, .vm, .vue, .wsdl, .xml, .xsl]
files: []
- name: pylint
languages: [Python]
extensions: [.py]
files: []
- name: revive
languages: [Go]
extensions: [.go]
files: []
- name: semgrep
languages: [Apex, C, CPP, CSharp, Dockerfile, Go, Java, Javascript, Kotlin, PHP, PLSQL, Python, Ruby, Rust, SQL, Scala, Shell, Swift, Terraform, TypeScript, YAML]
extensions: [.bash, .c, .cc, .cls, .cpp, .cs, .cxx, .dockerfile, .fnc, .gemspec, .go, .h, .hpp, .ino, .java, .jbuilder, .js, .jsm, .jsx, .kt, .kts, .mjs, .opal, .pck, .php, .pkb, .pkh, .pks, .plb, .pld, .plh, .pls, .podspec, .prc, .py, .rake, .rb, .rlib, .rs, .scala, .sh, .sql, .swift, .tf, .tpb, .tps, .trg, .trigger, .ts, .tsx, .tyb, .typ, .vue, .yaml, .yml]
files: []
- name: trivy
languages: [C, CPP, CSharp, Dart, Dockerfile, Elixir, Go, JSON, Java, Javascript, PHP, Python, Ruby, Rust, Scala, Swift, Terraform, TypeScript, XML, YAML]
extensions: [.c, .cc, .cpp, .cs, .cxx, .dart, .dockerfile, .ex, .exs, .gemspec, .go, .h, .hpp, .ino, .java, .jbuilder, .js, .jsm, .json, .jsx, .mjs, .opal, .php, .podspec, .pom, .py, .rake, .rb, .rlib, .rs, .scala, .swift, .tf, .ts, .tsx, .vue, .wsdl, .xml, .xsl, .yaml, .yml]
files: [.deps.json, Berksfile, Capfile, Cargo.lock, Cheffile, Directory.Packages.props, Dockerfile, Fastfile, Gemfile, Gemfile.lock, Guardfile, Package.resolved, Packages.props, Pipfile.lock, Podfile, Podfile.lock, Rakefile, Thorfile, Vagabondfile, Vagrantfile, build.sbt.lock, composer.lock, conan.lock, config.ru, go.mod, gradle.lockfile, mix.lock, package-lock.json, package.json, packages.config, packages.lock.json, pnpm-lock.yaml, poetry.lock, pom.xml, pubspec.lock, requirements.txt, uv.lock, yarn.lock]
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ tools:
- name: eslint
languages: [Javascript]
extensions: [.js, .jsm, .jsx, .mjs, .vue]
files: []
- name: lizard
languages: [Java, Javascript, Python]
extensions: [.java, .js, .jsm, .jsx, .mjs, .py, .vue]
files: []
- name: pmd
languages: [Java, Javascript]
extensions: [.java, .js, .jsm, .jsx, .mjs, .vue]
files: []
- name: pylint
languages: [Python]
extensions: [.py]
files: []
- name: semgrep
languages: [Java, Javascript, Python]
extensions: [.java, .js, .jsm, .jsx, .mjs, .py, .vue]
files: []
- name: trivy
languages: [JSON, Java, Javascript, Python]
extensions: [.java, .js, .jsm, .json, .jsx, .mjs, .py, .vue]
extensions: [.java, .js, .jsm, .json, .jsx, .mjs, .py, .vue]
files: [Pipfile.lock, gradle.lockfile, package-lock.json, package.json, pnpm-lock.yaml, poetry.lock, pom.xml, requirements.txt, uv.lock, yarn.lock]
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ tools:
- name: dartanalyzer
languages: [Dart]
extensions: [.dart]
files: []
- name: eslint
languages: [Javascript, TypeScript]
extensions: [.js, .jsm, .jsx, .mjs, .ts, .tsx, .vue]
files: []
- name: lizard
languages: [C, CPP, CSharp, Erlang, Fortran, Go, Java, Javascript, Kotlin, Lua, Objective C, PHP, Python, Ruby, Rust, Scala, Solidity, Swift, TypeScript]
extensions: [.c, .cc, .cpp, .cs, .cxx, .gemspec, .go, .h, .hpp, .ino, .java, .jbuilder, .js, .jsm, .jsx, .kt, .kts, .m, .mjs, .opal, .php, .podspec, .py, .rake, .rb, .rlib, .rs, .scala, .swift, .ts, .tsx, .vue]
files: []
- name: pmd
languages: [Apex, JSP, Java, Javascript, PLSQL, SQL, Velocity, VisualForce, XML]
extensions: [.cls, .component, .fnc, .java, .js, .jsm, .jsp, .jsx, .mjs, .page, .pck, .pkb, .pkh, .pks, .plb, .pld, .plh, .pls, .pom, .prc, .sql, .tpb, .tps, .trg, .trigger, .tyb, .typ, .vm, .vue, .wsdl, .xml, .xsl]
files: []
- name: pylint
languages: [Python]
extensions: [.py]
files: []
- name: revive
languages: [Go]
extensions: [.go]
files: []
- name: semgrep
languages: [Apex, C, CPP, CSharp, Dockerfile, Go, Java, Javascript, Kotlin, PHP, PLSQL, Python, Ruby, Rust, SQL, Scala, Shell, Swift, Terraform, TypeScript, YAML]
extensions: [.bash, .c, .cc, .cls, .cpp, .cs, .cxx, .dockerfile, .fnc, .gemspec, .go, .h, .hpp, .ino, .java, .jbuilder, .js, .jsm, .jsx, .kt, .kts, .mjs, .opal, .pck, .php, .pkb, .pkh, .pks, .plb, .pld, .plh, .pls, .podspec, .prc, .py, .rake, .rb, .rlib, .rs, .scala, .sh, .sql, .swift, .tf, .tpb, .tps, .trg, .trigger, .ts, .tsx, .tyb, .typ, .vue, .yaml, .yml]
files: []
- name: trivy
languages: [C, CPP, CSharp, Dart, Dockerfile, Elixir, Go, JSON, Java, Javascript, PHP, Python, Ruby, Rust, Scala, Swift, Terraform, TypeScript, XML, YAML]
extensions: [.c, .cc, .cpp, .cs, .cxx, .dart, .dockerfile, .ex, .exs, .gemspec, .go, .h, .hpp, .ino, .java, .jbuilder, .js, .jsm, .json, .jsx, .mjs, .opal, .php, .podspec, .pom, .py, .rake, .rb, .rlib, .rs, .scala, .swift, .tf, .ts, .tsx, .vue, .wsdl, .xml, .xsl, .yaml, .yml]
extensions: [.c, .cc, .cpp, .cs, .cxx, .dart, .dockerfile, .ex, .exs, .gemspec, .go, .h, .hpp, .ino, .java, .jbuilder, .js, .jsm, .json, .jsx, .mjs, .opal, .php, .podspec, .pom, .py, .rake, .rb, .rlib, .rs, .scala, .swift, .tf, .ts, .tsx, .vue, .wsdl, .xml, .xsl, .yaml, .yml]
files: [.deps.json, Berksfile, Capfile, Cargo.lock, Cheffile, Directory.Packages.props, Dockerfile, Fastfile, Gemfile, Gemfile.lock, Guardfile, Package.resolved, Packages.props, Pipfile.lock, Podfile, Podfile.lock, Rakefile, Thorfile, Vagabondfile, Vagrantfile, build.sbt.lock, composer.lock, conan.lock, config.ru, go.mod, gradle.lockfile, mix.lock, package-lock.json, package.json, packages.config, packages.lock.json, pnpm-lock.yaml, poetry.lock, pom.xml, pubspec.lock, requirements.txt, uv.lock, yarn.lock]
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
export default [
{
rules: {
"constructor-super": ["error"],
"for-direction": ["error"],
"getter-return": ["error", {"allowImplicit": false}],
"no-async-promise-executor": ["error"],
"no-case-declarations": ["error"],
"no-class-assign": ["error"],
"no-compare-neg-zero": ["error"],
"no-cond-assign": ["error", "except-parens"],
"no-constant-condition": ["error", {"checkLoops": true}],
"no-const-assign": ["error"],
"no-control-regex": ["error"],
"no-debugger": ["error"],
"no-delete-var": ["error"],
"no-dupe-args": ["error"],
"no-dupe-class-members": ["error"],
"no-dupe-else-if": ["error"],
"no-dupe-keys": ["error"],
"no-duplicate-case": ["error"],
"no-empty": ["error", {"allowEmptyCatch": false}],
"no-empty-character-class": ["error"],
"no-empty-pattern": ["error", {"allowObjectPatternsAsParameters": false}],
"no-ex-assign": ["error"],
"no-extra-boolean-cast": ["error", {"enforceForLogicalOperands": false}],
"no-extra-semi": ["error"],
"no-fallthrough": ["error", {"allowEmptyCase": false}],
"no-func-assign": ["error"],
"no-global-assign": ["error"],
"no-import-assign": ["error"],
"no-inner-declarations": ["error", "functions"],
"no-invalid-regexp": ["error"],
"no-irregular-whitespace": ["error", {"skipComments": false, "skipJSXText": false, "skipRegExps": false, "skipStrings": true, "skipTemplates": false}],
"no-loss-of-precision": ["error"],
"no-misleading-character-class": ["error"],
"no-mixed-spaces-and-tabs": ["error"],
"no-new-symbol": ["error"],
"no-nonoctal-decimal-escape": ["error"],
"no-obj-calls": ["error"],
"no-octal": ["error"],
"no-prototype-builtins": ["error"],
"no-redeclare": ["error", {"builtinGlobals": true}],
"no-regex-spaces": ["error"],
"no-self-assign": ["error", {"props": true}],
"no-setter-return": ["error"],
"no-shadow-restricted-names": ["error"],
"no-sparse-arrays": ["error"],
"no-this-before-super": ["error"],
"no-undef": ["error", {"typeof": false}],
"no-unexpected-multiline": ["error"],
"no-unreachable": ["error"],
"no-unsafe-finally": ["error"],
"no-unsafe-negation": ["error", {"enforceForOrderingRelations": false}],
"no-unsafe-optional-chaining": ["error", {"disallowArithmeticOperators": false}],
"no-unused-labels": ["error"],
"no-unused-vars": ["error"],
"no-useless-backreference": ["error"],
"no-useless-catch": ["error"],
"no-useless-escape": ["error"],
"no-with": ["error"],
"require-yield": ["error"],
"use-isnan": ["error", {"enforceForIndexOf": false, "enforceForSwitchCase": true}],
"valid-typeof": ["error", {"requireStringLiterals": false}],
}
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tools:
- name: eslint
languages: [Javascript, TypeScript]
extensions: [.js, .jsm, .jsx, .mjs, .ts, .tsx, .vue]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tools:
- name: pylint
languages: [Python]
extensions: [.py]
files: []
9 changes: 9 additions & 0 deletions plugins/tools/pylint/test/src/.codacy/tools-configs/pylint.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[MASTER]
ignore=CVS
persistent=yes
load-plugins=

[MESSAGES CONTROL]
disable=all
enable=C0123,C0200,C0303,E0100,E0101,E0102,E0103,E0104,E0105,E0106,E0107,E0108,E0110,E0112,E0113,E0114,E0115,E0116,E0117,E0202,E0203,E0211,E0236,E0238,E0239,E0240,E0241,E0301,E0302,E0601,E0603,E0604,E0701,E0702,E0704,E0710,E0711,E0712,E1003,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1132,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,R0202,R0203,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0120,W0122,W0124,W0150,W0199,W0221,W0222,W0233,W0404,W0410,W0601,W0602,W0604,W0611,W0612,W0622,W0702,W0705,W0711,W1300,W1301,W1302,W1303,W1305,W1306,W1307

2 changes: 2 additions & 0 deletions plugins/tools/pylint/test/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file should be successfully ignored by Codacy CLI as pylint does not support it.
django==1.11.29

Check warning on line 2 in plugins/tools/pylint/test/src/requirements.txt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

plugins/tools/pylint/test/src/requirements.txt#L2

Insecure dependency pypi/django@1.11.29 (CVE-2021-33203: django: Potential directory traversal via ``admindocs``) (update to 2.2.24)

Check failure on line 2 in plugins/tools/pylint/test/src/requirements.txt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

plugins/tools/pylint/test/src/requirements.txt#L2

Insecure dependency pypi/django@1.11.29 (CVE-2022-36359: An issue was discovered in the HTTP FileResponse class in Django 3.2 b ...) (update to 3.2.15)
Loading