I'm not sure if it's a bug or a feature.
When I enable Flow Strict with nonstrict-import lint, then I can't import from libraries that export Flow files, but they are not strict.
For example the Facebook's IDX:
Dependencies of a @flow strict module must also be @flow strict! (nonstrict-import)
1โ // @flow strict
2โ
3โ import idx from 'idx';
4โ
But I can still import any module that has a flow-typed library definition. Isn't that strange? Libraries that are not even shipped with types are considered strict, libraries with types are non-strict.
I realised IDX wasn't the best example, because its last version is strict...
But anyway, I think this behaviour is problematic, mainly for two reasons:
I just ran into this also. It'd be great if there were a sub-option available to exclude 3rd party modules (everything in the module.system.node.resolve_dirname folders) from the _strict_ requirement, like there are sub-options for the sketchy-null lint rule.
Perhaps with a note in the output about how many errors were supressed.
Yeah, perhaps nonstrict-import should imply untyped-import. (In the meantime, you may want to consider enabling that lint too.)
Would @flow strict-local be too weak for your use case?
In my case, yes. Ideally I'd like to use @flow strict, but not be held up by 3rd party modules not implementing it yet (or ever).
Yeah, perhaps
nonstrict-importshould implyuntyped-import. (In the meantime, you may want to consider enabling that lint too.)
I have untyped-import enabled too:
[strict]
nonstrict-import
unclear-type
untyped-import
untyped-type-import
unsafe-getters-setters
sketchy-null
Would
@flow strict-localbe too weak for your use case?
Yes, it would. My goal is to have all files in the project @flow strict eventually.
For now, if only non-strict libraries are blocking me from using @flow strict, then I add a comment to the import with // $FlowFixMe https://github.com/facebook/flow/issues/6628, but I'm not very happy about it.
I'm wondering if there are any updates on this. Is there a way to ignore nonstrict-import warnings only from specified directories? Take an example from CRA. Say I want to keep my src folder internally consistent with // @flow strict, but I want non-strict imports from the node_modules directory outside of src to be allowed.
Currently, ignoring a certain directory I am importing from gives me "Cannot resolve module [module_name]" errors, whereas not ignoring them results in the nonstrict-import errors mentioned.
I have worked around this for the time being by ignoring the modules in my .flowconfig, and then adding my own type definition in my project's flow-typed folder for it.
[ignore]
<PROJECT_ROOT>/node_modules/recompose
<PROJECT_ROOT>/node_modules/react-select
Same issue here.
One of our lib use a set of linting rules. It has a suppression comment in its code.
// flowlint-next-line unnecessary-optional-chain: off
The consuming app doesn't have the linter activated, or a different set of rules.
Error โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ node_modules/.../Foo.js.flow:
Redundant argument. This argument doesn't change any lint settings.
17โ
19โ // flowlint-next-line unnecessary-optional-chain: off
20โ some?.stuff
21โ
Most helpful comment
I have worked around this for the time being by ignoring the modules in my
.flowconfig, and then adding my own type definition in my project'sflow-typedfolder for it.