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
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,8 +458,9 @@ 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
450- (flycheck-def-option-var flycheck-solidity-addstd-contracts nil solidity-checker
463+ (flycheck-def-option-var flycheck-solidity-solc- addstd-contracts nil solidity-checker
451464 " Whether to add standard solidity contracts.
452465
453466When non-nil, enable add also standard solidity contracts via
@@ -456,26 +469,70 @@ When non-nil, enable add also standard solidity contracts via
456469 :safe #'booleanp
457470 :package-version '(solidity-mode . " 0.1.3" ))
458471
472+ (flycheck-def-option-var flycheck-solidity-solium-soliumrcfile nil solium-check
473+ " The path to use for soliumrc.json
474+
475+ The value of this variable is either a string denoting a path to the soliumrc.json
476+ or nil, to use the current directory. When non-nil,
477+ we pass the directory to solium via the `--config' option."
478+ :type '(choice (const :tag " No custom soliumrc" nil )
479+ (string :tag " Custom soliumrc file location" ))
480+ :safe #'stringp
481+ :package-version '(solidity-mode . " 0.1.4" ))
482+
459483 ; ; add dummy source-inplace definition to avoid errors
460484 (defvar source-inplace t )
461485 ; ; add a solidity mode callback to set the executable of solc for flycheck
462486 ; ; define solidity's flycheck syntax checker
463487 (flycheck-define-checker solidity-checker
464488 " A Solidity syntax checker using the solc compiler"
465489 :command (" solc"
466- (option-flag " --add-std" flycheck-solidity-addstd-contracts)
490+ (option-flag " --add-std" flycheck-solidity-solc- addstd-contracts)
467491 source-inplace)
468492 :error-patterns
469493 ((error line-start (file-name) " :" line " :" column " :" " Error: " (message ))
470494 (error line-start " Error: " (message ))
471495 (warning line-start (file-name) " :" line " :" column " :" " Warning: " (message )))
472496 :modes solidity-mode
473497 :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)))))
498+
499+ ; ; define solium flycheck syntax checker
500+ (flycheck-define-checker solium-checker
501+ " A Solidity linter using solium"
502+ :command (" solium"
503+ (option " --config=" flycheck-solidity-solium-soliumrcfile concat)
504+ " -f"
505+ source-inplace)
506+ :error-patterns
507+ ((error line-start (zero-or-more " " ) line " :" column (zero-or-more " " ) " error" (message ))
508+ (error line-start (zero-or-more not-newline) " [Fatal error]" (message ))
509+ (warning line-start (zero-or-more " " ) line " :" column (zero-or-more " " ) " warning" (message )))
510+ :error-filter
511+ ; ; Add fake line numbers if they are missing in the lint output
512+ (lambda (errors )
513+ (dolist (err errors)
514+ (unless (flycheck-error-line err)
515+ (setf (flycheck-error-line err) 1 )))
516+ errors)
517+ :modes solidity-mode
518+ :predicate (lambda () (eq major-mode 'solidity-mode )))
519+
520+ (when (string= solidity-flycheck-active-checker " solc" )
521+ (if (file-executable-p solidity-solc-path)
522+ (progn
523+ (add-to-list 'flycheck-checkers 'solidity-checker )
524+ (add-hook 'solidity-mode-hook
525+ (lambda ()
526+ (let ((solidity-command (concat solidity-solc-path)))
527+ (setq flycheck-solidity-checker-executable solidity-command)))))
528+ (error (format " Solidity Mode Configuration error. Requested solc flycheck integration but can't find solc at: %s " solidity-solc-path))))
529+
530+ (when (string= solidity-flycheck-active-checker " solium" )
531+ (if (file-executable-p solidity-solium-path)
532+ (progn
533+ (add-to-list 'flycheck-checkers 'solium-checker )
534+ (setq flycheck-solium-checker-executable solidity-solium-path))
535+ (error (format " Solidity Mode Configuration error. Requested solium flycheck integration but can't find solium at: %s " solidity-solium-path)))))
479536
480537(provide 'solidity-mode )
481538; ;; solidity-mode.el ends here
0 commit comments