This repository has been archived by the owner on Nov 11, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df2757d
commit 4b0fac2
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Linter Compiler Plugin | ||
|
||
This is a compiler plugin that adds additional lint checks to protect against sharp corners | ||
in the Scala compiler and standard libraries. | ||
|
||
It's a work in progress. | ||
|
||
## Usage | ||
|
||
Add it as a compiler plugin in your project, or run `sbt console` in this project to see it in action. | ||
|
||
## Currently suported warnings | ||
|
||
### Unsafe `==` | ||
|
||
scala> Nil == None | ||
<console>:29: warning: Comparing with == on instances of different types (object Nil, object None) will probably return false. | ||
Nil == None | ||
^ | ||
|
||
### Unsafe `contains` | ||
|
||
scala> List(1, 2, 3).contains("4") | ||
<console>:29: warning: SeqLike[Int].contains(java.lang.String) will probably return false. | ||
List(1, 2, 3).contains("4") | ||
^ | ||
|
||
|
||
### Wildcard import from `scala.collection.JavaConversions` | ||
|
||
scala> import scala.collection.JavaConversions._ | ||
<console>:29: warning: Conversions in scala.collection.JavaConversions._ are dangerous. | ||
import scala.collection.JavaConversions._ | ||
^ | ||
|
||
### Calling `Option#get` | ||
|
||
scala> Option(1).get | ||
<console>:29: warning: Calling .get on Option will throw an exception if the Option is None. | ||
Option(1).get | ||
^ | ||
|
||
## Future Work | ||
|
||
* Add more warnings | ||
* Pick and choose which warnings you want | ||
* Choose whether they should be warnings or errors | ||
|
||
### Ideas for new warnings | ||
|
||
Feel free to implement these, or add your own ideas. Pull requests welcome! | ||
|
||
* Warn on wildcard imports (either all with whitelist, or blacklist) | ||
* Require explicit `override` whenever a method is being overwritten | ||
* Implicit methods should always have explicit return types | ||
* Expressions spanning multiple lines should be enclosed in parentheses | ||
* Unused method argument warnings | ||
* Warn on unrestricted catch clauses (`case e => ...`) | ||
* Traversable#head, Traversable#last, Traversable#maxBy | ||
* Warn on shadowing variables, especially those of the same type | ||
* Warn on inexhaustive pattern matching |