Skip to content

Commit

Permalink
Version 3.3.0-114.0.dev
Browse files Browse the repository at this point in the history
Merge 2cce183 into dev
  • Loading branch information
Dart CI committed Nov 9, 2023
2 parents 33307e7 + 2cce183 commit 7ff3b1a
Show file tree
Hide file tree
Showing 83 changed files with 2,941 additions and 1,499 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ vars = {
# Checkout extra javascript engines for testing or benchmarking.
# d8, the V8 shell, is always checked out.
"checkout_javascript_engines": False,
"d8_tag": "version:11.9.95",
"d8_tag": "version:12.1.97",
"jsshell_tag": "version:95.0",

# https://chrome-infra-packages.appspot.com/p/fuchsia/third_party/clang
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ linter:
- camel_case_extensions
- camel_case_types
- cancel_subscriptions
- collection_methods_unrelated_type
- comment_references
#- constant_identifier_names
- control_flow_in_finally
Expand All @@ -38,8 +39,6 @@ linter:
- empty_statements
- hash_and_equals
- implementation_imports
#- invariant_booleans
- collection_methods_unrelated_type
- library_names
- library_prefixes
#- literal_only_boolean_expressions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) 2023, 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:_fe_analyzer_shared/src/scanner/token.dart';
import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';
import 'package:linter/src/rules/flutter_style_todos.dart';

class ConvertToFlutterStyleTodo extends ResolvedCorrectionProducer {
@override
bool get canBeAppliedInBulk => true;

@override
bool get canBeAppliedToFile => true;

@override
FixKind get fixKind => DartFixKind.CONVERT_TO_FLUTTER_STYLE_TODO;

@override
FixKind get multiFixKind => DartFixKind.CONVERT_TO_FLUTTER_STYLE_TODO_MULTI;

@override
Future<void> compute(ChangeBuilder builder) async {
var diagnosticOffset = diagnostic?.problemMessage.offset;
if (diagnosticOffset == null) return;

// Find the token that follows the reported diagnostic.
var token = node.beginToken;
do {
if (token.offset > diagnosticOffset) break;

token = token.next!;
} while (token != node.endToken);

// Identify the right comment.
Token? comment = token.precedingComments;
while (comment != null) {
if (comment.offset >= diagnosticOffset) break;
comment = comment.next;
}
if (comment == null) return;

var content = comment.lexeme;

// Try adding a missing leading space before `TODO`.
if (!content.startsWith('// ')) {
content = content.replaceFirst('//', '// ');
}

// Try removing an unwanted space after `TODO`.
if (content.length > 7 && content[7] == ' ') {
content = content.replaceRange(7, 8, '');
}

// Try adding a colon.
var index = content.indexOf(')') + 1;
if (content.length > index && !content.startsWith(':', index)) {
content = content.replaceFirst(')', '):');
}

// Try fixing the TODO case.
if (content.startsWith('// todo')) {
content = content.replaceRange(3, 7, 'TODO');
}

// TODO(pq): consider adding missing user info.
// Possibly inserting '(${Platform.environment['USER'] ?? Platform.environment['USERNAME']}')
// (assuming the environment variable is set).

// If the generated content doesn't match flutter style, don't apply it.
if (!content.startsWith(FlutterStyleTodos.todoExpectedRegExp)) return;

await builder.addDartFileEdit(file, (builder) {
builder.addReplacement(range.token(comment as Token), (builder) {
builder.write(content);
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2083,10 +2083,7 @@ LintCode.file_names:
notes: |-
The fix is to rename the file, but that's a refactoring.
LintCode.flutter_style_todos:
status: noFix
notes: |-
The fix would be to convert the existing TODO to the appropriate style, but
that can't reliably be done.
status: hasFix
LintCode.hash_and_equals:
status: hasFix
LintCode.implementation_imports:
Expand All @@ -2107,6 +2104,8 @@ LintCode.invariant_booleans:
Removed.
LintCode.iterable_contains_unrelated_type:
status: noFix
notes: |-
Removed.
LintCode.join_return_with_assignment:
status: needsFix
LintCode.leading_newlines_in_multiline_strings:
Expand All @@ -2131,6 +2130,8 @@ LintCode.lines_longer_than_80_chars:
status: noFix
LintCode.list_remove_unrelated_type:
status: noFix
notes: |-
Removed.
LintCode.literal_only_boolean_expressions:
status: noFix
LintCode.matching_super_parameters:
Expand Down
10 changes: 10 additions & 0 deletions pkg/analysis_server/lib/src/services/correction/fix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,16 @@ class DartFixKind {
DartFixKindPriority.IN_FILE,
'Convert to double quoted strings everywhere in file',
);
static const CONVERT_TO_FLUTTER_STYLE_TODO = FixKind(
'dart.fix.convert.toFlutterStyleTodo',
DartFixKindPriority.DEFAULT,
'Convert to flutter style todo',
);
static const CONVERT_TO_FLUTTER_STYLE_TODO_MULTI = FixKind(
'dart.fix.convert.toFlutterStyleTodo.multi',
DartFixKindPriority.IN_FILE,
'Convert to flutter style todos everywhere in file',
);
static const CONVERT_TO_FOR_ELEMENT = FixKind(
'dart.fix.convert.toForElement',
DartFixKindPriority.DEFAULT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import 'package:analysis_server/src/services/correction/dart/convert_to_cascade.
import 'package:analysis_server/src/services/correction/dart/convert_to_constant_pattern.dart';
import 'package:analysis_server/src/services/correction/dart/convert_to_contains.dart';
import 'package:analysis_server/src/services/correction/dart/convert_to_expression_function_body.dart';
import 'package:analysis_server/src/services/correction/dart/convert_to_flutter_style_todo.dart';
import 'package:analysis_server/src/services/correction/dart/convert_to_function_declaration.dart';
import 'package:analysis_server/src/services/correction/dart/convert_to_generic_function_syntax.dart';
import 'package:analysis_server/src/services/correction/dart/convert_to_if_null.dart';
Expand Down Expand Up @@ -566,6 +567,9 @@ class FixProcessor extends BaseProcessor {
LintNames.exhaustive_cases: [
AddMissingEnumLikeCaseClauses.new,
],
LintNames.flutter_style_todos: [
ConvertToFlutterStyleTodo.new,
],
LintNames.hash_and_equals: [
CreateMethod.equalsOrHashCode,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class LintNames {
static const String empty_statements = 'empty_statements';
static const String eol_at_end_of_file = 'eol_at_end_of_file';
static const String exhaustive_cases = 'exhaustive_cases';
static const String flutter_style_todos = 'flutter_style_todos';
static const String hash_and_equals = 'hash_and_equals';
static const String implicit_call_tearoffs = 'implicit_call_tearoffs';
static const String implicit_reopen = 'implicit_reopen';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright (c) 2023, 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:analysis_server/src/services/correction/fix.dart';
import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analyzer/src/dart/error/todo_codes.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'fix_processor.dart';

void main() {
defineReflectiveSuite(() {
defineReflectiveTests(ConvertToFlutterStyleTodoBulkTest);
defineReflectiveTests(ConvertToFlutterStyleTodoTest);
});
}

@reflectiveTest
class ConvertToFlutterStyleTodoBulkTest extends BulkFixProcessorTest {
@override
String get lintCode => LintNames.flutter_style_todos;

Future<void> test_singleFile() async {
await resolveTestCode('''
// TODO(user) msg.
void f() {
// todo(user) msg.
}
//TODO(user): msg.
void g() { }
''');
await assertHasFix('''
// TODO(user): msg.
void f() {
// TODO(user): msg.
}
// TODO(user): msg.
void g() { }
''');
}
}

@reflectiveTest
class ConvertToFlutterStyleTodoTest extends FixProcessorLintTest {
@override
FixKind get kind => DartFixKind.CONVERT_TO_FLUTTER_STYLE_TODO;

@override
String get lintCode => LintNames.flutter_style_todos;

Future<void> test_lowerCase() async {
await resolveTestCode('''
// todo(user): msg.
void f() { }
''');
await assertHasFix('''
// TODO(user): msg.
void f() { }
''');
}

Future<void> test_missingColon() async {
await resolveTestCode('''
// TODO(user) msg.
void f() { }
''');
await assertHasFix('''
// TODO(user): msg.
void f() { }
''', errorFilter: (e) => e.errorCode != TodoCode.TODO);
}

Future<void> test_missingColon_surroundingComments() async {
await resolveTestCode('''
// Leading comment.
// TODO(user) msg.
// Trailing comment.
void f() { }
''');
await assertHasFix('''
// Leading comment.
// TODO(user): msg.
// Trailing comment.
void f() { }
''', errorFilter: (e) => e.errorCode != TodoCode.TODO);
}

Future<void> test_missingColonAndMessage() async {
await resolveTestCode('''
// TODO(user)
void f() {}
''');
await assertNoFix(errorFilter: (e) => e.errorCode != TodoCode.TODO);
}

Future<void> test_missingLeadingSpace() async {
await resolveTestCode('''
//TODO(user): msg.
void f() {}
''');
await assertHasFix('''
// TODO(user): msg.
void f() {}
''', errorFilter: (e) => e.errorCode != TodoCode.TODO);
}

Future<void> test_unwantedSpaceBeforeUser() async {
await resolveTestCode('''
// TODO (user): msg.
void f() {}
''');
await assertHasFix('''
// TODO(user): msg.
void f() {}
''', errorFilter: (e) => e.errorCode != TodoCode.TODO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ import 'convert_to_constant_pattern_test.dart' as convert_to_constant_pattern;
import 'convert_to_contains_test.dart' as convert_to_contains;
import 'convert_to_double_quoted_string_test.dart'
as convert_to_double_quoted_string;
import 'convert_to_flutter_style_todo_test.dart'
as convert_to_flutter_style_todo;
import 'convert_to_for_element_test.dart' as convert_to_for_element;
import 'convert_to_function_declaration_test.dart'
as convert_to_function_declaration;
Expand Down Expand Up @@ -340,6 +342,7 @@ void main() {
convert_to_constant_pattern.main();
convert_to_contains.main();
convert_to_double_quoted_string.main();
convert_to_flutter_style_todo.main();
convert_to_for_element.main();
convert_to_function_declaration.main();
convert_to_generic_function_syntax.main();
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer/lib/src/lint/linter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ import 'package:glob/glob.dart';
import 'package:path/path.dart' as p;

export 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
export 'package:analyzer/src/lint/state.dart' show dart2_12, dart3, State;
export 'package:analyzer/src/lint/state.dart'
show dart2_12, dart3, dart3_3, State;

typedef Printer = void Function(String msg);

Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/lib/src/lint/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ final Version dart2_12 = Version(2, 12, 0);
/// A version describing Dart language version 3.0.0.
final Version dart3 = Version(3, 0, 0);

/// A version describing Dart language version 3.3.0.
final Version dart3_3 = Version(3, 3, 0);

/// A state that marks a lint as deprecated.
class DeprecatedState extends State {
/// An optional lint name that replaces the rule with this state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MissingDependencyValidator {
}
}
for (var name in usedDevDeps) {
if (!availableDevDeps.contains(name)) {
if (!availableDevDeps.contains(name) && !availableDeps.contains(name)) {
addDevDeps.add(name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ dev_dependencies:
''', usedDeps: {'path'}, usedDevDeps: {'lints', 'test'}, addDevDeps: ['test']);
}

test_missingDevDependency_inDeps_noError() {
assertNoErrors('''
name: sample
dependencies:
test: any
path: any
dev_dependencies:
lints: any
''', usedDeps: {'test', 'path'}, usedDevDeps: {'lints', 'path'});
}

test_missingDevDependency_noError() {
assertNoErrors('''
name: sample
Expand Down
Loading

0 comments on commit 7ff3b1a

Please sign in to comment.