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

Digit separators prevent formatting #1630

Open
anthonymoretti opened this issue Dec 19, 2024 · 4 comments
Open

Digit separators prevent formatting #1630

anthonymoretti opened this issue Dec 19, 2024 · 4 comments

Comments

@anthonymoretti
Copy link

Steps to reproduce:

  1. Make edits anywhere and Shift + Option + F and formatting works.
  2. Comment the first foo out and uncomment the second.
  3. Make edits anwwhere and Shift + Option + F and formatting doesn't work.
import 'package:flutter/material.dart';

const foo = 1000; // Formatting works.
// const foo = 1_000; // Formatting doesn't work.

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp();
  }
}
@srawlins
Copy link
Member

Thanks for the bug report. A few questions:

  • What version of Dart are you using?
  • What is Shift + Option + F? What program are you running when you press that?
  • Are the main function and the MyApp class important to the bug reproduction? Or the flutter import?
  • When you say, "formatting doesn't work", what do you mean? What did you expect to happen, and what happened instead of that?
  • Is the digit-separators feature enabled? Meaning, is the surrounding package's SDK constraint set to something like ^3.6.0, and have you run dart pub get or flutter pub get after setting that constraint?

@anthonymoretti
Copy link
Author

  • sdk: ">=3.6.0 <4.0.0"
  • VS Code keyboard shortcut for the "Format Document" command.
  • No. I just used the template that's automatically generated when you do flutter create app_name, and then I cut it back to something reasonably minimal, where it's clear enough that the rest of the code doesn't matter but there's still enough code to try different edits and see if the formatting works.
  • Example: Add extra indenting at the beginning of any line. Run the formatter without digit separators present and the redundant indents will be removed. Run the formatter with digit separators present and the redundant indents won't be removed.
  • Yes. I discovered the bug in my own project and then created this minimally reproducible example.

Sorry, I would have included this extra information in the initial bug report but I wasn't sure if I was raising the issue in the right place, so I kept it brief.

@srawlins
Copy link
Member

Excellent, thanks!

@julemand101
Copy link

Might be a different issue and if so, I can report that. But if I do the following:

$ dart --version
Dart SDK version: 3.6.0 (stable) (Thu Dec 5 07:46:24 2024 -0800) on "linux_x64"
$ dart create example
$ cd example/

Then I change lib/example.dart to the following content:

int calculate() {
  return 6_2 * 7;
}

And then run format I get the following error:

$ dart format --output=none .
Could not format because the source could not be parsed:

line 2, column 10 of lib/example.dart: This requires the 'digit-separators' language feature to be enabled.
  ╷
2 │   return 6_2 * 7;
  │          ^^^
  ╵

And the content of pubspec.yaml:

name: example
description: A sample command-line application.
version: 1.0.0
# repository: https://github.com/my_org/my_repo

environment:
  sdk: ^3.6.0

# Add regular dependencies here.
dependencies:
  # path: ^1.8.0

dev_dependencies:
  lints: ^5.0.0
  test: ^1.24.0

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

No branches or pull requests

3 participants