Coder Social home page Coder Social logo

aguerola / import-lint Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kawa1214/import-lint

0.0 0.0 0.0 267 KB

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

Home Page: https://pub.dev/packages/import_lint

License: Other

Shell 1.78% Dart 98.22%

import-lint's Introduction

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

analyzer:
  plugins:
    - import_lint

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...

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

analyzer:
  plugins:
    - import_lint

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: ...

Contribution

Welcome PRs!

You can develop locally by setting the path to an absolute path as shown below.

tools/analyzer_plugin/pubspec.yaml

dependencies:
  import_lint: ^x.x.x → import_lint:/Users/xxx/import-lint

import-lint's People

Contributors

kawa1214 avatar nitaking avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.