The Import Lint package defines import lint rules and report on lints found in Dart code.

Overview

cover

codecov

Why import lint?

The Import Lint package defines import lint rules and report on lints found in Dart code.

😻 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_file_path: Specify a file paths to analyze.
  • not_allow_imports: Specify import rules not to allow.
  • exclude_imports: Specify exclude import rules.

Example

analyzer:
    plugins:
        - import_lint

import_lint:
    rules:
        use_case_rule:
            target_file_path: "/**/use_case/*_use_case.dart"
            not_allow_imports: ["/**/use_case/*_use_case.dart"]
            exclude_imports: ["/lib/use_case/base_use_case.dart"]
        repository_rule:
            target_file_path: "/**/repository/*_repository.dart"
            not_allow_imports:
                ["/**/use_case/*_repository.dart", "/**/use_case/*_use_case.dart"]
            exclude_imports: []
        # add custom rules...

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

vscode

  1. run import_lint(CLI Support)
flutter pub run import_lint

or

dart pub run import_lint

Result

  • Passed

output

No issues found! 🎉
  • Failed Example

analysis_options.yaml

analyzer:
    plugins:
        - import_lint

import_lint:
    rules:
        use_case_rule:
            target_file_path: "/**/use_case/*_use_case.dart"
            not_allow_imports: ["/**/use_case/*_use_case.dart"]
            exclude_imports: ["/lib/use_case/base_use_case.dart"]
        repository_rule:
            target_file_path: "/**/repository/*_repository.dart"
            not_allow_imports:
                ["/**/use_case/*_repository.dart", "/**/use_case/*_use_case.dart"]
            exclude_imports: []

files

- lib
    - repository
        - test_one_repository.dart

            import 'package:import_analyzer_test/repository/test_two_repository.dart';
            import 'package:import_analyzer_test/use_case/test_one_use_case.dart';
            class TestOneRepository {}

        - test_two_repository.dart
        
            class TestTwoRepository {}
    
    - use_case

        - test_one_use_case.dart
        
            import 'package:import_analyzer_test/use_case/base_use_case.dart';
            class TestOneUseCase extends BaseUseCase {}
        
        - test_two_use_case.dart
        
            import 'package:import_analyzer_test/repository/test_one_repository.dart';
            import 'package:import_analyzer_test/use_case/test_one_use_case.dart';
            class TestTwoUseCase {}

output

use_case_rule • package:import_analyzer_test/use_case/test_two_use_case.dart:2 • import 'package:import_analyzer_test/use_case/test_one_use_case.dart'
repository_rule • package:import_analyzer_test/repository/test_one_repository.dart:1 • import 'package:import_analyzer_test/repository/test_two_repository.dart'
repository_rule • package:import_analyzer_test/repository/test_one_repository.dart:2 • import 'package:import_analyzer_test/use_case/test_one_use_case.dart'

3 issues found.

🧤 Features

  • Analyzer Plugin Support
  • CLI Support
  • Ignore Import Line
  • Add Test
Comments
  • VS Code doesn't show warning even though pub command does.

    VS Code doesn't show warning even though pub command does.

    Hi, thank you for publishing this awesome package!

    I've just started to try this package and I found my VS Code doesn't show any warnings, even if flutter pub run import_lint command does.

    This problem also happens on example project of this package.

    What I did was below.

    • git clone the repo of import-lint
    • open example directory on VS Code
    • run flutter pub get
    • run flutter pub run import_lint
    • open lib/repository/test_two_repository.dart file.

    and my flutter doctor is below.

    $ flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel master, 2.13.0-0.0.pre.390, on macOS 12.0.1 21A559 darwin-arm, locale ja-JP)
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    [✓] Xcode - develop for iOS and macOS (Xcode 13.3)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 2020.3)
    [✓] VS Code (version 1.61.2)
    [✓] Connected device (2 available)
        ! Error: Failed to prepare device for development. Please unlock and reconnect the device. (code
          806)
    [✓] HTTP Host Availability
    
    • No issues found!
    

    Do I need to do anything in addition to show up warnings on the editor?

    Thanks.

    opened by chooyan-eng 3
  • Not working at all

    Not working at all

    I tried using this in my personal project, but no warning was printed in the Dart Analysis pane on the IDE (IntelliJ IDEA Ultimate) and dart run import_lint only showed "No issues found!".

    I thought my settings might be wrong, so downloaded the code from this repository, but the example contained in it showed the same result.

    Environment

    > dart --version Dart SDK version: 2.16.1 (stable) (Tue Feb 8 12:02:33 2022 +0100) on "windows_x64"

    opened by kaboc 1
  • analysis_options.yaml in the parent directory could not be loaded

    analysis_options.yaml in the parent directory could not be loaded

    The plugin failed to start by following error:

    Failed to load options:: Exception:: Not found import_analysis_options.yaml file at the root of your project.
     FileSystemException:: Cannot open file, path = '/Users/mjhd/Projects/project_root/packages/package1/analysis_options.yaml' (OS Error:: No such file or directory, errno = 2)
    
    #0 new Rules.fromOptionsFile (package::import_lint/src/import_lint_options.dart::58::7)
    #1     new ImportLintOptions.init
    

    CLI also fails to start by the same error.

    My project structure looks like:

    - Project Root
      - analysis_options.yaml
      - packages/
        - package1/ (current context root)
          - lib/...
          - pubspec.yaml
        - package2/
          - lib/...
          - pubspec.yaml
    

    Dart Analyzer can read an options file in a parent directory of the target package's root.

    If the analyzer can’t find an analysis options file at the package root, it walks up the directory tree, looking for one. If no file is available, the analyzer defaults to standard checks.

    https://dart.dev/guides/language/analysis-options#the-analysis-options-file

    To support this behavior, context?.contextRoot.optionsFile should be used to load the options file.

    similar code in dart-code-metrics: https://github.com/dart-code-checker/dart-code-metrics/blob/7d8269b420d7b40562b72149f92949b288cf40f1/lib/src/analyzer_plugin/analyzer_plugin.dart#L236


    Thank you for creating this useful package, I will use this in my project!

    opened by mj-hd 1
  • migrate analyzer v5

    migrate analyzer v5

    close: #16

    Analyze

    • Deprecated NamespaceDirective.selectedSource, use element2.uri with DirectiveUriWithSource instead.

    Analyzer Plugin

    • Support version 5.x of the analyzer package
    • Call analyzeFiles from handleAffectedFiles only for files that are analyzed in this analysis context.
    • Using AnalysisContextCollection and AnalysisContext for analysis.
    • Support version 4.x of the analyzer package
    opened by kawa1214 0
  • Is there an option for the process to return non-zero code if there are any warnings?

    Is there an option for the process to return non-zero code if there are any warnings?

    I integrated lint checks in the pipeline, ad I would like it to fail if there are any warnings.

    For other linters, there's usually an option like --fatal-warnings that would make the process (and the step in the pipeline) to fail if there are any warnings, but it looks like this plugin ignores the command line args that were passed. Is there a way to achieve this?

    good first issue 
    opened by dusan-milosevic-the-real-one 3
  • merge fork

    merge fork

    Hi and thanks for this linter, it's very valuable to us!

    Unfortunately, we had to switch to the fork of this repo in order to also restrict imports of external dependencies.

    Are there any plans or intentions to merge this fork at some point? It introduces a few fixes and features.

    Thanks!

    opened by dominicmh 1
Releases(v0.9.4)
  • v0.9.4(Nov 12, 2022)

    What's Changed

    • migrate analyzer v5 by @kawa1214 in https://github.com/kawa1214/import-lint/pull/17
    • release: v0.9.4 by @kawa1214 in https://github.com/kawa1214/import-lint/pull/18

    Full Changelog: https://github.com/kawa1214/import-lint/compare/v0.9.3...v0.9.4

    Source code(tar.gz)
    Source code(zip)
Lint rules for Dart and Flutter used internally at NetGlade.

NetGlade Analysis Developed with ?? by NetGlade This package provides lint rules for Dart and Flutter which are used at NetGlade. Usage To use the lin

NetGlade 3 Dec 4, 2022
🟧 Lints for Dart and Flutter based on software industry standards and best practices.

Solid Lints Flutter/Dart lints configuration based on software engineering industry standards (ISO/IEC, NIST) and best practices. Usage Add dependency

Solid Software 17 Oct 12, 2022
Rules - Powerful and feature-rich validation library for both Dart and Flutter.

Introduction Rules - Powerful and feature-rich validation library for both Dart and Flutter. Rules is a simple yet powerful and feature-rich validatio

Ganesh Rathinavel 24 Dec 12, 2022
Linter rules corresponding to the guidelines in Effective Dart

effective_dart This package is deprecated. Before it was deprecated, it was the way to provide analysis options corresponding to the guidelines in Eff

Honza Bittner 127 Dec 9, 2022
Ruqe brings the convenient types and methods found in Rust into Dart, such as the Result, Option, pattern-matching, etc.

ruqe Ruqe brings the convenient types and methods found in Rust into Dart, such as the Result, Option, pattern-matching, etc. Additionally, the librar

Alexander Nitiola 12 Dec 28, 2022
Import & use javascript libraries in your flutter web projects

Import JS Library Import & use javascript libraries in your flutter web projects. flutter: assets: - assets/howler.js importJsLibrary(url: "./as

Florent CHAMPIGNY 29 Oct 1, 2022
A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your issue.

r_scan A flutter plugin about qr code or bar code scan , it can scan from file、url、memory and camera qr code or bar code .Welcome to feedback your iss

PengHui Li 112 Nov 11, 2022
Iosish indicator - 🍎 Create awesome and simple iOS style floating indicator which can be found when silent/sleep mode switched on Flutter.

Iosish indicator - ?? Create awesome and simple iOS style floating indicator which can be found when silent/sleep mode switched on Flutter.

Kim Seung Hwan 2 Apr 1, 2022
Lost and Found is an app to help people find their lost items.

lost_and_found A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started i

SonaCodeur 1 Jan 20, 2022
Pianokeysgame - A simple clone of the Grant Piano Keys game found at Dave and Busters Arcade

pianokeysgame Just a simple clone of the Grant Piano Keys game found at Dave and

Seth Moeckel 0 Feb 7, 2022
A sample project for following along a tutorial found on jap.alekhin.io.

Langaw Langaw is an endless tap game featured in the game development tutorial by Japa Alekhin Llemos in jap.alekhin.io. The tutorial series is split

Japa Alekhin Llemos 105 Oct 16, 2022
Write iOS&Android Code using Dart. This package liberates you from redundant glue code and low performance of Flutter Channel.

Dart_Native Dart_Native operates as both a code generator tool and a bridge to communicate between Dart and native APIs. Replaces the low-performing F

DartNative 893 Jan 4, 2023
Shader manages the compilation of your GLSL shaders into SPIR-V byte code and Dart code

shader Shader manages the compilation of your GLSL shaders into SPIR-V byte code and Dart code. Quickstart # Install cli dart pub global activate shad

Felix Blaschke 25 Dec 1, 2022
Simple Dart package with build-in code generation. It simplifies and speedup creation of cache mechanism for dart classes.

Simple Dart package with build-in code generation. It simplifies and speedup creation of cache mechanism for dart classes.

iteo 37 Jan 2, 2023
Enum extendable - Dart code generator. Generates enum extensions code.

Generates code for the extension on an enum. Overview Being able to add fields and methods to an enum. Let's say we have the following enum: enum Math

null 0 Jan 10, 2022
A full screen mobile scanner for scanning QR Code and Bar Code.

Flutter QR Bar Scanner A Full Screen Scanner for Scanning QR code and Barcode using Google's Mobile Vision API Reading & Scanning QR/Bar codes using F

Lutfor Rahman 31 Oct 5, 2022
Android test task master - Create PIN code screen, authentication by PIN code screen and menu screen

Here is described test tasks for a android dev. Need to implement three screens:

null 3 Oct 4, 2022
A Flutter mobile application built completely using DhiWise and Supabase without coding single line of code. With 100% system generated code

Flutter Expension Getting Started with Flutter ?? Generated with ❤️ from Dhiwise A Flutter mobile application built completely using DhiWise and Supab

DhiWise 11 Oct 23, 2022
Extract pubspec details (such as package version, author and description) into Dart code.

build_pubspec This package helps you convert fields from your pubspec.yaml file into Dart code. Based on the fields in your pubspec, this package will

dartside.dev 9 Jul 15, 2021