Re: Unused imports

2020-01-30 Thread Francesco Mecca via Digitalmars-d-learn

On Thursday, 30 January 2020 at 16:23:54 UTC, Michael wrote:

Is there a way to detect unused imports?

It happened to me that I used imports which I did not need in 
the end. So, I'd like to remove them easily.


https://issues.dlang.org/show_bug.cgi?id=20442

TL;DR
This has come up in the past and the typical answer was: "This 
should be implemented as a third party tool using dmd as a 
library".


It is a problem that there are no currently available tools to do 
that (maybe visual-d greys out unused imports) but I do agree 
that it should be provided as a third party.


Such a functionality could end up in:
https://github.com/dlang-community/D-Scanner

and it is also a good first time project for a beginner in the D 
ecosystem.


Unused imports

2020-01-30 Thread Michael via Digitalmars-d-learn

Is there a way to detect unused imports?

It happened to me that I used imports which I did not need in the 
end. So, I'd like to remove them easily.





Re: How to warn of unused imports?

2016-02-09 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 9 February 2016 at 17:54:30 UTC, Basile B. wrote:

On Tuesday, 9 February 2016 at 15:21:59 UTC, Basile B. wrote:

On Monday, 8 February 2016 at 20:48:29 UTC, cy wrote:

On Monday, 8 February 2016 at 18:57:52 UTC, Basile B. wrote:

Otherwise, it sounds like a decent enhancement request for 
DMD. I know other compilers who do this warning.


It definitely does sound like a decent enhancement request. I 
didn't know it wasn't implemented yet, but it should be 
pretty straightforward, since within DMD you can access the 
AST. Alternatively, implementing DIP50 might let you do it 
outside the compiler.


http://wiki.dlang.org/DIP50


DIP50 is a "golem"

It looks usefull, and it will help in many cases...but after a 
while it'll become a problem.


If you don't understand what's a "golem":

AlquiaDa was the golem of the CIA (in the 80's while russians 
were fighting in Afgnan). Useful until a certain point.


Useful until a certain point...


It's time for me to leave...once again alcool drives me crazy...
Latest weeks I've been ofensive against two guys: kinsley and 
lopatim...it's time for me to leave.


https://www.youtube.com/watch?v=6ixdPnLFVIo

seeya.


Re: How to warn of unused imports?

2016-02-09 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 9 February 2016 at 15:21:59 UTC, Basile B. wrote:

On Monday, 8 February 2016 at 20:48:29 UTC, cy wrote:

On Monday, 8 February 2016 at 18:57:52 UTC, Basile B. wrote:

Otherwise, it sounds like a decent enhancement request for 
DMD. I know other compilers who do this warning.


It definitely does sound like a decent enhancement request. I 
didn't know it wasn't implemented yet, but it should be pretty 
straightforward, since within DMD you can access the AST. 
Alternatively, implementing DIP50 might let you do it outside 
the compiler.


http://wiki.dlang.org/DIP50


DIP50 is a "golem"

It looks usefull, and it will help in many cases...but after a 
while it'll become a problem.


If you don't understand what's a "golem":

AlquiaDa was the golem of the CIA (in the 80's while russians 
were fighting in Afgnan). Useful until a certain point.


Useful until a certain point...


Re: How to warn of unused imports?

2016-02-09 Thread Basile B. via Digitalmars-d-learn

On Monday, 8 February 2016 at 20:48:29 UTC, cy wrote:

On Monday, 8 February 2016 at 18:57:52 UTC, Basile B. wrote:

Otherwise, it sounds like a decent enhancement request for 
DMD. I know other compilers who do this warning.


It definitely does sound like a decent enhancement request. I 
didn't know it wasn't implemented yet, but it should be pretty 
straightforward, since within DMD you can access the AST. 
Alternatively, implementing DIP50 might let you do it outside 
the compiler.


http://wiki.dlang.org/DIP50


DIP50 is a "golem"

It looks usefull, and it will help in many cases...but after a 
while it'll become a problem.


Re: How to warn of unused imports?

2016-02-08 Thread cy via Digitalmars-d-learn

On Monday, 8 February 2016 at 18:57:52 UTC, Basile B. wrote:

Otherwise, it sounds like a decent enhancement request for DMD. 
I know other compilers who do this warning.


It definitely does sound like a decent enhancement request. I 
didn't know it wasn't implemented yet, but it should be pretty 
straightforward, since within DMD you can access the AST. 
Alternatively, implementing DIP50 might let you do it outside the 
compiler.


http://wiki.dlang.org/DIP50


Re: How to warn of unused imports?

2016-02-08 Thread Basile B. via Digitalmars-d-learn

On Monday, 8 February 2016 at 08:50:17 UTC, Daniel Kozak wrote:

V Mon, 08 Feb 2016 08:25:09 +
cy via Digitalmars-d-learn  
napsáno:


When I factor out code from my modules, it really, really 
often leaves import statements that just sit there doing 
nothing, making it look like my program is more complex than 
it is. How do I get warned for leaving those, and a list of 
which ones I can safely remove?


I dont think there is a way right now. But in a future 
dscanner. https://github.com/Hackerpilot/Dscanner/issues/134


I don't think that Dscanner will be able to do this soon. Its 
scope is limited to a single module, it's not like DCD, which 
works with the imports and which is able to look-up elsewhere.


For example you'll see this if you try to make an analyzer that 
produces warnings for signed & unsigned comparison. It impossible 
without a bit of semantic (ref: 
https://github.com/Hackerpilot/Dscanner/issues/204).


Otherwise, it sounds like a decent enhancement request for DMD. I 
know other compilers who do this warning.


Re: How to warn of unused imports?

2016-02-08 Thread Ali Çehreli via Digitalmars-d-learn

On 02/08/2016 06:35 AM, Adam D. Ruppe wrote:

On Monday, 8 February 2016 at 08:25:09 UTC, cy wrote:

How do I get warned for leaving those, and a list of which ones I can
safely remove?


Remove one, recompile. If it passes, leave it. If not, undo and move on
to the next one.


Similarly, I comment out all; then uncomment one by one according to 
compilation errors.


Ali



Re: How to warn of unused imports?

2016-02-08 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 8 February 2016 at 08:25:09 UTC, cy wrote:
How do I get warned for leaving those, and a list of which ones 
I can safely remove?


Remove one, recompile. If it passes, leave it. If not, undo and 
move on to the next one.


Re: How to warn of unused imports?

2016-02-08 Thread Daniel Kozak via Digitalmars-d-learn
V Mon, 08 Feb 2016 08:25:09 +
cy via Digitalmars-d-learn  napsáno:

> When I factor out code from my modules, it really, really often 
> leaves import statements that just sit there doing nothing, 
> making it look like my program is more complex than it is. How do 
> I get warned for leaving those, and a list of which ones I can 
> safely remove?

I dont think there is a way right now. But in a future dscanner.
https://github.com/Hackerpilot/Dscanner/issues/134



How to warn of unused imports?

2016-02-08 Thread cy via Digitalmars-d-learn
When I factor out code from my modules, it really, really often 
leaves import statements that just sit there doing nothing, 
making it look like my program is more complex than it is. How do 
I get warned for leaving those, and a list of which ones I can 
safely remove?


Re: How to get warnings about unused imports ?

2013-07-03 Thread Namespace
You have to parse the unnamed import files, list all their 
identifiers (global variables, public functions etc.) and search 
for them. ;)
That could be a bit complicated. ;) Therefore I don't want to do 
it. Even with named imports you can get false positives.


But if you like it, you could improve it. The Lexer is my own and 
not that good, that would be start. On the wiki you can find 
other Lexer / Parsers, which are really good, but I haven't the 
time to replace my own and adapt the source or to work much on 
the project.


Re: How to get warnings about unused imports ?

2013-07-03 Thread Gabi

On Wednesday, 3 July 2013 at 06:12:46 UTC, Namespace wrote:

On Tuesday, 2 July 2013 at 21:49:37 UTC, Gabi wrote:

Hi,

How to find unused imports ?

It seems the compiler doesn't do it, but is there any other 
tool for that?
This seems like small issue, but those unused imports pile up 
pretty quickly


Regards,
Gabi


I'm working on something like that for a few days. It is still 
not completely finished, but it works so far. But currently 
only for named imports. Everything else was far too much work 
for me.


https://github.com/Dgame/SimpleDAT


This is great. Maybe point me to the right direction how to 
implement finding unnamed imports too ? It could be great 
exercise for me to learn D :)


Re: How to get warnings about unused imports ?

2013-07-02 Thread Namespace

On Tuesday, 2 July 2013 at 21:49:37 UTC, Gabi wrote:

Hi,

How to find unused imports ?

It seems the compiler doesn't do it, but is there any other 
tool for that?
This seems like small issue, but those unused imports pile up 
pretty quickly


Regards,
Gabi


I'm working on something like that for a few days. It is still 
not completely finished, but it works so far. But currently only 
for named imports. Everything else was far too much work for me.


https://github.com/Dgame/SimpleDAT


How to get warnings about unused imports ?

2013-07-02 Thread Gabi

Hi,

How to find unused imports ?

It seems the compiler doesn't do it, but is there any other tool 
for that?
This seems like small issue, but those unused imports pile up 
pretty quickly


Regards,
Gabi