@@ -64,6 +64,44 @@ def tmpdir(self, cmd, dir, files, filename, code):
6464 def issue_level (self , issue ):
6565 return "error" if issue ["FromLinter" ] == "typecheck" else "warning"
6666
67+ def canonical_error (self , issue ):
68+ mark = issue ["Text" ].rfind ("/" )
69+ package = issue ["Text" ][mark + 1 :- 1 ]
70+ # Go 1.4 introduces an annotation for package clauses in Go source that
71+ # identify a canonical import path for the package. If an import is
72+ # attempted using a path that is not canonical, the go command will
73+ # refuse to compile the importing package.
74+ #
75+ # When the linter runs, it creates a temporary directory, for example,
76+ # “.golangcilint-foobar”, then creates a symbolic link for all relevant
77+ # files, and writes the content of the current buffer in the correct
78+ # file. Unfortunately, canonical imports break this flow because the
79+ # temporary directory differs from the expected location.
80+ #
81+ # The only way to deal with this for now is to detect the error, which
82+ # may as well be a false positive, and then ignore all the warnings
83+ # about missing packages in the current file. Hopefully, the user has
84+ # “goimports” which will automatically resolve the dependencies for
85+ # them. Also, if the false positives are not, the programmer will know
86+ # about the missing packages during the compilation phase, so it’s not
87+ # a bad idea to ignore these warnings for now.
88+ #
89+ # See: https://golang.org/doc/go1.4#canonicalimports
90+ return {
91+ "FromLinter" : "typecheck" ,
92+ "Text" : "cannot lint package “{}” due to canonical import path" .format (package ),
93+ "Replacement" : issue ["Replacement" ],
94+ "SourceLines" : issue ["SourceLines" ],
95+ "Level" : "error" ,
96+ "Pos" : {
97+ "Filename" : self .filename ,
98+ "Shortname" : self .shortname ,
99+ "Offset" : 0 ,
100+ "Column" : 0 ,
101+ "Line" : 1
102+ }
103+ }
104+
67105 def execute (self , cmd ):
68106 lines = []
69107 output = self .communicate (cmd )
0 commit comments