Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dart-lang/dart_style
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.2.0
Choose a base ref
...
head repository: dart-lang/dart_style
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.2.1
Choose a head ref
  • 8 commits
  • 38 files changed
  • 6 contributors

Commits on Sep 27, 2021

  1. lints (#1061)

    * Enable and fix recommended lints
    
    * Enable and fix two more lints
    kevmoo authored Sep 27, 2021
    Copy the full SHA
    55512ec View commit details

Commits on Sep 28, 2021

  1. Copy the full SHA
    faf8672 View commit details

Commits on Oct 4, 2021

  1. Remove outdated references to "dartfmt". (#1065)

    * Remove outdated references to "dartfmt".
    
    There are still a few in the repo, but they are in code that exists to
    implement or test the legacy CLI. Those will go away when support for
    that is fully removed from the package in a future change.
    
    * Remove more uses.
    munificent authored Oct 4, 2021
    Copy the full SHA
    96cca43 View commit details

Commits on Oct 16, 2021

  1. Copy the full SHA
    ae3d7d3 View commit details

Commits on Oct 17, 2021

  1. Merge pull request #1067 from scheglov/latestAnalyzer-NamedType

    Require analyzer 2.6.0, use NamedType.
    scheglov authored Oct 17, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    stsewd Santos Gallegos
    Copy the full SHA
    08b0294 View commit details

Commits on Dec 10, 2021

  1. Copy the full SHA
    86b14a3 View commit details

Commits on Dec 16, 2021

  1. allow analyzer version 3.0.0 (#1079)

    * allow analyzer version 3.0.0
    
    * remove override
    
    * tiny bump
    
    Co-authored-by: Kevin Moore <kevmoo@google.com>
    jakemac53 and kevmoo authored Dec 16, 2021
    Copy the full SHA
    1c68e41 View commit details
  2. Bump to 2.2.1. (#1081)

    munificent authored Dec 16, 2021
    Copy the full SHA
    610ef57 View commit details
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.2.1

* Require `package:analyzer` version `2.6.0`.
* Use `NamedType` instead of `TypeName`.

# 2.2.0

* Fix analyzer dependency constraint (#1051).
@@ -78,7 +83,7 @@

* Change the path used in error messages when reading from stdin from "<stdin>"
to "stdin". The former crashes on Windows since it is not a valid Windows
pathname. To get the old behavior, pass `--stdin-name=<stdin>`.
pathname. To get the old behavior, pass `--stdin-name=<stdin>`.

# 1.3.5

12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -99,17 +99,9 @@ If you need to run a different version of the formatter, you can
[globally activate][] the package from the dart_style package on
pub.dev:

$ pub global activate dart_style
$ dartfmt ...

For this to work, you need to put pub's bin directory on your PATH before the
Dart SDK directory. Otherwise, the SDK's dartfmt will shadow this one.

[globally activate]: https://dart.dev/tools/pub/cmd/pub-global

If you don't want pub to put `dartfmt` on your PATH, you can run it explicitly:

$ pub global activate dart_style --no-executables
$ pub global activate dart_style
$ pub global run dart_style:format ...

## Using the dart_style API
@@ -121,7 +113,7 @@ API for formatting code. Simple usage looks like this:
import 'package:dart_style/dart_style.dart';
main() {
var formatter = new DartFormatter();
final formatter = DartFormatter();
try {
print(formatter.format("""
4 changes: 3 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml
linter:
rules:
- avoid_dynamic_calls
- directives_ordering
- prefer_equal_for_default_values
- prefer_generic_function_type_aliases
- slash_for_doc_comments
15 changes: 7 additions & 8 deletions benchmark/benchmark.dart
Original file line number Diff line number Diff line change
@@ -6,12 +6,11 @@ library dart_style.benchmark.benchmark;

import 'dart:io';

import 'package:path/path.dart' as p;

import 'package:dart_style/dart_style.dart';
import 'package:path/path.dart' as p;

const NUM_TRIALS = 100;
const FORMATS_PER_TRIAL = 30;
const _numTrials = 100;
const _formatsPerTrial = 30;

/// Note, these files use ".txt" because while they can be *parsed* correctly,
/// they don't resolve without error. That's OK because the formatter doesn't
@@ -24,17 +23,17 @@ void main(List<String> args) {

// Run the benchmark several times. This ensures the VM is warmed up and lets
// us see how much variance there is.
for (var i = 0; i <= NUM_TRIALS; i++) {
for (var i = 0; i <= _numTrials; i++) {
var start = DateTime.now();

// For a single benchmark, format the source multiple times.
var result;
for (var j = 0; j < FORMATS_PER_TRIAL; j++) {
String? result;
for (var j = 0; j < _formatsPerTrial; j++) {
result = formatSource();
}

var elapsed =
DateTime.now().difference(start).inMilliseconds / FORMATS_PER_TRIAL;
DateTime.now().difference(start).inMilliseconds / _formatsPerTrial;

// Keep track of the best run so far.
if (elapsed >= best) continue;
4 changes: 2 additions & 2 deletions bin/format.dart
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ void main(List<String> args) async {
return;
}

if (argResults['verbose'] && !argResults['help']) {
if (argResults['verbose'] && !(argResults['help'] as bool)) {
usageError(parser, 'Can only use --verbose with --help.');
}

@@ -52,7 +52,7 @@ void main(List<String> args) async {
}

void checkForReporterCollision(String chosen, String other) {
if (!argResults[other]) return;
if (!(argResults[other] as bool)) return;

usageError(parser, 'Cannot use --$chosen and --$other at the same time.');
}
5 changes: 2 additions & 3 deletions example/format.dart
Original file line number Diff line number Diff line change
@@ -4,10 +4,9 @@
import 'dart:io';
import 'dart:mirrors';

import 'package:path/path.dart' as p;

import 'package:dart_style/dart_style.dart';
import 'package:dart_style/src/debug.dart' as debug;
import 'package:path/path.dart' as p;

void main(List<String> args) {
// Enable debugging so you can see some of the formatter's internal state.
@@ -33,7 +32,7 @@ void runFormatter(String source, int pageWidth,
try {
var formatter = DartFormatter(pageWidth: pageWidth);

var result;
String result;
if (isCompilationUnit) {
result = formatter.format(source);
} else {
2 changes: 1 addition & 1 deletion lib/dart_style.dart
Original file line number Diff line number Diff line change
@@ -3,5 +3,5 @@
// BSD-style license that can be found in the LICENSE file.
export 'src/dart_formatter.dart';
export 'src/exceptions.dart';
export 'src/style_fix.dart';
export 'src/source_code.dart';
export 'src/style_fix.dart';
12 changes: 6 additions & 6 deletions lib/src/argument_list_visitor.dart
Original file line number Diff line number Diff line change
@@ -64,8 +64,8 @@ class ArgumentListVisitor {
Token rightParenthesis,
List<Expression> arguments) {
// Look for a single contiguous range of block function arguments.
var functionsStart;
var functionsEnd;
int? functionsStart;
int? functionsEnd;

for (var i = 0; i < arguments.length; i++) {
var argument = arguments[i];
@@ -104,7 +104,7 @@ class ArgumentListVisitor {
// another: argument);
if (functionsStart != null &&
arguments[0] is NamedExpression &&
(functionsStart > 0 || functionsEnd < arguments.length)) {
(functionsStart > 0 || functionsEnd! < arguments.length)) {
functionsStart = null;
}

@@ -125,7 +125,7 @@ class ArgumentListVisitor {
return false;
}

for (var i = 0; i < functionsStart; i++) {
for (var i = 0; i < functionsStart!; i++) {
var argument = arguments[i];
if (argument is! NamedExpression) continue;

@@ -135,7 +135,7 @@ class ArgumentListVisitor {
}
}

for (var i = functionsEnd; i < arguments.length; i++) {
for (var i = functionsEnd!; i < arguments.length; i++) {
if (isArrow(arguments[i] as NamedExpression)) {
functionsStart = null;
break;
@@ -153,7 +153,7 @@ class ArgumentListVisitor {
// functions in the middle.
var argumentsBefore = arguments.take(functionsStart).toList();
var functions = arguments.sublist(functionsStart, functionsEnd);
var argumentsAfter = arguments.skip(functionsEnd).toList();
var argumentsAfter = arguments.skip(functionsEnd!).toList();

return ArgumentListVisitor._(
visitor,
12 changes: 8 additions & 4 deletions lib/src/chunk_builder.dart
Original file line number Diff line number Diff line change
@@ -312,7 +312,7 @@ class ChunkBuilder {

// Make sure there is at least one newline after a line comment and allow
// one or two after a block comment that has nothing after it.
var linesAfter;
int linesAfter;
if (i < comments.length - 1) {
linesAfter = comments[i + 1].linesBefore;
} else {
@@ -432,6 +432,8 @@ class ChunkBuilder {
_pendingWhitespace = Whitespace.newline;
}
break;
default:
break;
}
}

@@ -670,8 +672,8 @@ class ChunkBuilder {
var result = writer.writeLines(_formatter.indent,
isCompilationUnit: _source.isCompilationUnit);

var selectionStart;
var selectionLength;
int? selectionStart;
int? selectionLength;
if (_source.selectionStart != null) {
selectionStart = result.selectionStart;
var selectionEnd = result.selectionEnd;
@@ -734,6 +736,8 @@ class ChunkBuilder {
// We should have pinned these down before getting here.
assert(false);
break;
default:
break;
}

_pendingWhitespace = Whitespace.none;
@@ -928,7 +932,7 @@ class ChunkBuilder {
void _hardenRules() {
if (_hardSplitRules.isEmpty) return;

void walkConstraints(rule) {
void walkConstraints(Rule rule) {
rule.harden();

// Follow this rule's constraints, recursively.
2 changes: 1 addition & 1 deletion lib/src/cli/format_command.dart
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ class FormatCommand extends Command<int> {
}

// Can't use --verbose with anything but --help.
if (argResults['verbose'] && !argResults['help']) {
if (argResults['verbose'] && !(argResults['help'] as bool)) {
usageException('Can only use --verbose with --help.');
}

2 changes: 1 addition & 1 deletion lib/src/cli/formatter_options.dart
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import 'show.dart';
import 'summary.dart';

// Note: The following line of code is modified by tool/grind.dart.
const dartStyleVersion = '2.2.0';
const dartStyleVersion = '2.2.1';

/// Global options that affect how the formatter produces and uses its outputs.
class FormatterOptions {
2 changes: 1 addition & 1 deletion lib/src/cli/options.dart
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ void defineOptions(ArgParser parser,
}

List<int>? parseSelection(ArgResults argResults, String optionName) {
var option = argResults[optionName];
var option = argResults[optionName] as String?;
if (option == null) return null;

// Can only preserve a selection when parsing from stdin.
3 changes: 2 additions & 1 deletion lib/src/dart_formatter.dart
Original file line number Diff line number Diff line change
@@ -8,8 +8,9 @@ import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/error/error.dart';
// ignore: implementation_imports
import 'package:analyzer/src/dart/scanner/scanner.dart';
import 'package:analyzer/src/generated/parser.dart';
// ignore: implementation_imports
import 'package:analyzer/src/string_source.dart';
import 'package:pub_semver/pub_semver.dart';

2 changes: 1 addition & 1 deletion lib/src/debug.dart
Original file line number Diff line number Diff line change
@@ -222,7 +222,7 @@ void dumpConstraints(List<Chunk> chunks) {
void dumpLines(List<Chunk> chunks, int firstLineIndent, SplitSet splits) {
var buffer = StringBuffer();

void writeIndent(indent) => buffer.write(gray('| ' * (indent ~/ 2)));
void writeIndent(int indent) => buffer.write(gray('| ' * (indent ~/ 2)));

void writeChunksUnsplit(List<Chunk> chunks) {
for (var chunk in chunks) {
3 changes: 2 additions & 1 deletion lib/src/fast_hash.dart
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ library dart_style.src.fast_hash;
abstract class FastHash {
static int _nextId = 0;

/// A semi-unique numeric indentifier for the object.
/// A semi-unique numeric identifier for the object.
///
/// This is useful for debugging and also speeds up using the object in hash
/// sets. Ids are *semi*-unique because they may wrap around in long running
@@ -18,5 +18,6 @@ abstract class FastHash {
final int id = _nextId = (_nextId + 1) & 0x0fffffff;

@override
// ignore: hash_and_equals
int get hashCode => id;
}
2 changes: 1 addition & 1 deletion lib/src/io.dart
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ bool processDirectory(FormatterOptions options, Directory directory) {

// If the path is in a subdirectory starting with ".", ignore it.
var parts = p.split(p.relative(entry.path, from: directory.path));
var hiddenIndex;
int? hiddenIndex;
for (var i = 0; i < parts.length; i++) {
if (parts[i].startsWith('.')) {
hiddenIndex = i;
8 changes: 3 additions & 5 deletions lib/src/line_splitting/line_splitter.dart
Original file line number Diff line number Diff line change
@@ -120,17 +120,15 @@ class LineSplitter {

/// Creates a new splitter for [_writer] that tries to fit [chunks] into the
/// page width.
LineSplitter(this.writer, List<Chunk> chunks, int blockIndentation,
int firstLineIndent,
LineSplitter(
this.writer, this.chunks, this.blockIndentation, int firstLineIndent,
{bool flushLeft = false})
: chunks = chunks,
// Collect the set of rules that we need to select values for.
: // Collect the set of rules that we need to select values for.
rules = chunks
.map((chunk) => chunk.rule)
.whereType<Rule>()
.toSet()
.toList(growable: false),
blockIndentation = blockIndentation,
firstLineIndent = flushLeft ? 0 : firstLineIndent + blockIndentation {
_queue.bindSplitter(this);

2 changes: 1 addition & 1 deletion lib/src/line_splitting/rule_set.dart
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ class RuleSet {

// Test this rule against the other rules being bound.
for (var other in rule.constrainedRules) {
var otherValue;
int? otherValue;
// Hardened rules are implicitly bound.
if (other.isHardened) {
otherValue = other.fullySplitValue;
2 changes: 1 addition & 1 deletion lib/src/line_splitting/solve_state.dart
Original file line number Diff line number Diff line change
@@ -347,7 +347,7 @@ class SolveState {
var splitSpans = <Span>{};

// The nesting level of the chunk that ended the previous line.
var previousNesting;
NestingLevel? previousNesting;

for (var i = 0; i < _splitter.chunks.length; i++) {
var chunk = _splitter.chunks[i];
4 changes: 2 additions & 2 deletions lib/src/line_splitting/solve_state_queue.dart
Original file line number Diff line number Diff line change
@@ -203,8 +203,8 @@ class SolveStateQueue {
var rightChild = _queue[rightChildIndex]!;

var comparison = _compare(leftChild, rightChild);
var minChildIndex;
var minChild;
int minChildIndex;
SolveState minChild;

if (comparison < 0) {
minChild = leftChild;
Loading