Skip to content

Commit

Permalink
Have the analyze portion of publishing validation only analyze bin/ a…
Browse files Browse the repository at this point in the history
…nd lib/ (#4068)
  • Loading branch information
devoncarew authored Dec 4, 2023
1 parent 92cd5a1 commit db003f2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 36 deletions.
3 changes: 0 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ linter:
- avoid_unused_constructor_parameters
- avoid_void_async
- cancel_subscriptions
- dangling_library_doc_comments
- directives_ordering
- library_annotations
- missing_whitespace_between_adjacent_strings
Expand All @@ -44,8 +43,6 @@ linter:
- unawaited_futures
- unnecessary_lambdas
- unnecessary_library_directive
- unnecessary_null_aware_assignments
- unnecessary_parenthesis
- unnecessary_statements
- use_enums
- use_super_parameters
8 changes: 5 additions & 3 deletions lib/src/validator/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ import '../validator.dart';

/// Runs `dart analyze` and gives a warning if it returns non-zero.
class AnalyzeValidator extends Validator {
/// Only analyze dart code in the following sub-folders.
// Only analyze dart code in the following sub-folders.
static const List<String> _dirsToAnalyze = ['lib', 'bin'];

@override
Future<void> validate() async {
final dirsToAnalyze = ['lib', 'test', 'bin']
final dirs = _dirsToAnalyze
.map((dir) => p.join(entrypoint.rootDir, dir))
.where(dirExists);
final result = await runProcess(
Platform.resolvedExecutable,
['analyze', ...dirsToAnalyze, p.join(entrypoint.rootDir, 'pubspec.yaml')],
['analyze', ...dirs, p.join(entrypoint.rootDir, 'pubspec.yaml')],
);
if (result.exitCode != 0) {
final limitedOutput = limitLength(result.stdout.join('\n'), 1000);
Expand Down
3 changes: 1 addition & 2 deletions lib/src/validator/compiled_dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import 'package:path/path.dart' as path;
import '../io.dart';
import '../validator.dart';

/// Validates that a package doesn't contain compiled Dartdoc
/// output.
/// Validates that a package doesn't contain compiled Dartdoc output.
class CompiledDartdocValidator extends Validator {
@override
Future validate() {
Expand Down
28 changes: 0 additions & 28 deletions test/validator/analyze_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,4 @@ void main() {
workingDirectory: d.sandbox,
);
});

test('should warn if package contains warnings in test folder', () async {
await d.dir(appPath, [
d.validPubspec(),
d.file('LICENSE', 'Eh, do what you want.'),
d.file('README.md', "This package isn't real."),
d.file('CHANGELOG.md', '# 1.0.0\nFirst version\n'),
d.dir('lib', [d.file('test_pkg.dart', 'int i = 1;')]),
d.dir('test', [
d.file('test_pkg.dart', '''
void main() {
final a = 10; // Unused.
}
'''),
]),
]).create();

await expectValidation(
error: allOf([
contains('`dart analyze` found the following issue(s):'),
contains('Analyzing lib, test, pubspec.yaml...'),
contains('warning -'),
contains("The value of the local variable 'a' isn't used"),
contains('Package has 1 warning.'),
]),
exitCode: DATA,
);
});
}

0 comments on commit db003f2

Please sign in to comment.