728x90
728x90

Tailing Comma 적용 방법

들어가며

  • Visual Studio Code 같은 IDE에서 Dart를 사용할 때, 쉼표(,)로 줄바꿈을 하는 Trailing Comma를 적용하는 방법을 간단하게 정리해본다.

 

방법

  • Flutter 프로젝트 최상단 경로(@/@)에 있는 @analysis_options.yaml@ 파일에 다음과 같은 @formatter@를 추가해준다.
  • Flutter SDK 3.7.0 버전부터 Trailing Comma 포맷팅이 기본적으로 적용되지 않는데, 다음과 같이 수동으로 적용될 수 있도록 설정할 수 있다.

 

/analysis_options.yaml
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.

formatter:
  trailing_commas: preserve

 

Trailing Comma 가 적용되는 모습

 

@trailing_commas: always@ 로 설정할 경우, 항상 Trailing Comma 포맷팅이 적용된다.

 

참고 사이트

 

Why are trailing commas auto deleted and not formatted in flutter?

The trailing commas used to be auto formatted now does not format it but instead it deletes them. The same happens in Android Studio. What might cause this? This is the dart settings: "[dart]&...

stackoverflow.com

 

728x90
728x90

'Programming > Dart' 카테고리의 다른 글

[Dart] 자료형 비교 (var, const, final)  (0) 2026.02.03
[Dart] 함수 파라미터(Argument/Parameter)  (0) 2026.01.30