TykTechnologies / tyk

Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols
Other
9.68k stars 1.08k forks source link

[TT-13280] Adjust golangci-lint to raise up errors in PRs directly #6634

Closed titpetric closed 2 weeks ago

titpetric commented 2 weeks ago

User description

TT-13280
Summary golangci-lint: fix output format to enable github actions to pick up on golangci-lint reported issues
Type Task Task
Status In Dev
Points N/A
Labels SESAP

https://tyktech.atlassian.net/browse/TT-13280


PR Type

enhancement, configuration changes


Description


Changes walkthrough πŸ“

Relevant files
Enhancement
bad.go
Add TestChange struct with Copy method in Go package         

apidef/bad.go
  • Added a new Go package apidef.
  • Introduced a struct TestChange with a sync.Mutex.
  • Implemented a Copy method for TestChange.
  • +9/-0     
    Configuration changes
    ci-tests.yml
    Update golangci-lint configuration in GitHub Actions         

    .github/workflows/ci-tests.yml
  • Modified golangci-lint command to include golangcilint.xml in output
    format.
  • Adjusted linting commands for both pull request and push events.
  • +2/-2     

    πŸ’‘ PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    buger commented 2 weeks ago

    Let's make that PR title a πŸ’― shall we? πŸ’ͺ

    <p>
    Your <em>PR title</em> and <em>story title</em> look <strong>slightly different</strong>. Just checking in to know if it was intentional!
    </p>
    <table>
      <tr>
        <th>Story Title</th>
        <td>golangci-lint: fix output format to enable github actions to pick up on golangci-lint reported issues</td>
      </tr>
      <tr>
          <th>PR Title</th>
          <td>[TT-13280] Adjust golangci-lint to raise up errors in PRs directly</td>
        </tr>
    </table>
    <p>
      Check out this <a href="https://www.atlassian.com/blog/git/written-unwritten-guide-pull-requests">guide</a> to learn more about PR best-practices.
    </p>
    github-actions[bot] commented 2 weeks ago

    PR Reviewer Guide πŸ”

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 πŸ”΅πŸ”΅βšͺβšͺβšͺ
    πŸ§ͺ No relevant tests
    πŸ”’ No security concerns identified
    ⚑ Recommended focus areas for review

    Synchronization Issue
    The struct `TestChange` includes a `sync.Mutex`. However, the `Copy` method returns a copy of `TestChange` by value, which can lead to copying of the mutex. This is generally unsafe and can cause runtime issues as mutexes should not be copied.
    github-actions[bot] commented 2 weeks ago

    API Changes

    no api changes detected
    github-actions[bot] commented 2 weeks ago

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Prevent potential concurrency issues by avoiding copying mutexes by value ___ **Avoid copying the mutex by value in the Copy method of TestChange struct. This can
    lead to subtle bugs by copying the lock state. Consider returning a pointer to a new
    instance of TestChange or explicitly handling the mutex.** [apidef/bad.go [7-8]](https://github.com/TykTechnologies/tyk/pull/6634/files#diff-62e2fc9df5eff27d39d10a8f2ef85be72987435733e4b1d040be9905fe805fa5R7-R8) ```diff -func (p TestChange) Copy() TestChange { - return p +func (p *TestChange) Copy() *TestChange { + return &TestChange{} } ```
    Suggestion importance[1-10]: 9 Why: The suggestion addresses a critical concurrency issue by preventing the mutex from being copied by value, which can lead to subtle bugs. Changing the method to return a pointer to a new instance of `TestChange` is a valid and necessary improvement to ensure thread safety.
    9
    sonarcloud[bot] commented 2 weeks ago

    Quality Gate Passed Quality Gate passed

    Issues
    0 New issues
    0 Accepted issues

    Measures
    0 Security Hotspots
    0.0% Coverage on New Code
    0.0% Duplication on New Code

    See analysis details on SonarCloud