Skip to content

Commit 358a072

Browse files
authored
Merge branch 'main' into patch-1
2 parents 572f67f + 8f1843c commit 358a072

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1356
-377
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
# Initializes the CodeQL tools for scanning.
3535
- name: Initialize CodeQL
36-
uses: github/codeql-action/init@4e94bd11f71e507f7f87df81788dff88d1dacbfb
36+
uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee
3737
with:
3838
languages: ${{ matrix.language }}
3939
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -44,7 +44,7 @@ jobs:
4444
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
4545
# If this step fails, then you should remove it and run the build manually (see below)
4646
- name: Autobuild
47-
uses: github/codeql-action/autobuild@4e94bd11f71e507f7f87df81788dff88d1dacbfb
47+
uses: github/codeql-action/autobuild@0499de31b99561a6d14a36a5f662c2a54f91beee
4848

4949
# ℹ️ Command-line programs to run using the OS shell.
5050
# 📚 https://git.io/JvXDl
@@ -58,4 +58,4 @@ jobs:
5858
# make release
5959

6060
- name: Perform CodeQL Analysis
61-
uses: github/codeql-action/analyze@4e94bd11f71e507f7f87df81788dff88d1dacbfb
61+
uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee

.github/workflows/scorecards-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ jobs:
4949

5050
# Upload the results to GitHub's code scanning dashboard.
5151
- name: "Upload to code-scanning"
52-
uses: github/codeql-action/upload-sarif@4e94bd11f71e507f7f87df81788dff88d1dacbfb
52+
uses: github/codeql-action/upload-sarif@0499de31b99561a6d14a36a5f662c2a54f91beee
5353
with:
5454
sarif_file: results.sarif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include: ../analysis_options.yaml
2+
3+
analyzer:
4+
errors:
5+
experimental_member_use: ignore
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
void printLowerH() {
2+
// #docregion chain
3+
// .fromCharCode(72) resolves to the String "H",
4+
// then the instance method .toLowerCase() is called on that String.
5+
String lowerH = .fromCharCode(72).toLowerCase();
6+
// Instead of String.fromCharCode(72).toLowerCase()
7+
8+
print(lowerH); // Output: h
9+
// #enddocregion chain
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Point {
2+
final double x, y;
3+
const Point(this.x, this.y);
4+
const Point.origin() : x = 0, y = 0; // Named constructor
5+
6+
// Factory constructor
7+
factory Point.fromList(List<double> list) {
8+
return Point(list[0], list[1]);
9+
}
10+
}
11+
12+
// Use dot shorthand syntax on a named constructor:
13+
Point origin = .origin(); // Instead of Point.origin()
14+
15+
// Use dot shorthand syntax on a factory constructor:
16+
Point p1 = .fromList([1.0, 2.0]); // Instead of Point.fromList([1.0, 2.0])
17+
18+
// Use dot shorthand syntax on a generic class constructor:
19+
List<int> intList = .filled(5, 0); // Instead of List.filled(5, 0)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
enum Status { none, running, stopped, paused }
2+
3+
class Point {
4+
final double x, y;
5+
const Point(this.x, this.y);
6+
const Point.origin() : x = 0.0, y = 0.0;
7+
}
8+
9+
// Use dot shorthand syntax for enum value:
10+
const Status defaultStatus = .running; // Instead of Status.running
11+
12+
// Use dot shorthand syntax to invoke a const named constructor:
13+
const Point myOrigin = .origin(); // Instead of Point.origin()
14+
15+
// Use dot shorthand syntax in a const collection literal:
16+
const List<Point> keyPoints = [.origin(), .new(1.0, 1.0)];
17+
// Instead of [Point.origin(), Point(1.0, 1.0)]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
enum LogLevel { debug, info, warning, error }
2+
3+
/// Returns the color code to use for the specified log [level].
4+
String colorCode(LogLevel level) {
5+
// Use dot shorthand syntax for enum values in switch cases:
6+
return switch (level) {
7+
.debug => 'gray', // Instead of LogLevel.debug
8+
.info => 'blue', // Instead of LogLevel.info
9+
.warning => 'orange', // Instead of LogLevel.warning
10+
.error => 'red', // Instead of LogLevel.error
11+
};
12+
}
13+
14+
// Example usage:
15+
String warnColor = colorCode(.warning); // Returns 'orange'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// ignore_for_file: dead_code
2+
enum Color { red, green, blue }
3+
4+
// Use dot shorthand syntax for equality expressions:
5+
void allowedExamples() {
6+
Color myColor = Color.red;
7+
bool condition = true;
8+
9+
// OK: `myColor` is a `Color`, so `.green` is inferred as `Color.green`.
10+
if (myColor == .green) {
11+
print('The color is green.');
12+
}
13+
14+
// OK: Works with `!=` as well.
15+
if (myColor != .blue) {
16+
print('The color is not blue.');
17+
}
18+
19+
// OK: The context for the ternary is the variable `inferredColor`
20+
// being assigned to, which has a type of `Color`.
21+
Color inferredColor = condition ? .green : .blue;
22+
print('Inferred color is $inferredColor');
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// ignore_for_file: dead_code
2+
enum Color { red, green, blue }
3+
4+
void notAllowedExamples() {
5+
Color myColor = Color.red;
6+
bool condition = true;
7+
8+
// ERROR: The shorthand must be on the right side of `==`.
9+
// Dart's `==` operator is not symmetric for this feature.
10+
// ignore: dot_shorthand_missing_context
11+
if (.red == myColor) {
12+
print('This will not compile.');
13+
}
14+
15+
// ERROR: The right-hand side is a complex expression (a conditional expression),
16+
// which is not a valid target for shorthand in a comparison.
17+
// ignore: dot_shorthand_missing_context
18+
if (myColor == (condition ? .green : .blue)) {
19+
print('This will not compile.');
20+
}
21+
22+
// ERROR: The type context is lost by casting `myColor` to `Object`.
23+
// The compiler no longer knows that `.green` should refer to `Color.green`.
24+
// ignore: dot_shorthand_undefined_member
25+
if ((myColor as Object) == .green) {
26+
print('This will not compile.');
27+
}
28+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Logger {
2+
static void log(String message) {
3+
print(message);
4+
}
5+
}
6+
7+
void main() {
8+
// ERROR: An expression statement can't begin with `.`.
9+
// The compiler has no type context (like a variable assignment)
10+
// to infer that `.log` should refer to `Logger.log`.
11+
// ignore: dot_shorthand_undefined_member
12+
.log('Hello');
13+
}

0 commit comments

Comments
 (0)