diagnostics_no_leading_underscores_for_local_identifiers 진단: 지역 변수가 밑줄로 시작할 때

diagnostics_no_leading_underscores_for_local_identifiers 진단: 지역 변수가 밑줄로 시작할 때

Dart 분석기가 내보내는 진단에는 이름이 있어요. no_leading_underscores_for_local_identifiers지역 변수의 이름이 밑줄로 시작할 때 분석기가 알려주는 진단이에요. 지역 변수는 애초에 선언한 라이브러리 밖에서 보이지 않으니, private을 뜻하는 밑줄이 아무 의미가 없어요.

출처: no_leading_underscores_for_local_identifiers

본문

설명

분석기는 지역 변수의 이름이 밑줄로 시작할 때 이 진단을 만들어요. 지역 변수는 본질적으로 선언한 라이브러리 밖에서는 보이지 않으므로, private을 나타내는 밑줄은 아무 가치도 더해 주지 않아요.

예시

아래 코드는 파라미터 _s가 밑줄로 시작해서 이 진단을 만들어요.

int f(String _s) => _s.length;

흔한 해결 방법

밑줄을 제거해요.

int f(String s) => s.length;

더 알아보기