enable lint prefer_interpolation_to_compose_strings (#83407)

This commit is contained in:
Alexandre Ardhuin
2021-06-01 20:14:06 +02:00
committed by GitHub
parent 71e711547f
commit 34059eec2c
96 changed files with 367 additions and 345 deletions

View File

@@ -243,8 +243,8 @@ Future<void> verifyNoMissingLicense(String workingDirectory, { bool checkMinimum
await _verifyNoMissingLicenseForExtension(workingDirectory, 'swift', overrideMinimumMatches ?? 10, _generateLicense('// '));
await _verifyNoMissingLicenseForExtension(workingDirectory, 'gradle', overrideMinimumMatches ?? 80, _generateLicense('// '));
await _verifyNoMissingLicenseForExtension(workingDirectory, 'gn', overrideMinimumMatches ?? 0, _generateLicense('# '));
await _verifyNoMissingLicenseForExtension(workingDirectory, 'sh', overrideMinimumMatches ?? 1, '#!/usr/bin/env bash\n' + _generateLicense('# '));
await _verifyNoMissingLicenseForExtension(workingDirectory, 'bat', overrideMinimumMatches ?? 1, '@ECHO off\n' + _generateLicense('REM '));
await _verifyNoMissingLicenseForExtension(workingDirectory, 'sh', overrideMinimumMatches ?? 1, '#!/usr/bin/env bash\n${_generateLicense('# ')}');
await _verifyNoMissingLicenseForExtension(workingDirectory, 'bat', overrideMinimumMatches ?? 1, '@ECHO off\n${_generateLicense('REM ')}');
await _verifyNoMissingLicenseForExtension(workingDirectory, 'ps1', overrideMinimumMatches ?? 1, _generateLicense('# '));
await _verifyNoMissingLicenseForExtension(workingDirectory, 'html', overrideMinimumMatches ?? 1, '<!DOCTYPE HTML>\n<!-- ${_generateLicense('')} -->', trailingBlank: false);
await _verifyNoMissingLicenseForExtension(workingDirectory, 'xml', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->');
@@ -252,7 +252,7 @@ Future<void> verifyNoMissingLicense(String workingDirectory, { bool checkMinimum
Future<void> _verifyNoMissingLicenseForExtension(String workingDirectory, String extension, int minimumMatches, String license, { bool trailingBlank = true }) async {
assert(!license.endsWith('\n'));
final String licensePattern = license + '\n' + (trailingBlank ? '\n' : '');
final String licensePattern = '$license\n${trailingBlank ? '\n' : ''}';
final List<String> errors = <String>[];
await for (final File file in _allFiles(workingDirectory, extension, minimumMatches: minimumMatches)) {
final String contents = file.readAsStringSync().replaceAll('\r\n', '\n');
@@ -317,13 +317,13 @@ Future<void> verifyNoBadImportsInFlutter(String workingDirectory) async {
.map<String>((Directory entity) => path.basename(entity.path))
.toList()..sort();
if (!_listEquals<String>(packages, directories)) {
errors.add(
'flutter/lib/*.dart does not match flutter/lib/src/*/:\n'
'These are the exported packages:\n' +
packages.map<String>((String path) => ' lib/$path.dart').join('\n') +
'These are the directories:\n' +
directories.map<String>((String path) => ' lib/src/$path/').join('\n')
);
errors.add(<String>[
'flutter/lib/*.dart does not match flutter/lib/src/*/:',
'These are the exported packages:',
...packages.map<String>((String path) => ' lib/$path.dart'),
'These are the directories:',
...directories.map<String>((String path) => ' lib/src/$path/')
].join('\n'));
}
// Verify that the imports are well-ordered.
final Map<String, Set<String>> dependencyMap = <String, Set<String>>{};
@@ -347,7 +347,7 @@ Future<void> verifyNoBadImportsInFlutter(String workingDirectory) async {
continue;
// Sanity check before performing _deepSearch, to ensure there's no rogue
// dependencies.
final String validFilenames = dependencyMap.keys.map((String name) => name + '.dart').join(', ');
final String validFilenames = dependencyMap.keys.map((String name) => '$name.dart').join(', ');
errors.add(
'$key imported package:flutter/$dependency.dart '
'which is not one of the valid exports { $validFilenames }.\n'
@@ -359,10 +359,7 @@ Future<void> verifyNoBadImportsInFlutter(String workingDirectory) async {
for (final String package in dependencyMap.keys) {
final List<String> loop = _deepSearch<String>(dependencyMap, package);
if (loop != null) {
errors.add(
'${yellow}Dependency loop:$reset ' +
loop.join(' depends on ')
);
errors.add('${yellow}Dependency loop:$reset ${loop.join(' depends on ')}');
}
}
// Fail if any errors

View File

@@ -636,7 +636,7 @@ Future<void> _runFrameworkTests() async {
await _runFlutterTest(
path.join(flutterRoot, 'packages', 'flutter'),
options: <String>['--dart-define=dart.vm.product=true', ...soundNullSafetyOptions],
tests: <String>[ 'test_release' + path.separator ],
tests: <String>['test_release${path.separator}'],
);
}

View File

@@ -41,28 +41,31 @@ void main() {
test('analyze.dart - verifyDeprecations', () async {
final String result = await capture(() => verifyDeprecations(testRootPath, minimumMatches: 2), exitCode: 1);
final String lines = <String>[
'test/analyze-test-input/root/packages/foo/deprecation.dart:12: Deprecation notice does not match required pattern.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:18: Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide: STYLE_GUIDE_URL',
'test/analyze-test-input/root/packages/foo/deprecation.dart:25: Deprecation notice should be a grammatically correct sentence and end with a period.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:29: Deprecation notice does not match required pattern.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:32: Deprecation notice does not match required pattern.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:37: Deprecation notice does not match required pattern.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:41: Deprecation notice does not match required pattern.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:48: End of deprecation notice does not match required pattern.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:51: Unexpected deprecation notice indent.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:70: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:76: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:82: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.',
'test/analyze-test-input/root/packages/foo/deprecation.dart:99: Deprecation notice does not match required pattern. You might have used double quotes (") for the string instead of single quotes (\').',
]
.map((String line) {
return line
.replaceAll('/', Platform.isWindows ? r'\' : '/')
.replaceAll('STYLE_GUIDE_URL', 'https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo')
.replaceAll('RELEASES_URL', 'https://flutter.dev/docs/development/tools/sdk/releases');
})
.join('\n');
expect(result,
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
+
(
'test/analyze-test-input/root/packages/foo/deprecation.dart:12: Deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:18: Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide: STYLE_GUIDE_URL\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:25: Deprecation notice should be a grammatically correct sentence and end with a period.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:29: Deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:32: Deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:37: Deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:41: Deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:48: End of deprecation notice does not match required pattern.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:51: Unexpected deprecation notice indent.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:70: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:76: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:82: Deprecation notice does not accurately indicate a dev branch version number; please see RELEASES_URL to find the latest dev build version number.\n'
'test/analyze-test-input/root/packages/foo/deprecation.dart:99: Deprecation notice does not match required pattern. You might have used double quotes (") for the string instead of single quotes (\').\n'
.replaceAll('/', Platform.isWindows ? r'\' : '/')
.replaceAll('STYLE_GUIDE_URL', 'https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo')
.replaceAll('RELEASES_URL', 'https://flutter.dev/docs/development/tools/sdk/releases')
)
+
'$lines\n'
'See: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes\n'
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
);
@@ -70,15 +73,12 @@ void main() {
test('analyze.dart - verifyNoMissingLicense', () async {
final String result = await capture(() => verifyNoMissingLicense(testRootPath, checkMinimums: false), exitCode: 1);
final String lines = 'test/analyze-test-input/root/packages/foo/foo.dart'
.replaceAll('/', Platform.isWindows ? r'\' : '/');
expect(result,
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
+
(
'The following 1 file does not have the right license header:\n'
'test/analyze-test-input/root/packages/foo/foo.dart\n'
.replaceAll('/', Platform.isWindows ? r'\' : '/')
)
+
'The following 1 file does not have the right license header:\n'
'$lines\n'
'The expected license header is:\n'
'// Copyright 2014 The Flutter Authors. All rights reserved.\n'
'// Use of this source code is governed by a BSD-style license that can be\n'
@@ -90,15 +90,15 @@ void main() {
test('analyze.dart - verifyNoTrailingSpaces', () async {
final String result = await capture(() => verifyNoTrailingSpaces(testRootPath, minimumMatches: 2), exitCode: 1);
final String lines = <String>[
'test/analyze-test-input/root/packages/foo/spaces.txt:5: trailing U+0020 space character',
'test/analyze-test-input/root/packages/foo/spaces.txt:9: trailing blank line',
]
.map((String line) => line.replaceAll('/', Platform.isWindows ? r'\' : '/'))
.join('\n');
expect(result,
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
+
(
'test/analyze-test-input/root/packages/foo/spaces.txt:5: trailing U+0020 space character\n'
'test/analyze-test-input/root/packages/foo/spaces.txt:9: trailing blank line\n'
.replaceAll('/', Platform.isWindows ? r'\' : '/')
)
+
'$lines\n'
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'
);
});