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

FED-3159 Fix required prop null-safe-conditional linting #948

Merged
merged 3 commits into from
Sep 20, 2024

Conversation

greglittlefield-wf
Copy link
Contributor

@greglittlefield-wf greglittlefield-wf commented Sep 19, 2024

Motivation

The over_react analyzer plugin is always supposed to lint for missing required props, unless they're on props declared in non-null safe libraries.

There's a bug in this conditional that instead checks the language version of the library the component is consumed in, as opposed to the library the component is declared in.

This prevents consumers from getting static warnings in cases where they'll get runtime errors.

For example, expected behavior:

//@dart=2.11

import 'package:null_safe_package/has_required.dart';

class NonNullSafeMixesInRequiredProps = UiProps with HasRequiredProps;
UiFactory<NonNullSafeMixesInRequiredProps>  NonNullSafeMixesInRequiredProps = ...;

example() {
  // Should lint about missing required props
  HasRequired()();
  // Should not lint, because this props class is not null-safe
  NonNullSafeMixesInRequired()(); 
}

vs actual behavior:

example() {
  // Does not lint - incorrect behavior ❌ 
  HasRequired()(); 
  // Does not lint - correct behavior ✅
  NonNullSafeMixesInRequired()(); 
}

Changes

  • Update logic to check the null safety status of the library containing the props class, not the file it's being used in
  • Add regression test
  • Semi-related cleanup: replace withNullability util with the LibraryElement.isNonNullableByDefault API, which I just learned about!

Release Notes

  • Fix late required prop linting not working in non-null-safe libraries

Review

See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.

Please review:

QA Checklist

  • Tests were updated and provide good coverage of the changeset and other affected code
  • Manual testing was performed if needed
    • Steps from PR author:
      • Regression test fails in commit before the fix was added ( 4e52637), and passes afterwards (latest CI passes)
    • Anything falling under manual testing criteria outlined in CONTRIBUTING.md

Merge Checklist

While we perform many automated checks before auto-merging, some manual checks are needed:

  • A Frontend Frameworks Design member has reviewed these changes
  • There are no unaddressed comments - this check can be automated if reviewers use the "Request Changes" feature
  • For release PRs - Version metadata in Rosie comment is correct

@aviary3-wk
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

@@ -138,16 +140,26 @@ class MissingRequiredPropTest_NoErrors extends MissingRequiredPropTest {
test() => InheritsLateRequired()();
Copy link
Contributor Author

@greglittlefield-wf greglittlefield-wf Sep 19, 2024

Choose a reason for hiding this comment

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

This existing test case (test_noErrorsInheritsLateRequired) and the newly-added regression test should, together, validate the behavior we want to see.

@@ -220,7 +219,8 @@ class MissingRequiredPropDiagnostic extends ComponentUsageDiagnosticContributor
continue;
}

if (withNullability(result) || requiredness != PropRequiredness.late) {
// Late required prop validation is only enabled for props classes that have migrated to null safety.
if (propsClassElement.library.isNonNullableByDefault || requiredness != PropRequiredness.late) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main fix; instead of checking result.library, we're now checking propsClassElement.library

@greglittlefield-wf greglittlefield-wf marked this pull request as ready for review September 19, 2024 21:42
@greglittlefield-wf greglittlefield-wf changed the title Fix required prop null-safe-conditional linting FED-3159 Fix required prop null-safe-conditional linting Sep 19, 2024
Copy link
Contributor

@aaronlademann-wf aaronlademann-wf left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@sydneyjodon-wk sydneyjodon-wk left a comment

Choose a reason for hiding this comment

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

QA +1

  • regression test used to fail and now it passes with the fix
  • I was also using the branch yesterday in some consumer repos and saw expected warnings show up on this branch that didn't show up when using over_react master

@greglittlefield-wf
Copy link
Contributor Author

@Workiva/release-management-p

Copy link

@rmconsole-wf rmconsole-wf left a comment

Choose a reason for hiding this comment

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

+1 from RM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants