Skip to content

Improve error message for Linter warning: lower_case_with_underscores / dart(file_names) #5270

@Yegair

Description

@Yegair

Is your feature request related to a problem? Please describe.
The problem is that sometimes when creating a new file, one might type in an uppercase character by accident. Dart-Code then immediately shows the lower_case_with_underscores warning. However, fixing the issue can be rather tricky, because VSCode doesn't want to change its internal cache of file names, when the only thing that changes about the file name is the casing.

For example create a new file test.dart with the following contents:

// test.dart

part 'test_part.dart`;

Then create another file test_Part.dart (intentionally using an uppercase P):

// test_Part.dart

part of 'test.dart';

The linter will immediatly recognize the problem and highlight it:

// test_Part.dart

part of 'test.dart';
^^^^
The file name 'test_Part.dart' isn't a lower_case_with_underscores identifier.
Try changing the name to follow the lower_case_with_underscores style.

Now change the file name in VSCode to test_part.dart to fix the problem.
Notice how Dart-Code still highlights the problem, although it should be fixed.

// test_part.dart

part of 'test.dart';
^^^^
The file name 'test_Part.dart' isn't a lower_case_with_underscores identifier.
Try changing the name to follow the lower_case_with_underscores style.

The problem has been analyzed thoroughly in #3236 and the issue seems to be the internal file-name cache of VSCode. Also a solution that works reliably has been found: #3236 (comment)

I managed to fix the issue by inserting an underscore at a random location in the file name, like button_s.dart. After this the warning disappeared. I then closed VSC, then reopened it, and renamed the file again back to buttons.dart. And the warning did not come back.

So the fix is for example to rename test_part.dart -> test_p_art.dart and then close/restart VSCode and again rename it back test_p_art.dart -> test_part.dart. Now VSCode has updated its internal cache, because a change was made that was not just an uppercase -> lowercase change.

Describe the solution you'd like

It would be great to have a hint in the error message that shows up, that helps to fix the issue. Maybe a link to some small documentation snippet or something in this direction.

It took me 30 minutes to figure out what the problem was and how to fix it, because the solution that I have linked did not show up at the top of the Google search results and when I found it, it took a while to read through the comments to find the solution.

Describe alternatives you've considered
I don't think there is a good alternative, besides VSCode changing its weird behaviour regarding file name caching. For example offering a quick fix will probably not work, since one has to restart VSCode to make the fix work.

Additional context

Screenshot 2024-09-16 at 17 01 17

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions