bluefireteam / vscode-dart-import

A simple plugin for VSCode to change all Dart/Flutter imports to relative format.
64 stars 14 forks source link

[bug] Breaks if pubspec.yaml has nested "name" key #15

Closed danielmahon closed 4 years ago

danielmahon commented 4 years ago

Looks like it is matching name: with any spaces in front of it, which matches nested "name" keys. I believe the flutter name: key you care about has to be in the top level of the YAML tree so you should be able to remove the preceding space matching. Space counts in YAML so any preceding spaces to the root name would be incorrect. Am I missing another issue?

Will break with pubspec.yaml like:

name: flutter_app
description: A new Flutter project.

dev_dependencies:
  flutter_launcher_name:

flutter_launcher_name:
  name: "My App"

# Workaround
# flutter_launcher_name: { name: "My App" }

https://github.com/luanpotter/vscode-dart-import/blob/7d9c85372868a8110b0259c783fe1342f47c1d18/src/extension.ts#L38

should change to:

 const packageNameMatch = /^name:\s*(.*)$/mg.exec(nameLine); 

Thanks for this library!

abusaadp commented 4 years ago

Also change const possibleNameLines = pubspec.getText().split('\n').filter((line) => line.match(/^\s*name:/)); to const possibleNameLines = pubspec.getText().split('\n').filter((line) => line.match(/^name:/));