Skip to content

Commit a5ec37d

Browse files
authored
Apply class modifiers to all the classes. (#1575)
Now that we've bumped the major version and can make breaking changes, I went ahead and locked down all of the classes. It mostly matters for the public ones, but I went ahead and applied it to the internal ones too just to see if it makes things easier to maintain.
1 parent 0945c9d commit a5ec37d

Some content is hidden

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

60 files changed

+100
-94
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
If `--stdin-name` and `--language-version` are both omitted, then parses
6868
stdin using the latest supported language version.
6969

70+
* **Apply class modifiers to API classes.** The dart_style package exposes only
71+
a few classes in its public API: `DartFormatter`, `SourceCode`,
72+
`FormatterException`, and `UnexpectedOutputException`. None were ever
73+
intended to be extended or implemented. They are now all marked `final` to
74+
make that intention explicit.
75+
7076
## 2.3.7
7177

7278
* Allow passing a language version to `DartFomatter()`. Formatted code will be

lib/src/back_end/code.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ enum _Marker { start, end }
177177

178178
/// Traverses a [Code] tree and produces the final string of output code and
179179
/// the selection markers, if any.
180-
class _StringBuilder {
180+
final class _StringBuilder {
181181
/// Pre-calculated whitespace strings for various common levels of
182182
/// indentation.
183183
///

lib/src/back_end/code_writer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import 'solution_cache.dart';
2020
/// an instance of this class. It has methods that the piece can call to add
2121
/// output text to the resulting code, recursively format child pieces, insert
2222
/// whitespace, etc.
23-
class CodeWriter {
23+
final class CodeWriter {
2424
final int _pageWidth;
2525

2626
/// Previously cached formatted subtrees.
@@ -415,7 +415,7 @@ enum Whitespace {
415415
}
416416

417417
/// A level of indentation in the indentation stack.
418-
class _Indent {
418+
final class _Indent {
419419
/// The total number of spaces of indentation.
420420
final int indent;
421421

lib/src/back_end/solution.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import 'solution_cache.dart';
1717
/// of the pieces in the tree so they can format themselves. That in turn
1818
/// yields a total number of overflow characters, cost, and formatted output,
1919
/// which are all stored here.
20-
class Solution implements Comparable<Solution> {
20+
final class Solution implements Comparable<Solution> {
2121
/// The states that pieces have been bound to.
2222
///
2323
/// Note that order that keys are inserted into this map is significant. When

lib/src/back_end/solution_cache.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import 'solver.dart';
2222
/// the same child Piece and wanting to format it separately with the same
2323
/// indentation. When that happens, sharing this cache allows us to reuse that
2424
/// cached subtree Solution.
25-
class SolutionCache {
25+
final class SolutionCache {
2626
final _cache = <_Key, Solution>{};
2727

2828
/// Returns a previously cached solution for formatting [root] with leading

lib/src/back_end/solver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const _maxAttempts = 10000;
4242
/// use it across different Solutions. This enables us to both divide and
4343
/// conquer the Piece tree and solve portions separately, while also
4444
/// reusing work across different solutions.
45-
class Solver {
45+
final class Solver {
4646
final SolutionCache _cache;
4747

4848
final int _pageWidth;

lib/src/cli/format_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'output.dart';
1414
import 'show.dart';
1515
import 'summary.dart';
1616

17-
class FormatCommand extends Command<int> {
17+
final class FormatCommand extends Command<int> {
1818
@override
1919
String get name => 'format';
2020

lib/src/cli/formatter_options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'summary.dart';
1515
const dartStyleVersion = '2.3.7';
1616

1717
/// Global options that affect how the formatter produces and uses its outputs.
18-
class FormatterOptions {
18+
final class FormatterOptions {
1919
/// The language version formatted code should be parsed at or `null` if not
2020
/// specified.
2121
final Version? languageVersion;

lib/src/cli/summary.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import '../source_code.dart';
88
import 'formatter_options.dart';
99

1010
/// The kind of summary shown after all formatting is complete.
11-
class Summary {
11+
final class Summary {
1212
static const Summary none = Summary._();
1313

1414
/// Creates a Summary that tracks how many files were formatted and the total
@@ -41,7 +41,7 @@ class Summary {
4141
}
4242

4343
/// Tracks how many files were formatted and the total time.
44-
class _LineSummary extends Summary {
44+
final class _LineSummary extends Summary {
4545
final DateTime _start = DateTime.now();
4646

4747
/// The number of processed files.
@@ -81,7 +81,7 @@ class _LineSummary extends Summary {
8181
}
8282

8383
/// Reports how long it took for format each file.
84-
class _ProfileSummary implements Summary {
84+
final class _ProfileSummary implements Summary {
8585
/// The files that have been started but have not completed yet.
8686
///
8787
/// Maps a file label to the time that it started being formatted.

lib/src/constants.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const tallStyleExperimentFlag = 'tall-style';
1313

1414
/// Constants for the cost heuristics used to determine which set of splits is
1515
/// most desirable.
16-
class Cost {
16+
final class Cost {
1717
/// The cost of splitting after the `=>` in a lambda or arrow-bodied member.
1818
///
1919
/// We make this zero because there is already a span around the entire body
@@ -64,7 +64,7 @@ class Cost {
6464
}
6565

6666
/// Constants for the number of spaces for various kinds of indentation.
67-
class Indent {
67+
final class Indent {
6868
/// Reset back to no indentation.
6969
static const none = 0;
7070

0 commit comments

Comments
 (0)