From 4c673e02e4b7c9f6ebe1051fe72b78dc30557663 Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Fri, 6 Feb 2026 09:01:25 +0000 Subject: [PATCH 1/7] Add ESLint configuration file path as a flag --- action.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/action.yml b/action.yml index aa45524..773250f 100644 --- a/action.yml +++ b/action.yml @@ -47,6 +47,11 @@ inputs: default: "" description: >- Eventual registry address. + eslint_config_path: + required: false + default: "" + description: >- + Path to the ESLint configuration file to use for the analysis. If not provided, the action will rely on the default configuration provided by Codacy CLI V2. runs: using: "composite" @@ -64,6 +69,10 @@ runs: if [ "${{ inputs.api_token }}" != "" ]; then /tmp/codacy-cli-v2 init --api-token ${{inputs.api_token}} --provider ${{inputs.provider}} --organization ${{inputs.owner}} --repository ${{inputs.repository}} fi + if [ "${{ inputs.eslint_config_path }}" != "" ]; then + /tmp/codacy-cli-v2 init + mv ${{ inputs.eslint_config_path }} ./.codacy/tools-configs/ + fi if [ "${{ inputs.registry }}" != "" ]; then /tmp/codacy-cli-v2 install -r ${{ inputs.registry }} else From f6225587393bb9768a32ced992ff84bfb6f394fa Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Mon, 16 Feb 2026 14:54:06 +0000 Subject: [PATCH 2/7] make the config_path flag general for the tool analysing the code --- action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 773250f..160eb3d 100644 --- a/action.yml +++ b/action.yml @@ -47,11 +47,11 @@ inputs: default: "" description: >- Eventual registry address. - eslint_config_path: + tool_config_path: required: false default: "" description: >- - Path to the ESLint configuration file to use for the analysis. If not provided, the action will rely on the default configuration provided by Codacy CLI V2. + Path to the tool configuration file to use for the analysis. If not provided, the action will rely on the default configuration provided by Codacy CLI V2. runs: using: "composite" @@ -69,9 +69,9 @@ runs: if [ "${{ inputs.api_token }}" != "" ]; then /tmp/codacy-cli-v2 init --api-token ${{inputs.api_token}} --provider ${{inputs.provider}} --organization ${{inputs.owner}} --repository ${{inputs.repository}} fi - if [ "${{ inputs.eslint_config_path }}" != "" ]; then + if [ "${{ inputs.tool_config_path }}" != "" ]; then /tmp/codacy-cli-v2 init - mv ${{ inputs.eslint_config_path }} ./.codacy/tools-configs/ + mv ${{ inputs.tool_config_path }} ./.codacy/tools-configs/ fi if [ "${{ inputs.registry }}" != "" ]; then /tmp/codacy-cli-v2 install -r ${{ inputs.registry }} From 71f615f91b63700b7926017a4b6ca2d9f9242b6e Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Mon, 16 Feb 2026 15:07:33 +0000 Subject: [PATCH 3/7] add codacy suggestions --- .gitignore | 3 ++- action.yml | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6eca42a..1b001f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ -.github/instructions \ No newline at end of file +.github/instructions +.codacy/ \ No newline at end of file diff --git a/action.yml b/action.yml index 160eb3d..05eac86 100644 --- a/action.yml +++ b/action.yml @@ -68,10 +68,11 @@ runs: chmod +x /tmp/codacy-cli-v2 if [ "${{ inputs.api_token }}" != "" ]; then /tmp/codacy-cli-v2 init --api-token ${{inputs.api_token}} --provider ${{inputs.provider}} --organization ${{inputs.owner}} --repository ${{inputs.repository}} + else + /tmp/codacy-cli-v2 init fi if [ "${{ inputs.tool_config_path }}" != "" ]; then - /tmp/codacy-cli-v2 init - mv ${{ inputs.tool_config_path }} ./.codacy/tools-configs/ + mv "${{ inputs.tool_config_path }}" ./.codacy/tools-configs/ fi if [ "${{ inputs.registry }}" != "" ]; then /tmp/codacy-cli-v2 install -r ${{ inputs.registry }} From 06a7e70f74ff3073db3977aef8d0473fe7dc1deb Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Tue, 17 Feb 2026 12:35:56 +0000 Subject: [PATCH 4/7] test workflow --- eslint.config.mjs | 82 +++++++++++++++++++++++++++++++++++++++++++++++ test.js | 31 ++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 eslint.config.mjs create mode 100644 test.js diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..0bca1e4 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,82 @@ +import js from '@eslint/js'; +import globals from 'globals'; +import tsParser from '@typescript-eslint/parser'; +import tseslint from '@typescript-eslint/eslint-plugin'; + +// Plugin Imports +import angularEslint from '@angular-eslint/eslint-plugin'; +import eslintPlugin from 'eslint-plugin-eslint-plugin'; +import importPlugin from 'eslint-plugin-import'; +import mochaPlugin from 'eslint-plugin-mocha'; +import nPlugin from 'eslint-plugin-n'; +import reactPlugin from 'eslint-plugin-react'; +import reactHooksPlugin from 'eslint-plugin-react-hooks'; +import unusedImportsPlugin from 'eslint-plugin-unused-imports'; + +export default [ + js.configs.recommended, + + { + // 1. Target both JS and TS files + files: ['**/*.{js,jsx,ts,tsx}'], + languageOptions: { + ecmaVersion: 2022, + sourceType: 'module', + // --- ADDED: TypeScript Parser --- + parser: tsParser, + parserOptions: { + ecmaFeatures: { jsx: true }, + }, + globals: { + ...globals.browser, + ...globals.node, + ...globals.mocha, + }, + }, + plugins: { + '@typescript-eslint': tseslint, + n: nPlugin, + react: reactPlugin, + 'react-hooks': reactHooksPlugin, + import: importPlugin, + 'unused-imports': unusedImportsPlugin, + mocha: mochaPlugin, + 'eslint-plugin': eslintPlugin, + '@angular-eslint': angularEslint, + }, + rules: { + // Include recommended TS rules + ...tseslint.configs.recommended.rules, + '@typescript-eslint/no-unused-expressions': 'off', // Disable conflicting rule + + // --- React & Hooks --- + 'react/jsx-uses-react': 'error', + 'react/jsx-uses-vars': 'error', + 'react-hooks/rules-of-hooks': 'error', + + + // --- Node & Imports --- + 'n/no-missing-require': 'error', + 'import/no-duplicates': 'error', + + // --- Unused Imports (Refined for TS) --- + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': 'off', // Turn off both to let plugin handle it + 'unused-imports/no-unused-imports': 'error', + 'unused-imports/no-unused-vars': [ + 'warn', + { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" } + ], + + // --- Mocha & Angular --- + 'mocha/no-exclusive-tests': 'error', + '@angular-eslint/component-selector': [ + 'error', + { type: 'element', prefix: 'app', style: 'kebab-case' } + ] + }, + settings: { + react: { version: 'detect' }, + } + } +]; \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 0000000..e466a4c --- /dev/null +++ b/test.js @@ -0,0 +1,31 @@ +// [eslint-plugin-import] Error: Duplicate imports +/*eslint es-x/no-modules: off */ +import React from 'react'; +import { useState } from 'react'; + +// [eslint-plugin-unused-imports] Error: Unused import +import { useEffect } from 'react'; + +// [eslint-plugin-n] Error: Missing require (file doesn't exist) +import fs from 'node:fs'; +const missing = require('./non-existent-file.js'); + +// [eslint-plugin-mocha] Error: Exclusive test (.only is forbidden) +describe('My Test Suite', () => { + it.only('should fail linting', () => { + // ... + }); +}); + +function App() { + // [eslint-plugin-react-hooks] Error: Hooks must be at top level + if (true) { + const [count, setCount] = useState(0); + } + + return ( +
Hello World
+ ); +} + +export default App; \ No newline at end of file From 23c2b17667f0b305abd93daf9e87369ec826d3b9 Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Tue, 17 Feb 2026 12:37:21 +0000 Subject: [PATCH 5/7] removed files --- eslint.config.mjs | 82 ----------------------------------------------- test.js | 31 ------------------ 2 files changed, 113 deletions(-) delete mode 100644 eslint.config.mjs delete mode 100644 test.js diff --git a/eslint.config.mjs b/eslint.config.mjs deleted file mode 100644 index 0bca1e4..0000000 --- a/eslint.config.mjs +++ /dev/null @@ -1,82 +0,0 @@ -import js from '@eslint/js'; -import globals from 'globals'; -import tsParser from '@typescript-eslint/parser'; -import tseslint from '@typescript-eslint/eslint-plugin'; - -// Plugin Imports -import angularEslint from '@angular-eslint/eslint-plugin'; -import eslintPlugin from 'eslint-plugin-eslint-plugin'; -import importPlugin from 'eslint-plugin-import'; -import mochaPlugin from 'eslint-plugin-mocha'; -import nPlugin from 'eslint-plugin-n'; -import reactPlugin from 'eslint-plugin-react'; -import reactHooksPlugin from 'eslint-plugin-react-hooks'; -import unusedImportsPlugin from 'eslint-plugin-unused-imports'; - -export default [ - js.configs.recommended, - - { - // 1. Target both JS and TS files - files: ['**/*.{js,jsx,ts,tsx}'], - languageOptions: { - ecmaVersion: 2022, - sourceType: 'module', - // --- ADDED: TypeScript Parser --- - parser: tsParser, - parserOptions: { - ecmaFeatures: { jsx: true }, - }, - globals: { - ...globals.browser, - ...globals.node, - ...globals.mocha, - }, - }, - plugins: { - '@typescript-eslint': tseslint, - n: nPlugin, - react: reactPlugin, - 'react-hooks': reactHooksPlugin, - import: importPlugin, - 'unused-imports': unusedImportsPlugin, - mocha: mochaPlugin, - 'eslint-plugin': eslintPlugin, - '@angular-eslint': angularEslint, - }, - rules: { - // Include recommended TS rules - ...tseslint.configs.recommended.rules, - '@typescript-eslint/no-unused-expressions': 'off', // Disable conflicting rule - - // --- React & Hooks --- - 'react/jsx-uses-react': 'error', - 'react/jsx-uses-vars': 'error', - 'react-hooks/rules-of-hooks': 'error', - - - // --- Node & Imports --- - 'n/no-missing-require': 'error', - 'import/no-duplicates': 'error', - - // --- Unused Imports (Refined for TS) --- - 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': 'off', // Turn off both to let plugin handle it - 'unused-imports/no-unused-imports': 'error', - 'unused-imports/no-unused-vars': [ - 'warn', - { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" } - ], - - // --- Mocha & Angular --- - 'mocha/no-exclusive-tests': 'error', - '@angular-eslint/component-selector': [ - 'error', - { type: 'element', prefix: 'app', style: 'kebab-case' } - ] - }, - settings: { - react: { version: 'detect' }, - } - } -]; \ No newline at end of file diff --git a/test.js b/test.js deleted file mode 100644 index e466a4c..0000000 --- a/test.js +++ /dev/null @@ -1,31 +0,0 @@ -// [eslint-plugin-import] Error: Duplicate imports -/*eslint es-x/no-modules: off */ -import React from 'react'; -import { useState } from 'react'; - -// [eslint-plugin-unused-imports] Error: Unused import -import { useEffect } from 'react'; - -// [eslint-plugin-n] Error: Missing require (file doesn't exist) -import fs from 'node:fs'; -const missing = require('./non-existent-file.js'); - -// [eslint-plugin-mocha] Error: Exclusive test (.only is forbidden) -describe('My Test Suite', () => { - it.only('should fail linting', () => { - // ... - }); -}); - -function App() { - // [eslint-plugin-react-hooks] Error: Hooks must be at top level - if (true) { - const [count, setCount] = useState(0); - } - - return ( -
Hello World
- ); -} - -export default App; \ No newline at end of file From 98f81609e7c2b02c36ab30b14412dc9fae9ddfda Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Thu, 19 Feb 2026 12:10:20 +0000 Subject: [PATCH 6/7] removed normal init command --- README.md | 1 + action.yml | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6066efd..5204c53 100644 --- a/README.md +++ b/README.md @@ -53,3 +53,4 @@ steps: | `tool` | Yes | - | The tool to use for analysis. | | `upload_report` | No | false | Whether to upload the report to Codacy. | | `sarif_file_path` | No | "./report.sarif" | The path to the SARIF file to upload. | +| `tool_file_path` | No | - | The path to the tool configuration file you need for the analysis. | diff --git a/action.yml b/action.yml index 05eac86..a62bf01 100644 --- a/action.yml +++ b/action.yml @@ -68,8 +68,6 @@ runs: chmod +x /tmp/codacy-cli-v2 if [ "${{ inputs.api_token }}" != "" ]; then /tmp/codacy-cli-v2 init --api-token ${{inputs.api_token}} --provider ${{inputs.provider}} --organization ${{inputs.owner}} --repository ${{inputs.repository}} - else - /tmp/codacy-cli-v2 init fi if [ "${{ inputs.tool_config_path }}" != "" ]; then mv "${{ inputs.tool_config_path }}" ./.codacy/tools-configs/ @@ -85,7 +83,7 @@ runs: run: | echo "Running the tool" if [ "${{ inputs.api_token }}" != "" ]; then - /tmp/codacy-cli-v2 analyze -t ${{inputs.tool}} ${{inputs.directory}} --format sarif -o ${{inputs.sarif_file_path}} --api-token ${{inputs.api_token}} --provider ${{inputs.provider}} --organization ${{inputs.owner}} --repository ${{inputs.repository}} + /tmp/codacy-cli-v2 analyze -t ${{inputs.tool}} --format sarif -o ${{inputs.sarif_file_path}} --api-token ${{inputs.api_token}} --provider ${{inputs.provider}} --organization ${{inputs.owner}} --repository ${{inputs.repository}} else /tmp/codacy-cli-v2 analyze -t ${{inputs.tool}} --format sarif -o ${{inputs.sarif_file_path}} fi From 6d7418afaaa75ad3b1fab3219f4ef6a09d80636f Mon Sep 17 00:00:00 2001 From: DMarinhoCodacy Date: Thu, 19 Feb 2026 14:38:09 +0000 Subject: [PATCH 7/7] fix README file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5204c53..e36b567 100644 --- a/README.md +++ b/README.md @@ -53,4 +53,4 @@ steps: | `tool` | Yes | - | The tool to use for analysis. | | `upload_report` | No | false | Whether to upload the report to Codacy. | | `sarif_file_path` | No | "./report.sarif" | The path to the SARIF file to upload. | -| `tool_file_path` | No | - | The path to the tool configuration file you need for the analysis. | +| `tool_config_path` | No | - | The path to the tool configuration file you need for the analysis. |