- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.5k
 
Add execinquery linter #2677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Add execinquery linter #2677
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            12 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b2bca04
              
                Add execinquery
              
              
                1uf3 c37041f
              
                Add more test case and change version
              
              
                1uf3 eba848c
              
                review: fix go mod
              
              
                ldez 2cb86de
              
                review: preset and alphabetical order
              
              
                ldez 23575d9
              
                review: rename files and fix tests
              
              
                ldez 73ef64f
              
                review: fix analyzer
              
              
                ldez eef9f55
              
                review: fix tests
              
              
                ldez 4f0673a
              
                review: fix imports
              
              
                ldez 86ad25f
              
                update go.mod
              
              
                1uf3 7e4a5d4
              
                delete previous version
              
              
                1uf3 5bcdbea
              
                review: fix go.mod
              
              
                ldez f71c595
              
                review: remove temp fix
              
              
                ldez File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package golinters | ||
| 
     | 
||
| import ( | ||
| "github.com/lufeee/execinquery" | ||
| "golang.org/x/tools/go/analysis" | ||
| 
     | 
||
| "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
| ) | ||
| 
     | 
||
| func NewExecInQuery() *goanalysis.Linter { | ||
| a := execinquery.Analyzer | ||
| 
     | 
||
| return goanalysis.NewLinter( | ||
| a.Name, | ||
| a.Doc, | ||
| []*analysis.Analyzer{a}, | ||
| nil, | ||
| ).WithLoadMode(goanalysis.LoadModeSyntax) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // args: -Eexecinquery | ||
| package testdata | ||
| 
     | 
||
| import ( | ||
| "context" | ||
| "database/sql" | ||
| ) | ||
| 
     | 
||
| func execInQuery(db *sql.DB) { | ||
| test := "a" | ||
| 
     | 
||
| _, err := db.Query("Update * FROM hoge where id = ?", test) // ERROR "It's better to use Execute method instead of Query method to execute `UPDATE` query" | ||
| if err != nil { | ||
| return | ||
| } | ||
| 
     | 
||
| db.QueryRow("Update * FROM hoge where id = ?", test) // ERROR "It's better to use Execute method instead of QueryRow method to execute `UPDATE` query" | ||
| if err != nil { | ||
| return | ||
| } | ||
| 
     | 
||
| ctx := context.Background() | ||
| 
     | 
||
| _, err = db.QueryContext(ctx, "Update * FROM hoge where id = ?", test) // ERROR "It's better to use Execute method instead of QueryContext method to execute `UPDATE` query " | ||
| if err != nil { | ||
| return | ||
| } | ||
| 
     | 
||
| db.QueryRowContext(ctx, "Update * FROM hoge where id = ?", test) // ERROR "It's better to use Execute method instead of QueryRowContext method to execute `UPDATE` query" | ||
| } | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.