Skip to content

Commit 065a8a4

Browse files
committed
Merge pull request #112 from Workiva/format-strong-mode
Analyze: support strong mode
2 parents 22e11a7 + 29475fb commit 065a8a4

File tree

8 files changed

+84
-10
lines changed

8 files changed

+84
-10
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Changelog
22

3+
## 1.0.6
4+
5+
- **Improvement:** `--strong` flag added to the Analyze task.
6+
- **Improvement:** The Analyze task's `--fatal-hints` flag is now implemented
7+
by utilizing the `--fatal-hints` flag on `dartanalyzer` instead of parsing
8+
the output.
9+
- **Documentation:** Add zsh completion instructions to the README.
10+
11+
## 1.0.5
12+
13+
### New Feature: pub server support for tests and coverage
14+
15+
- The Test and Coverage tasks now take a `--pub-serve` flag that will
16+
automatically spin up a pub server that is used to run the tests.
17+
- Tests that require a pub transformer can now be run by passing in this flag!
18+
19+
### Changes
20+
21+
- **Improvement:** `--fatal-hints` flag added to the Analyze task.
22+
323
## 1.0.4
424

525
- **Tooling:** Bash completions are available in the `tool/` directory! See the

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ need to know how to use the `dart_dev` tool.
7171
- **Coverage:** collects coverage over test suites (unit, integration, and functional) and generates a report. Uses the [`coverage` package](https://github.com/dart-lang/coverage).
7272
- **Code Formatting:** runs the [`dartfmt` tool from the `dart_style` package](https://github.com/dart-lang/dart_style) over source code.
7373
- **Static Analysis:** runs the [`dartanalyzer`](https://www.dartlang.org/tools/analyzer/) over source code.
74-
- **Documentation Generation:** runs the tool from [the `dartdoc` package](https://github.com/dart-lang/dartdoc) to generate docs.
74+
- **Documentation Generation:** runs the tool from [the `dartdoc` package](https://github.com/dart-lang/dartdoc) to generate docs.
7575
- **Serving Examples:** uses [`pub serve`](https://www.dartlang.org/tools/pub/cmd/pub-serve.html) to serve the project examples.
7676
- **Applying a License to Source Files:** copies a LICENSE file to all applicable files.
7777

@@ -253,10 +253,16 @@ All configuration options for the `analyze` task are found on the
253253
<td>Show hint results.</td>
254254
</tr>
255255
<tr>
256-
<td><code>fatalHints</code></td>
257-
<td><code>bool</code></td>
258-
<td><code>false</code></td>
259-
<td>Fail on hints (requests hints to be true).</td>
256+
<td><code>fatalHints</code></td>
257+
<td><code>bool</code></td>
258+
<td><code>false</code></td>
259+
<td>Fail on hints (requests hints to be true).</td>
260+
</tr>
261+
<tr>
262+
<td><code>strong</code></td>
263+
<td><code>bool</code></td>
264+
<td><code>false</code></td>
265+
<td>Enable strong static checks ([https://goo.gl/DqcBsw](Enable strong static checks (https://goo.gl/DqcBsw))</td>
260266
</tr>
261267
</tbody>
262268
</table>
@@ -431,7 +437,7 @@ object.
431437
<td><code>List&lt;String&gt;</code></td>
432438
<td><code>[]</code></td>
433439
<td>Platforms on which to run the tests (handled by the Dart test runner). See https://github.com/dart-lang/test#platform-selector-syntax for a full list of supported platforms.
434-
<strong>* Not all platforms are supported by all continuous integration servers. Please consult your CI server's documentation for more details.</strong>
440+
<strong>* Not all platforms are supported by all continuous integration servers. Please consult your CI server's documentation for more details.</strong>
435441
</td>
436442
</tr>
437443
<tr>

lib/src/tasks/analyze/api.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ AnalyzeTask analyze(
2626
{List<String> entryPoints: defaultEntryPoints,
2727
bool fatalWarnings: defaultFatalWarnings,
2828
bool hints: defaultHints,
29-
bool fatalHints: defaultFatalHints}) {
29+
bool fatalHints: defaultFatalHints,
30+
bool strong: defaultStrong}) {
3031
var executable = 'dartanalyzer';
3132
var args = [];
3233
if (fatalWarnings) {
@@ -37,6 +38,9 @@ AnalyzeTask analyze(
3738
} else if (fatalHints) {
3839
args.add('--fatal-hints');
3940
}
41+
if (strong) {
42+
args.add('--strong');
43+
}
4044

4145
args.addAll(_findFilesFromEntryPoints(entryPoints));
4246

lib/src/tasks/analyze/cli.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ class AnalyzeCli extends TaskCli {
3636
..addFlag('fatal-hints',
3737
defaultsTo: defaultFatalHints,
3838
negatable: true,
39-
help: 'Treat hints as fatal.');
39+
help: 'Treat hints as fatal.')
40+
..addFlag('strong',
41+
defaultsTo: defaultStrong,
42+
negatable: true,
43+
help: 'Enable strong static checks (https://goo.gl/DqcBsw)');
4044

4145
final String command = 'analyze';
4246

@@ -47,6 +51,7 @@ class AnalyzeCli extends TaskCli {
4751
bool hints = TaskCli.valueOf('hints', parsedArgs, config.analyze.hints);
4852
bool fatalHints =
4953
TaskCli.valueOf('fatal-hints', parsedArgs, config.analyze.fatalHints);
54+
bool strong = TaskCli.valueOf('strong', parsedArgs, config.analyze.strong);
5055

5156
if (!hints && fatalHints) {
5257
return new CliResult.fail('You must enable hints to fail on hints.');
@@ -56,7 +61,8 @@ class AnalyzeCli extends TaskCli {
5661
entryPoints: entryPoints,
5762
fatalWarnings: fatalWarnings,
5863
hints: hints,
59-
fatalHints: fatalHints);
64+
fatalHints: fatalHints,
65+
strong: strong);
6066
var title = task.analyzerCommand;
6167
if (fatalHints) title += ' (treating hints as fatal)';
6268

lib/src/tasks/analyze/config.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ const List<String> defaultEntryPoints = const ['lib/'];
2020
const bool defaultFatalWarnings = true;
2121
const bool defaultHints = true;
2222
const bool defaultFatalHints = false;
23+
const bool defaultStrong = false;
2324

2425
class AnalyzeConfig extends TaskConfig {
2526
List<String> entryPoints = defaultEntryPoints.toList();
2627
bool fatalWarnings = defaultFatalWarnings;
2728
bool hints = defaultHints;
2829
bool fatalHints = defaultFatalHints;
30+
bool strong = defaultStrong;
2931
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
library analyze_strong;
2+
3+
import 'dart:collection';
4+
5+
class MyList extends ListBase<int> implements List {
6+
Object length;
7+
8+
MyList(this.length);
9+
10+
operator[](index) => "world";
11+
operator[]=(index, value) {}
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: analyze_strong
2+
version: 0.0.0
3+
dev_dependencies:
4+
dart_dev:
5+
path: ../../../..

test/integration/analyze_test.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ import 'package:test/test.dart';
2424
const String projectWithErrors = 'test/fixtures/analyze/errors';
2525
const String projectWithHints = 'test/fixtures/analyze/hints';
2626
const String projectWithNoIssues = 'test/fixtures/analyze/no_issues';
27+
const String projectWithStaticTypingIssues = 'test/fixtures/analyze/strong';
2728

2829
Future<Analysis> analyzeProject(String projectPath,
2930
{bool fatalWarnings: true,
3031
bool hints: true,
31-
bool fatalHints: false}) async {
32+
bool fatalHints: false,
33+
bool strong: false}) async {
3234
await Process.run('pub', ['get'], workingDirectory: projectPath);
3335

3436
var args = ['run', 'dart_dev', 'analyze'];
3537
args.add(fatalWarnings ? '--fatal-warnings' : '--no-fatal-warnings');
3638
args.add(hints ? '--hints' : '--no-hints');
39+
args.add(strong ? '--strong' : '--no-strong');
3740
args.add(fatalHints ? '--fatal-hints' : ' --no-fatal-hints');
3841

3942
TaskProcess process =
@@ -139,5 +142,21 @@ void main() {
139142
expect(analysis.numErrors, equals(1));
140143
expect(analysis.numWarnings, equals(1));
141144
});
145+
146+
test(
147+
'should not report any issues on project with static typing issues if strong mode is off',
148+
() async {
149+
Analysis analysis =
150+
await analyzeProject(projectWithStaticTypingIssues, strong: false);
151+
expect(analysis.exitCode, equals(0));
152+
});
153+
154+
test(
155+
'should report issues on project with static typing issues if strong mode is on',
156+
() async {
157+
Analysis analysis =
158+
await analyzeProject(projectWithStaticTypingIssues, strong: true);
159+
expect(analysis.numErrors, greaterThan(0));
160+
});
142161
});
143162
}

0 commit comments

Comments
 (0)