2

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

1 Answer 1

2

Instead, it complains about not being able to resolve any packages […] and since the path does not match the buffer path all thos results are displayed at the minibuffer instead of actaully highlighting the code.

This is not quite right. The problem is that the errors aren't in the right format — the -parse-tslint function expects a JSON object, but the checker is printing errors as plain text. Then Flycheck complain, because it's seeing two contradictory pieces of info: 1. no errors could be found in the output but 2. the checker returned non-0.

Your real problem seems to be Flycheck's way of feeding input to tslint: it creates a temporary file, but typescript doesn't find the files it expects in there, besides the current file being edited.

Three possible solutions:

  • tell Flycheck to verify in place (source-inplace)
  • feed the file to tslint on stdin
  • use the :working-directory parameter

(there's more information on all three in the manual)

Also, please report the fact that tslint is printing its output as text despite the --format json flag as a bug to tslint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.