microsoft / microsoft/rnx-kit

Suggestion: Flag unused imports after inlining platform checks

Open
#2,602 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
1.7k
Forks
119
Avg merge
1d 5h
Merged PRs (30d)
52

Description

import { DateTimePickerAndroid } from "@react-native-community/datetimepicker";
import { Platform } from "react-native";

export default () => {
  if (Platform.OS === "android") {
    return DateTimePickerAndroid.open(datePickerOptions);
  } else if (Platform.OS === "ios") {
    // return something iOS specific
  } else {
    // return something else
  }
};

Metro can inline platform checks with a plugin. In the above example, targeting ios will make DateTimePickerAndroid unused. However, the import statement will remain and we will still import @react-native-community/datetimepicker on iOS. There should be a way to flag this as unused on certain platforms.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Metro inline platform-check plugin linked in the issue and inspect how platform-specific branches are transformed. Determine how unused imports should be detected after inlining, then verify that imports for excluded platforms are flagged or removed without affecting imports still used by the selected platform.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
build-system, mobile, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.