[Tool] Add ability to check dependencies independently of dev-dependencies, exclude integration_test from dependencies (#6446)

Create a linter that ensures that `integration_test` is not used in dependencies. 

Will be paired with a change to documentation 
```
If you are considering adding an external dependency:

Consider other options, and discuss with #hackers-ecosystem in Discord.
* If you add a dev_dependency on an external package, pin it to a specific version if at all possible.
* If you add a dependency on an external package in an example/, pin it to a specific version if at all possible.
* Some dependencies should only be linked as dev dependencies like integration_test 
```

Related to flutter/flutter/issues/145992
This commit is contained in:
Reid Baker
2024-04-03 15:44:11 -04:00
committed by GitHub
parent c1216f542a
commit 3ff376b7b7
2 changed files with 75 additions and 1 deletions

View File

@ -1734,6 +1734,65 @@ ${_topicsSection()}
]),
);
});
test('fails when integration_test is used in non dev dependency',
() async {
final RepositoryPackage package =
createFakePackage('a_package', packagesDir, examples: <String>[]);
package.pubspecFile.writeAsStringSync('''
${_headerSection('a_package')}
${_environmentSection()}
${_dependenciesSection(<String>['integration_test: \n sdk: flutter'])}
${_devDependenciesSection()}
${_topicsSection()}
''');
Error? commandError;
final List<String> output = await runCapturingPrint(runner, <String>[
'pubspec-check',
], errorHandler: (Error e) {
commandError = e;
});
expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains(
'The following unexpected non-local dependencies were found:\n'
' integration_test\n'
'Please see https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#Dependencies '
'for more information and next steps.'),
]),
);
});
test('passes when integration_test is used in non published package',
() async {
final RepositoryPackage package =
createFakePackage('a_package', packagesDir, examples: <String>[]);
package.pubspecFile.writeAsStringSync('''
${_headerSection('a_package', publishable: false)}
${_environmentSection()}
${_dependenciesSection(<String>['integration_test: \n sdk: flutter'])}
${_devDependenciesSection()}
${_topicsSection()}
''');
final List<String> output = await runCapturingPrint(runner, <String>[
'pubspec-check',
]);
expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for a_package...'),
contains('Ran for'),
]),
);
});
});
});