Giter VIP home page Giter VIP logo

eslint-plugin-ft-flow's Introduction

flow-typed

A repository of high-quality, third-party library type definitions for use with Flow.

ci status npm package docs discord package health


⚠️ Version 4.0 will release soon! ⚠️

And with it comes new features, most notably the support for definition dependencies.

Learn how to add dependencies to a definition from the main branch docs which can be consumed with the v4 CLI.

$ yarn global add flow-typed@next
# or
$ npm install -g flow-typed@next

What's happening to master?

Nothing for the most part! CLI versions < v4 will still pull definitions from master so if you have library definitions that don't require dependencies we still recommend you contribute to master and it'll get periodically synced back to main for users >= v4.

Eventually we will deprecate master in favour of main.


Check out the quick start page in the docs to get started. It will walk you through installing typedefs, using them, as well as writing and including your own.

Huh?

When you start a project with Flow, you likely want to use some third-party libraries that were not written with Flow. By default, Flow will just ignore these libraries leaving them untyped. As a result, Flow can't give errors if you accidentally mis-use the library (nor will it be able to auto-complete the library).

To address this, Flow supports library definitions which allow you to describe the interface of a module or library separate from the implementation of that module/library.

The flow-typed repo is a collection of high-quality library definitions, tests to ensure that definitions remain high quality, and tooling to make it as easy as possible to import them into your project.

All you have to do when you add one or more new dependencies to your project is run flow-typed install. This will search the libdef repo and download all the libdefs that are relevant for your project and install them for you. After that, simply check them in and be on your way!

The CLI

The flow-typed npm package provides a CLI that includes several commands for working with this repository. The full list of commands is available in the docs .

FAQs

Before opening an issue, take a look at the FAQs. Chances are your question has already been answered! If not, don't hesitate to open an issue.

How Do I Contribute Library Definitions?

Just send a pull request! The documentation highlighted in CONTRIBUTING.md should give a detailed overview of how to raise a pull request following our best practices.

Contributing to the CLI

Bugfixes and improvements to the core CLI are welcome. If you'd like to contribute a new feature, consider opening an issue first to discuss it.

Active Maintenance Team

Andrew Smith Brian Chen Georges-Antoine Assi Pascal Duez Ville Saukkonen
@AndrewSouthpaw @Brianzchen @GAntoine @pascalduez @villesau

eslint-plugin-ft-flow's People

Contributors

brianzchen avatar dannymx avatar dependabot[bot] avatar hyperupcall avatar nmn avatar short-dsb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

eslint-plugin-ft-flow's Issues

`ft-flow/enforce-suppression-code`: TypeError: Cannot read properties of undefined (reading 'startsWith')

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! 😊

flow type the repo

The eslint rules are for flowtype, we might as well flowtype the project to give more stability, consistency

Allow mixed type-import-style

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?

Function type parameters spacing issues

I have noticed two issues around type parameters:

  1. Function type parameters get spaces
  2. Utility functions such as $NonMaybeType and indexed accessor

My .eslintrc
image

Issue 1

When 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.
image

Issue 2

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.
image

I would love to contribute, if I have time to take a look. Let me know if this is expected behaviour.

`globalScope.__defineGeneric` is not a function

globalScope.__defineGeneric is not a funtion

Hello. 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.

Fix mapped types throwing eslint errors

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)

No sourceCode in context

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

Add meta.schema to rules

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

Suggested improvements to `no-flow-fix-me-in-strict-files` rule

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?

Recommended configuration not working with enums

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.

improve readme generator

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

Improve test runner

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

Switch to use `hermes-eslint` as the recommended parser

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.