-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't typecheck or load files under node_modules/ unless they're imported by flow-typed files #869
Comments
This seems like a good idea to me, but it also sounds really hard, given how things currently work. |
Also #863 for an easy way to make this problem more user-visible. |
When I test my own code with Flow I'm not interested at all in type errors in the Shouldn't
I agree, but do you expect Flow to show you errors in those imported files? Personally I only want errors from my own code. Flow should be smart enough to understand that code in |
We made a big change here in the last release. Only @flow files will be parsed, which I suspect will improve this situation considerably. |
@samwgoldman, thanks for the update! Just tested it and t does check a lot less files which is good! An option to totally switch it off for node modules would be great though. |
@jamiter It's not (yet) very common, but files under node_modules can have type definitions that are used by your project. For example, my react-save-refs and ud modules both do, so by default you get type-checking on calls to them without any configuration needed. (babel-plugin-transform-flow-comments can be used to do this, though it has issues like T7054. Instead, I just include the babel-transpiled code in the NPM package, and then include the original source with the ".flow" suffix to the filename, which Flow reads instead. This is set up by the "prepublish" commands in the scripts section of the modules' package.json.) |
@agentme, thank you for the clarification. I'm new to FlowType and still getting to know all implementation details. I understand your use case, but it could lead to issues if some module is running another (out of date) flow version, right? In your case you can update your own module and push it to NPM, but it won't always be that easy. So I still think that Flow should understand the types defined in node modules, but not show any errors in the command line about them. Only when your own code doesn't match any defined types (in node modules or your own code). How can you use Flow in CI when it throws errors about code you do not own? |
If a newer version of Flow caused it to not understand the types in one of my modules, the error message would be more useful than silently failing so I knew there was something wrong. I can always add the module to my .flowconfig's [ignore] section. (I currently have to do that with the fbjs module and some babel modules which seem to have some invalid flow-typed code.) |
Just to get this right: You can add it to your ignore section, but then you will get The new version seems to ignore most |
I'm very interested in using flow but I'm running into this issue as well. My project is reporting errors about files I can't really do much about. I feel like there should be an option to ignore errors in the "node_modules" folder. At first I thought [ignore] was exactly what I needed until I ran into "Required module not found" errors all over. I realize that flow needs to have knowledge of the files included in a project, but it would be nice if there was an option to silence errors found in the If I submitted a PR for this, would it be considered? |
@toddw What errors are you running into specifically? |
|
@toddw Thanks! The solution in this case is to ignore the specific files that are problematic: I haven't tested it, but this should work:
I've also sent an upstream change to fix fbjs, so the next version should no longer cause this issue. We're also working to fix the invalid JSON errors, so that shouldn't be an issue soon. Ignoring everything in |
Thanks @samwgoldman, if I use I've never written anything in OCaml so this is taking me longer than I hoped but I was thinking like the following: (sorry for the screenshot and not a legit PR but I'm just throwing around ideas) |
Well, using fbjs isn't really advisable in general, but if you do want to I'd recommend waiting for the new release, which fixes the issue you ran into. Regarding suppressing, I'm not sure how I feel about it. On one hand, we want to fix those issues, not suppress them. On the other hand, lots of new users run into issues and making their path easier is important. I don't want to discourage you from trying, but I'm not confident that a PR adding this feature would be merged. |
Fair enough. fbjs is probably not the best example. I'm imagining a scenario where some other 3rd party component has flow errors. As flow gets wider adoption, as I'm sure it will, it seems inevitable that people will run into more issues. I didn't think [ignore] worked the way it does. I expected it to work as [supress] which I think should be considered. Either way, I appreciate the time you took to address my issue and I should be unblocked by your suggestion. |
Update, I've been using flow for the past 20 days and this continues to be an annoying problem.
I do use |
Just adding my 2¢ - this is a big oversight. It seems to me I currently have two options:
Both of these seem pretty unacceptable to me. Is there any workaround? |
This is a pretty big pain point. Flow seemed like the nicest way to get some sort of static typechecking incrementally added to our JS codebase, but both "ignore all the module not found errors" and "ignore all the errors coming out of node_modules" aren't really things I want to say when trying to sell the team on Flow. |
It's not just fbjs that's an issue:
I don't know if it's practical to ignore individual npm packages as they identify themselves as being problematic. I don't see any issue with ignoring the node_modules folder. I've done it and run flow and it works just fine. |
In my projects I've had success ignoring problematic modules on a case-by-case basis. For example, I'm not saying the current situation is ideal, but for larger projects I haven't had issues selectively ignoring node modules. |
It's by no way ideal, but as an intermediate solution @iansinnott's approach has worked for me too. I'd also like to see this better resolved however. Hitting immediate hurdles like this one are not a great first impression, even if Flow is a really great tool. |
I'm all for adding One solution would be to implement a syntax for ignoring certain classes of errors in the config file, like with eslint. For example, you could just mark |
I take back what I said. Ignoring the whole |
Who is the we in this statement? Because the manifestation of this issue is that every consumer of a library with type errors is shouted at by flow, and it does not seem at all reasonable to suggest that all those users be expected to take responsibility for fixing upstream issues. It's really just noise that distracts people from writing their own code - library maintainers will get their own errors if they use flow in their projects - it doesn't make sense to push those errors out to everyone. |
I think I'm going to pull Flow from both of the projects I started to use it on. I'm just running into too many issues that wind up slowing me down rather than help me get my work done. I'll revisit later though, for sure. IMO, I don't think there should be a separate project (flowtyped) to handle 3rd party libraries' typedefs. I think Flow should have some innate ability for library maintainers to export types and indicate to Flow (in a project using said libraries) how to find the types and incorporate them into the dev's project. |
@ffxsam Libraries can include their own Flow types. It's not well documented but there's some information about how to do it here: #1996 (comment). (The flowtyped project is for libraries that don't bundle their own types.) |
@mrkev Thanks for the followup. FYI, I have |
@HunderlineK Idk man, I just hopped into this issue14 hours ago ¯\(ツ)/¯. I'm sure somewhere in the thread there's discussion about why it was closed. You can |
Summary: With this patch there is a new section in `.flowconfig`: ```ini [silence] /path/to/file.js /path/to/dir ``` Paths in `[silence]` will still be typechecked, but any errors will be silenced as if there was a `suppress_comment` comment string on every line where there are errors. I called it `silence` to make it stand out from `ignore` and `suppress_comment` as it currently silences all errors, including lints. I believe this fixes #869, though I admit I didn't read the whole issue. (If this is accepted I'll add docs in a follow-up). Closes #4916 Reviewed By: mroch Differential Revision: D8172236 Pulled By: mrkev fbshipit-source-id: 1ce6771d0065dc42070fee3aa472cf0e760d8dad
For those still following this issue, in the next release of Flow I added a new Often third-party libraries have broken type definitions or have type The Conceptually one can think of declaration mode as if Flow still typechecks the I believe by leveraging |
@LegNeato except the fact that flow will still walk through not relevant files (even just to check if marked with |
This isn't quite true: .json files are always checked for syntax correctness, which is annoying because many dependencies intentionally publish tests that contain broken .json files. |
@levenleven say you have 3 JS files: A, B and C. A has an
The only way to know what files should be re-checked is if you form a full dependency graph at the beginning of the type-checking process. Flow goes the safe route in including all files in this graph so you could change any file and all files that depend on it would be automatically re-checked. Perhaps there's optimizations that could be made, sure, but I'd say that's a separate issue. |
@agentme so ignore all test json and/or treat json as declarations: [ignore]
**/(__)?tests?(__)?/*.json
[declarations]
**/*.json
@levenleven I assure you Flow has been used on bigger codebases than yours in many large monorepos. Also, the things to check vs not check are usually project dependent...Flow's default behavior + config option customization is pretty much the only good method to make sure no files are missed in the general case as @mrkev demonstrates. FWIW you might carve huge chunks off for your use-case by doing creative things in your config like: [ignore]
**
[include]
**/*.js(on)? So with the next Flow version we have:
There are no known use-cases that can't be fixed with a combination of these. The Flow defaults may not work out of the box for your project but that doesn't mean there is an issue here. Before
|
@LegNeato Nice suggestion, but once you |
I'm running flow 0.76.0. 16 files in node modules don't pass the flow check. One of these files is None of the following patterns silences flow errors in this file (or any of the other 15 files, for that matter):
So either the docs are wrong, or the feature was shipped but it's broken. EDIT: So, as @LegNeato mentioned in #4916 , this isn't a problem with |
I'll take a look and see what is up...in my testing it worked and it landed with tests. Maybe something is wonky. Thanks for trying it! |
Thanks @LetNeato, I'm really looking forward to using this! |
exactly as @levenleven noticed. [ignore] section has the highest precedence. Would be great if every sections [include], [ignore], [libs], [declarations] has also option for exclusive rule like .gitignore ! prefix. |
- Includes workaround for `config-chain` including intentionally broken test files in its repo: facebook/flow#869 - Includes Hack for externals with Parcel: parcel-bundler/parcel#144
Ignore invalid json files in flow config to prevent expected failures from producing errors. See facebook/flow#869
I think there is more problems with |
Most of my errors are gone by adding following to .flowconfig
|
Use
|
Why is this issue closed? The problem has not been answered and has not been marked as |
Can we be given a simple option to just ignore all
|
Thanks @FanchenBao. This should be a best practice of all flow projects. I'm surprised it's not often mentioned in other places. I think at least the flow doc should just say |
Most of the files under node_modules aren't the responsibility of my project, errors in them are probably due to them being written for a different Flow version, and the only reason to parse them would be if my project has flow-typed files referring to types in them.
It seems like a common issue is that Flow takes longer to start up than it ought to because it reads all of the javascript files under node_modules/ when the user isn't interested in typechecking most of them (#863). Tons of files under node_modules/ are sub-dependencies of other non-Flow-typed dependencies. People can manually ignore individual dependencies to speed things up (example), but this loses its effectiveness with the newly-released npm 3 because now dependencies aren't usually nested. (Browserify's many dependencies are now placed directly under node_modules/ instead of node_modules/browserify/node_modules/, so ignoring
.*node_modules/browserify.*
is no longer nearly as effective.)It makes sense to check the flow types of files under node_modules/ if they're imported by flow-typed files in the project itself, and maybe the types of the files those ones include if it's necessary to fully figure out their types, but I think most/all users would prefer that files under node_modules/ would not be even loaded for typechecking unless they're imported by a flow-typed file in the project proper. Maybe this could be a (default-on?) setting in
.flowconfig
.The text was updated successfully, but these errors were encountered: