Skip to content

Digit separators prevent formatting #1630

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

Closed
anthonymoretti opened this issue Dec 19, 2024 · 7 comments
Closed

Digit separators prevent formatting #1630

anthonymoretti opened this issue Dec 19, 2024 · 7 comments
Labels

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

@julemand101
Copy link

@Ramgopaljakhar
Thanks for trying to help but if you read my comment, the issue can be reproduced without any extensions and a clean Dart SDK installation.

Since you feel the need to write such comment, is it because you can't reproduce the issue yourself?

@munificent munificent added the bug label Jan 21, 2025
@ramtinabadi
Copy link

I am facing the same issue.

Here are my details:

  1. Versions:
Flutter 3.27.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 68415ad1d9 (9 days ago) • 2025-01-13 10:22:03 -0800
Engine • revision e672b006cb
Tools • Dart 3.6.1 • DevTools 2.40.2
  1. No doctor error
  2. VS Code version: 1.96.4
  3. Flutter VS Code plugin version: 3.102.0
  4. SDK version in pubspec: ^3.6.0

My experience:
The formatter works in all files that do not have the digit separator. However, when a file has a digit separator, the formatter does nothing when saving the file. It won't reformat the code or change the style of the code in any way.

Since the files that were affected by this bug were large files, I wasn't quite sure what the problem was. After seeing this issue, I removed the digit separators and the formatter worked as usual.

@munificent
Copy link
Member

This is already fixed in the latest version of dart_style. It will also be fixed in the upcoming 3.7.0 release of the Dart SDK.

I have a cherry-pick change out to roll a fix into the Dart SDK 3.6.x stable branch. When (if?) we cut a new stable release of 3.6.x, that will hopefully have the fix.

In the meantime, I'm really sorry for the bug. It sucks that we shipped digit separators in 3.6.0 but you can't format them. It was an oversight on my part and unfortunately it wasn't caught by tests. :(

I'm going to close this because there's no ongoing work left to do in the dart_style repo to fix this. (I've published 2.3.8 with a fix for the 3.6.x SDK branch, and the main branch of dart_style is already fixed.) But it may be some time because users on Dart SDK 3.6.x get a fix. Sorry about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants
@munificent @srawlins @julemand101 @anthonymoretti @ramtinabadi and others