Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the latest language version if we can't find a package. #1573

Merged
merged 7 commits into from
Oct 8, 2024

Conversation

munificent
Copy link
Member

In the new tall-style behavior where we look for a surrounding package config to infer the language version of each file, we have to decide what to do when that look-up process fails (either because there is no package config, or it's malformed).

Initially, I had it error out on that file. That's consistent with the library API where the formatter requires a language version before it will do anything.

But it's not consistent with the language spec and our other tools. For them, if there is no valid surrounding package config, the file should be treated as the latest language version.

This PR does that.

It also fixes the catastrophic UX that the current code has which is that when a file can't have its language version inferred... it is silently skipped without telling the user anything. Oops. Now it just formats the file as expected.

This can find, read, and merge them. It handles `include` inside the
file.

It works using an abstraction over the file system so that (in theory at
least), this code could be harvested and made reusable by other tools
that need to work with analysis_options.yaml files but don't want to
work directly with files on disk.

It also includes an implementation of that abstraction using dart:io.

Right now, this is all just private inside dart_style, but is organized
so that it would be easy to pull out into a separate package later if we
want.
It was getting pretty huge. I didn't want to stuff more tests in there
for CLI integration of analysis_options, so splitting it up into smaller
files first.

There are no meaningful changes here, just moving code around.
When formatting from the CLI using files or stdin with a --stdin-name
option, looks in the surrounding directories for an
analysis_options.yaml file. If found and the file specifies a formatter
page width, uses that.

Handles includes and merging as well. Doesn't handle "package:" includes
yet.
In the new tall-style behavior where we look for a surrounding package
config to infer the language version of each file, we have to decide
what to do when that look-up process fails (either because there is no
package config, or it's malformed).

Initially, I had it error out on that file. That's consistent with the
library API where the formatter *requires* a language version before it
will do anything.

But it's not consistent with the language spec and our other tools. For
them, if there is no valid surrounding package config, the file should
be treated as the latest language version.

This PR does that.

It also fixes the catastrophic UX that the current code has which is
that when a file can't have its language version inferred... it is
silently skipped without telling the user anything. Oops. Now it just
formats the file as expected.
Base automatically changed from analysis-options to main October 7, 2024 22:56
# Conflicts:
#	lib/src/analysis_options/analysis_options_file.dart
#	lib/src/analysis_options/file_system.dart
#	lib/src/analysis_options/io_file_system.dart
#	lib/src/config_cache.dart
#	lib/src/io.dart
#	lib/src/testing/test_file_system.dart
#	test/analysis_options/analysis_options_file_test.dart
#	test/cli/language_version_test.dart
@munificent munificent merged commit 618883f into main Oct 8, 2024
7 checks passed
@munificent munificent deleted the default-latest-language branch October 8, 2024 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants