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

Add Linting to require conditions for multiplatform dependencies with mismatched platforms. #6251

Merged
merged 6 commits into from
May 7, 2024

Conversation

waltflanagan
Copy link
Member

  • Extract dependency relationship linting to dedicated method
  • Add linting to ensure conditions are included for targets that dont supported all the required platforms of a target.

Fixes #5978.

Short description 📝

Adding linting to call out when a platform condition is required. It's more complicated than just checking the set of platforms of each target because some target relationships (iOS app depending on WatchOS App) are valid. Here we constrain the linting logic to just linkable targets but we could include

How to test the changes locally 🧐

Tests were added to replicate the issue and are passing with the addition of the linting rules.

Contributor checklist ✅

  • The code has been linted using run mise run lint:fix
  • The change is tested via unit testing or acceptance testing, or both
  • The title of the PR is formulated in a way that is usable as a changelog entry
  • In case the PR introduces changes that affect users, the documentation has been updated

Reviewer checklist ✅

  • The code architecture and patterns are consistent with the rest of the codebase
  • Reviewer has checked that, if needed, the PR includes the label changelog:added, changelog:fixed, or changelog:changed, and the title is usable as a changelog entry

@alexanderwe
Copy link
Collaborator

@waltflanagan Thanks a lot for taking care of this issue. So basically you introduced a linting rule whenever a depdendency without conditions is linked to a target which supported set destinations is a superset of of the linked target and the target is not linked with any conditions did I see that correct ?

if !unaccountedPlatforms.isEmpty {
let missingPlatforms = unaccountedPlatforms.map(\.rawValue).joined(separator: ", ")
return [LintingIssue(
reason: "Target \(fromTargetName) with depends on \(dependentTarget.target.name) and but does not support the required platforms \(missingPlatforms). This dependency requires a condition.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of making this message a little more verbose ?

Suggested change
reason: "Target \(fromTargetName) with depends on \(dependentTarget.target.name) and but does not support the required platforms \(missingPlatforms). This dependency requires a condition.",
reason: "Target \(fromTargetName) which \(dependentTarget.target.name) is depending on, does not support the required platforms \(missingPlatforms). \(fromTargetName) requires a condition which restricts it to at most \(missingPlatforms)",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like it!

@waltflanagan waltflanagan requested review from a team and fortmarek and removed request for a team May 6, 2024 02:09
Copy link
Member

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably derive the condition ourselves if it's not specified, but I'd also lean to forcing developers to be explicit about it.

Sources/TuistGenerator/Linter/GraphLinter.swift Outdated Show resolved Hide resolved
@pepicrft pepicrft added changelog:changed PR will be listed in the Changed section of CHANGELOG changelog:added PR will be listed in the Added section of CHANGELOG and removed changelog:changed PR will be listed in the Changed section of CHANGELOG labels May 6, 2024
Copy link
Collaborator

@alexanderwe alexanderwe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx a lot for the addition 👍

@fortmarek fortmarek merged commit 3ccc534 into main May 7, 2024
8 checks passed
@fortmarek fortmarek deleted the MultiplatformDependencyLinting branch May 7, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:added PR will be listed in the Added section of CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Defined platforms are wrongfully elevated to support more then indented
4 participants