Skip to content

Commit 1b71fd0

Browse files
authored
Merge pull request #35 from rowanthorpe/fix-for-newer-solium-invocation
Conditionally add flag to solium invocation & tweak output parsing for newer solium
2 parents d89dae0 + 6efe814 commit 1b71fd0

File tree

1 file changed

+62
-76
lines changed

1 file changed

+62
-76
lines changed

solidity-flycheck.el

Lines changed: 62 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -74,91 +74,77 @@ Possible values are:
7474
:package-version '(solidity . "0.1.5"))
7575

7676
(flycheck-def-option-var flycheck-solidity-solium-soliumrcfile nil solium-check
77-
"The path to use for soliumrc.json
77+
"The path to use for soliumrc.json
7878
7979
The value of this variable is either a string denoting a path to the soliumrc.json
8080
or nil, to use the current directory. When non-nil,
8181
we pass the directory to solium via the `--config' option."
82-
:type '(choice (const :tag "No custom soliumrc" nil)
83-
(string :tag "Custom soliumrc file location"))
84-
:safe #'stringp
85-
:package-version '(solidity-mode . "0.1.4"))
86-
87-
;; add a solidity mode callback to set the executable of solc for flycheck
88-
;; define solidity's flycheck syntax checker
89-
;; (let ((next-checkers-val `((,solidity-flycheck-chaining-error-level . solium-checker))))
90-
;; (flycheck-define-checker solidity-checker
91-
;; "A Solidity syntax checker using the solc compiler"
92-
;; :command ("solc" source-inplace)
93-
;; :error-patterns
94-
;; ((error line-start (file-name) ":" line ":" column ":" " Error: " (message))
95-
;; (error line-start "Error: " (message))
96-
;; (warning line-start (file-name) ":" line ":" column ":" " Warning: " (message)))
97-
;; :next-checkers next-checkers-val
98-
;; ;; :next-checkers `((,solidity-flycheck-chaining-error-level . solium-checker))
99-
;; :modes solidity-mode
100-
;; :predicate (lambda () (eq major-mode 'solidity-mode))))
101-
102-
;; expanded the flycheck-define-checker macro as per advice given in gitter
103-
;; https://gitter.im/flycheck/flycheck?at=5a43b3a8232e79134d98872b in order to avoid the
104-
;; next-checkers `'` introduced by the flycheck-define-checker macro
105-
(progn
106-
(flycheck-def-executable-var solidity-checker "solc")
107-
(flycheck-define-command-checker 'solidity-checker "A Solidity syntax checker using the solc compiler" :command
108-
'("solc" source-inplace)
109-
:error-patterns
110-
'((error line-start
111-
(file-name)
112-
":" line ":" column ":" " Error: "
113-
(message))
114-
(error line-start "Error: "
115-
(message))
116-
(warning line-start
117-
(file-name)
118-
":" line ":" column ":" " Warning: "
119-
(message)))
120-
:modes 'solidity-mode :predicate
121-
#'(lambda nil
122-
(eq major-mode 'solidity-mode))
123-
:next-checkers
124-
`((,solidity-flycheck-chaining-error-level . solium-checker))
125-
:standard-input 'nil :working-directory 'nil))
126-
127-
;; define solium flycheck syntax checker
128-
(flycheck-define-checker solium-checker
129-
"A Solidity linter using solium"
130-
:command ("solium"
131-
(option "--config=" flycheck-solidity-solium-soliumrcfile concat)
132-
"-f"
133-
source-inplace)
134-
:error-patterns
135-
((error line-start (zero-or-more " ") line ":" column (zero-or-more " ") "error" (message))
136-
(error line-start (zero-or-more not-newline) "[Fatal error]" (message))
137-
(warning line-start (zero-or-more " ") line ":" column (zero-or-more " ") "warning" (message)))
138-
:error-filter
139-
;; Add fake line numbers if they are missing in the lint output
140-
(lambda (errors)
141-
(dolist (err errors)
142-
(unless (flycheck-error-line err)
143-
(setf (flycheck-error-line err) 1)))
144-
errors)
145-
:modes solidity-mode
146-
:predicate (lambda () (eq major-mode 'solidity-mode)))
147-
148-
;; first try to add solium to the checker's list since if we got solc
149-
;; it must come after it in the list due to it being chained after solc
82+
:type '(choice (const :tag "No custom soliumrc" nil)
83+
(string :tag "Custom soliumrc file location"))
84+
:safe #'stringp
85+
:package-version '(solidity-mode . "0.1.4"))
86+
15087
(when solidity-flycheck-solium-checker-active
151-
(if (funcall flycheck-executable-find solidity-solium-path)
152-
(progn
153-
(add-to-list 'flycheck-checkers 'solium-checker)
154-
(setq flycheck-solium-checker-executable solidity-solium-path))
155-
(error (format "Solidity Mode Configuration error. Requested solium flycheck integration but can't find solium at: %s" solidity-solium-path))))
88+
;; define solium flycheck syntax checker
89+
;; expanded the flycheck-define-checker macro in order to eval certain args, as per advice given in gitter
90+
;; https://gitter.im/flycheck/flycheck?at=5a43b3a8232e79134d98872b
91+
;; first try to add solium to the checker's list since if we got solc
92+
;; it must come after it in the list due to it being chained after solc
93+
(flycheck-def-executable-var solium-checker "solium")
94+
(let ((solium-full-path (funcall flycheck-executable-find solidity-solium-path)))
95+
(if solium-full-path
96+
(let ((solium-has-reporter (string-match-p "--reporter" (shell-command-to-string (concat solium-full-path " --help")))))
97+
(flycheck-define-command-checker 'solium-checker
98+
"A Solidity linter using solium"
99+
:command `("solium"
100+
,(if solium-has-reporter "--reporter=gcc" "")
101+
(option "--config=" flycheck-solidity-solium-soliumrcfile concat)
102+
"-f"
103+
source-inplace)
104+
:error-patterns `((error line-start (zero-or-more not-newline) "[Fatal error]" (message))
105+
,(if solium-has-reporter
106+
'(error line-start (file-name) ":" line ":" column ": error: " (message))
107+
'(error line-start (zero-or-more " ") line ":" column (zero-or-more " ") "error" (message)))
108+
,(if solium-has-reporter
109+
'(warning line-start (file-name) ":" line ":" column ": warning: " (message))
110+
'(warning line-start (zero-or-more " ") line ":" column (zero-or-more " ") "warning" (message))))
111+
:error-filter
112+
;; Add fake line numbers if they are missing in the lint output
113+
#'(lambda (errors)
114+
(dolist (err errors)
115+
(unless (flycheck-error-line err)
116+
(setf (flycheck-error-line err) 1)))
117+
errors)
118+
:modes 'solidity-mode
119+
:predicate #'(lambda nil (eq major-mode 'solidity-mode))
120+
:next-checkers 'nil
121+
:standard-input 'nil
122+
:working-directory 'nil)
123+
(add-to-list 'flycheck-checkers 'solium-checker)
124+
(setq flycheck-solium-checker-executable solidity-solium-path))
125+
(error (format "Solidity Mode Configuration error. Requested solium flycheck integration but can't find solium at: %s" solidity-solium-path)))))
156126

157127
(when solidity-flycheck-solc-checker-active
128+
;; add a solidity mode callback to set the executable of solc for flycheck
129+
;; define solidity's flycheck syntax checker
130+
;; expanded the flycheck-define-checker macro in order to eval certain args, as per advice given in gitter
131+
;; https://gitter.im/flycheck/flycheck?at=5a43b3a8232e79134d98872b
132+
(flycheck-def-executable-var solidity-checker "solc")
158133
(if (funcall flycheck-executable-find solidity-solc-path)
159134
(progn
160-
(add-to-list 'flycheck-checkers 'solidity-checker)
161-
(setq flycheck-solidity-checker-executable solidity-solc-path))
135+
(flycheck-define-command-checker 'solidity-checker
136+
"A Solidity syntax checker using the solc compiler"
137+
:command '("solc" source-inplace)
138+
:error-patterns '((error line-start (file-name) ":" line ":" column ":" " Error: " (message))
139+
(error line-start "Error: " (message))
140+
(warning line-start (file-name) ":" line ":" column ":" " Warning: " (message)))
141+
:modes 'solidity-mode
142+
:predicate #'(lambda nil (eq major-mode 'solidity-mode))
143+
:next-checkers `((,solidity-flycheck-chaining-error-level . solium-checker))
144+
:standard-input 'nil
145+
:working-directory 'nil)
146+
(add-to-list 'flycheck-checkers 'solidity-checker)
147+
(setq flycheck-solidity-checker-executable solidity-solc-path))
162148
(error (format "Solidity Mode Configuration error. Requested solc flycheck integration but can't find solc at: %s" solidity-solc-path))))
163149

164150
(provide 'solidity-flycheck)

0 commit comments

Comments
 (0)