* UpperCamelCase

class, enum, typedef, type parametes (annotaion class with parameter) 등

 

* lowerCamelCase

class members, top-level definitions, variables, parameters, and named parameters, constant variable, enum values

- constant variable 하고 enum values 가 좀 특이하네

- enum SCREAMING_CAPS 스타일은 내가 만든 거 아닐때만 쓰라고 하는 듯 (기존 코드 또는 protobuf로 생성한 코드)

 

const pi = 3.14;
const defaultTimeout = 1000;
final urlScheme = RegExp('^([a-z]+):');

enum BeeGees {
  barryGibb,
  mauriceGibb,
  robinGibb
}

class Dice {
  static final numberGenerator = Random();
}

 

* lowercase_with_underscores

filename, import prefixes

- 파일명하고 디렉토리는 언더스코어로~~

 

* import 관련

알파벳 및 섹션별 정렬

위에부터 dart: > package: > relative imports (relative 사용도 추천하진 않는 듯)

대충 dart > 남들 package > 내 package 순으로 정리하면 될 듯

 

 

* 참고

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

 

Effective Dart: Style

Formatting and naming rules for consistent, readable code.

dart.dev

 

'dart' 카테고리의 다른 글

flutter vscode 설정  (0) 2021.05.05
flutter 폴더 구조 정리  (0) 2021.05.05
dart,flutter convention 및 linter  (0) 2021.05.05
flutter 유튜브 참고  (0) 2021.05.05
flutter 유튜브 채널 요약 좀 해보자  (0) 2021.05.05

 

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

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

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

'가장 작은 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