Skip to content
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

Prettier and @typescript-eslint disagree on function types in generics #33452

Closed
joeframbach opened this issue Mar 19, 2022 · 0 comments
Closed
Labels
Needs: Triage 🔍 Resolution: Locked This issue was locked by the bot.

Comments

@joeframbach
Copy link
Contributor

Description

TypeScript projects passing setState argument types to a generic function trips up ESLint's JavaScript rules and does not instead use the TypeScript replacement. Prettier and ESLint disagree on the style and nobody is happy.

// Suppose we have some function with a type argument
declare function foo<T>(): any;

// This is OK! We can call it with a number type argument.
foo<number>();

// This is OK! We can call it with an array type argument.
foo<[number, string]>();

// This is OK! We can call it with a function type argument.
foo<[() => void]>();

// This is NOT OK! We can not call it with an array type argument containing a function, like React setState syntax for example.
// eslint's no-spaced-func wants this:
foo<[number,() => void]>();
//         ~~ no space here
// but Prettier wants to inject a space here, and nobody is happy.
// eslint's no-spaced-func has been deprecated for a long time in favor of func-call-spacing, but that doesn't work either.

// eslint's func-call-spacing wants this:
foo<[number,() => void]>();
//         ~~ no space here
// but Prettier wants to inject a space here, and nobody is happy.

// Using @typescript-eslint/func-call-spacing, this now works.
// @typescript-eslint/func-call-spacing is ok with either of these:
foo<[number,() => void]>(); // but Prettier will inject a space here,
foo<[number, () => void]>(); // and everyone is happy.

Version

0.67.3

Output of npx react-native info

info Fetching system and libraries information...
System:
    OS: macOS 12.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 31.27 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.0.0 - ~/.nvm/versions/node/v16.0.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.0.0/bin/yarn
    npm: 7.10.0 - ~/.nvm/versions/node/v16.0.0/bin/npm
    Watchman: 2022.03.07.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK:
      API Levels: 29, 30
      Build Tools: 30.0.2, 32.0.0, 32.1.0
      System Images: android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8193401
    Xcode: 13.3/13E113 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_322 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.67.3 => 0.67.3
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. npx react-native init MyApp --template react-native-template-typescript
  2. In App.tsx write:
declare function foo<T>(): T;
foo<[string, () => number]>();

ESLint complains about the space between , and (. When fixed, Prettier complains about the missing space. When fixed, ESLint complains about the space between , and (.

Snack, code example, screenshot, or link to a repository

No response

joeframbach added a commit to joeframbach/react-native that referenced this issue Mar 19, 2022
Summary:
Fixes facebook#33452 by replacing deprecated no-spaced-func ESLint rule and adding related TypeScript.

Changelog: [General][Fixed] - Update function spacing linting rules

See facebook#33452 - Existing function spacing linting should pass as expected.
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this issue Jan 15, 2023
…acebook#33453)

Summary:
Fixes facebook#33452 by replacing deprecated no-spaced-func ESLint rule and adding related TypeScript.

Changelog: [General][Fixed] - Update function spacing linting rules

See facebook#33452 - Existing function spacing linting should pass as expected.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[CATEGORY] [TYPE] - Message

Pull Request resolved: facebook#33453

Reviewed By: lunaleaps, cortinico

Differential Revision: D35011944

Pulled By: GijsWeterings

fbshipit-source-id: 441650045d89a01a9114103da0c080643f9cb82c
@facebook facebook locked as resolved and limited conversation to collaborators Apr 1, 2023
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Triage 🔍 Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants