GithubHelp home page GithubHelp logo

importas's Introduction

A linter to enforce importing certain packages consistently.

What is this for?

Ideally, go imports should avoid aliasing. Sometimes though, especially with Kubernetes API code, it becomes unavoidable, because many packages are imported as e.g. "[package]/v1alpha1" and you end up with lots of collisions if you use "v1alpha1".

This linter lets you enforce that whenever (for example) "pkg/apis/serving/v1alpha1" is aliased, it is aliased as "servingv1alpha1".

Usage

importas \
  -alias knative.dev/serving/pkg/apis/autoscaling/v1alpha1:autoscalingv1alpha1 \
  -alias knative.dev/serving/pkg/apis/serving/v1:servingv1 \
  ./...

-no-unaliased option

By default, importas allows non-aliased imports, even when the package is specified by -alias flag. With -no-unaliased option, importas does not allow this.

importas -no-unaliased \
  -alias knative.dev/serving/pkg/apis/autoscaling/v1alpha1:autoscalingv1alpha1 \
  -alias knative.dev/serving/pkg/apis/serving/v1:servingv1 \
  ./...

-no-extra-aliases option

By default, importas allows aliases which are not specified by -alias flags. With -no-extra-aliases option, importas does not allow any unspecified aliases.

importas -no-extra-aliases \
  -alias knative.dev/serving/pkg/apis/autoscaling/v1alpha1:autoscalingv1alpha1 \
  -alias knative.dev/serving/pkg/apis/serving/v1:servingv1 \
  ./...

Use regular expression

You can specify the package path by regular expression, and alias by regular expression replacement syntax like following snippet.

importas -alias 'knative.dev/serving/pkg/apis/(\w+)/(v[\w\d]+):$1$2'

$1 represents the text of the first submatch. See detail.

So it will enforce that

"knative.dev/serving/pkg/apis/autoscaling/v1alpha1" is aliased by "autoscalingv1alpha1", and "knative.dev/serving/pkg/apis/serving/v1" is aliased by "servingv1"

importas's People

Contributors

julz avatar ldez avatar mattysweeps avatar sachaos avatar svilgelm avatar tomfeigin avatar

Watchers

 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.