In a package I am working on I want to define a flycheck checker only if the user has flycheck installed already. To do this, I am using the macro (with-eval-after-load "flycheck" ...) as follows:
(with-eval-after-load "flycheck"
(flycheck-define-checker go-mod
"A syntax checker for go.mod files."
:command ("go" "list" "-m")
:error-patterns
((error line-start (file-name) ":" line ": " (message) line-end))
:modes go-mod-mode))
When I do this however, many flycheck errors appear. For example it says that go-mod and go-mod-mode are free variables,it's misinterpreting the (error line-start ...) part, and saying that the function flycheck-define-checker is not know to be defined.
Adding (require ...) resolves these warnings but I only want this to be required if the user has "flycheck" installed already. What can I do to suppress these errors.