flow-typed / eslint-plugin-ft-flow Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://www.npmjs.com/package/eslint-plugin-ft-flow
License: Other
Home Page: https://www.npmjs.com/package/eslint-plugin-ft-flow
License: Other
I think this rule is a really good idea. I have a suggestion for improvements though before I can enable it in our codebase. For example, this should be an error (I actually thought this is what the rule is supposed to catch):
// @flow strict
export const test: $FlowFixMe = 42;
Flow is happy, Eslint rule is happy (it should not be). Another example which I think is wrong is this:
// @flow strict
// $FlowExpectedError[incompatible-type]
export const test: string = 42;
It's wrong because it's a Flow test (__flowtests__/test.js
) and the error is expected to happen ($FlowExpectedError
). In other words, it's correct that Flow complains here (I marked it as expected) but it doesn't mean the file cannot be strict. This case is actually very common in our codebase where we have many strictly typed flow test files. It would be correct if the suppression was for example $FlowFixMe
or $FlowIssue
.
What do you think about this?
https://github.com/flow-typed/eslint-plugin-ft-flow/blob/master/src/utilities/getBuiltinRule.js
This file looks very outdated, maybe need to investigate and cleanup
I feel like this name would be more descriptive. The rule doesn't catch only $FlowFixMe
but other suppression comments as well, see:
Related discussion here: #14
Hola, I am trying to replace eslint-plugin-flowtype
with eslint-plugin-ft-flow
and there is a new rule ft-flow/enforce-suppression-code
. Unfortunately, it fails in many files on our codebase with the following error:
$ /Users/martinzlamal/Work/adeira/universe/node_modules/.bin/eslint src/sx-design/src/constants.js
Oops! Something went wrong! :(
ESLint: 7.32.0
TypeError: Cannot read properties of undefined (reading 'startsWith')
Occurred while linting /Users/martinzlamal/Work/adeira/universe/src/sx-design/src/constants.js:19
at /Users/martinzlamal/Work/adeira/universe/node_modules/eslint-plugin-ft-flow/dist/rules/enforceSuppressionCode.js:21:17
at Array.forEach (<anonymous>)
at isMissingSuppressionCode (/Users/martinzlamal/Work/adeira/universe/node_modules/eslint-plugin-ft-flow/dist/rules/enforceSuppressionCode.js:20:33)
at handleComment (/Users/martinzlamal/Work/adeira/universe/node_modules/eslint-plugin-ft-flow/dist/rules/enforceSuppressionCode.js:32:24)
at Array.forEach (<anonymous>)
at Program (/Users/martinzlamal/Work/adeira/universe/node_modules/eslint-plugin-ft-flow/dist/rules/enforceSuppressionCode.js:41:119)
at /Users/martinzlamal/Work/adeira/universe/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/martinzlamal/Work/adeira/universe/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/martinzlamal/Work/adeira/universe/node_modules/eslint/lib/linter/node-event-generator.js:293:26)
The simplest file where this is happening is probably: https://github.com/adeira/universe/blob/02aa03c955c17ebb4a60d4f1f7ce65c19943f9ac/src/sx-design/src/constants.js (clone the repo and run yarn eslint src/sx-design/src/constants.js
to reproduce)
Thanks for having a look! ๐
I'd like to ensure no side effects are introduced by type imports, that means if I only import a type from a module, it should use the declaration syntax (import type { X } from 'y'
).
If I import a mix of types and normal exports from a module though, I don't care about this:
// this separation is not useful as the first import will run any module side effects.
import { X } from 'y';
import type { Z } from 'y';
Right now the type-import-style
rule doesn't allow to specify this. Do you think it could be implemented?
We just released v0.8.0 of hermes-eslint
.
As of this release we have full support for ESLint 8+ - meaning we support the latest ESTree syntax for class properties, class private properties and optional chaining.
hermes-eslint
also has a fully-featured scope analyser which understands flow types. This means that the rules ft-flow/define-flow-type
and ft-flow/use-flow-type
are no longer needed! Also fun side-note that the rules react/jsx-uses-react
and react/jsx-uses-vars
are not needed because the analyser also supports JSX!
Worth noting that this will also reveal a bunch of no-undef
errors in codebases because types are now analysed by the lint rule and types like $ReadOnly
are global and have no global declared by ESLint. So no-undef
should ideally be turned off in the recommended config. Flow checks this anyway, so it's a superfluous rule.
type TypographyPathifyT = {
[key in keyof TypographyVariantsT]: string,
};
Will first produce 'key' is defined but never used.eslint[no-unused-vars](https://eslint.org/docs/latest/rules/no-unused-vars)
and then using mapped types more will produce, 'key' is already defined.eslint[no-redeclare](https://eslint.org/docs/latest/rules/no-redeclare)
DeprecationWarning: "type-import-style with @babel/eslint-parser parser" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/latest/extend/custom-rules#options-schemas
I opened this issue: facebook/hermes#1311
But not totally sure where the best place for asking this is, so repeating:
In ft-flow, there is this line:
node_modules/eslint-plugin-ft-flow/dist/rules/defineFlowType.js:75:44
var newGetScope = context.sourceCode.getScope;
Which errors with:
TypeError: Cannot read properties of undefined (reading 'getScope')
Based on the error, it says while trying to lint this line:
import typeof Yargs from 'yargs';
If I switch to @babel/eslint-parser
and version 2.0.3 then it passes just fine.
I updated from 2.0.3 to 3.0.4 due to: facebook/hermes#1285
no-flow-suppressions-in-strict-files and newline-after-flow-annotation at the very least do not seem to notice the @flow strict
annotation if it's inside a multiline comment, such as:
/*
* @flow strict
* Copyright (C) 2017 MetaBrainz Foundation
*
* This file is part of MusicBrainz, the open internet music database,
* and is licensed under the GPL version 2, or (at your option) any
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
*/
Having {/* $FlowIgnore[sketchy-null-number] */}
in that same file does not trigger the rule, but it should.
I couldn't figure it out yet, but once I add extends: ['plugin:ft-flow/recommended']
the linter crashes for enum types:
yarn run v1.22.17
$ ./node_modules/.bin/eslint ./app.js
app.js
22:7 error Parsing error: Unexpected token, expected "{" (22:7)
โ 1 problem (1 error, 0 warnings)
Without ft-flow/recommended
it works though.
globalScope.__defineGeneric
is not a funtionHello. What problem do I try to solve: we try to migrate our out-of-date flow to the latest version, and on the way installed ft-flow
to lint it. We have no-undef
rule, and need to override it for flow internal types, i.e. $Values<...>
, $Keys<...>
, ..., because they conflict with eslint's no-undef
now.
I'm trying to add ft-flow
to .eslintrs.js
, which kinda works until I start adding rules beyond recommended extension. My config (relevant parts, I guess):
module.exports = {
parser: 'hermes-eslint',
parserOptions: {
ecmaVersion: 9,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
babelOptions: {
configFile: path.resolve(__dirname, './babel.config.js'),
},
},
extends: [
// ...
'plugin:ft-flow/recommended'
],
plugins: [
'ft-flow',
// ...
],
env: {
browser: true,
jquery: true,
node: true,
jest: true,
es6: true,
},
root: true,
rules: {
'ft-flow/use-flow-type': 1,
'ft-flow/define-flow-type': 1, // this rule breaks
// ...
},
// ...
}
The line of code where I get the error (I guess, $Values<...>
breaks it)
export type ResourceType = $Values<typeof RESOURCE_TYPES>
ESLint: 8.56.0
TypeError: globalScope.__defineGeneric is not a function
Occurred while linting [some js file here]
Rule: "ft-flow/define-flow-type"
at makeDefined (PATH/node_modules/eslint-plugin-ft-flow/dist/rules/defineFlowType.js:28:21)
at GenericTypeAnnotation (PATH/node_modules/eslint-plugin-ft-flow/dist/rules/defineFlowType.js:67:9)
at PATH/node_modules/eslint/lib/linter/timing.js:141:28
at ruleErrorHandler (PATH/node_modules/eslint/lib/linter/linter.js:1076:28)
at PATH/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (PATH/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (PATH/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
at NodeEventGenerator.applySelectors (PATH/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
at NodeEventGenerator.enterNode (PATH/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
There is similar issue in your legacy (right?) project, but no solutions provided whatsoever. What can I do? Or maybe this is a bug? Thank you in advance.
Details here,
gajus/eslint-plugin-flowtype#500
I have noticed two issues around type parameters:
$NonMaybeType
and indexed accessorWhen using a React state hook I want to explicitly type the state property useState<?string>(null)
. This is being formatted as useState < ?string > (null);
by the plugin. This causes no linting warnings or errors based on recommended settings.
When using $NonMaybeType
with indexed types I get a trailing space added $NonMaybeType<SomeType['someNestedArray'][0]>
comes out like $NonMaybeType<SomeType['someNestedArray'][0] >
. This now throws a linting warning (recommended settings) that the generic parameter should not have trailing spaces.
I would love to contribute, if I have time to take a look. Let me know if this is expected behaviour.
The current main README.md is templated and can only be created on master, it uses a tool called gitdown. Ideally this shouldn't be hard to simply it into a node script so it can be run anywhere
The eslint rules are for flowtype, we might as well flowtype the project to give more stability, consistency
Currently yarn test
just runs every test, and if you want to filter it down you have to comment out test suites which is a really clunky process. Maybe some cli options with mocha or swap out to jest or something
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.