Skip to content

Commit 845cd52

Browse files
committed
fix: Only consider LanguageFiles from the API for Trivy CF-1742
1 parent 5996608 commit 845cd52

File tree

6 files changed

+129
-5
lines changed

6 files changed

+129
-5
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
export default [
2+
{
3+
rules: {
4+
"constructor-super": ["error"],
5+
"for-direction": ["error"],
6+
"getter-return": ["error", {"allowImplicit": false}],
7+
"no-async-promise-executor": ["error"],
8+
"no-case-declarations": ["error"],
9+
"no-class-assign": ["error"],
10+
"no-compare-neg-zero": ["error"],
11+
"no-cond-assign": ["error", "except-parens"],
12+
"no-constant-condition": ["error", {"checkLoops": true}],
13+
"no-const-assign": ["error"],
14+
"no-control-regex": ["error"],
15+
"no-debugger": ["error"],
16+
"no-delete-var": ["error"],
17+
"no-dupe-args": ["error"],
18+
"no-dupe-class-members": ["error"],
19+
"no-dupe-else-if": ["error"],
20+
"no-dupe-keys": ["error"],
21+
"no-duplicate-case": ["error"],
22+
"no-empty": ["error", {"allowEmptyCatch": false}],
23+
"no-empty-character-class": ["error"],
24+
"no-empty-pattern": ["error", {"allowObjectPatternsAsParameters": false}],
25+
"no-ex-assign": ["error"],
26+
"no-extra-boolean-cast": ["error", {"enforceForLogicalOperands": false}],
27+
"no-extra-semi": ["error"],
28+
"no-fallthrough": ["error", {"allowEmptyCase": false}],
29+
"no-func-assign": ["error"],
30+
"no-global-assign": ["error"],
31+
"no-import-assign": ["error"],
32+
"no-inner-declarations": ["error", "functions"],
33+
"no-invalid-regexp": ["error"],
34+
"no-irregular-whitespace": ["error", {"skipComments": false, "skipJSXText": false, "skipRegExps": false, "skipStrings": true, "skipTemplates": false}],
35+
"no-loss-of-precision": ["error"],
36+
"no-misleading-character-class": ["error"],
37+
"no-mixed-spaces-and-tabs": ["error"],
38+
"no-new-symbol": ["error"],
39+
"no-nonoctal-decimal-escape": ["error"],
40+
"no-obj-calls": ["error"],
41+
"no-octal": ["error"],
42+
"no-prototype-builtins": ["error"],
43+
"no-redeclare": ["error", {"builtinGlobals": true}],
44+
"no-regex-spaces": ["error"],
45+
"no-self-assign": ["error", {"props": true}],
46+
"no-setter-return": ["error"],
47+
"no-shadow-restricted-names": ["error"],
48+
"no-sparse-arrays": ["error"],
49+
"no-this-before-super": ["error"],
50+
"no-undef": ["error", {"typeof": false}],
51+
"no-unexpected-multiline": ["error"],
52+
"no-unreachable": ["error"],
53+
"no-unsafe-finally": ["error"],
54+
"no-unsafe-negation": ["error", {"enforceForOrderingRelations": false}],
55+
"no-unsafe-optional-chaining": ["error", {"disallowArithmeticOperators": false}],
56+
"no-unused-labels": ["error"],
57+
"no-unused-vars": ["error"],
58+
"no-useless-backreference": ["error"],
59+
"no-useless-catch": ["error"],
60+
"no-useless-escape": ["error"],
61+
"no-with": ["error"],
62+
"require-yield": ["error"],
63+
"use-isnan": ["error", {"enforceForIndexOf": false, "enforceForSwitchCase": true}],
64+
"valid-typeof": ["error", {"requireStringLiterals": false}],
65+
}
66+
}
67+
];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tools:
2+
- name: eslint
3+
languages: [Javascript, TypeScript]
4+
extensions: [.js, .jsm, .jsx, .mjs, .ts, .tsx, .vue]

plugins/tools/pylint/test/src/.codacy/tools-configs/languages-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ tools:
22
- name: pylint
33
languages: [Python]
44
extensions: [.py]
5+
files: []
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
tools:
2+
- name: dartanalyzer
3+
languages: [Dart]
4+
extensions: [.dart]
5+
files: []
6+
- name: eslint
7+
languages: [Javascript, TypeScript]
8+
extensions: [.js, .jsm, .jsx, .mjs, .ts, .tsx, .vue]
9+
files: []
10+
- name: lizard
11+
languages: [C, CPP, CSharp, Erlang, Fortran, Go, Java, Javascript, Kotlin, Lua, Objective C, PHP, Python, Ruby, Rust, Scala, Solidity, Swift, TypeScript]
12+
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]
13+
files: []
14+
- name: pmd
15+
languages: [Apex, JSP, Java, Javascript, PLSQL, SQL, Velocity, VisualForce, XML]
16+
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]
17+
files: []
18+
- name: pylint
19+
languages: [Python]
20+
extensions: [.py]
21+
files: []
22+
- name: revive
23+
languages: [Go]
24+
extensions: [.go]
25+
files: []
26+
- name: semgrep
27+
languages: [Apex, C, CPP, CSharp, Dockerfile, Go, Java, Javascript, Kotlin, PHP, PLSQL, Python, Ruby, Rust, SQL, Scala, Shell, Swift, Terraform, TypeScript, YAML]
28+
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]
29+
files: []
30+
- name: trivy
31+
languages: [C, CPP, CSharp, Dart, Dockerfile, Elixir, Go, JSON, Java, Javascript, PHP, Python, Ruby, Rust, Scala, Swift, Terraform, TypeScript, XML, YAML]
32+
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]
33+
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]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
severity:
2+
- LOW
3+
- MEDIUM
4+
- HIGH
5+
- CRITICAL
6+
7+
scan:
8+
scanners:
9+
- vuln
10+
- secret

tools/language_config.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import (
2323
// This file is responsible for building the languages-config.yaml file.
2424
//
2525

26+
// Tools that support specific files (hardcoded list)
27+
// We want to move this to the API in the future
28+
var supportSpecificFiles = map[string]bool{
29+
"trivy": true,
30+
}
31+
2632
// buildToolLanguageInfoFromAPI builds tool language information from API data
2733
// This is the core shared logic used by both GetToolLanguageMappingFromAPI and buildToolLanguageConfigFromAPI
2834
func buildToolLanguageInfoFromAPI() (map[string]domain.ToolLanguageInfo, error) {
@@ -90,9 +96,12 @@ func buildToolLanguageInfoFromAPI() (map[string]domain.ToolLanguageInfo, error)
9096
extensionsSet[ext] = struct{}{}
9197
}
9298
}
93-
if files, exists := languageFilesMap[lowerLang]; exists {
94-
for _, file := range files {
95-
filesSet[file] = struct{}{}
99+
// Only populate files if the tool supports specific files
100+
if supportSpecificFiles[toolName] {
101+
if files, exists := languageFilesMap[lowerLang]; exists {
102+
for _, file := range files {
103+
filesSet[file] = struct{}{}
104+
}
96105
}
97106
}
98107
}
@@ -262,8 +271,8 @@ func buildRemoteModeLanguagesConfig(apiTools []domain.Tool, toolIDMap map[string
262271
}
263272
}
264273

265-
// Add repository-specific files if they exist
266-
if hasFiles {
274+
// Add repository-specific files if they exist and tool supports specific files
275+
if hasFiles && supportSpecificFiles[shortName] {
267276
for _, file := range repoLang.Files {
268277
filesSet[file] = struct{}{}
269278
}

0 commit comments

Comments
 (0)