코딩 컨벤션(가이드라인)에 따라 코드를 작성하다 보면 자연스레 이쁜 코드를 작성하는 습관이 들어서,

개인적으로 코딩 컨벤션은 최대한 맞추려고 하는 편이다.

기본적으로 언어별, 프레임워크별, 라이브러리별 컨벤션이 약간씩 차이나는 경우가 있는데,

'가장 작은 scope 기준으로 스타일을 맞춘다는' 기본 컨셉만 지키면 크게 무리가 없다

예) 특정 파일에 함수와 파일이 컨벤션이 다른 경우, 더 작은 scope인 함수에 맞춘다

scope: 블럭 < 함수 < 파일 < 모듈(디렉토리) < ...

 

* 코딩 컨벤션

dart 하고 flutter가 가끔 차이나는 경우가 있는 거 같네. 대략적인것만 훑어보고 linter 대로 따라가자

github.com/flutter/flutter/issues/20858

 

Should global constants be prefixed with `k` ? · Issue #20858 · flutter/flutter

The Flutter style guide recommends prefixing global constants with 'k', https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#begin-global-constant-names-with-prefix-k , But ...

github.com

 

* 그러면 linter는 뭘로 할까나~

flutter linter는 구글이 주도하는 pedantic하고, 커뮤니티쪽에서 주도하는 effective_dart를 많이 사용하는 듯 하다

고민해봤자 답 없으니 star 수 더 많은 pedantic 사용하자

 

github.com/google/pedantic

 

google/pedantic

How to get the most value from Dart static analysis - google/pedantic

github.com

github.com/tenhobi/effective_dart

 

tenhobi/effective_dart

Linter rules corresponding to the guidelines in Effective Dart - tenhobi/effective_dart

github.com


* 사용 방법 요약

1. pubspec.yaml

dev_dependencies:
  pedantic: ^1.11.0

2. analysis_options.yaml 파일 프로젝트 최상단에 생성하고 아래 내용 작성

include: package:pedantic/analysis_options.yaml

3. 따로 세부설정은 하지 않음

 


 

* 코딩 컨벤션 참고

dart.dev/guides/language/effective-dart/style

 

Effective Dart: Style

Formatting and naming rules for consistent, readable code.

dart.dev

github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo

 

flutter/flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond. - flutter/flutter

github.com

 

+ Recent posts