Git Product home page Git Product logo

dat's Introduction

DAT

D Analysis Tool

This project uses the Lexer and Parser of https://github.com/Hackerpilot/Dscanner

Check your (named) imports on unused or under used.


Usage:
--minImportUsage - The minimum of usage for imports. If this is deceeded, there is a warning.
-miu - the same
--minVarUsage - The minimum of usage for variables. If this is deceeded, there is a warning.
-mvu - the same
--quit - No warning for public or package imports/variables and for variables within a unittest.
-q - the same

test.d:
module test;

import std.stdio; public { import std.file : read, mkdir; import std.string : format, strip; } import std.array : split, join, empty; import std.algorithm : startsWith, endsWith; import std.c.string : memcpy;

bool isEmpty(string test) { return test.strip().empty(); }

private void _foo() { int[] arr; int[4] arrs; int[int] arrt; int[ulong] arrt2; }

string fmt() { string str = "one\nnew line";

{
	string str_;
	str = "abc";
}

void* p;
std.c.string.memcpy(p, &str, str.sizeof);

return format("%d.%d.%d", 0, 9, 9);

}

@property const(string) bar() pure { return ""; }

struct C { private: int id; }

C[void*] c_map;

void main() { uint id = 0; id++;

byte[] _buffer;
_buffer = new byte[4];

byte[byte*] bbmap;

const uint msize = 42;
void[] memory = new void[msize];
assert(memory !is null);

}

debug { string outdir = "Debug"; } else { string outdir = "Release"; }

void unused() { if (!outdir) mkdir(outdir); else mkdir(outdir ~ "_New"); }

struct Foo { int foo1;

enum : ubyte {
	Unused,
}

int foo2;

}

Checked with: dat test.d -miu=2

 :: Check minimum import usage:
----
Warning:
test.d(5): Named import 'read' of module 'std.file' is never used.
But maybe the import is used outside, because it is marked as public.

Warning:
test.d(6): Named import 'format' of module 'std.string' is used only 1 times.
But maybe the import is used outside, because it is marked as public.

Warning:
test.d(6): Named import 'strip' of module 'std.string' is used only 1 times.
But maybe the import is used outside, because it is marked as public.

Warning:
test.d(8): Named import 'split' of module 'std.array' is never used.

Warning:
test.d(8): Named import 'join' of module 'std.array' is never used.

Warning:
test.d(8): Named import 'empty' of module 'std.array' is used only 1 times.

Warning:
test.d(9): Named import 'startsWith' of module 'std.algorithm' is never used.

Warning:
test.d(9): Named import 'endsWith' of module 'std.algorithm' is never used.

=> Therefore it is useless to import std.algorithm.

Warning:
test.d(10): Named import 'memcpy' of module 'std.c.string' is used only 1 times.


-------
9 occurrences in 1 files.

And with dat test.d -miu=2 -q

 :: Check minimum import usage:
----
Warning:
test.d(8): Named import 'split' of module 'std.array' is never used.

Warning:
test.d(8): Named import 'join' of module 'std.array' is never used.

Warning:
test.d(8): Named import 'empty' of module 'std.array' is used only 1 times.

Warning:
test.d(9): Named import 'startsWith' of module 'std.algorithm' is never used.

Warning:
test.d(9): Named import 'endsWith' of module 'std.algorithm' is never used.

=> Therefore it is useless to import std.algorithm.

Warning:
test.d(10): Named import 'memcpy' of module 'std.c.string' is used only 1 times.


-------
6 occurrences in 1 files.

And for std/stdio.d checked with: dat D:/D/dmd2/src/phobos/std/stdio.d -miu=2

Warning:
D:/D/dmd2/src/phobos/std/stdio.d(35): Named import 'FHND_WCHAR' of module 'std.c.stdio' is used only 1 times.

Warning:
D:/D/dmd2/src/phobos/std/stdio.d(3145): Named import 'memcpy' of module 'core.stdc.string' is used only 1 times.
But maybe the import is used outside, because it is marked as public.

And finally a test for unused/underused variables with dat test.d -mvu=1

 :: Check minimum variable usage:
----
Warning:
test.d(17): Variable 'arr' of type int[] is never used.

Warning:
test.d(18): Variable 'arrs' of type int[4] is never used.

Warning:
test.d(19): Variable 'arrt' of type int[int] is never used.

Warning:
test.d(20): Variable 'arrt2' of type int[ulong] is never used.

Warning:
test.d(27): Variable 'str_' of type string is never used.

Warning:
test.d(44): Variable 'id' of type int is never used.

Warning:
test.d(47): Variable 'c_map' of type void* is never used.

Warning:
test.d(56): Variable 'bbmap' of type byte[byte*] is never used.

Warning:
test.d(77): Variable 'foo1' of type int is never used.
But maybe it is used outside, because it is marked as public.

Warning:
test.d(83): Variable 'foo2' of type int is never used.
But maybe it is used outside, because it is marked as public.

-------
10 occurrences in 1 files.

And with dat test.d -mvu=1 -q

 :: Check minimum variable usage:
----
Warning:
test.d(17): Variable 'arr' of type int[] is never used.

Warning:
test.d(18): Variable 'arrs' of type int[4] is never used.

Warning:
test.d(19): Variable 'arrt' of type int[int] is never used.

Warning:
test.d(20): Variable 'arrt2' of type int[ulong] is never used.

Warning:
test.d(27): Variable 'str_' of type string is never used.

Warning:
test.d(44): Variable 'id' of type int is never used.

Warning:
test.d(47): Variable 'c_map' of type void* is never used.

Warning:
test.d(56): Variable 'bbmap' of type byte[byte*] is never used.

-------
8 occurrences in 1 files.

dat's People

Contributors

dgame avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

dat's Issues

not working with DMD64 D Compiler v2.070.2

not working with DMD64 D Compiler v2.070.2.
occur should be ulong in main.d, but also some goto tricks which are not compatible.

stdx/d/parser.d(4082): Error: goto skips declaration of variable stdx.d.parser.Parser.parsePrimaryExpression.b at stdx/d/parser.d(4110) stdx/d/parser.d(5484): Error: goto skips declaration of variable stdx.d.parser.Parser.parseTypeSuffix.type at stdx/d/parser.d(5486)

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.