Add spaces after flow control statements (#126320)
This commit is contained in:
@@ -68,7 +68,7 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
|
||||
|
||||
late TestScenario currentValue;
|
||||
bool get resample {
|
||||
switch(currentValue) {
|
||||
switch (currentValue) {
|
||||
case TestScenario.resampleOn90Hz:
|
||||
case TestScenario.resampleOn59Hz:
|
||||
return true;
|
||||
@@ -78,7 +78,7 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
|
||||
}
|
||||
}
|
||||
double get frequency {
|
||||
switch(currentValue) {
|
||||
switch (currentValue) {
|
||||
case TestScenario.resampleOn90Hz:
|
||||
case TestScenario.resampleOff90Hz:
|
||||
return 90.0;
|
||||
@@ -92,7 +92,7 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
|
||||
|
||||
@override
|
||||
String describeValue(TestScenario value) {
|
||||
switch(value) {
|
||||
switch (value) {
|
||||
case TestScenario.resampleOn90Hz:
|
||||
return 'resample on with 90Hz input';
|
||||
case TestScenario.resampleOn59Hz:
|
||||
|
||||
@@ -13,7 +13,7 @@ Future<void> main() => driver.integrationDriver(
|
||||
final Map<String, dynamic> fullyLiveResult =
|
||||
data?['fullyLive'] as Map<String,dynamic>;
|
||||
|
||||
if(benchmarkLiveResult['frame_count'] as int < 10
|
||||
if (benchmarkLiveResult['frame_count'] as int < 10
|
||||
|| fullyLiveResult['frame_count'] as int < 10) {
|
||||
print('Failure Details:\nNot Enough frames collected: '
|
||||
'benchmarkLive ${benchmarkLiveResult['frameCount']}, '
|
||||
|
||||
@@ -112,6 +112,9 @@ Future<void> run(List<String> arguments) async {
|
||||
printProgress('Trailing spaces...');
|
||||
await verifyNoTrailingSpaces(flutterRoot); // assumes no unexpected binaries, so should be after verifyNoBinaries
|
||||
|
||||
printProgress('Spaces after flow control statements...');
|
||||
await verifySpacesAfterFlowControlStatements(flutterRoot);
|
||||
|
||||
printProgress('Deprecations...');
|
||||
await verifyDeprecations(flutterRoot);
|
||||
|
||||
@@ -1040,6 +1043,38 @@ Future<void> verifyNoTrailingSpaces(String workingDirectory, { int minimumMatche
|
||||
}
|
||||
}
|
||||
|
||||
final RegExp _flowControlStatementWithoutSpace = RegExp(r'(^|[ \t])(if|switch|for|do|while|catch)\(', multiLine: true);
|
||||
|
||||
Future<void> verifySpacesAfterFlowControlStatements(String workingDirectory, { int minimumMatches = 4000 }) async {
|
||||
const Set<String> extensions = <String>{
|
||||
'.dart',
|
||||
'.java',
|
||||
'.js',
|
||||
'.kt',
|
||||
'.swift',
|
||||
'.c',
|
||||
'.cc',
|
||||
'.cpp',
|
||||
'.h',
|
||||
'.m',
|
||||
};
|
||||
final List<File> files = await _allFiles(workingDirectory, null, minimumMatches: minimumMatches)
|
||||
.where((File file) => extensions.contains(path.extension(file.path)))
|
||||
.toList();
|
||||
final List<String> problems = <String>[];
|
||||
for (final File file in files) {
|
||||
final List<String> lines = file.readAsLinesSync();
|
||||
for (int index = 0; index < lines.length; index += 1) {
|
||||
if (lines[index].contains(_flowControlStatementWithoutSpace)) {
|
||||
problems.add('${file.path}:${index + 1}: no space after flow control statement');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (problems.isNotEmpty) {
|
||||
foundError(problems);
|
||||
}
|
||||
}
|
||||
|
||||
String _bullets(String value) => ' * $value';
|
||||
|
||||
Future<void> verifyIssueLinks(String workingDirectory) async {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
|
||||
bool isThereMeaningOfLife = true;
|
||||
|
||||
void main() {
|
||||
if (isThereMeaningOfLife) {}
|
||||
if(isThereMeaningOfLife) {}
|
||||
//^
|
||||
|
||||
switch (isThereMeaningOfLife) {
|
||||
case false:
|
||||
case true:
|
||||
}
|
||||
switch(isThereMeaningOfLife) {
|
||||
// ^
|
||||
case false:
|
||||
case true:
|
||||
}
|
||||
|
||||
for (int index = 0; index < 10; index++) {}
|
||||
for(int index = 0; index < 10; index++) {}
|
||||
// ^
|
||||
|
||||
while (isThereMeaningOfLife) {}
|
||||
while(isThereMeaningOfLife) {}
|
||||
// ^
|
||||
|
||||
try {
|
||||
} catch (e) {}
|
||||
try {
|
||||
} catch(e) {}
|
||||
// ^
|
||||
}
|
||||
@@ -124,6 +124,24 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('analyze.dart - verifySpacesAfterFlowControlStatements', () async {
|
||||
final String result = await capture(() => verifySpacesAfterFlowControlStatements(testRootPath, minimumMatches: 2), shouldHaveErrors: true);
|
||||
final String lines = <String>[
|
||||
'║ test/analyze-test-input/root/packages/foo/spaces_after_flow.dart:11: no space after flow control statement',
|
||||
'║ test/analyze-test-input/root/packages/foo/spaces_after_flow.dart:18: no space after flow control statement',
|
||||
'║ test/analyze-test-input/root/packages/foo/spaces_after_flow.dart:25: no space after flow control statement',
|
||||
'║ test/analyze-test-input/root/packages/foo/spaces_after_flow.dart:29: no space after flow control statement',
|
||||
'║ test/analyze-test-input/root/packages/foo/spaces_after_flow.dart:35: no space after flow control statement',
|
||||
]
|
||||
.map((String line) => line.replaceAll('/', Platform.isWindows ? r'\' : '/'))
|
||||
.join('\n');
|
||||
expect(result,
|
||||
'╔═╡ERROR╞═══════════════════════════════════════════════════════════════════════\n'
|
||||
'$lines\n'
|
||||
'╚═══════════════════════════════════════════════════════════════════════════════\n'
|
||||
);
|
||||
});
|
||||
|
||||
test('analyze.dart - verifyNoBinaries - positive', () async {
|
||||
final String result = await capture(() => verifyNoBinaries(
|
||||
testRootPath,
|
||||
|
||||
@@ -44,7 +44,7 @@ Future<void> main(List<String> rawArgs) async {
|
||||
test = ABTest.fromJsonMap(
|
||||
const JsonDecoder().convert(await file.readAsString()) as Map<String, dynamic>
|
||||
);
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
_usage('Could not parse json file "$filename"');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ String getArtifactPath() {
|
||||
String? _findMatchId(List<String> idList, String idPattern) {
|
||||
String? candidate;
|
||||
idPattern = idPattern.toLowerCase();
|
||||
for(final String id in idList) {
|
||||
for (final String id in idList) {
|
||||
if (id.toLowerCase() == idPattern) {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ public class $pluginClass: NSObject, FlutterPlugin {
|
||||
// build files.
|
||||
await build(buildTarget, validateNativeBuildProject: false);
|
||||
|
||||
switch(buildTarget) {
|
||||
switch (buildTarget) {
|
||||
case 'apk':
|
||||
if (await exec(
|
||||
path.join('.', 'gradlew'),
|
||||
|
||||
@@ -47,7 +47,7 @@ public class MainActivity extends FlutterActivity implements MethodChannel.Metho
|
||||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
|
||||
switch(methodCall.method) {
|
||||
switch (methodCall.method) {
|
||||
case "pipeFlutterViewEvents":
|
||||
result.success(null);
|
||||
return;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class SimplePlatformView implements PlatformView, MethodChannel.MethodCal
|
||||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
|
||||
switch(methodCall.method) {
|
||||
switch (methodCall.method) {
|
||||
case "pipeTouchEvents":
|
||||
touchPipe.enable();
|
||||
result.success(null);
|
||||
|
||||
@@ -31,7 +31,7 @@ class TouchPipe implements View.OnTouchListener {
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
if(!mEnabled)
|
||||
if (!mEnabled)
|
||||
return;
|
||||
mEnabled = false;
|
||||
mView.setOnTouchListener(null);
|
||||
|
||||
@@ -162,7 +162,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
|
||||
diff.write(currentDiff);
|
||||
}
|
||||
return diff.toString();
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
|
||||
setState(() {
|
||||
_lastTestStatus = _LastTestStatus.success;
|
||||
});
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_lastTestStatus = _LastTestStatus.error;
|
||||
lastError = '$e';
|
||||
@@ -125,7 +125,7 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
|
||||
setState(() {
|
||||
windowClickCount++;
|
||||
});
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_lastTestStatus = _LastTestStatus.error;
|
||||
lastError = '$e';
|
||||
|
||||
@@ -224,7 +224,7 @@ class _LeaveBehindListItem extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
confirmDismiss: !confirmDismiss ? null : (DismissDirection dismissDirection) async {
|
||||
switch(dismissDirection) {
|
||||
switch (dismissDirection) {
|
||||
case DismissDirection.endToStart:
|
||||
return await _showConfirmationDialog(context, 'archive') ?? false;
|
||||
case DismissDirection.startToEnd:
|
||||
|
||||
@@ -72,7 +72,7 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
|
||||
return const UnderlineTabIndicator();
|
||||
}
|
||||
|
||||
switch(_demoStyle) {
|
||||
switch (_demoStyle) {
|
||||
case TabsDemoStyle.iconsAndText:
|
||||
return ShapeDecoration(
|
||||
shape: const RoundedRectangleBorder(
|
||||
|
||||
@@ -26,7 +26,7 @@ Set<String> _unTestedDemos = Set<String>.from(_allDemos);
|
||||
class _MessageHandler {
|
||||
static LiveWidgetController? controller;
|
||||
Future<String> call(String message) async {
|
||||
switch(message) {
|
||||
switch (message) {
|
||||
case 'demoNames':
|
||||
return const JsonEncoder.withIndent(' ').convert(_allDemos);
|
||||
case 'profileDemos':
|
||||
|
||||
@@ -110,7 +110,7 @@ public class MainActivity extends FlutterActivity implements MethodChannel.Metho
|
||||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
|
||||
switch(methodCall.method) {
|
||||
switch (methodCall.method) {
|
||||
case "getStoragePermission":
|
||||
if (permissionResult != null) {
|
||||
result.error("error", "already waiting for permissions", null);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SimplePlatformView implements PlatformView, MethodChannel.MethodCal
|
||||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
|
||||
switch(methodCall.method) {
|
||||
switch (methodCall.method) {
|
||||
case "pipeTouchEvents":
|
||||
touchPipe.enable();
|
||||
result.success(null);
|
||||
|
||||
@@ -31,7 +31,7 @@ class TouchPipe implements View.OnTouchListener {
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
if(!mEnabled)
|
||||
if (!mEnabled)
|
||||
return;
|
||||
mEnabled = false;
|
||||
mView.setOnTouchListener(null);
|
||||
|
||||
@@ -144,7 +144,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
|
||||
diff.write(currentDiff);
|
||||
}
|
||||
return diff.toString();
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ class NestedViewEventBodyState extends State<NestedViewEventBody> {
|
||||
setState(() {
|
||||
_lastTestStatus = _LastTestStatus.success;
|
||||
});
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_lastTestStatus = _LastTestStatus.error;
|
||||
lastError = '$e';
|
||||
@@ -165,7 +165,7 @@ class NestedViewEventBodyState extends State<NestedViewEventBody> {
|
||||
setState(() {
|
||||
nestedViewClickCount++;
|
||||
});
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_lastTestStatus = _LastTestStatus.error;
|
||||
lastError = '$e';
|
||||
|
||||
@@ -91,7 +91,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return ${componentColor('md.comp.filled-text-field.disabled.leading-icon')};
|
||||
}
|
||||
if(states.contains(MaterialState.error)) {
|
||||
if (states.contains(MaterialState.error)) {
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return ${componentColor('md.comp.filled-text-field.error.hover.leading-icon')};
|
||||
}
|
||||
@@ -114,7 +114,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return ${componentColor('md.comp.filled-text-field.disabled.trailing-icon')};
|
||||
}
|
||||
if(states.contains(MaterialState.error)) {${componentColor('md.comp.filled-text-field.error.trailing-icon') == componentColor('md.comp.filled-text-field.error.focus.trailing-icon') ? '' : '''
|
||||
if (states.contains(MaterialState.error)) {${componentColor('md.comp.filled-text-field.error.trailing-icon') == componentColor('md.comp.filled-text-field.error.focus.trailing-icon') ? '' : '''
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return ${componentColor('md.comp.filled-text-field.error.hover.trailing-icon')};
|
||||
}
|
||||
@@ -138,7 +138,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return textStyle.copyWith(color: ${componentColor('md.comp.filled-text-field.disabled.label-text')});
|
||||
}
|
||||
if(states.contains(MaterialState.error)) {
|
||||
if (states.contains(MaterialState.error)) {
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return textStyle.copyWith(color: ${componentColor('md.comp.filled-text-field.error.hover.label-text')});
|
||||
}
|
||||
@@ -162,7 +162,7 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return textStyle.copyWith(color: ${componentColor('md.comp.filled-text-field.disabled.label-text')});
|
||||
}
|
||||
if(states.contains(MaterialState.error)) {
|
||||
if (states.contains(MaterialState.error)) {
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return textStyle.copyWith(color: ${componentColor('md.comp.filled-text-field.error.hover.label-text')});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user