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

Enable fixes/assits to edit other files #187

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions packages/custom_lint_core/lib/src/change_reporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ abstract class ChangeBuilder {
///
/// The builder passed to the [buildFileEdit] function has additional support
/// for working with Dart source files.
///
/// Use the [customPath] if the collection of edits should be written to another
/// dart file.
void addDartFileEdit(
void Function(DartFileEditBuilder builder) buildFileEdit, {
ImportPrefixGenerator importPrefixGenerator,
String? customPath,
});

/// Use the [buildFileEdit] function to create a collection of edits to the
Expand All @@ -76,18 +80,26 @@ abstract class ChangeBuilder {
///
/// The builder passed to the [buildFileEdit] function has no special support
/// for any particular kind of file.
///
/// Use the [customPath] if the collection of edits should be written to another
/// file.
void addGenericFileEdit(
void Function(analyzer_plugin.FileEditBuilder builder) buildFileEdit,
);
void Function(analyzer_plugin.FileEditBuilder builder) buildFileEdit, {
String? customPath,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'd need this on all addXFileEdit, such as addDartFileEdit

Copy link
Author

Choose a reason for hiding this comment

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

Done. customPath parameter added to all addXFileEdit methods

});

/// Use the [buildFileEdit] function to create a collection of edits to the
/// currently analyzed file. The edits will be added to the source change
/// that is being built.
///
/// The builder passed to the [buildFileEdit] function has additional support
/// for working with YAML source files.
///
/// Use the [customPath] if the collection of edits should be written to another
/// YAML file.
void addYamlFileEdit(
void Function(YamlFileEditBuilder builder) buildFileEdit,
String? customPath,
);
}

Expand All @@ -110,12 +122,13 @@ class _ChangeBuilderImpl implements ChangeBuilder {
void addDartFileEdit(
void Function(DartFileEditBuilder builder) buildFileEdit, {
ImportPrefixGenerator? importPrefixGenerator,
String? customPath,
}) {
_operations.add(
importPrefixGenerator == null
? _innerChangeBuilder.addDartFileEdit(path, buildFileEdit)
? _innerChangeBuilder.addDartFileEdit(customPath ?? path, buildFileEdit)
: _innerChangeBuilder.addDartFileEdit(
path,
customPath ?? path,
buildFileEdit,
importPrefixGenerator: importPrefixGenerator,
),
Expand All @@ -124,19 +137,21 @@ class _ChangeBuilderImpl implements ChangeBuilder {

@override
void addGenericFileEdit(
void Function(analyzer_plugin.FileEditBuilder builder) buildFileEdit,
) {
void Function(analyzer_plugin.FileEditBuilder builder) buildFileEdit, {
String? customPath,
}) {
_operations.add(
_innerChangeBuilder.addGenericFileEdit(path, buildFileEdit),
_innerChangeBuilder.addGenericFileEdit(customPath ?? path, buildFileEdit),
);
}

@override
void addYamlFileEdit(
void Function(YamlFileEditBuilder builder) buildFileEdit,
String? customPath,
) {
_operations.add(
_innerChangeBuilder.addYamlFileEdit(path, buildFileEdit),
_innerChangeBuilder.addYamlFileEdit(customPath ?? path, buildFileEdit),
);
}

Expand Down