Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ce5f567

Browse files
author
Dart CI
committed
Version 2.18.0-94.0.dev
Merge commit '2d1dc8523aabb11960d596968819b519aa9d326d' into 'dev'
2 parents 90c8544 + 2d1dc85 commit ce5f567

File tree

18 files changed

+622
-159
lines changed

18 files changed

+622
-159
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Scorecards supply-chain security
2+
on:
3+
# Only the default branch is supported.
4+
branch_protection_rule:
5+
schedule:
6+
# “At 00:00 (UTC) daily.”
7+
- cron: '0 0 * * *'
8+
9+
# Declare default permissions as read only.
10+
permissions: read-all
11+
12+
jobs:
13+
analysis:
14+
name: Scorecards analysis
15+
runs-on: ubuntu-latest
16+
permissions:
17+
# Needed to upload the results to code-scanning dashboard.
18+
security-events: write
19+
actions: read
20+
contents: read
21+
22+
steps:
23+
- name: "Checkout code"
24+
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3.0.0
25+
with:
26+
persist-credentials: false
27+
28+
- name: "Run analysis"
29+
uses: ossf/scorecard-action@c1aec4ac820532bab364f02a81873c555a0ba3a1 # v1.0.4
30+
with:
31+
results_file: results.sarif
32+
results_format: sarif
33+
# Read-only PAT token. To create it,
34+
# follow the steps in https://github.com/ossf/scorecard-action#pat-token-creation.
35+
repo_token: ${{ secrets.SCORECARD_READ_TOKEN }}
36+
# Publish the results to enable scorecard badges. For more details, see
37+
# https://github.com/ossf/scorecard-action#publishing-results.
38+
# For private repositories, `publish_results` will automatically be set to `false`,
39+
# regardless of the value entered here.
40+
publish_results: true
41+
42+
# Upload the results as artifacts (optional).
43+
- name: "Upload artifact"
44+
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # v3.0.0
45+
with:
46+
name: SARIF file
47+
path: results.sarif
48+
retention-days: 5
49+
50+
# Upload the results to GitHub's code scanning dashboard.
51+
- name: "Upload to code-scanning"
52+
uses: github/codeql-action/upload-sarif@5f532563584d71fdef14ee64d17bafb34f751ce5 # v1.0.26
53+
with:
54+
sarif_file: results.sarif

CHANGELOG.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,23 @@ them, you must set the lower bound on the SDK constraint for your package to
274274

275275
#### Linter
276276

277-
Updated the Linter to `1.22.0`, which includes changes that
278-
279-
- fixes null-safe variance exceptions in `invariant_booleans`
277+
Updated the Linter to `1.23.0`, which includes changes that
278+
279+
- fixes `no_leading_underscores_for_local_identifiers`
280+
to lint local function declarations.
281+
- fixes `avoid_init_to_null` to correctly handle super
282+
initializing defaults that are non-null.
283+
- updates `no_leading_underscores_for_local_identifiers`
284+
to allow identifiers with just underscores.
285+
- fixes `flutter_style_todos` to support usernames that
286+
start with a digit.
287+
- updates `require_trailing_commas` to handle functions
288+
in asserts and multi-line strings.
289+
- updates `unsafe_html` to allow assignments to
290+
`img.src`.
291+
- fixes `unnecessary_null_checks` to properly handle map
292+
literal entries.
293+
- fixes null-safe variance exceptions in `invariant_booleans`.
280294
- updates `depend_on_referenced_packages` to treat `flutter_gen` as a virtual
281295
package, not needing an explicit dependency.
282296
- updates `unnecessary_null_checks` and

DEPS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ vars = {
122122
"intl_rev": "9669926609e7efc17dfd74fbb44ec719a7e573cc",
123123
"jinja2_rev": "2222b31554f03e62600cd7e383376a7c187967a1",
124124
"json_rpc_2_rev": "7e00f893440a72de0637970325e4ea44bd1e8c8e",
125-
"linter_rev": "14c916a16e78315e212cf79e7ccf4c19159a1bda",
125+
"linter_rev": "4305b933c8ed0275f26a99bd1ade39fe9130e6a5", # 1.23.0
126126
"lints_rev": "8294e5648ab49474541527e2911e72e4c5aefe55",
127127
"logging_rev": "dfbe88b890c3b4f7bc06da5a7b3b43e9e263b688",
128128
"markdown_rev": "7479783f0493f6717e1d7ae31cb37d39a91026b2",
@@ -170,8 +170,8 @@ vars = {
170170
"webdev_rev": "8c814f9d89915418d8abe354ff9befec8f2906b2",
171171
"webdriver_rev": "ff5ccb1522edf4bed578ead4d65e0cbc1f2c4f02",
172172
"webkit_inspection_protocol_rev": "dd6fb5d8b536e19cedb384d0bbf1f5631923f1e8",
173-
"yaml_edit_rev": "4fadb43801b07f90b3f0c6065dbce4efc6d8d55e",
174-
"yaml_rev": "ad0779d1baa25c6b10a192d080efc45de02b6a32",
173+
"yaml_edit_rev": "0b74d85fac10b4fbf7d1a347debcf16c8f7b0e9c",
174+
"yaml_rev": "0971c06490b9670add644ed62182acd6a5536946",
175175
"zlib_rev": "faff052b6b6edcd6dd548513fe44ac0941427bf0",
176176

177177
# Windows deps

pkg/analysis_server/lib/src/services/correction/dart/add_trailing_comma.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class AddTrailingComma extends CorrectionProducer {
3030
await _insertComma(builder, node.parameters.last);
3131
} else if (node is Assertion) {
3232
await _insertComma(builder, node.message ?? node.condition);
33+
} else if (node is ListLiteral) {
34+
await _insertComma(builder, node.elements.last);
35+
} else if (node is SetOrMapLiteral) {
36+
await _insertComma(builder, node.elements.last);
3337
}
3438
}
3539

pkg/analysis_server/test/src/services/correction/fix/add_trailing_comma_test.dart

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,50 @@ void f(a, b) {
102102
''');
103103
}
104104

105+
@failingTest
106+
Future<void> test_list_literal() async {
107+
await resolveTestCode('''
108+
void f() {
109+
var l = [
110+
'a',
111+
'b'
112+
];
113+
print(l);
114+
}
115+
''');
116+
await assertHasFix('''
117+
void f() {
118+
var l = [
119+
'a',
120+
'b',
121+
];
122+
print(l);
123+
}
124+
''');
125+
}
126+
127+
@failingTest
128+
Future<void> test_map_literal() async {
129+
await resolveTestCode('''
130+
void f() {
131+
var l = {
132+
'a': 1,
133+
'b': 2
134+
};
135+
print(l);
136+
}
137+
''');
138+
await assertHasFix('''
139+
void f() {
140+
var l = {
141+
'a': 1,
142+
'b': 2,
143+
};
144+
print(l);
145+
}
146+
''');
147+
}
148+
105149
Future<void> test_named() async {
106150
await resolveTestCode('''
107151
void f({a, b}) {
@@ -140,6 +184,28 @@ void f(a, b) {
140184
f('a',
141185
'b',);
142186
}
187+
''');
188+
}
189+
190+
@failingTest
191+
Future<void> test_set_literal() async {
192+
await resolveTestCode('''
193+
void f() {
194+
var l = {
195+
'a',
196+
'b'
197+
};
198+
print(l);
199+
}
200+
''');
201+
await assertHasFix('''
202+
void f() {
203+
var l = {
204+
'a',
205+
'b',
206+
};
207+
print(l);
208+
}
143209
''');
144210
}
145211
}

pkg/analyzer/lib/src/summary2/macro_application.dart

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ import 'package:_fe_analyzer_shared/src/macros/executor/multi_executor.dart';
1010
import 'package:_fe_analyzer_shared/src/macros/executor/protocol.dart' as macro;
1111
import 'package:analyzer/dart/ast/ast.dart';
1212
import 'package:analyzer/dart/ast/token.dart';
13+
import 'package:analyzer/dart/element/nullability_suffix.dart';
1314
import 'package:analyzer/dart/element/type.dart';
1415
import 'package:analyzer/dart/element/visitor.dart';
1516
import 'package:analyzer/src/dart/element/element.dart';
17+
import 'package:analyzer/src/dart/element/type_system.dart';
1618
import 'package:analyzer/src/summary2/library_builder.dart';
1719
import 'package:analyzer/src/summary2/link.dart';
20+
import 'package:analyzer/src/summary2/linked_element_factory.dart';
1821
import 'package:analyzer/src/summary2/macro_application_error.dart';
1922
import 'package:analyzer/src/summary2/macro_declarations.dart';
2023

@@ -25,9 +28,12 @@ class LibraryMacroApplier {
2528

2629
final List<_MacroTarget> _targets = [];
2730

28-
final macro.IdentifierResolver _identifierResolver = _IdentifierResolver();
31+
late final macro.IdentifierResolver _identifierResolver =
32+
_IdentifierResolver(_linker.elementFactory, declarationBuilder);
2933

30-
final macro.TypeResolver _typeResolver = _TypeResolver();
34+
late final macro.TypeResolver _typeResolver = _TypeResolver(
35+
typeSystem: libraryBuilder.element.typeSystem,
36+
);
3137

3238
late final macro.ClassIntrospector _classIntrospector =
3339
_ClassIntrospector(declarationBuilder);
@@ -451,9 +457,13 @@ class _ClassIntrospector implements macro.ClassIntrospector {
451457
}
452458

453459
@override
454-
Future<List<macro.FieldDeclaration>> fieldsOf(macro.ClassDeclaration clazz) {
455-
// TODO: implement fieldsOf
456-
throw UnimplementedError();
460+
Future<List<macro.FieldDeclaration>> fieldsOf(
461+
covariant ClassDeclarationImpl clazz,
462+
) async {
463+
return clazz.element.fields
464+
.where((e) => !e.isSynthetic)
465+
.map(declarationBuilder.fromElement.fieldElement)
466+
.toList();
457467
}
458468

459469
@override
@@ -493,10 +503,19 @@ class _ClassIntrospector implements macro.ClassIntrospector {
493503
}
494504

495505
class _IdentifierResolver extends macro.IdentifierResolver {
506+
final LinkedElementFactory elementFactory;
507+
final DeclarationBuilder declarationBuilder;
508+
509+
_IdentifierResolver(
510+
this.elementFactory,
511+
this.declarationBuilder,
512+
);
513+
496514
@override
497-
Future<macro.Identifier> resolveIdentifier(Uri library, String name) {
498-
// TODO: implement resolveIdentifier
499-
throw UnimplementedError();
515+
Future<macro.Identifier> resolveIdentifier(Uri library, String name) async {
516+
final libraryElement = elementFactory.libraryOfUri2(library.toString());
517+
final element = libraryElement.scope.lookup(name).getter!;
518+
return declarationBuilder.fromElement.identifier(element);
500519
}
501520
}
502521

@@ -571,12 +590,61 @@ class _MacroTargetElementCollector extends GeneralizingElementVisitor<void> {
571590
}
572591
}
573592

574-
class _TypeResolver implements macro.TypeResolver {
593+
class _StaticTypeImpl extends macro.StaticType {
594+
final TypeSystemImpl typeSystem;
595+
final DartType type;
596+
597+
_StaticTypeImpl(this.typeSystem, this.type);
598+
575599
@override
576-
Future<macro.StaticType> resolve(macro.TypeAnnotationCode type) {
577-
// TODO: implement resolve
600+
Future<bool> isExactly(_StaticTypeImpl other) {
601+
// TODO: implement isExactly
578602
throw UnimplementedError();
579603
}
604+
605+
@override
606+
Future<bool> isSubtypeOf(_StaticTypeImpl other) {
607+
// TODO(scheglov) write tests
608+
return Future.value(
609+
typeSystem.isSubtypeOf(type, other.type),
610+
);
611+
}
612+
}
613+
614+
class _TypeResolver implements macro.TypeResolver {
615+
final TypeSystemImpl typeSystem;
616+
617+
_TypeResolver({
618+
required this.typeSystem,
619+
});
620+
621+
@override
622+
Future<macro.StaticType> resolve(macro.TypeAnnotationCode type) async {
623+
var dartType = _resolve(type);
624+
return _StaticTypeImpl(typeSystem, dartType);
625+
}
626+
627+
DartType _resolve(macro.TypeAnnotationCode type) {
628+
// TODO(scheglov) write tests
629+
if (type is macro.NamedTypeAnnotationCode) {
630+
final identifier = type.name as IdentifierImpl;
631+
final element = identifier.element;
632+
if (element is ClassElementImpl) {
633+
return element.instantiate(
634+
typeArguments: type.typeArguments.map(_resolve).toList(),
635+
nullabilitySuffix: type.isNullable
636+
? NullabilitySuffix.question
637+
: NullabilitySuffix.none,
638+
);
639+
} else {
640+
// TODO(scheglov) Implement other elements.
641+
throw UnimplementedError('(${element.runtimeType}) $element');
642+
}
643+
} else {
644+
// TODO(scheglov) Implement other types.
645+
throw UnimplementedError('(${type.runtimeType}) $type');
646+
}
647+
}
580648
}
581649

582650
extension on macro.MacroExecutionResult {

0 commit comments

Comments
 (0)