enable unnecessary_string_escapes and use_raw_strings (#68302)
This commit is contained in:
committed by
GitHub
parent
a4ac7cce82
commit
ae06c19a37
@@ -347,7 +347,7 @@ class _WindowsUtils extends OperatingSystemUtils {
|
||||
// `where` could be missing if system32 is not on the PATH.
|
||||
throwToolExit(
|
||||
'Cannot find the executable for `where`. This can happen if the System32 '
|
||||
'folder (e.g. C:\\Windows\\System32 ) is removed from the PATH environment '
|
||||
r'folder (e.g. C:\Windows\System32 ) is removed from the PATH environment '
|
||||
'variable. Ensure that this is present and then try again after restarting '
|
||||
'the terminal and/or IDE.'
|
||||
);
|
||||
|
||||
@@ -110,7 +110,7 @@ class AttachCommand extends FlutterCommand {
|
||||
final String name = 'attach';
|
||||
|
||||
@override
|
||||
final String description = '''
|
||||
final String description = r'''
|
||||
Attach to a running app.
|
||||
|
||||
For attaching to Android or iOS devices, simply using `flutter attach` is
|
||||
@@ -118,13 +118,13 @@ usually sufficient. The tool will search for a running Flutter app or module,
|
||||
if available. Otherwise, the tool will wait for the next Flutter app or module
|
||||
to launch before attaching.
|
||||
|
||||
For Fuchsia, the module name must be provided, e.g. `\$flutter attach
|
||||
For Fuchsia, the module name must be provided, e.g. `$flutter attach
|
||||
--module=mod_name`. This can be called either before or after the application
|
||||
is started.
|
||||
|
||||
If the app or module is already running and the specific observatory port is
|
||||
known, it can be explicitly provided to attach via the command-line, e.g.
|
||||
`\$ flutter attach --debug-port 12345`''';
|
||||
`$ flutter attach --debug-port 12345`''';
|
||||
|
||||
int get debugPort {
|
||||
if (argResults['debug-port'] == null) {
|
||||
|
||||
@@ -591,7 +591,7 @@ class FuchsiaDevice extends Device {
|
||||
if (_cachedHostAddress != null) {
|
||||
return _cachedHostAddress;
|
||||
}
|
||||
final RunResult result = await shell('echo \$SSH_CONNECTION');
|
||||
final RunResult result = await shell(r'echo $SSH_CONNECTION');
|
||||
void fail() {
|
||||
throwToolExit('Failed to get local address, aborting.\n$result');
|
||||
}
|
||||
|
||||
@@ -91,9 +91,9 @@ class RemoveFrameworkLinkAndEmbeddingMigration extends IOSMigrator {
|
||||
}
|
||||
|
||||
// Embed and thin frameworks in a script instead of using Xcode's link / embed build phases.
|
||||
const String thinBinaryScript = 'xcode_backend.sh\\" thin';
|
||||
const String thinBinaryScript = r'xcode_backend.sh\" thin';
|
||||
if (line.contains(thinBinaryScript) && !line.contains(' embed')) {
|
||||
return line.replaceFirst(thinBinaryScript, 'xcode_backend.sh\\" embed_and_thin');
|
||||
return line.replaceFirst(thinBinaryScript, r'xcode_backend.sh\" embed_and_thin');
|
||||
}
|
||||
|
||||
if (line.contains('/* App.framework ') || line.contains('/* Flutter.framework ')) {
|
||||
|
||||
@@ -181,7 +181,7 @@ List<String> _xcodeBuildSettingsLines({
|
||||
|
||||
// iOS does not link on Flutter in any build phase. Add the linker flag.
|
||||
if (!useMacOSConfig) {
|
||||
xcodeBuildSettings.add('OTHER_LDFLAGS=\$(inherited) -framework Flutter');
|
||||
xcodeBuildSettings.add(r'OTHER_LDFLAGS=$(inherited) -framework Flutter');
|
||||
}
|
||||
|
||||
if (!project.isModule) {
|
||||
|
||||
@@ -23,8 +23,8 @@ import 'package:intl/intl.dart' as intl;
|
||||
/// Callers can lookup localized strings with an instance of @(class) returned
|
||||
/// by `@(class).of(context)`.
|
||||
///
|
||||
/// Applications need to include `@(class).delegate()` in their app\'s
|
||||
/// localizationDelegates list, and the locales they support in the app\'s
|
||||
/// Applications need to include `@(class).delegate()` in their app's
|
||||
/// localizationDelegates list, and the locales they support in the app's
|
||||
/// supportedLocales list. For example:
|
||||
///
|
||||
/// ```
|
||||
@@ -215,17 +215,17 @@ const String loadBodyDeferredLoadingTemplate = '''return @(lookupName)(locale);'
|
||||
|
||||
// DELEGATE LOOKUP TEMPLATES
|
||||
|
||||
const String lookupFunctionTemplate = '''
|
||||
const String lookupFunctionTemplate = r'''
|
||||
@(class) @(lookupName)(Locale locale) {
|
||||
@(lookupBody)
|
||||
assert(false, '@(class).delegate failed to load unsupported locale "\$locale"');
|
||||
assert(false, '@(class).delegate failed to load unsupported locale "$locale"');
|
||||
return null;
|
||||
}''';
|
||||
|
||||
const String lookupFunctionDeferredLoadingTemplate = '''
|
||||
const String lookupFunctionDeferredLoadingTemplate = r'''
|
||||
Future<@(class)> @(lookupName)(Locale locale) {
|
||||
@(lookupBody)
|
||||
assert(false, '@(class).delegate failed to load unsupported locale "\$locale"');
|
||||
assert(false, '@(class).delegate failed to load unsupported locale "$locale"');
|
||||
return null;
|
||||
}''';
|
||||
|
||||
|
||||
@@ -261,6 +261,19 @@ String describeLocale(String tag) {
|
||||
/// foo$bar = 'foo\$bar'
|
||||
/// ```
|
||||
String generateString(String value) {
|
||||
if (<String>['\n', '\f', '\t', '\r', '\b'].every((String pattern) => !value.contains(pattern))) {
|
||||
final bool hasDollar = value.contains(r'$');
|
||||
final bool hasBackslash = value.contains(r'\');
|
||||
final bool hasQuote = value.contains("'");
|
||||
final bool hasDoubleQuote = value.contains('"');
|
||||
if (!hasQuote) {
|
||||
return hasBackslash || hasDollar ? "r'$value'" : "'$value'";
|
||||
}
|
||||
if (!hasDoubleQuote) {
|
||||
return hasBackslash || hasDollar ? 'r"$value"' : '"$value"';
|
||||
}
|
||||
}
|
||||
|
||||
const String backslash = '__BACKSLASH__';
|
||||
assert(
|
||||
!value.contains(backslash),
|
||||
@@ -272,17 +285,17 @@ String generateString(String value) {
|
||||
value = value
|
||||
// Replace backslashes with a placeholder for now to properly parse
|
||||
// other special characters.
|
||||
.replaceAll('\\', backslash)
|
||||
.replaceAll('\$', '\\\$')
|
||||
.replaceAll("'", "\\'")
|
||||
.replaceAll('"', '\\"')
|
||||
.replaceAll('\n', '\\n')
|
||||
.replaceAll('\f', '\\f')
|
||||
.replaceAll('\t', '\\t')
|
||||
.replaceAll('\r', '\\r')
|
||||
.replaceAll('\b', '\\b')
|
||||
.replaceAll(r'\', backslash)
|
||||
.replaceAll(r'$', r'\$')
|
||||
.replaceAll("'", r"\'")
|
||||
.replaceAll('"', r'\"')
|
||||
.replaceAll('\n', r'\n')
|
||||
.replaceAll('\f', r'\f')
|
||||
.replaceAll('\t', r'\t')
|
||||
.replaceAll('\r', r'\r')
|
||||
.replaceAll('\b', r'\b')
|
||||
// Reintroduce escaped backslashes into generated Dart string.
|
||||
.replaceAll(backslash, '\\\\');
|
||||
.replaceAll(backslash, r'\\');
|
||||
|
||||
return "'$value'";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user