패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.0.0

import_lint

Import Lint 패키지는 가져오기 Lint 규칙을 정의하고 Dart 코드에서 발견된 Lint를 보고합니다.

AndroidiOSmacOSWindowsLinux
30일 다운로드
1만
좋아요
28
Pub 점수
150

패키지 설치

flutter pub add import_lint

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Import Lint 패키지는 Dart 코드에서 일관되고 깔끔한 가져오기 관행을 강제하기 위한 린트 규칙 세트를 제공합니다. 이 패키지는 가져오기 문장을 분석하고 사용되지 않는 가져오기, 중복된 가져오기 또는 잘못된 가져오기 순서와 같은 문제를 보고합니다. Dart 분석 도구와 통합되어 프로젝트 전반에 걸쳐 코드 품질과 가독성을 유지하는 데 도움이 됩니다. 팀이 가져오기 패턴을 표준화하고 소스 파일의 혼잡함을 줄이고자 할 때 특히 유용합니다.

사용 사례

  • 일관된 가져오기 스타일 강제 적용
  • 사용되지 않는 또는 중복된 가져오기 감지
  • 코드 가독성 향상
  • 팀 전체의 코딩 기준 유지
  • 개발 중에 가져오기 정리 자동화

주요 기능

  • 사용자 지정 가능한 가져오기 lint 규칙
  • Dart 분석 서버와의 통합
  • 실시간 린트 보고
  • 여러 플랫폼을 지원합니다
  • 오픈소스이며 커뮤니티 유지보수

적합한 대상

  • Dart 및 Flutter 개발 팀
  • 엄격한 코드 품질이 필요한 프로젝트
  • 자동 린팅을 위한 CI/CD 파이프라인
  • 코드 위생에 집중하는 개발자

고려 사항

  • analysis_options.yaml에서 구성이 필요합니다
  • 구형 코드베이스에 맞게 조정이 필요할 수 있습니다
  • Dart SDK 버전 호환성에 따라 다릅니다
  • 독립형 포맷터는 아니지만 기존 도구를 보완합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

cover

Why import_lint?

The import_lint package defines rules to restrict imports and performs static analysis. It was inspired by eslint/no-restricted-paths.

😻 Usage

  1. Add import_lint as a dev_dependencies in pubspec.yamls.
flutter pub add --dev import_lint

or

dart pub add --dev import_lint
  1. You have lints configured in an analysis_options.yaml file at the root of your project.
  • target: Define the file paths of the targets to be restricted using glob patterns.
  • from: Define the paths that are not allowed to be used in imports using glob patterns.
  • except: Define the exception paths for the 'from' rule using glob patterns.

Example of analysis_options.yaml

plugins:
  import_lint: <version number>

import_lint:
  rules:
    example_rule:
      target: "package:example/target/*.dart"
      from: "package:example/from/*.dart"
      except: ["package:example/from/except.dart"]
    self_rule:
      target: "package:example/self/*.dart"
      from: "package:example/self/*.dart"
      except: []
    only_rule:
      target: "package:example/*[!only]/*.dart"
      from: "package:example/only_from/*.dart"
      except: []
    package_rule:
      target: "package:example/**/*.dart"
      from: "package:import_lint/*.dart"
      except: []
    # add custom rules...

Note: import_lint requires Dart 3.10 or later (analyzer plugin support was added in Dart 3.10 / Flutter 3.38). The top-level plugins: section is the new analyzer plugin system. After any change to the plugins: section, the Dart Analysis Server must be restarted to see the effects (VS Code: Dart: Restart Analysis Server).

By adding import_lint plugin to get the warnings directly in your IDE by configuring.

vscode

  1. run import_lint(CLI Support)
flutter run import_lint

or

dart run import_lint

Example

example/analysis_options.yaml

plugins:
  import_lint:
    path: ..

import_lint:
  rules:
    example_rule:
      target: "package:example/target/*.dart"
      from: "package:example/from/*.dart"
      except: ["package:example/from/except.dart"]
    self_rule:
      target: "package:example/self/*.dart"
      from: "package:example/self/*.dart"
      except: []
    only_rule:
      target: "package:example/*[!only]/*.dart"
      from: "package:example/only_from/*.dart"
      except: []
    package_rule:
      target: "package:example/**/*.dart"
      from: "package:import_lint/*.dart"
      except: []

files

example/lib

output

$ dart run import_lint

Analyzing...
   warning • /example/lib/not/1.dart:1:8 • package:example/only_from/1.dart • only_rule
   warning • /example/lib/target/1.dart:2:8 • package:example/from/test.dart • example_rule
   warning • /example/lib/self/1.dart:1:8 • package:example/self/2.dart • self_rule
   warning • /example/lib/package/1.dart:1:8 • package:import_lint/import_lint.dart • package_rule

4 issues found.

Option

Rule Severities

To change the severity of a rule, add a severity key to the rule configuration.

  • warning (default)
  • error (exit code 1 when lint is found)
import_lint:
  severity: "error"
  rules: ...

Note on IDE severity: The severity: "error" setting is honored by dart run import_lint (exit code 1). In the IDE, analysis_server_plugin registers a fixed warning severity. To see import_lint errors as errors in the IDE, add this to analysis_options.yaml:

analyzer:
  errors:
    import_lint: error

Contribution

Welcome PRs!

To develop locally, clone the repo and enable the plugin from a local path in your host project's analysis_options.yaml:

plugins:
  import_lint:
    path: /path/to/your/import-lint
    diagnostics:
      import_lint: true

For CLI use (dart run import_lint), also add it under dev_dependencies:

dev_dependencies:
  import_lint:
    path: /path/to/your/import-lint

Then run dart pub get in the host project and restart the Dart Analysis Server. No separate tools/analyzer_plugin directory is needed — the plugin entry point is lib/main.dart in this package.

카테고리

의존성

의존성 목록 8 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.