Skip to content

Commit

Permalink
Enable dart_flutter_team_lints v2.0 (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Sep 13, 2023
1 parent 416c8c2 commit c10c9ea
Show file tree
Hide file tree
Showing 32 changed files with 108 additions and 88 deletions.
8 changes: 0 additions & 8 deletions pkgs/dart_pad/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,8 @@ analyzer:

linter:
rules:
- always_declare_return_types
- avoid_private_typedef_functions
- avoid_void_async
- directives_ordering
- prefer_final_in_for_each
- prefer_final_locals
- prefer_mixin
- prefer_relative_imports
- prefer_single_quotes
- sort_pub_dependencies
- unawaited_futures
- use_enums
- use_super_parameters
4 changes: 2 additions & 2 deletions pkgs/dart_pad/lib/core/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Dependencies get deps => Dependencies.instance;
/// A simple dependency manager. This class manages a collection of singletons.
/// You can create separate `Dependency` instances to manage separate sets of
/// collections (for instance, one for testing). Or, you can use the single
/// [dependency] instance defined in this library to set up all the singletons
/// [deps] instance defined in this library to set up all the singletons
/// for your application.
///
/// Dependencies dependencies = new Dependencies();
Expand All @@ -34,7 +34,7 @@ Dependencies get deps => Dependencies.instance;
/// dependencies.setDependency(DogManager, new MockDogManager());
/// dependencies.runInZone(executeTests);
///
/// It will execute the method [executeTests] in a new Zone. Any queries to
/// It will execute the method `executeTests` in a new Zone. Any queries to
/// [Dependencies.instance] will return the new dependencies set up for that
/// zone.
class Dependencies {
Expand Down
3 changes: 2 additions & 1 deletion pkgs/dart_pad/lib/editing/editor_codemirror.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ class CodeMirrorFactory extends EditorFactory {
}
},
hintRenderer: (html.Element element, HintResult hint) {
final escapeHtml = HtmlEscape().convert as String Function(String?);
final escapeHtml =
const HtmlEscape().convert as String Function(String?);
if (completion.type != 'type-quick_fix') {
element.innerHtml = escapeHtml(completion.displayString)
.replaceFirst(escapeHtml(stringToReplace),
Expand Down
4 changes: 2 additions & 2 deletions pkgs/dart_pad/lib/elements/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class AnsiConsoleHandler {
0xa5a5a5, // bright white
];

/// We set this to [darkModeAnsiColors] or [lightModeAnsiColors] in constructor
/// depending on [_darkMode].
/// We set this to [darkModeAnsiColors] or [lightModeAnsiColors] in
/// the constructor depending on if `darkMode` is enabled or not.
late final List<int> _themeModeAnsiColors;

// Certain ranges that are matched here do not contain real graphics rendition
Expand Down
6 changes: 3 additions & 3 deletions pkgs/dart_pad/lib/elements/elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class DToast extends DElement {
// Add to the DOM, start a timer, make it visible.
document.body!.children.add(element);

Timer(Duration(milliseconds: 16), () {
Timer(const Duration(milliseconds: 16), () {
element.classes.toggle('showing', true);
});
}
Expand Down Expand Up @@ -331,7 +331,7 @@ abstract class DDialog extends DElement {
// Add to the DOM, start a timer, make it visible.
document.body!.children.add(element);

Timer(Duration(milliseconds: 16), () {
Timer(const Duration(milliseconds: 16), () {
element.classes.toggle('showing', true);
});
}
Expand All @@ -342,7 +342,7 @@ abstract class DDialog extends DElement {
pane.hide();

// Start a timer, hide, remove from dom.
Timer(Duration(milliseconds: 16), () {
Timer(const Duration(milliseconds: 16), () {
element.classes.toggle('showing', false);
element.onTransitionEnd.first.then((event) {
dispose();
Expand Down
4 changes: 2 additions & 2 deletions pkgs/dart_pad/lib/embed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class Embed extends EditorUi {

void _init() {
deps[GistLoader] = GistLoader.defaultFilters();
deps[Analytics] = Analytics();
deps[Analytics] = const Analytics();

final channel = queryParams.channel;
if (Channel.urlMapping.keys.contains(channel)) {
Expand Down Expand Up @@ -1377,7 +1377,7 @@ class EmbedContext extends Context {

/// Counts the number of lines in [str].
static int countLinesInString(String str) =>
LineSplitter().convert(str).length;
const LineSplitter().convert(str).length;
}

final RegExp _flutterUrlExp =
Expand Down
6 changes: 3 additions & 3 deletions pkgs/dart_pad/lib/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class GitHubUIController {

void setupGithubGistListeners() {
_playground.mutableGist.onChanged
.debounce(Duration(milliseconds: 100))
.debounce(const Duration(milliseconds: 100))
.listen((_) {
setUnsavedLocalEdits();
});
Expand All @@ -170,12 +170,12 @@ class GitHubUIController {
_updateStarredGistMenuState();
});
_starUnstarButton.onClick
.debounce(Duration(milliseconds: 100))
.debounce(const Duration(milliseconds: 100))
.listen(_starredButtonClickHandler);

// This will only happen when we make 'contenteditable' true while authenticated.
_titleElement.element.onInput
.debounce(Duration(milliseconds: 100))
.debounce(const Duration(milliseconds: 100))
.listen((_) {
_playground.mutableGist.description = _titleElement.text;
setUnsavedLocalEdits();
Expand Down
10 changes: 7 additions & 3 deletions pkgs/dart_pad/lib/playground.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,19 @@ class Playground extends EditorUi implements GistContainer, GistController {
void _initGistStorage() {
// If there was a change, and the gist is dirty, write the gist's contents
// to storage.
mutableGist.onChanged.debounce(Duration(milliseconds: 100)).listen((_) {
mutableGist.onChanged
.debounce(const Duration(milliseconds: 100))
.listen((_) {
if (mutableGist.dirty) {
_gistStorage.setStoredGist(mutableGist.createGist());
}
});
}

void _initLayoutDetection() {
mutableGist.onChanged.debounce(Duration(milliseconds: 32)).listen((_) {
mutableGist.onChanged
.debounce(const Duration(milliseconds: 32))
.listen((_) {
if (hasFlutterContent(context.dartSource)) {
_changeLayout(Layout.flutter);
} else if (hasHtmlContent(context.dartSource)) {
Expand Down Expand Up @@ -526,7 +530,7 @@ class Playground extends EditorUi implements GistContainer, GistController {
executionService.onStderr.listen((m) => showOutput(m, error: true));

// Set up Google Analytics.
deps[Analytics] = Analytics();
deps[Analytics] = const Analytics();

// Set up the gist loader.
deps[GistLoader] = GistLoader.defaultFilters();
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dart_pad/lib/search_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class SearchController {
}
// queue up a second attempt at select all because sometimes browser flakes on first
// (this sometimes happens on the first time the search dialog is opened)
Timer(Duration(milliseconds: 20), () {
Timer(const Duration(milliseconds: 20), () {
findTextInput.focus();
findTextInput.select();
});
Expand Down
3 changes: 2 additions & 1 deletion pkgs/dart_pad/lib/services/execution_iframe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ require(["dartpad_main", "dart_sdk"], function(dartpad_main, dart_sdk) {
_frame = clone;
}

return _readyCompleter.future.timeout(Duration(seconds: 1), onTimeout: () {
return _readyCompleter.future.timeout(const Duration(seconds: 1),
onTimeout: () {
if (!_readyCompleter.isCompleted) _readyCompleter.complete();
});
}
Expand Down
18 changes: 12 additions & 6 deletions pkgs/dart_pad/lib/sharing/exercise_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ class ExerciseFileMetadata {

ExerciseFileMetadata.fromMap(Map<String, dynamic>? map) {
if (map == null) {
throw MetadataException('Null json was given to ExerciseFileMetadata().');
throw const MetadataException(
'Null json was given to ExerciseFileMetadata().');
}

if (map['name'] == null ||
map['name'] is! String ||
(map['name'] as String).isEmpty) {
throw MetadataException('The "name" field is required for each file.');
throw const MetadataException(
'The "name" field is required for each file.');
}

name = map.containsKey('name') ? map['name'] as String : '';
Expand All @@ -63,26 +65,30 @@ class ExerciseMetadata {

ExerciseMetadata.fromMap(Map<String, dynamic>? map) {
if (map == null) {
throw MetadataException('Null json was given to ExerciseMetadata().');
throw const MetadataException(
'Null json was given to ExerciseMetadata().');
}

if (map['name'] == null ||
map['name'] is! String ||
(map['name'] as String).isEmpty) {
throw MetadataException('The "name" field is required for an exercise.');
throw const MetadataException(
'The "name" field is required for an exercise.');
}

if (map['mode'] == null ||
map['mode'] is! String ||
!exerciseModeNames.containsKey(map['mode'])) {
throw MetadataException('A "mode" field of "dart", "html" or "flutter" '
throw const MetadataException(
'A "mode" field of "dart", "html" or "flutter" '
'is required for an exercise.');
}

if (map['files'] == null ||
map['files'] is! List ||
(map['files'] as List).isEmpty) {
throw MetadataException('Each exercise must have at least one file in '
throw const MetadataException(
'Each exercise must have at least one file in '
'its "files" array.');
}

Expand Down
15 changes: 8 additions & 7 deletions pkgs/dart_pad/lib/sharing/gists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,11 @@ $styleRef$dartRef </head>
final metadataResponse = await _client.get(metadataUrl);

if (metadataResponse.statusCode == 404) {
throw GistLoaderException(GistLoaderFailureType.contentNotFound);
throw const GistLoaderException(GistLoaderFailureType.contentNotFound);
} else if (metadataResponse.statusCode == 403) {
throw GistLoaderException(GistLoaderFailureType.rateLimitExceeded);
throw const GistLoaderException(GistLoaderFailureType.rateLimitExceeded);
} else if (metadataResponse.statusCode != 200) {
throw GistLoaderException(GistLoaderFailureType.unknown);
throw const GistLoaderException(GistLoaderFailureType.unknown);
}

final metadataContent = extractGitHubResponseBody(metadataResponse.body);
Expand All @@ -654,7 +654,7 @@ $styleRef$dartRef </head>
final yamlMap = yaml.loadYaml(metadataContent);

if (yamlMap is! Map) {
throw FormatException();
throw const FormatException();
}

metadata = ExerciseMetadata.fromMap(yamlMap.cast());
Expand All @@ -674,12 +674,13 @@ $styleRef$dartRef </head>

if (contentResponse.statusCode == 404) {
// Blame the metadata for listing an invalid file.
throw GistLoaderException(
throw const GistLoaderException(
GistLoaderFailureType.invalidExerciseMetadata);
} else if (metadataResponse.statusCode == 403) {
throw GistLoaderException(GistLoaderFailureType.rateLimitExceeded);
throw const GistLoaderException(
GistLoaderFailureType.rateLimitExceeded);
} else if (metadataResponse.statusCode != 200) {
throw GistLoaderException(GistLoaderFailureType.unknown);
throw const GistLoaderException(GistLoaderFailureType.unknown);
}

return extractGitHubResponseBody(contentResponse.body);
Expand Down
8 changes: 4 additions & 4 deletions pkgs/dart_pad/lib/workshops.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ class WorkshopUi extends EditorUi {
// Put onchange handler on document and if there are changes
// store them in local storage.
editor.document.onChange
.debounce(Duration(milliseconds: 500))
.debounce(const Duration(milliseconds: 500))
.listen((_) => _handleChangeInUsersWork());
editor.document.onChange.listen((_) => busyLight.on());
editor.document.onChange
.debounce(Duration(milliseconds: 1250))
.debounce(const Duration(milliseconds: 1250))
.listen((_) => performAnalysis());

editorFactory.registerCompleter(
Expand Down Expand Up @@ -225,7 +225,7 @@ class WorkshopUi extends EditorUi {
executionService.onStdout.listen(showOutput);
executionService.onStderr.listen((m) => showOutput(m, error: true));
// Set up Google Analytics.
deps[Analytics] = Analytics();
deps[Analytics] = const Analytics();

// Use null safety for workshops
(deps[DartservicesApi] as DartservicesApi).rootUrl = serverUrl;
Expand Down Expand Up @@ -461,7 +461,7 @@ class WorkshopUi extends EditorUi {
div.children.clear();
div.setInnerHtml(
markdown.markdownToHtml(_workshopState.currentStep.instructions,
blockSyntaxes: [markdown.TableSyntax()]),
blockSyntaxes: [const markdown.TableSyntax()]),
validator: _htmlValidator);
hljs.highlightAll();
div.scrollTop = 0;
Expand Down
7 changes: 4 additions & 3 deletions pkgs/dart_pad/lib/workshops/src/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ class GithubWorkshopFetcher extends WorkshopFetcherImpl {

final statusCode = res.statusCode;
if (statusCode == 404) {
throw WorkshopFetchException(WorkshopFetchExceptionType.contentNotFound);
throw const WorkshopFetchException(
WorkshopFetchExceptionType.contentNotFound);
} else if (statusCode == 403) {
throw WorkshopFetchException(
throw const WorkshopFetchException(
WorkshopFetchExceptionType.rateLimitExceeded);
} else if (statusCode != 200) {
throw WorkshopFetchException(WorkshopFetchExceptionType.unknown);
throw const WorkshopFetchException(WorkshopFetchExceptionType.unknown);
}

return extractGitHubResponseBody(res.body);
Expand Down
4 changes: 2 additions & 2 deletions pkgs/dart_pad/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ packages:
dependency: "direct dev"
description:
name: dart_flutter_team_lints
sha256: e2f4fcafdaf0797e5af1c5c162d0b6c5025e9228ab3f95174340ed35c85dccd6
sha256: "66517b1f6a53e3275938eece5fe0df6960d1e86a82bad074d7364a9a5c97ae10"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
version: "2.0.0"
dart_style:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dart_pad/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dev_dependencies:
build_runner: ^2.4.4
build_test: ^2.1.7
build_web_compilers: ^4.0.3
dart_flutter_team_lints: ^1.0.0
dart_flutter_team_lints: ^2.0.0
git: ^2.0.0
grinder: ^0.9.4
json_serializable: ^6.7.0
Expand Down
16 changes: 9 additions & 7 deletions pkgs/dart_pad/test/e2e/playground_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ void main() async {
Future<void> waitForPageToStabilize() async {
while (true) {
final versionsElement =
await driver.findElement(By.id('dartpad-version'));
await driver.findElement(const By.id('dartpad-version'));
if ((await versionsElement.text).isNotEmpty) {
return;
}
await Future<void>.delayed(Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));
}
}

Expand All @@ -85,7 +85,7 @@ void main() async {
uri: Uri.parse('http://localhost:4444/wd/hub/'),
desired: Capabilities.chrome);

await Future<void>.delayed(Duration(milliseconds: 2000));
await Future<void>.delayed(const Duration(milliseconds: 2000));

// Go to your page
await driver.get('http://localhost:8000/');
Expand All @@ -97,14 +97,15 @@ void main() async {
});

Future<void> writeScript(String content) async {
final codeMirror = await driver.findElement(By.className('CodeMirror'));
final codeMirror =
await driver.findElement(const By.className('CodeMirror'));
content = content.replaceAll('\n', '\\n');
await driver
.execute('arguments[0].CodeMirror.setValue("$content");', [codeMirror]);
}

Future<void> runScript() async {
final runButton = await driver.findElement(By.id('run-button'));
final runButton = await driver.findElement(const By.id('run-button'));
await runButton.click();
}

Expand All @@ -114,7 +115,7 @@ void main() async {
Future<String> waitForOutput(String sample) async {
while (true) {
final outputPanel =
await driver.findElement(By.id('right-output-panel-content'));
await driver.findElement(const By.id('right-output-panel-content'));
final text = await outputPanel.text;
if (text.contains(sample)) {
return text;
Expand All @@ -123,7 +124,8 @@ void main() async {
}

test('Version text is displayed', () async {
final versionsElement = await driver.findElement(By.id('dartpad-version'));
final versionsElement =
await driver.findElement(const By.id('dartpad-version'));
expect(await versionsElement.text, startsWith('Based on Flutter'));
}, skip: runningInCi);

Expand Down
Loading

0 comments on commit c10c9ea

Please sign in to comment.