super-linter / super-linter

Combination of multiple linters to run as a GitHub Action or standalone
https://github.com/super-linter/super-linter
MIT License
9.54k stars 973 forks source link

Super linter fails linting a simple go repository with files in more than one folder (Inner error given by golangci-lint linter). #6294

Closed andrew-field closed 1 month ago

andrew-field commented 1 month ago

Is there an existing issue for this?

Are you using the latest Super-linter version available?

Are you resonably sure that it's a Super-linter issue, and not an issue related to a tool that Super-linter runs?

Current Behavior

I run the super linter through a github action for a very simple go repository with two folders and a go file in each, to lint the files. The super linter uses the golangci-lint linter. The action fails and the go linter is given as the error. The output is:

2024-10-21 15:28:05 [INFO]   Linting GO items...
  Error: -21 15:28:12 [ERROR]   Found errors when linting GO. Exit code: 1.
  2024-10-21 15:28:12 [INFO]   Stderr contents for GO:
  ------
  level=error msg="[linters_context] typechecking error: named files must all be in one directory; have /github/workspace/folder1 and /github/workspace/folder2"
  ------

Expected Behavior

The action passes and no error is given. When running the golangci-lint linter directly using any of the following commands, the linter produces no errors, therefore the super linter should produce no errors.

golangci-lint run
golangci-lint run ./...
golangci-lint run -c golangci.yml
golangci-lint run -c golangci.yml --fast

I have tested this with the latest golangci-lint version 1.61 and also 1.60.3, the current version of golangci-lint used by the super linter. The golangci.yml configuration file used in the commands above is the same configuration file found in the TEMPLATES folder of the super linter.

Super-Linter version

Latest and 6.9.0

Super-linter configuration

---
name: Lint Latest

on: # yamllint disable-line rule:truthy
  push: null
  pull_request: null

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

permissions: {}

jobs:
  build:
    name: Lint
    runs-on: ubuntu-latest

    permissions:
      contents: read
      packages: read
      # To report GitHub Actions status checks
      statuses: write

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          # super-linter needs the full git history to get the
          # list of files that changed across commits
          fetch-depth: 0

      - name: Super-linter Latest
        uses: super-linter/super-linter@latest
        env:
          # To report GitHub Actions status checks
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          VALIDATE_JSCPD: false

Relevant log output

2024-10-21 15:43:26 [DEBUG]   Started GitHub Actions log group: GO
  2024-10-21 15:43:26 [INFO]   Linting GO items...
  2024-10-21 15:43:26 [DEBUG]   PARALLEL_RESULTS_FILE_PATH for GO: /tmp/super-linter-output/super-linter-worker-results-GO.json
  2024-10-21 15:43:26 [DEBUG]   LOG_DEBUG is enabled. Enable verbose ouput for parallel
  2024-10-21 15:43:26 [DEBUG]   PARALLEL_COMMAND for GO: parallel --will-cite --keep-order --max-procs 4 --xargs --results /tmp/super-linter-output/super-linter-worker-results-GO.json --verbose
  2024-10-21 15:43:26 [DEBUG]   PARALLEL_COMMAND for GO after updating the number of files to lint per process: parallel --will-cite --keep-order --max-procs 4 --xargs --results /tmp/super-linter-output/super-linter-worker-results-GO.json --verbose
  2024-10-21 15:43:26 [DEBUG]   LINTER_WORKING_DIRECTORY for GO: /github/workspace
  2024-10-21 15:43:26 [DEBUG]   PARALLEL_COMMAND for GO after updating the working directory: parallel --will-cite --keep-order --max-procs 4 --xargs --results /tmp/super-linter-output/super-linter-worker-results-GO.json --verbose --workdir /github/workspace
  2024-10-21 15:43:26 [DEBUG]   Checking if /action/lib/.automation/.checkov.yaml contains a 'directory:' configuration option
  2024-10-21 15:43:26 [DEBUG]   /action/lib/.automation/.checkov.yaml doesn't contain a 'directory:' statement
  2024-10-21 15:43:26 [DEBUG]   Adding the '--directory' option to the Checkov command.
  2024-10-21 15:43:26 [DEBUG]   Check if GO command needs check only mode or fix mode options or commands by checking if FIX_GO variable is defined.
  2024-10-21 15:43:26 [DEBUG]   FIX_GO is set. Check if we need to add check only mode options or fix mode options or commands.
  2024-10-21 15:43:26 [DEBUG]   Fix mode for GO is not enabled. Check if GO needs options to enable check mode.
  2024-10-21 15:43:26 [DEBUG]   There are no options or commands for check only mode or fix mode to add at the end of the command for GO
  2024-10-21 15:43:26 [DEBUG]   Load command for GO: LINTER_COMMANDS_ARRAY_GO. Contents: golangci-lint run -c /action/lib/.automation/.golangci.yml --fast
  2024-10-21 15:43:26 [DEBUG]   GO doesn't need any further options or commands for fix mode or check mode.
  2024-10-21 15:43:26 [DEBUG]   Completed the initialization of linter command for GO. Result: golangci-lint run -c /action/lib/.automation/.golangci.yml --fast
  2024-10-21 15:43:26 [DEBUG]   LINTER_COMMAND_ARRAY for GO has 5 elements: golangci-lint run -c /action/lib/.automation/.golangci.yml --fast
  2024-10-21 15:43:26 [DEBUG]   PARALLEL_COMMAND for GO after LINTER_COMMAND_ARRAY concatenation: parallel --will-cite --keep-order --max-procs 4 --xargs --results /tmp/super-linter-output/super-linter-worker-results-GO.json --verbose --workdir /github/workspace golangci-lint run -c /action/lib/.automation/.golangci.yml --fast
  2024-10-21 15:43:33 [DEBUG]   PARALLEL_COMMAND_OUTPUT for GO (exit code: 1): cd /github/workspace || exit 255; golangci-lint run -c /action/lib/.automation/.golangci.yml --fast /github/workspace/folder1/multiply.go /github/workspace/folder2/add.go
  2024-10-21 15:43:33 [DEBUG]   Parallel output file (/tmp/super-linter-output/super-linter-worker-results-GO.json) contents for GO:
  { "Seq": 1, "Host": ":", "Starttime": 1729525406.437, "JobRuntime": 6.908, "Send": 0, "Receive": 0, "Exitval": 7, "Signal": 0, "Command": "golangci-lint run -c /action/lib/.automation/.golangci.yml --fast /github/workspace/folder1/multiply.go /github/workspace/folder2/add.go", "V": [ "/github/workspace/folder1/multiply.go","/github/workspace/folder2/add.go" ], "Stdout": "", "Stderr": "level=error msg=\"[linters_context] typechecking error: named files must all be in one directory; have /github/workspace/folder1 and /github/workspace/folder2\"
  " }
  Error: -21 15:43:33 [ERROR]   Found errors when linting GO. Exit code: 1.
  2024-10-21 15:43:33 [DEBUG]   RESULTS_OBJECT for GO:
  [
    {
      "Seq": 1,
      "Host": ":",
      "Starttime": 1729525406.437,
      "JobRuntime": 6.908,
      "Send": 0,
      "Receive": 0,
      "Exitval": 7,
      "Signal": 0,
      "Command": "golangci-lint run -c /action/lib/.automation/.golangci.yml --fast /github/workspace/folder1/multiply.go /github/workspace/folder2/add.go",
      "V": [
        "/github/workspace/folder1/multiply.go",
        "/github/workspace/folder2/add.go"
      ],
      "Stdout": "",
      "Stderr": "level=error msg=\"[linters_context] typechecking error: named files must all be in one directory; have /github/workspace/folder1 and /github/workspace/folder2\"
  "
    }
  ]
  2024-10-21 15:43:33 [DEBUG]   Set INDEX for GO to: 2
  2024-10-21 15:43:33 [DEBUG]   Stdout for GO is empty
  2024-10-21 15:43:33 [INFO]   Stderr contents for GO:
  ------
  level=error msg="[linters_context] typechecking error: named files must all be in one directory; have /github/workspace/folder1 and /github/workspace/folder2"
  ------
  2024-10-21 15:43:33 [DEBUG]   Saving stderr for GO to /tmp/super-linter-output/super-linter-parallel-stderr-GO in case we need it later
  2024-10-21 15:43:33 [DEBUG]   Ending GitHub Actions log group: GO

Steps To Reproduce

Run the super linter for any go repository with more than two folders and go files.

Anything else?

My repository shows the problem: https://github.com/andrew-field/InvestigateSuperLinterBug https://github.com/andrew-field/InvestigateSuperLinterBug/actions

As can be seen from the logs, the problem is caused by running the golangci-lint linter with the following command. golangci-lint run -c /action/lib/.automation/.golangci.yml --fast /github/workspace/folder1/multiply.go /github/workspace/folder2/add.go, where each file is named and given as an argument.

I guess my main questions are:

  1. Why are the names of all the go files given as arguments?
  2. Could we change the command to run the linter to: golangci-lint run ./... -c /action/lib/.automation/.golangci.yml --fast or even more succinctly, golangci-lint run -c /action/lib/.automation/.golangci.yml --fast, which I believe does the same thing of linting all the files, without passing all the files as arguments and without the error?
  3. If not changing the command as above, could this be configured somehow/an option for the super linter to run the golangci-lint linter in this way?
ferrarimarco commented 1 month ago

Hi @andrew-field, thanks for reporting this issue and for providing such a detailed report.

Let me try reproducing this in a test in order to understand what's happening.

andrew-field commented 1 month ago

I provided a link to my test repo, which might help.

ferrarimarco commented 1 month ago

Yes, this is helpful. Thanks @andrew-field !

ferrarimarco commented 1 month ago

And, to answer your questions:

Why are the names of all the go files given as arguments?

Because the GO "language" expects to lint individual Go files.

Could we change the command to run the linter to: golangci-lint run ./... -c /action/lib/.automation/.golangci.yml --fast or even more succinctly, golangci-lint run -c /action/lib/.automation/.golangci.yml --fast, which I believe does the same thing of linting all the files, without passing all the files as arguments and without the error? If not changing the command as above, could this be configured somehow/an option for the super linter to run the golangci-lint linter in this way?

This is already implemented using the GO_MODULES "language". Can you try adding VALIDATE_GO: false in your configuration? It should only run GO_MODULES linting which does what you ask.

andrew-field commented 1 month ago

Ah yes, I see. Thanks very much. Indeed, the debug log shows the command is running the golangci-lint program without the individual files for the Go_Modules lint. Reading the description for the variable VALIDATE_GO seems quite clear now...not sure where I misunderstood in the first place... Might I humbly suggest though that the default value for VALIDATE_GO is changed to false? It says VALIDATE_GO should be set to false if VALIDATE_GO_MODULES is true but they are both set to true by default at the moment.

ferrarimarco commented 1 month ago

Thanks for getting back with this update :)

VALIDATE_xxx variables are all true by default, so that would require a breaking change. :(

Closing because we understood what this is about here.