Skip to content

Handle removed dart style cli option#466

Draft
robbecker-wf wants to merge 4 commits intomasterfrom
handle_removed_dart_style_cli_option
Draft

Handle removed dart style cli option#466
robbecker-wf wants to merge 4 commits intomasterfrom
handle_removed_dart_style_cli_option

Conversation

@robbecker-wf
Copy link
Member

Summary

Working on adding support for configuring the language version in the FormatTool as well as not trying to pass the removed -w command when running dart_style directly

ArgResults? argResults,
List<String>? configuredFormatterArgs,
bool passWriteArgForOverwrite = true,
String? languageVersion,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a non-formatting change

defaultMode: defaultMode,
exclude: exclude,
formatter: formatter,
languageVersion: languageVersion,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a non-formatting change

/// `--language-version`.
///
/// If null, `latest` will be used when dart_dev decides the flag is needed.
String? languageVersion;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a non-formatting change

FormatMode? mode, {
ArgResults? argResults,
List<String>? configuredFormatterArgs,
String? languageVersion,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a non-formatting change. added languageVersion

// 1. Mode flag(s), if configured
if (mode == FormatMode.check) ...['-o', 'none', '--set-exit-if-changed'],
if (mode == FormatMode.dryRun) ...['-o', 'none'],
if (languageVersion != null) '--language-version=$languageVersion',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a non-formatting change

FormatMode? defaultMode,
List<Glob>? exclude,
Formatter? formatter,
String? languageVersion,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a non-formatting change

formatter,
dartStyleSupportsWriteArg,
configuredLanguageVersion: languageVersion,
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a non-formatting change. determine if we should use -w and what the language version to use is.

mode,
argResults: context.argResults,
configuredFormatterArgs: configuredFormatterArgs,
languageVersion: formatterLanguageVersion,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass in the language version

argResults: context.argResults,
configuredFormatterArgs: configuredFormatterArgs,
passWriteArgForOverwrite: dartStyleSupportsWriteArg,
languageVersion: formatterLanguageVersion,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass in language version and -w usage

@@ -515,14 +580,99 @@ ProcessDeclaration buildFormatProcess([Formatter? formatter]) {
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new util methods

///
/// Unless [verbose] is true, the list of inputs will be abbreviated to avoid an
/// unnecessarily long log.
void logCommand(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rest is formatting below here

@@ -13,10 +13,10 @@ import '../utils/assert_no_positional_args_nor_args_after_separator.dart';
/// Use [DevTool.fromFunction] to create [FunctionTool] instances.
class FunctionTool extends DevTool {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only formatting changes in this file

@@ -28,19 +28,22 @@ class OverReactFormatTool extends DevTool {
Iterable<String> paths = context.argResults?.rest ?? [];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only formatting changes in this file

@@ -27,12 +27,15 @@ final _log = Logger('Process');
/// It is also possible to run this tool directly in a dart script:
/// ProcessTool(exe, args).run();
class ProcessTool extends DevTool {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only formatting changes in this file

@@ -50,48 +50,66 @@ class TestTool extends DevTool {
@override
final ArgParser argParser = ArgParser()
..addSeparator('======== Selecting Tests')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only formatting changes in this file

@@ -54,13 +54,16 @@ class TuneupCheckTool extends DevTool {
..addFlag('ignore-infos', help: 'Ignore any info level issues.');

@override
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only formatting changes in this file

@@ -64,27 +64,40 @@ class WebdevServeTool extends DevTool {

@override
final ArgParser argParser = ArgParser()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only formatting changes in this file

@@ -0,0 +1,4 @@
name: has_dart_style_v2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test fixture

@@ -0,0 +1,4 @@
name: has_dart_style_v3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test fixture

orderedEquals(['a', 'b', '-w']));
expect(
buildArgs(['a', 'b'], FormatMode.overwrite),
orderedEquals(['a', 'b', '-w']),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test with -w

);
});

test('mode=overwrite without write arg', () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test without -w

);
});

test('adds latest language version flag when configured', () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 tests to test the new language version config

);
});

test('adds latest language version flag when configured', () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 new tests

expect(execution.directiveOrganization, isNull);
});

test(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new tests for dart_style

final execution = buildExecution(
context,
configuredFormatterArgs: ['--fix', '--follow-links'],
formatter: Formatter.dartFormat,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updates to test for language version under dart 3

test('<=5 inputs and verbose=false', () async {
expect(Logger.root.onRecord,
emitsThrough(infoLogOf(contains('dartfmt -x -y a b'))));
expect(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format changes below

);
});

test('detects languageVersion', () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test

String formatToolCascadeSrc({String formatter = 'dartfmt'}) =>
String formatToolCascadeSrc({
String formatter = 'dartfmt',
String? languageVersion,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add language version

);
});

test(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test

@@ -0,0 +1,3 @@
void main() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test fixture

);
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get the language version from config

failedToReconstructFormatterArgs,
failedToParseFormatterArgs,
failedToParseLineLength,
failedToParseLanguageVersion,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new error

}
}
return null;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new util function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant