4
4
5
5
; ; Author: Lefteris Karapetsas <[email protected] >
6
6
; ; Keywords: languages
7
- ; ; Version: 0.1.3
7
+ ; ; Version: 0.1.4
8
8
9
9
; ; This program is free software; you can redistribute it and/or modify
10
10
; ; it under the terms of the GNU General Public License as published by
43
43
" Callback hook to execute whenever a solidity file is loaded."
44
44
:group 'solidity )
45
45
46
- (defcustom solidity-solc-path " /usr/bin/ solc"
46
+ (defcustom solidity-solc-path " solc"
47
47
" Path to the solc binary."
48
48
:group 'solidity
49
49
:type 'string
50
50
:package-version '(solidity . " 0.1.1" ))
51
51
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
+
52
64
(defvar solidity-mode-map
53
65
(let ((map (make-keymap )))
54
66
(define-key map " \C -j" 'newline-and-indent )
@@ -446,8 +458,9 @@ Highlight the 1st result."
446
458
(when (eval-when-compile (require 'flycheck nil 'noerror ))
447
459
; ; Avoid reference to free variable warnings
448
460
(defvar flycheck-solidity-checker-executable )
461
+ (defvar flycheck-solium-checker-executable )
449
462
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
451
464
" Whether to add standard solidity contracts.
452
465
453
466
When non-nil, enable add also standard solidity contracts via
@@ -456,26 +469,70 @@ When non-nil, enable add also standard solidity contracts via
456
469
:safe #'booleanp
457
470
:package-version '(solidity-mode . " 0.1.3" ))
458
471
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
+
459
483
; ; add dummy source-inplace definition to avoid errors
460
484
(defvar source-inplace t )
461
485
; ; add a solidity mode callback to set the executable of solc for flycheck
462
486
; ; define solidity's flycheck syntax checker
463
487
(flycheck-define-checker solidity-checker
464
488
" A Solidity syntax checker using the solc compiler"
465
489
:command (" solc"
466
- (option-flag " --add-std" flycheck-solidity-addstd-contracts)
490
+ (option-flag " --add-std" flycheck-solidity-solc- addstd-contracts)
467
491
source-inplace)
468
492
:error-patterns
469
493
((error line-start (file-name) " :" line " :" column " :" " Error: " (message ))
470
494
(error line-start " Error: " (message ))
471
495
(warning line-start (file-name) " :" line " :" column " :" " Warning: " (message )))
472
496
:modes solidity-mode
473
497
: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)))))
479
536
480
537
(provide 'solidity-mode )
481
538
; ;; solidity-mode.el ends here
0 commit comments