Unverified Commit 52f8b89c authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] dont allow creating package name that is invalid (#67786)

According to https://dart.dev/tools/pub/pubspec#name , uppercase is not permitted for package names.
parent bd813879
...@@ -134,12 +134,11 @@ class CreateCommand extends FlutterCommand { ...@@ -134,12 +134,11 @@ class CreateCommand extends FlutterCommand {
defaultsTo: 'kotlin', defaultsTo: 'kotlin',
allowed: <String>['java', 'kotlin'], allowed: <String>['java', 'kotlin'],
); );
// TODO(egarciad): Remove this flag. https://github.com/flutter/flutter/issues/52363
argParser.addFlag( argParser.addFlag(
'androidx', 'skip-name-checks',
help: 'integration test only parameter to allow creating applications/plugins with '
'invalid names.',
hide: true, hide: true,
negatable: true,
help: 'Deprecated. Setting this flag has no effect.',
); );
} }
...@@ -396,9 +395,11 @@ class CreateCommand extends FlutterCommand { ...@@ -396,9 +395,11 @@ class CreateCommand extends FlutterCommand {
} }
final String projectName = stringArg('project-name') ?? globals.fs.path.basename(projectDirPath); final String projectName = stringArg('project-name') ?? globals.fs.path.basename(projectDirPath);
error = _validateProjectName(projectName); if (!boolArg('skip-name-checks')) {
if (error != null) { error = _validateProjectName(projectName);
throwToolExit(error); if (error != null) {
throwToolExit(error);
}
} }
if (boolArg('with-driver-test')) { if (boolArg('with-driver-test')) {
...@@ -889,9 +890,10 @@ const Set<String> _packageDependencies = <String>{ ...@@ -889,9 +890,10 @@ const Set<String> _packageDependencies = <String>{
'yaml', 'yaml',
}; };
// A valid Dart identifier. // A valid Dart identifier that can be used for a package, i.e. no
// capital letters.
// https://dart.dev/guides/language/language-tour#important-concepts // https://dart.dev/guides/language/language-tour#important-concepts
final RegExp _identifierRegExp = RegExp('[a-zA-Z_][a-zA-Z0-9_]*'); final RegExp _identifierRegExp = RegExp('[a-z_][a-z0-9_]*');
// non-contextual dart keywords. // non-contextual dart keywords.
//' https://dart.dev/guides/language/language-tour#keywords //' https://dart.dev/guides/language/language-tour#keywords
......
...@@ -2037,7 +2037,7 @@ void main() { ...@@ -2037,7 +2037,7 @@ void main() {
const String projectName = 'foo_BarBaz'; const String projectName = 'foo_BarBaz';
final Directory projectDir = tempDir.childDirectory(projectName); final Directory projectDir = tempDir.childDirectory(projectName);
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=linux', projectDir.path]); await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=linux', '--skip-name-checks', projectDir.path]);
final Directory platformDir = projectDir.childDirectory('linux'); final Directory platformDir = projectDir.childDirectory('linux');
const String classFilenameBase = 'foo_bar_baz_plugin'; const String classFilenameBase = 'foo_bar_baz_plugin';
...@@ -2070,7 +2070,7 @@ void main() { ...@@ -2070,7 +2070,7 @@ void main() {
const String projectName = 'foo_BarBaz'; const String projectName = 'foo_BarBaz';
final Directory projectDir = tempDir.childDirectory(projectName); final Directory projectDir = tempDir.childDirectory(projectName);
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=windows', projectDir.path]); await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=windows', '--skip-name-checks', projectDir.path]);
final Directory platformDir = projectDir.childDirectory('windows'); final Directory platformDir = projectDir.childDirectory('windows');
const String classFilenameBase = 'foo_bar_baz_plugin'; const String classFilenameBase = 'foo_bar_baz_plugin';
......
...@@ -16,5 +16,7 @@ void main() { ...@@ -16,5 +16,7 @@ void main() {
expect(isValidPackageName('foo_bar'), true); expect(isValidPackageName('foo_bar'), true);
expect(isValidPackageName('_foo_bar'), true); expect(isValidPackageName('_foo_bar'), true);
expect(isValidPackageName('fizz93'), true); expect(isValidPackageName('fizz93'), true);
expect(isValidPackageName('Foo_bar'), false);
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment