44
55; ; Author: Lefteris Karapetsas <lefteris@refu.co>
66; ; Keywords: languages
7- ; ; Version: 0.1.4
7+ ; ; Version: 0.1.5
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
5555 :type 'string
5656 :package-version '(solidity . " 0.1.4" ))
5757
58- (defcustom solidity-flycheck-active -checker " solc "
59- " Choice of active checker. Either solc or solium ."
58+ (defcustom solidity-flycheck-solc -checker-active nil
59+ " A boolean flag denoting if solc flycheck checker should be active ."
6060 :group 'solidity
61- :type 'string
62- :package-version '(solidity . " 0.1.4" ))
61+ :type 'boolean
62+ :safe #'booleanp
63+ :package-version '(solidity . " 0.1.5" ))
64+
65+ (defcustom solidity-flycheck-solium-checker-active nil
66+ " A boolean flag denoting if solium flycheck checker should be active."
67+ :group 'solidity
68+ :type 'boolean
69+ :safe #'booleanp
70+ :package-version '(solidity . " 0.1.5" ))
71+
72+ (defcustom solidity-flycheck-chaining-error-level 'warning
73+ " The maximum error level at which chaining of checkers will happen.
74+
75+ This means that this is the error level for which solc checker will allow
76+ next checkers to run. By default this is the warning level.
77+ Possible values are:
78+
79+ `info'
80+ If any errors higher than info level are found in solc, then solium
81+ will not run.
82+
83+ `warning'
84+ If any errors higher than warning level are found in solc, then solium
85+ will not run.
86+
87+ `error'
88+ If any errors higher than error level are found in solc, then solium
89+ will not run.
90+ t
91+ Solium will always run."
92+ :group 'solidity
93+ :type '(choice (const :tag " Chain after info-error level" info)
94+ (const :tag " Chain after warning-error level" warning )
95+ (const :tag " Chain after error-error level" error )
96+ (const :tag " Always chain" t ))
97+ :package-version '(solidity . " 0.1.5" )
98+ :safe #'symbolp )
6399
64100(defvar solidity-mode-map
65101 (let ((map (make-keymap )))
@@ -482,19 +518,50 @@ we pass the directory to solium via the `--config' option."
482518
483519 ; ; add dummy source-inplace definition to avoid errors
484520 (defvar source-inplace t )
521+
485522 ; ; add a solidity mode callback to set the executable of solc for flycheck
486523 ; ; define solidity's flycheck syntax checker
487- (flycheck-define-checker solidity-checker
488- " A Solidity syntax checker using the solc compiler"
489- :command (" solc"
490- (option-flag " --add-std" flycheck-solidity-solc-addstd-contracts)
491- source-inplace)
492- :error-patterns
493- ((error line-start (file-name) " :" line " :" column " :" " Error: " (message ))
494- (error line-start " Error: " (message ))
495- (warning line-start (file-name) " :" line " :" column " :" " Warning: " (message )))
496- :modes solidity-mode
497- :predicate (lambda () (eq major-mode 'solidity-mode )))
524+ ; ; (let ((next-checkers-val `((,solidity-flycheck-chaining-error-level . solium-checker))))
525+ ; ; (flycheck-define-checker solidity-checker
526+ ; ; "A Solidity syntax checker using the solc compiler"
527+ ; ; :command ("solc"
528+ ; ; (option-flag "--add-std" flycheck-solidity-solc-addstd-contracts)
529+ ; ; source-inplace)
530+ ; ; :error-patterns
531+ ; ; ((error line-start (file-name) ":" line ":" column ":" " Error: " (message))
532+ ; ; (error line-start "Error: " (message))
533+ ; ; (warning line-start (file-name) ":" line ":" column ":" " Warning: " (message)))
534+ ; ; :next-checkers next-checkers-val
535+ ; ; ;; :next-checkers `((,solidity-flycheck-chaining-error-level . solium-checker))
536+ ; ; :modes solidity-mode
537+ ; ; :predicate (lambda () (eq major-mode 'solidity-mode))))
538+
539+ ; ; expanded the flycheck-define-checker macro as per advice given in gitter
540+ ; ; https://gitter.im/flycheck/flycheck?at=5a43b3a8232e79134d98872b in order to avoid the
541+ ; ; next-checkers `'` introduced by the flycheck-define-checker macro
542+ (progn
543+ (flycheck-def-executable-var solidity-checker " solc" )
544+ (flycheck-define-command-checker 'solidity-checker " A Solidity syntax checker using the solc compiler" :command
545+ '(" solc"
546+ (option-flag " --add-std" flycheck-solidity-solc-addstd-contracts)
547+ source-inplace)
548+ :error-patterns
549+ '((error line-start
550+ (file-name)
551+ " :" line " :" column " :" " Error: "
552+ (message ))
553+ (error line-start " Error: "
554+ (message ))
555+ (warning line-start
556+ (file-name)
557+ " :" line " :" column " :" " Warning: "
558+ (message )))
559+ :modes 'solidity-mode :predicate
560+ #' (lambda nil
561+ (eq major-mode 'solidity-mode ))
562+ :next-checkers
563+ `((, solidity-flycheck-chaining-error-level . solium-checker))
564+ :standard-input 'nil :working-directory 'nil ))
498565
499566 ; ; define solium flycheck syntax checker
500567 (flycheck-define-checker solium-checker
@@ -517,22 +584,24 @@ we pass the directory to solium via the `--config' option."
517584 :modes solidity-mode
518585 :predicate (lambda () (eq major-mode 'solidity-mode )))
519586
520- (when (string= solidity-flycheck-active-checker " solc" )
587+ ; ; first try to add solium to the checker's list since if we got solc
588+ ; ; it must come after it in the list due to it being chained after solc
589+ (when solidity-flycheck-solium-checker-active
590+ (if (file-executable-p solidity-solium-path)
591+ (progn
592+ (add-to-list 'flycheck-checkers 'solium-checker )
593+ (setq flycheck-solium-checker-executable solidity-solium-path))
594+ (error (format " Solidity Mode Configuration error. Requested solium flycheck integration but can't find solium at: %s " solidity-solium-path))))
595+
596+ (when solidity-flycheck-solc-checker-active
521597 (if (file-executable-p solidity-solc-path)
522598 (progn
523599 (add-to-list 'flycheck-checkers 'solidity-checker )
524600 (add-hook 'solidity-mode-hook
525601 (lambda ()
526602 (let ((solidity-command (concat solidity-solc-path)))
527603 (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)))))
604+ (error (format " Solidity Mode Configuration error. Requested solc flycheck integration but can't find solc at: %s " solidity-solc-path)))))
536605
537606(provide 'solidity-mode )
538607; ;; solidity-mode.el ends here
0 commit comments