Flutter

[Flutter] lint / linter

hymndaniel 2023. 5. 24. 16:36

Lint 또는 Linter 는 프로그래밍 오류, 버그 , 문체 오류 및 의심스러운 구문을 표시하는 데 사용되는 정적 코드 분석 도구 입니다 . (위키피디아)

Flutter project에 Lint 를 적용하기 위해 조사를 해본 결과, 다음과 같이 요약할 수 있을 것 같다.

혼자 개발하거나 팀으로 개발하거나 Lint는 효율적인 개발 퍼포먼스에 도움이 된다.

Flutter v2.3.0 이후부터 flutter create로 생성된 Flutter 앱, 패키지 및 플러그인은 Lint가 미리 정의된 analysis_options.yaml 파일과 함께 기본 제공된다.

프로젝트 내부에 analysis_options.yaml 파일에 linter rule을 설정할 수 있다.

linter:

  rules:
    always_declare_return_types: false
    annotate_overrides: true

설정 가능한 규칙은 아래 링크에 정리되어있다.

https://dart-lang.github.io/linter/lints/

 

Linter for Dart

Linter for Dart Lint Rules Using the Linter Supported Lint Rules This list is auto-generated from our sources. Rules are organized into familiar rule groups. errors - Possible coding errors. style - Matters of style, largely derived from the official Dart

dart-lang.github.io

그런데 규칙이 정말 많아서 무엇을 해야할지 모르겠다.

Flutter에서 사용하는 Lint는 커뮤니티 중심으로 만들어진 lint패키지와, Dart에서 공식적으로 출시한 lints와 이를 flutter용으로 확장한 flutter_lints가 있다고 한다.

flutter_lints 패키지가 권장되고 인기도 많다.

https://pub.dev/packages/flutter_lints

 

flutter_lints | Dart Package

Recommended lints for Flutter apps, packages, and plugins to encourage good coding practices.

pub.dev

flutter_lints 패키지를 적용하기 위해서 아래 명령어를 실행한다.

flutter pub add --dev flutter_lints

analysis_options.yaml 파일에 다음 내용을 추가한다. 

include: package:flutter_lints/flutter.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.
include: package:flutter_lints/flutter.yaml

linter:
  # The lint rules applied to this project can be customized in the
  # section below to disable rules from the `package:flutter_lints/flutter.yaml`
  # included above or to enable additional rules. A list of all available lints
  # and their documentation is published at
  # https://dart-lang.github.io/linter/lints/index.html.
  #
  # Instead of disabling a lint rule for the entire project in the
  # section below, it can also be suppressed for a single line of code
  # or a specific dart file by using the `// ignore: name_of_lint` and
  # `// ignore_for_file: name_of_lint` syntax on the line or in the file
  # producing the lint.
  rules:
    # avoid_print: false  # Uncomment to disable the `avoid_print` rule
    # prefer_single_quotes: true  # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

 

 

 

 

참고

https://sudarlife.tistory.com/entry/Flutter-%ED%94%8C%EB%9F%AC%ED%84%B0-Linting-%EC%84%A4%EC%A0%95%EC%9C%BC%EB%A1%9C-%ED%9D%94%ED%95%98%EA%B2%8C-%EC%8B%A4%EC%88%98%ED%95%A0-%EC%88%98-%EC%9E%88%EB%8A%94-%EA%B2%83%EC%9D%84-build-%EC%A0%84-%EB%B0%A9%EC%A7%80%ED%95%98%EA%B8%B0

 

[ Flutter : 플러터 ] Linting 설정으로, 흔하게 실수할 수 있는 것을 build 전 방지하기.

안녕하세요 개발하는 남자 개남입니다. 오늘 정리해볼 포스팅의 주제는 Linting에 대해서 정리해보려고 합니다. Linting이란? 린트 (lint) 또는 린터 (linter)는 소스 코드를 분석하여 프로그램 오류, 버

sudarlife.tistory.com

https://ctoahn.tistory.com/22

 

[Flutter] Lint : 코딩컨벤션

팀에서 여러 개발자와 함께 앱을 개발할 때 가장 먼저 결정해야 하는 것이 바로 코딩 컨벤션이다. 팀에서 결정한 규칙에 따라서 코드를 만들어야 하고, 규칙을 정했으면 개발자들은 그 규칙에

ctoahn.tistory.com

 

 
 
728x90