Giter Club home page Giter Club logo

surveyor's Introduction

📐 surveyor

Tools for surveying Dart packages.

Build Status Pub

Disclaimer: This is not an officially supported Google product.

Installing

These tools are best run from source. To get the sources, clone the surveyor repo like this:

$ git clone https://github.com/pq/surveyor.git

From there you can run the examples.

Examples

Surveying API Use

dart run example/api_surveyor.dart <path_to_project>

will analyze projects at the given path and identify uses of a few specific APIs.

Surveying async Identifier Use

dart run example/async_surveyor.dart <path_to_project>

will analyze projects at the given path and identify places where "async" is used as a simple identifer. These places would produce errors if async become a reserved keyword.

Note that this generates a lot of output. To make sure none of it is lost, consider redirecting to a file. For example:

dart run example/async_surveyor.dart  <path>  2>&1 | tee survey_out.txt

Surveying Errors

dart run example/error_surveyor.dart <path_to_project>

will analyze projects at the given path, filtering for errors.

Surveying Lint Rule Violations

dart run example/lint_surveyor.dart <path_to_project>

will analyze projects at the given path and identify violations of lint rules (custom rules or ones defined by package:linter).

Surveying API Doc Scoring

dart run example/doc_surveyor/lib/main.dart <path_to_project>

will analyze the project at the given path flagging public members that are missing API docs.

A sample run produces output like this:

122 public members
Members without docs:
Void • <path-to-provider-repo>/packages/provider/lib/src/proxy_provider.dart • 107:1
NumericProxyProvider • <path-to-provider-repo>/packages/provider/lib/src/proxy_provider.dart • 177:1
Score: 0.98

Surveying Widget Use

dart run example/widget_surveyor/lib/widget_surveyor.dart <path_to_project>

will analyze the project at the given path and present a list of found Widget child-parent 2-Grams.

A sample run produces a csv file with contents like this:

AppBar -> Text, 1
Center -> Column, 1
Column -> Text, 3
FloatingActionButton -> Icon, 1
MaterialApp -> MyHomePage, 1
Scaffold -> AppBar, 1
Scaffold -> Center, 1
Scaffold -> FloatingActionButton, 1
null -> MaterialApp, 1
null -> MyApp, 1
null -> Scaffold, 1

(Note that by default package dependencies will only be installed if a .packages file is absent from the project under analysis. If you want to make sure package dependencies are (re)installed, run with the --force-install option.)

Related Work

See also package:pub_crawl, which can be used to fetch package sources for analysis from pub.

Features and bugs

This is very much a work in progress. Please file feature requests, bugs and any feedback in the issue tracker.

Thanks!

surveyor's People

Contributors

bwilkerson avatar csells avatar devoncarew avatar johnpryan avatar mit-mit avatar polina-c avatar pq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

surveyor's Issues

[Feature request] Use surveyor to assess whether an API doc is complete or not

A recent analysis on the Flutter’s API doc satisfaction showed that users find API docs with full sample code (snippet) more satisfying.

This new feature may scan the class files that generate API docs and identify which class doc contains what content, so that we can tell which classes need more attention, without going through the docs manually.

For example, the Card class's dart file creates an API doc that includes: a short code sample, a full sample in an app (snippet), and an image.

We can identify these by looking at the patterns like these in the code.

  1. short code sample: {@tool sample -- See TextField class for an example.
  2. short code sample AND full app (snippet): {@tool snippet -- See Card class for an example.
  3. image: ![image_description_here](image_url_here.png) -- This pattern may be within a sample.

If a surveyor can scan the dart files and identify the patterns, then the surveyor is expected to generate a file that looks like this.

api, sample, snippet, image // these are column names
TextField, 1, 0, 0
Card, 1, 1, 1
...

Note: There is a script that can show whether a doc has sample or snippet.
TMPDIR=/tmp dart dev/bots/analyze-sample-code.dart --temp=samples running from the flutter directory will generate outputs in /tmp/samples. However, this is not in a desirable format, and does not contain image information.

Surveyor cannot detect child/children, when the child/children are functions calls

The example below is from a Flutter Create submission, named ‘realx’.

In this example, the Row widget takes two children, where each child widget is a function soundBtn() that returns a GestureDetector widget.

class HomeRoute extends StatelessWidget {
  row(s1, s2, context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [soundBtn(s1, context), soundBtn(s2, context),],
    );
  }

  soundBtn(sound, context) {
    return GestureDetector(
      onTap: () { Navigator.push(context, MaterialPageRoute(builder: (context) => PlayRoute(sound: sound))); },
      child: Column(
        children: [
          Image.asset('assets/icons/$sound.png'),
          Text(sound.toUpperCase(), style: TextStyle(color: Colors.white, fontSize: 16, letterSpacing: 3.0))
        ],
      ),
    );
  }

But in the Flutter Outline as well as in the surveyor's 2-gram output file, this Row widget doesn’t seem to carry any children widget.

Flutter Outline (partially captured):
image

Surveyor output:

Column -> Image, 1
Column -> Text, 2
GestureDetector -> Column, 1
GestureDetector -> PlayRoute, 1
null -> GestureDetector, 1
null -> Row, 1 
 . . .

This makes it hard to analyze the characteristics of leaf widgets. I’d like the surveyor to take care of this case.

However, if this is a non-trivial change, as a minimal effort, we could consider adding -> unknown to the 2-gram output file, whenever an empty child or children appears.

For instance, if the analyzer says that the Row widget is a leaf, but if it contains children keyword in the code, add Row -> unknown to the 2-gram output. In that way we can at least know that the Row is not a leaf widget.

introduce sdkPath API to analysis driver

To support cases where clients need to customize SDK location, we could add an API like:

var driver = Driver.forArgs([packageFolder], sdkPath: myPath);
...
await driver.analyze();

fix widget surveyor to work in switch statements

To see where this is not working look at accident_reporting:

    MaterialApp(
      home: HomePage(),
      onGenerateRoute: (RouteSettings settings) {
        switch (settings.name) {
          case '/home':
            return PageTransition(child: HomePage(),type: PageTransitionType.leftToRight);
            break;
          case '/second':
            return PageTransition(child: PageOne(),type: PageTransitionType.leftToRight);
            break;
          case '/third':
            return PageTransition(
                child: PageTwo(
                  mapData: settings.arguments,
                ),type: PageTransitionType.leftToRight);
            break;

and notice that we do not track PageTransitions and PageOne, etc.

(EDIT: PageTransition is not a Widget...)

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.