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

Narrow regexp for import search in bot's analyze script. #26539

Merged
merged 1 commit into from
Jan 14, 2019

Conversation

gspencergoog
Copy link
Contributor

This was causing analysis to fail when there was an import statement in a comment, such as when snippets add imports to their examples.

I narrowed the RegExp to match only those lines which aren't commented out, but it really should probably be using the analysis server to catch all cases (e.g. if someone put the doc comment into /** */ comments, it could still match). Since this is a Flutter-specific script, it's probably not worth doing that.

final RegExp _importPattern = RegExp(r"import 'package:flutter/([^.]+)\.dart'");
final RegExp _importMetaPattern = RegExp(r"import 'package:meta/meta.dart'");
final RegExp _importPattern = RegExp(r'''^\s*import (['"])package:flutter/([^.]+)\.dart\1''');
final RegExp _importMetaPattern = RegExp(r'''^\s*import (['"])package:meta/meta.dart\1''');
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we expected imports to use single quotes?

Copy link
Member

Choose a reason for hiding this comment

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

I think checking for both makes this more resilient to lint failures.

Copy link
Contributor Author

@gspencergoog gspencergoog Jan 14, 2019

Choose a reason for hiding this comment

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

We do, but if this check doesn't look for double quotes, then it might miss a problem in imports. There is another analyzer lint that checks for double quotes here, so it will still fail the analysis.

I wanted those to be independent checks: imagine if you put double quotes on a problematic import: the analysis would fail the first time on the double quote check, but give no other errors. The second time you ran it, it would give the "import problem" error. The way this RegExp is, you'd now get both errors on the first run.

final RegExp _importPattern = RegExp(r"import 'package:flutter/([^.]+)\.dart'");
final RegExp _importMetaPattern = RegExp(r"import 'package:meta/meta.dart'");
final RegExp _importPattern = RegExp(r'''^\s*import (['"])package:flutter/([^.]+)\.dart\1''');
final RegExp _importMetaPattern = RegExp(r'''^\s*import (['"])package:meta/meta.dart\1''');
Copy link
Member

Choose a reason for hiding this comment

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

How do these ignore comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "^" anchors the search at the start of the line.

Copy link
Member

Choose a reason for hiding this comment

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

mind = blown

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@gspencergoog gspencergoog merged commit 35fcd90 into flutter:master Jan 14, 2019
@zoechi zoechi added the team Infra upgrades, team productivity, code health, technical debt. See also team: labels. label Jan 15, 2019
kangwang1988 pushed a commit to XianyuTech/flutter that referenced this pull request Feb 12, 2019
This was causing analysis to fail when there was an import statement in a comment, such as when snippets add imports to their examples.

I narrowed the RegExp to match only those lines which aren't commented out, but it really should probably be using the analysis server to catch all cases (e.g. if someone put the doc comment into /** */ comments, it could still match). Since this is a Flutter-specific script, it's probably not worth doing that.
@gspencergoog gspencergoog deleted the fix_analyze branch February 12, 2019 17:35
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
team Infra upgrades, team productivity, code health, technical debt. See also team: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants