第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 go/analysis 為 Go 檢查器定義修復(fù)操作?

如何使用 go/analysis 為 Go 檢查器定義修復(fù)操作?

Go
天涯盡頭無女友 2022-05-23 16:11:44
我最近使用 and 編寫了一個 Go 檢查器golang.org/x/tools/go/analysis,golang.org/x/tools/go/analysis/singlechecker并且我設(shè)法編寫了自己的自定義文件操作機(jī)制(跟蹤文件偏移等),但我覺得我在與系統(tǒng)作斗爭。https://pkg.go.dev/golang.org/x/tools/go/analysis/internal/checker中似乎Fix定義了一個標(biāo)志,但我不知道如何使用它或掛鉤到使用它的系統(tǒng).也可以定義-fix        apply all suggested fixes當(dāng)檢查器編譯時singlechecker:import (    "golang.org/x/tools/go/analysis/singlechecker")var (    Analyzer = &analysis.Analyzer{        Name: "name",        Run: run,    }    // Can't define a "fix" flag because golang.org/x/tools/go/analysis/internal/checker    // defines it and flags cannot be redefined.    // Fix = flag.Bool("autofix", false, "apply fixes automatically")    Fix bool)func main() {    // NOTE:    // Don't do this at home. This should be properly integrated with    // "golang.org/x/tools/go/analysis/internal/checker" flags (specifically -fix    // flag) but I have no idea how to do that and the documentation is non existent.    if len(os.Args) > 1 {        for _, arg := range os.Args[1:] {            if arg == "-fix" {                Fix = true                break            }        }    }    singlechecker.Main(Analyzer)}我也找不到任何關(guān)于它的文檔。Fix在此處啟用標(biāo)志時應(yīng)該運(yùn)行的代碼: https ://github.com/golang/tools/blob/268ba720d32c891185aa340e8851e215f23173db/go/analysis/internal/checker/checker.go#L265任何線索如何使用它?
查看完整描述

2 回答

?
qq_笑_17

TA貢獻(xiàn)1818條經(jīng)驗 獲得超7個贊

可以這樣做:


    pass.Report(

    analysis.Diagnostic{

        Pos:     be.Pos(),

        Message: fmt.Sprintf("do not compare errors directly, use errors.Is() instead: %q", oldExpr),

        SuggestedFixes: []analysis.SuggestedFix{

            {

                Message: fmt.Sprintf("should replace %q with %q", oldExpr, newExpr),

                TextEdits: []analysis.TextEdit{

                    {

                        Pos:     be.Pos(),

                        End:     be.End(),

                        NewText: []byte(newExpr),

                    },

                },

            },

        },

    },

開始閱讀的好地方是https://godoc.org/golang.org/x/tools/go/analysis#Diagnostic


查看完整回答
反對 回復(fù) 2022-05-23
?
胡子哥哥

TA貢獻(xiàn)1825條經(jīng)驗 獲得超6個贊

您可以-fix=true在運(yùn)行檢查器時提供標(biāo)志。singlechecker將通過運(yùn)行checker.RegisterFlags()來注冊該標(biāo)志。然后,傳遞的標(biāo)志將在analysisflags.Parse()中解析


查看完整回答
反對 回復(fù) 2022-05-23
  • 2 回答
  • 0 關(guān)注
  • 245 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號