This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contribute a dart fix declaritive fix
- Loading branch information
1 parent
c90b19f
commit 1c1a69a
Showing
9 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
# for details. All rights reserved. Use of this source code is governed by a | ||
# BSD-style license that can be found in the LICENSE file. | ||
|
||
# Please add new fixes to the top of the file. For documentation about this file | ||
# format, see https://dart.dev/go/data-driven-fixes. | ||
|
||
version: 1 | ||
|
||
transforms: | ||
# whereNotNull() => nonNulls | ||
# https://github.com/dart-lang/collection/issues/350 | ||
- title: "Replace with 'nonNulls'" | ||
date: 2024-06-11 | ||
element: | ||
uris: [ 'package:collection/collection.dart' ] | ||
inClass: 'IterableNullableExtension' | ||
method: 'whereNotNull' | ||
changes: | ||
- kind: 'replacedBy' | ||
newElement: | ||
uris: [ 'dart:core' ] | ||
inClass: 'NullableIterableExtensions' | ||
getter: 'nonNulls' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ environment: | |
|
||
dev_dependencies: | ||
dart_flutter_team_lints: ^3.0.0 | ||
path: ^1.9.0 | ||
test: ^1.16.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
@TestOn('vm') | ||
library; | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:path/path.dart' as p; | ||
import 'package:test/test.dart'; | ||
|
||
// Used for debugging the test. | ||
const keepTempDir = false; | ||
|
||
void main() { | ||
test("'dart fix' integration", () { | ||
// create temp dir | ||
final tempDir = Directory.systemTemp.createTempSync('test'); | ||
|
||
var sdkVersion = Platform.version; | ||
if (sdkVersion.contains(' ')) { | ||
sdkVersion = sdkVersion.substring(0, sdkVersion.indexOf(' ')); | ||
} | ||
|
||
try { | ||
// set up project | ||
writeFile(tempDir, 'pubspec.yaml', ''' | ||
name: test_project | ||
environment: | ||
sdk: '^$sdkVersion' | ||
dependencies: | ||
collection: | ||
path: ${Directory.current.path} | ||
'''); | ||
final sourceFile = File(p.join('test_fixes', 'renames.dart')); | ||
writeFile( | ||
tempDir, | ||
p.join('lib', sourceFile.name), | ||
sourceFile.readAsStringSync(), | ||
); | ||
|
||
// run pub get | ||
pubGet(tempDir); | ||
|
||
// dart fix | ||
dartFix(tempDir); | ||
|
||
// verify no analysis issues | ||
dartAnalyze(tempDir); | ||
} finally { | ||
// ignore: dead_code | ||
if (keepTempDir) { | ||
print('dart fix test temp dir: ${tempDir.path}'); | ||
} else { | ||
tempDir.deleteSync(recursive: true); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
void writeFile(Directory dir, String filePath, String contents) { | ||
final file = File(p.join(dir.path, filePath)); | ||
file.parent.createSync(); | ||
file.writeAsStringSync(contents); | ||
} | ||
|
||
void pubGet(Directory dir) { | ||
exec('pub', ['get'], cwd: dir); | ||
} | ||
|
||
void dartFix(Directory dir) { | ||
exec('fix', ['--apply'], cwd: dir); | ||
} | ||
|
||
void dartAnalyze(Directory dir) { | ||
exec('analyze', [], cwd: dir); | ||
} | ||
|
||
void exec(String command, List<String> args, {required Directory cwd}) { | ||
printOnFailure('dart $command ${args.join(', ')}'); | ||
|
||
final result = Process.runSync( | ||
Platform.resolvedExecutable, | ||
[command, ...args], | ||
workingDirectory: cwd.path, | ||
); | ||
|
||
var out = result.stdout as String; | ||
if (out.isNotEmpty) printOnFailure(out); | ||
out = result.stderr as String; | ||
if (out.isNotEmpty) printOnFailure(out); | ||
|
||
if (result.exitCode != 0) { | ||
fail('dart $command: exitCode ${result.exitCode}'); | ||
} | ||
} | ||
|
||
extension on File { | ||
String get name => p.basename(path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## What's here? | ||
|
||
For information about the files in this directory, see | ||
https://github.com/flutter/flutter/wiki/Data-driven-Fixes#testing. | ||
|
||
## Organization | ||
|
||
The contents of this directory are used to test the `dart fix` refactorings | ||
offered by this package. See `lib/dart_fix.yaml` for the fix definitions. | ||
|
||
Note that files in this directory are excluded from analysis. | ||
|
||
## Running the dart fix tests | ||
|
||
In order to test the fixes manually: | ||
|
||
```bash | ||
> cd test_fixes | ||
> dart fix --compare-to-golden | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include: package:dart_flutter_team_lints/analysis_options.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:collection/collection.dart'; | ||
|
||
void main() { | ||
final list1 = <String?>['foo', 'bar', null, 'baz']; | ||
// ignore: unused_local_variable | ||
final list2 = list1.whereNotNull(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:collection/collection.dart'; | ||
|
||
void main() { | ||
final list1 = <String?>['foo', 'bar', null, 'baz']; | ||
// ignore: unused_local_variable | ||
final list2 = list1.nonNulls; | ||
} |