Skip to content

Commit 1b4f5f9

Browse files
committed
Integrate with solium linter
1 parent bfca76b commit 1b4f5f9

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

solidity-mode.el

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
;; Author: Lefteris Karapetsas <lefteris@refu.co>
66
;; Keywords: languages
7-
;; Version: 0.1.3
7+
;; Version: 0.1.4
88

99
;; This program is free software; you can redistribute it and/or modify
1010
;; it under the terms of the GNU General Public License as published by
@@ -43,12 +43,24 @@
4343
"Callback hook to execute whenever a solidity file is loaded."
4444
:group 'solidity)
4545

46-
(defcustom solidity-solc-path "/usr/bin/solc"
46+
(defcustom solidity-solc-path "solc"
4747
"Path to the solc binary."
4848
:group 'solidity
4949
:type 'string
5050
:package-version '(solidity . "0.1.1"))
5151

52+
(defcustom solidity-solium-path "solium"
53+
"Path to the solium binary."
54+
:group 'solidity
55+
:type 'string
56+
:package-version '(solidity . "0.1.4"))
57+
58+
(defcustom solidity-flycheck-active-checker "solc"
59+
"Choice of active checker. Either solc or solium."
60+
:group 'solidity
61+
:type 'string
62+
:package-version '(solidity . "0.1.4"))
63+
5264
(defvar solidity-mode-map
5365
(let ((map (make-keymap)))
5466
(define-key map "\C-j" 'newline-and-indent)
@@ -446,6 +458,7 @@ Highlight the 1st result."
446458
(when (eval-when-compile (require 'flycheck nil 'noerror))
447459
;; Avoid reference to free variable warnings
448460
(defvar flycheck-solidity-checker-executable)
461+
(defvar flycheck-solium-checker-executable)
449462

450463
(flycheck-def-option-var flycheck-solidity-addstd-contracts nil solidity-checker
451464
"Whether to add standard solidity contracts.
@@ -471,11 +484,33 @@ When non-nil, enable add also standard solidity contracts via
471484
(warning line-start (file-name) ":" line ":" column ":" " Warning: " (message)))
472485
:modes solidity-mode
473486
:predicate (lambda () (eq major-mode 'solidity-mode)))
474-
(add-to-list 'flycheck-checkers 'solidity-checker)
475-
(add-hook 'solidity-mode-hook
476-
(lambda ()
477-
(let ((solidity-command (concat solidity-solc-path)))
478-
(setq flycheck-solidity-checker-executable solidity-command)))))
487+
488+
;; define solium flycheck syntax checker
489+
(flycheck-define-checker solium-checker
490+
"A Solidity linter using solium"
491+
:command ("solium" "-f" source-inplace)
492+
:error-patterns
493+
((error line-start (zero-or-more " ") line ":" column (zero-or-more " ") "error" (message))
494+
(warning line-start (zero-or-more " ") line ":" column (zero-or-more " ") "warning" (message)))
495+
:modes solidity-mode
496+
:predicate (lambda () (eq major-mode 'solidity-mode)))
497+
498+
(when (string= solidity-flycheck-active-checker "solc")
499+
(if (file-executable-p solidity-solc-path)
500+
(progn
501+
(add-to-list 'flycheck-checkers 'solidity-checker)
502+
(add-hook 'solidity-mode-hook
503+
(lambda ()
504+
(let ((solidity-command (concat solidity-solc-path)))
505+
(setq flycheck-solidity-checker-executable solidity-command)))))
506+
(error (format "Solidity Mode Configuration error. Requested solc flycheck integration but can't find solc at: %s" solidity-solc-path))))
507+
508+
(when (string= solidity-flycheck-active-checker "solium")
509+
(if (file-executable-p solidity-solium-path)
510+
(progn
511+
(add-to-list 'flycheck-checkers 'solium-checker)
512+
(setq flycheck-solium-checker-executable solidity-solium-path))
513+
(error (format "Solidity Mode Configuration error. Requested solium flycheck integration but can't find solium at: %s" solidity-solium-path)))))
479514

480515
(provide 'solidity-mode)
481516
;;; solidity-mode.el ends here

0 commit comments

Comments
 (0)