Open Gozala opened 7 years ago
I have being trying to figure out the way to implement this, digging through flow-base code but honestly I'm quite lost.
From what I understand there is hard wired assumption that there is .flowconfig
file associated with every file which isn't going to be the case here.
If someone more knowledgeable about the code base could offer a guidance I'd like to take a stab at it. Maybe @nmote ?
Looking into this further it seems that there is no way to run flow check-contents
without specifying a --root
which happens to contain .flowconfig
. Which I find unfortunate
It seems there is also facebook/flow#389 issue on file with a request to make .flowconfig
optional. Maybe @gabelevi has something to say ?
In the meantime I'm considering to add try
directory to this repo with a blank .flowconfig
and use that as root for this feature.
So I created pull #88 that implements this functionality. Specifically if you create new tab and set language to js
and the code has /* @flow */
pragma, with this changes extension will type check it with flow's default config, reporting problems or succeeding.
Still I think proper solution would be to remove a .flowconfig
requirement from flow
and also make project root optional. That way no workarounds described in pull request will be necessary. In fact js libraries that wrap flow
also seem to have ton of code to just deal with these requirements, so removing it would make everything way simpler.
Now there is one scenario where #88 still won't type check. Say you do draft the code in unsaved buffer and everything is fine, and then you save that buffer into file that isn't under the directory containing .flowconfig
and further edits won't be type checked. Main reason is because flow
wrapper libraries again do a lot to detect the root and bail when if they can't find it. So application of the same workaround won't really work, at best this workaround could be uplifted to the nuclide libraries but then again actually breaking .flowconfig
requirement seems like a much better option.
Currently to sketch some ideas I with flow one needs to create a project with flow configuration, for that reason I often time tend to reach over for flowtype.org/try instead. It would be really nice if I were able to type check arbitrary buffers with flow if they are starting with
@flow
pragma.