Request for comment: Default enablement for InspectionGadget inspections
The good people at JetBrains have agreed to allow third-party inspections to be enabled by default. This is cool for a variety of reasons, and I'm very glad they did. Anything that will both increase the use of IG inspections, make the code that my grandchildren have to maintain cleaner, and make the out-of-box IDEA experience feel even more vastly cool and powerful than currently is something to be very glad of, even if it's a feature I personally will never use. That just leaves open the question exactly which IG inspections should be enabled by default. After much consideration and discussion with friends, here's the list I've come up with. These inspections will be shipped enabled by default in the next EAP. I would love to hear any arguments against any these being enabled when a new user first downloads IDEA, or suggestions for any other existing inspections that should be part of the new IDEA user experience. Thanks.
Inspections enabled by default:
'private' method declared 'final'
'static' method declared 'final'
expression.equals("literal") rather than "literal".equals(expression)
Missorted modifers
'continue' or 'break' inside 'finally' block
'return' inside 'finally' block
'throw' inside 'finally' block
Manual array copy
Unnecessary temporary object in conversion from String
Unnecessary temporary object in conversion to String
Incompatible bitwise mask operation
Infinite loop statement
Infinite recursion
Loop statement that doesn't loop
Mismatched query and update of collection
Mismatched read and write of array
Object.equals(null)
Static method referenced via subclass
'for' loop replaceable by 'for each' (J2SDK 5.0 only)
Pointless arithmetic expression
Pointless bitwise expression
Pointless boolean expression
Redundant conditional expression
Redundant 'if' statement
Redundant local variable
Unnecessary boxing (J2SDK 5.0 only)
Unnecessary 'continue' statement
Unnecessary label on 'break' statement
Unnecessary label on 'continue' statement
Unnecessary 'return' statement
Unnecessary semicolon
Unnecessary unboxing (J2SDK 5.0 only)
Unused label
'while' loop replacable by 'for each' (J2SDK 5.0 only)
--Dave Griffith
请先登录再写评论。
I would add the following to BooleanConstructorVisitor.visitNewExpression():
Dave,
Are there any plans to add 'code style' inspections to InspectionGadgets?
What I mean are the kinds of things that CheckStyle looks for. For
example correctness of JavaDoc format, line indents, etc.
Thanks,
Ted
There are limits to even my obsessivness, and those limits stop well before coding up a huge number of inspections for whitespace conventions. If you care about whitespace, configure your code style as you like it and then hit Ctrl-Alt-L.
IDEA already has javadoc format inspections, although some of them are (somewhat inexplicably) only available via the batch inspection tool, rather than interactively.
--Dave Griffith
BL> You win:-)
YES !!!
I'll be magnanimous in victory and let you retain some residues of self respect
:)
Instead of removing the inspection, change it to:
booleanValue ? Boolean.TRUE : Boolean.FALSE;
I don't really like this, but I like even less new Boolean(booleanValue);
Just put up the fix. It tests for JDK1.3 calls with a boolean argument, and if so gives a quickfix of
For 1.4 or later it uses
I've also updated the quickfix to test for calls which have string literal arguments. Thus
gets quickfixed to
In my defense, the Boolean constructor inspection was probably the first one I wrote, and I frankly didn't know what I was doing.
--Dave Griffith
Thanks to everyone who commented. I didn't take all suggestions, but I did consider all of them, and decided carefully for each. Here's the list I'll be enabling by default in the next EAP.
'private' method declared 'final'
'static' method declared 'final'
'clone()' doesn't call 'super.clone()'
'clone()' doesn't declare CloneNotSupportedException
expression.equals("literal") rather than "literal".equals(expression)
'continue' or 'break' inside 'finally' block
Empty 'catch' block
Empty 'finally' block
Empty 'try' block
'return' inside 'finally' block
'throw' inside 'finally' block
'finalize()' called explicitly
'finalize()' doesn't call 'super.finalize()'
Boolean constructor call
Instantiating object to get Class object
Manual array copy
Redundant String constructor call
Redundant 'String.toString()'
Unnecessary temporary object in conversion from String
Unnecessary temporary object in conversion to String
Octal integer
Incompatible bitwise mask operation
Infinite loop statement
Infinite recursion
Loop statement that doesn't loop
Malformed regular expression
Mismatched query and update of collection
Mismatched read and write of array
Object.equals(null)
Result of method call ignored
Statement with empty body
String comparison using '==', instead of '.equals()'
Field accessed in both synchronized and unsynchronized contexts
Synchronization on a non-final field
Class explicitly extends java.lang.Object
'for' loop replaceable by 'for each' (J2SDK 5.0 only)
Pointless arithmetic expression
Pointless bitwise expression
Pointless boolean expression
Redundant conditional expression
Redundant 'if' statement
Redundant local variable
Type parameter explicitly extends java.lang.Object
Unnecessary boxing (J2SDK 5.0 only)
Unnecessary 'continue' statement
Unnecessary label on 'break' statement
Unnecessary label on 'continue' statement
Unnecessary 'return' statement
Unnecessary semicolon
Unnecessary unboxing (J2SDK 5.0 only)
Unused label
'while' loop replacable by 'for each' (J2SDK 5.0 only)
--Dave Griffith
Whoops, bad edit. That inspection will not be enabled by default.
--Dave Griffith
Dave,
That about:
Constructor not protected in abstract class
Static inheritance
'instanceof' on 'catch' parameter
Overridable method call in constructor
Thanks!
Mostly, skipping these was to avoid reactions of "Hey, why is this thing complaining! There's nothing wrong with this code!" The last thing I want is new users to think that IDEA is an annoying nanny. I like these inspections, and run with all of them, but didn't think they should be part of a new user's IDEA experience.
--Dave Griffith
Ok, mostly of above realy not error, but 'Overridable method call in constructor':
This is hidden NPE in inner classes of 'this$0' reference. I think, that this may be as 'error'. Even more, i set up this inspection as 'Error', becouse it very hard to find bug with it.