I want flycheck to use the tslint's --type-check flag to compile my typescript files. In order to see unused imports on the fly inside emacs. By tslint docs
--type-check Enables the type checker when running linting rules. --project must be specified in order to enable type checking.
I also found out that I can set flycheck-tslint-args to add aditional aguments to tslint while also setting the --project flag to tsconfig.json path. Here it is what I have accomplished so far. I am creating a flycheck checker like below
;; Hardcoding this for now
(setq cesco-flycheck-typescript-tsconfig "/Users/cesco/go/src/github.com/cescoferraro/achars/tsconfig.json")
(flycheck-define-checker typescript-tslint-cesco
""
:command ("tslint" "--format" "json"
(config-file "--config" flycheck-typescript-tslint-config)
(config-file "--project" cesco-flycheck-typescript-tsconfig)
(option "--rules-dir" flycheck-typescript-tslint-rulesdir)
(eval flycheck-tslint-args)
source)
:error-parser flycheck-parse-tslint
:modes (web-mode))
My typescript config hook
(defun setup-tide-mode ()
(interactive)
(tide-setup)
(flycheck-mode +1)
(flycheck-select-checker 'typescript-tslint-cesco)
(setq flycheck-tslint-args . ("--type-check"))
(setq flycheck-check-syntax-automatically '(save mode-enabled))
(eldoc-mode +1)
(tide-hl-identifier-mode +1)
(add-to-list 'company-backends '(company-tide :with company-yasnippet))
)
(add-hook 'typescript-mode-hook #'setup-tide-mode)
The problem is that the source file used in the actual tslint command is placed at "/var/folders/...." and tslint would fail becouse tsconfig.js by default only includes files within this folder. If I include this into tsconfig.json
"include": [
"/var/folders/**/*"
]
Then tslint does not exists with errors. Instead, it complains about not being able to resolve any packages because there is no node_modules folder at /var/folders/43rr43r4/wherever and since the path does not match the buffer path all thos results are displayed at the minibuffer instead of actaully highlighting the code.
Suspicious state from syntax checker typescript-tslint-cesco: Flycheck checker typescript-tslint-cesco returned non-zero exit code 1, but its output contained no errors: Error at /var/folders/5d/5rzjf50s31z3_yhgy4hw1n_80000gn/T/flycheck2097Ejk/router.epic.tsx:2:28: Cannot find module 'rxjs'.
Error at /var/folders/5d/5rzjf50s31z3_yhgy4hw1n_80000gn/T/flycheck2097Ejk/router.epic.tsx:3:29: Cannot find module 'react-redux-firebase'.
Error at /var/folders/5d/5rzjf50s31z3_yhgy4hw1n_80000gn/T/flycheck2097Ejk/router.epic.tsx:4:22: Cannot find module 'connected-react-router'.
Error at /var/folders/5d/5rzjf50s31z3_yhgy4hw1n_80000gn/T/flycheck2097Ejk/router.epic.tsx:7:46: Cannot find name 'Action'.
Try installing a more recent version of typescript-tslint-cesco, and please open a bug report if the issue persists in the latest release. Thanks!
I can also run M-x flycheck-compile RET typescript-tslint-cesco RET and then It runs fine but still errors with code 2 abnormally and I dont get any highlighting.
-*- mode: compilation; default-directory: "~/go/src/github.com/cescoferraro/achars/app/containers/" -*-
Compilation started at Fri May 19 13:45:34
tslint --format json --config /Users/cesco/go/src/github.com/cescoferraro/achars/tslint.json --project /Users/cesco/go/src/github.com/cescoferraro/achars/tsconfig.json --type-check /Users/cesco/go/src/github.com/cescoferraro/achars/app/containers/router.epic.tsx
[{"endPosition":{"character":50,"line":2,"position":98},"failure":"All imports are unused.","fix":{"innerStart":48,"innerLength":50,"innerText":""},"name":"/Users/cesco/go/src/github.com/cescoferraro/achars/app/containers/router.epic.tsx","ruleName":"no-unused-variable","ruleSeverity":"ERROR","startPosition":{"character":0,"line":2,"position":48}}]
Compilation exited abnormally with code 2 at Fri May 19 13:45:38