Skip to content

Commit

Permalink
modify: delete unnecessary insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurogoma4D committed Jan 28, 2024
1 parent d062985 commit d5b8b6d
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import 'package:custom_lint_builder/custom_lint_builder.dart';
import '../riverpod_custom_lint.dart';
import 'convert_to_widget_utils.dart';

final _emptyPattern = RegExp(r'^\s*$');

class ConvertToStatelessBaseWidget extends RiverpodAssist {
ConvertToStatelessBaseWidget({
required this.targetWidget,
Expand Down Expand Up @@ -223,19 +221,20 @@ class ConvertToStatelessBaseWidget extends RiverpodAssist {
.firstWhereOrNull((element) => element.name.lexeme == 'build');
if (buildMethod == null) return;

builder.addInsertion(stateClass.sourceRange.end, (insertionBuilder) {
final outsideRange = SourceRange(
widgetClass.sourceRange.end,
stateClass.sourceRange.offset - widgetClass.sourceRange.end,
);
final outsideLines = source.contents.data.substring(
outsideRange.offset,
outsideRange.end,
final outsideRange = SourceRange(
widgetClass.sourceRange.end,
stateClass.sourceRange.offset - widgetClass.sourceRange.end,
);
final outsideLines = source.contents.data.substring(
outsideRange.offset,
outsideRange.end,
);
if (outsideLines.trim().isNotEmpty) {
builder.addSimpleInsertion(
stateClass.sourceRange.end,
'${outsideLines.trimRight()}\n',
);
if (!_emptyPattern.hasMatch(outsideLines)) {
insertionBuilder.write(outsideLines);
}
});
}

// ignore: prefer_foreach
for (final range in deleteRanges) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@
{
"fileStamp": 0,
"edits": [
{
"offset": 1167,
"length": 0,
"replacement": ""
},
{
"offset": 1085,
"length": 20,
Expand Down Expand Up @@ -137,11 +132,6 @@
{
"fileStamp": 0,
"edits": [
{
"offset": 1515,
"length": 0,
"replacement": ""
},
{
"offset": 1445,
"length": 29,
Expand Down Expand Up @@ -176,11 +166,6 @@
{
"fileStamp": 0,
"edits": [
{
"offset": 1818,
"length": 0,
"replacement": ""
},
{
"offset": 1757,
"length": 20,
Expand Down Expand Up @@ -215,11 +200,6 @@
{
"fileStamp": 0,
"edits": [
{
"offset": 2167,
"length": 0,
"replacement": ""
},
{
"offset": 2106,
"length": 20,
Expand Down Expand Up @@ -254,11 +234,6 @@
{
"fileStamp": 0,
"edits": [
{
"offset": 2550,
"length": 0,
"replacement": ""
},
{
"offset": 2489,
"length": 20,
Expand Down Expand Up @@ -337,67 +312,67 @@
"fileStamp": 0,
"edits": [
{
"offset": 4298,
"offset": 4340,
"length": 0,
"replacement": ""
"replacement": "\n\nconst _constantNumber = 42;\n"
},
{
"offset": 4272,
"offset": 4314,
"length": 1,
"replacement": ""
},
{
"offset": 4235,
"offset": 4277,
"length": 26,
"replacement": ""
},
{
"offset": 4234,
"offset": 4276,
"length": 1,
"replacement": ""
},
{
"offset": 4200,
"offset": 4242,
"length": 7,
"replacement": ""
},
{
"offset": 4179,
"offset": 4221,
"length": 1,
"replacement": ""
},
{
"offset": 4167,
"offset": 4209,
"length": 7,
"replacement": ""
},
{
"offset": 4166,
"offset": 4208,
"length": 1,
"replacement": ""
},
{
"offset": 4083,
"offset": 4125,
"length": 7,
"replacement": ""
},
{
"offset": 4049,
"offset": 4091,
"length": 20,
"replacement": "BuildContext context, WidgetRef ref"
},
{
"offset": 4004,
"offset": 4046,
"length": 7,
"replacement": ""
},
{
"offset": 3878,
"length": 95,
"offset": 3891,
"length": 124,
"replacement": ""
},
{
"offset": 3766,
"offset": 3779,
"length": 112,
"replacement": ""
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@
{
"fileStamp": 0,
"edits": [
{
"offset": 1167,
"length": 0,
"replacement": ""
},
{
"offset": 1085,
"length": 20,
Expand Down Expand Up @@ -118,11 +113,6 @@
{
"fileStamp": 0,
"edits": [
{
"offset": 1515,
"length": 0,
"replacement": ""
},
{
"offset": 1445,
"length": 29,
Expand Down Expand Up @@ -157,11 +147,6 @@
{
"fileStamp": 0,
"edits": [
{
"offset": 1818,
"length": 0,
"replacement": ""
},
{
"offset": 1757,
"length": 20,
Expand Down Expand Up @@ -196,11 +181,6 @@
{
"fileStamp": 0,
"edits": [
{
"offset": 2167,
"length": 0,
"replacement": ""
},
{
"offset": 2106,
"length": 20,
Expand Down Expand Up @@ -235,11 +215,6 @@
{
"fileStamp": 0,
"edits": [
{
"offset": 2550,
"length": 0,
"replacement": ""
},
{
"offset": 2489,
"length": 20,
Expand Down Expand Up @@ -318,67 +293,67 @@
"fileStamp": 0,
"edits": [
{
"offset": 4298,
"offset": 4340,
"length": 0,
"replacement": ""
"replacement": "\n\nconst _constantNumber = 42;\n"
},
{
"offset": 4272,
"offset": 4314,
"length": 1,
"replacement": ""
},
{
"offset": 4235,
"offset": 4277,
"length": 26,
"replacement": ""
},
{
"offset": 4234,
"offset": 4276,
"length": 1,
"replacement": ""
},
{
"offset": 4200,
"offset": 4242,
"length": 7,
"replacement": ""
},
{
"offset": 4179,
"offset": 4221,
"length": 1,
"replacement": ""
},
{
"offset": 4167,
"offset": 4209,
"length": 7,
"replacement": ""
},
{
"offset": 4166,
"offset": 4208,
"length": 1,
"replacement": ""
},
{
"offset": 4083,
"offset": 4125,
"length": 7,
"replacement": ""
},
{
"offset": 4049,
"offset": 4091,
"length": 20,
"replacement": "BuildContext context, WidgetRef ref"
},
{
"offset": 4004,
"offset": 4046,
"length": 7,
"replacement": ""
},
{
"offset": 3878,
"length": 95,
"offset": 3891,
"length": 124,
"replacement": ""
},
{
"offset": 3766,
"offset": 3779,
"length": 112,
"replacement": ""
},
Expand Down
Loading

0 comments on commit d5b8b6d

Please sign in to comment.