Skip to content

Commit

Permalink
chore: Enable lint and fix some unused warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
He-Pin committed May 21, 2024
1 parent 7f6dddc commit 7c96397
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 30 deletions.
10 changes: 9 additions & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ trait FastparseModule extends CommonCrossModule with Mima{
Seq(PathRef(file))
}

override def scalacOptions =
super.scalacOptions() ++
Agg.when(scalaVersion() != scala3)(
"-Xfatal-warnings",
"-Xlint:unused",
"-Wconf:cat=feature:s,cat=deprecation:s"
)

def mimaReportBinaryIssues() =
if (this.isInstanceOf[ScalaNativeModule] || this.isInstanceOf[ScalaJSModule]) T.command()
else super.mimaReportBinaryIssues()
Expand Down Expand Up @@ -206,7 +214,7 @@ trait CommonTestModule extends ScalaModule with TestModule.Utest{

override def scalacOptions =
super.scalacOptions() ++
Agg.when(scalaVersion() == scala213)(
Agg.when(scalaVersion() != scala3)(
"-Xfatal-warnings",
"-Xlint:unused",
"-Wconf:cat=feature:s,cat=deprecation:s"
Expand Down
4 changes: 3 additions & 1 deletion cssparse/src/cssparse/CssParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ object CssRulesParser {
case (ident, Some((token, Ast.StringToken(string)))) => (ident, Some(token), Some(string))
case (ident, Some((token, Ast.IdentToken(string)))) => (ident, Some(token), Some(string))
case (ident, None) => (ident, None, None)
case _ => throw new IllegalArgumentException("Should not happen.")
})
}
}
Expand Down Expand Up @@ -204,8 +205,9 @@ object CssRulesParser {
def atRule[$: P] = P( complexAtRule | declAtRule | (simpleAtRule ~ ";") )

def qualifiedRule[$: P] = P( ((selector ~ ws) | (!"{" ~ componentValue).rep) ~ "{" ~ declarationList ~ ws ~ "}" ).map{
case (values: Seq[Option[Ast.ComponentValue]], block) => Ast.QualifiedRule(Right(values.flatten), block)
case (values: Seq[Option[Ast.ComponentValue]] @unchecked, block) => Ast.QualifiedRule(Right(values.flatten), block)
case (selector: Ast.Selector, block) => Ast.QualifiedRule(Left(selector), block)
case _ => throw new IllegalArgumentException("Should not happen.")
}

def ruleList[$: P]: P[Ast.RuleList] = P( (whitespaceToken | atRule | qualifiedRule).rep ).map{
Expand Down
22 changes: 11 additions & 11 deletions cssparse/test/src/cssparse/CssTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object CssTests extends TestSuite {
|
""".stripMargin,
CssRulesParser.ruleList(_)
)
) : @unchecked

assert(
value1 ==
Expand Down Expand Up @@ -54,7 +54,7 @@ object CssTests extends TestSuite {
| -ms-text-size-adjust: 100%;
|}
|
""".stripMargin, CssRulesParser.ruleList(_))
""".stripMargin, CssRulesParser.ruleList(_)) : @unchecked

assert(
value2 ==
Expand All @@ -81,7 +81,7 @@ object CssTests extends TestSuite {
| box-shadow: none !important;
| }
|
""".stripMargin, CssRulesParser.ruleList(_))
""".stripMargin, CssRulesParser.ruleList(_)) : @unchecked

val expected = RuleList(Seq(
QualifiedRule(
Expand All @@ -108,7 +108,7 @@ object CssTests extends TestSuite {
| background-color: #31b0d5;
| }
|
""".stripMargin, CssRulesParser.ruleList(_))
""".stripMargin, CssRulesParser.ruleList(_)) : @unchecked

assert(
value4 ==
Expand All @@ -128,15 +128,15 @@ object CssTests extends TestSuite {
}

test("test5"){
val Parsed.Success(value5, index5) = parse(
val Parsed.Success(value5, _) = parse(
"""
|
| [hidden],
| template {
| display: none;
| }
|
""".stripMargin, CssRulesParser.ruleList(_))
""".stripMargin, CssRulesParser.ruleList(_)) : @unchecked

assert(value5 == RuleList(Seq(
QualifiedRule(
Expand All @@ -148,7 +148,7 @@ object CssTests extends TestSuite {
}

test("test6"){
val Parsed.Success(value6, index6) = parse(
val Parsed.Success(value6, _) = parse(
"""
|
|@media (min-width: 768px) {
Expand All @@ -157,7 +157,7 @@ object CssTests extends TestSuite {
| }
| }
|
""".stripMargin, CssRulesParser.ruleList(_))
""".stripMargin, CssRulesParser.ruleList(_)) : @unchecked

assert(value6 == RuleList(Seq(
AtRule("media", Seq(
Expand All @@ -170,7 +170,7 @@ object CssTests extends TestSuite {
}

test("test7"){
val Parsed.Success(value7, index7) = parse(
val Parsed.Success(value7, _) = parse(
"""|
|@rule {
| unicode-range: U+26; /* single codepoint */
Expand All @@ -179,7 +179,7 @@ object CssTests extends TestSuite {
| unicode-range: U+4??; /* wildcard range */
| unicode-range: U+0025-00FF, U+4??;
|}
""".stripMargin, CssRulesParser.ruleList(_))
""".stripMargin, CssRulesParser.ruleList(_)) : @unchecked
assert(value7 == RuleList(Seq(
AtRule("rule", Seq(), Some(Left(
DeclarationList(Seq(
Expand All @@ -202,7 +202,7 @@ object CssTests extends TestSuite {
| /* test comment */
|}
|
""".stripMargin, CssRulesParser.ruleList(_))
""".stripMargin, CssRulesParser.ruleList(_)) : @unchecked

assert(
value2 ==
Expand Down
2 changes: 1 addition & 1 deletion fastparse/src-2.12/fastparse/internal/NoWarn.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fastparse.internal

object NoWarn{
object NoWarn {
@deprecated("Use scala.annotation.nowarn instead", "3.1.1")
class nowarn(msg: String = "")
}
1 change: 0 additions & 1 deletion fastparse/src-2/fastparse/internal/MacroImpls.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fastparse.internal

import fastparse.{EagerOps, Implicits, ParserInput, ParsingRun}

import scala.annotation.tailrec
import scala.reflect.macros.blackbox.Context

/**
Expand Down
5 changes: 0 additions & 5 deletions fastparse/src-2/fastparse/internal/MacroRepImpls.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fastparse.internal

import scala.reflect.macros.blackbox.Context
import language.experimental.macros

/**
* Implementations of the various `.rep`/`.repX` overloads. The most common
Expand Down Expand Up @@ -115,23 +114,20 @@ object MacroRepImpls{
def repXMacro1[T: c.WeakTypeTag, V: c.WeakTypeTag](c: Context)
(repeater: c.Tree,
ctx: c.Tree): c.Tree = {
import c.universe._
MacroRepImpls.repXMacro0[T, V](c)(None, None)(repeater, ctx)
}

def repXMacro2[T: c.WeakTypeTag, V: c.WeakTypeTag](c: Context)
(min: c.Tree)
(repeater: c.Tree,
ctx: c.Tree): c.Tree = {
import c.universe._
MacroRepImpls.repXMacro0[T, V](c)(None, Some(min))(repeater, ctx)
}

def repXMacro1ws[T: c.WeakTypeTag, V: c.WeakTypeTag](c: Context)
(repeater: c.Tree,
whitespace: c.Tree,
ctx: c.Tree): c.Tree = {
import c.universe._
MacroRepImpls.repXMacro0[T, V](c)(Some(whitespace), None)(repeater, ctx)
}

Expand All @@ -140,7 +136,6 @@ object MacroRepImpls{
(repeater: c.Tree,
whitespace: c.Tree,
ctx: c.Tree): c.Tree = {
import c.universe._
MacroRepImpls.repXMacro0[T, V](c)(Some(whitespace), Some(min))(repeater, ctx)
}
}
3 changes: 1 addition & 2 deletions fastparse/src-2/fastparse/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ package object fastparse extends fastparse.SharedPackageDefs {
// `terminalMsgs` once we exit the unary_!, to ensure these do not
// end up in error messages
ctx.terminalMsgs = startTerminals
ctx.reportTerminalMsg(startPos, Msgs.empty)
ctx.reportTerminalMsg(startPos, msg)
}
res.cut = startCut
res
Expand All @@ -320,7 +320,6 @@ package object fastparse extends fastparse.SharedPackageDefs {
ctx.noDropBuffer = true
parse
ctx.noDropBuffer = oldNoCut
val msg = ctx.shortMsg

val res =
if (ctx.isSuccess) ctx.freshSuccessUnit(startPos)
Expand Down
2 changes: 1 addition & 1 deletion fastparse/src-3/fastparse/internal/MacroInlineImpls.scala
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ object MacroInlineImpls {
output.append(Left(s(i)))
case '-' =>
i += 1
val Left(last) = output.remove(output.length - 1)
val Left(last) = output.remove(output.length - 1) : @unchecked
output.append(Right((last, s(i))))
case c => output.append(Left(c))
}
Expand Down
8 changes: 4 additions & 4 deletions fastparse/src/fastparse/ParsingRun.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fastparse

import fastparse.internal.{Instrument, Lazy, Msgs, Util}
import fastparse.internal.{Instrument, Msgs}

/**
* Models an in-progress parsing run; contains all the mutable state that may
Expand Down Expand Up @@ -40,7 +40,7 @@ import fastparse.internal.{Instrument, Lazy, Msgs, Util}
* `P(...)` parser.
* @param terminalMsgs When tracing is enabled, this collects up all the
* upper-most failures that happen at [[traceIndex]]
* (in [[Lazy]] wrappers) so they can be shown to the
* (in [[fastparse.internal.Lazy]] wrappers) so they can be shown to the
* user at end-of-parse as suggestions for what could
* make the parse succeed. For terminal parsers like
* [[LiteralStr]], it just aggregate's the string
Expand All @@ -60,7 +60,7 @@ import fastparse.internal.{Instrument, Lazy, Msgs, Util}
* we only aggregate the portion of the parser msg
* that takes place after `traceIndex`
* @param failureStack The stack of named `P(...)` parsers in effect when
* the failure occured; only constructed when tracing
* the failure occurred; only constructed when tracing
* is enabled via `traceIndex != -1`
* @param isSuccess Whether or not the parse is currently successful
* @param logDepth How many nested `.log` calls are currently surrounding us.
Expand Down Expand Up @@ -316,7 +316,7 @@ final class ParsingRun[+T](val input: ParserInput,
this.asInstanceOf[ParsingRun[Nothing]]
}

def checkForDrop() = !noDropBuffer && cut
def checkForDrop(): Boolean = !noDropBuffer && cut
}

object ParsingRun{
Expand Down
1 change: 0 additions & 1 deletion fastparse/src/fastparse/Whitespace.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fastparse

import fastparse._
import fastparse.internal.{Msgs, Util}

import scala.annotation.{switch, tailrec}
Expand Down
5 changes: 4 additions & 1 deletion fastparse/test/src/fastparse/ExampleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package test.fastparse
import utest._
import fastparse._
import fastparse.internal.Logger

import scala.annotation.nowarn
/**
* Demonstrates simultaneously parsing and
* evaluating simple arithmetic expressions
*/
@fastparse.internal.NoWarn.nowarn("msg=comparing values of types Unit and Unit using `==` will always yield true")
@nowarn("msg=comparing values of types Unit and Unit using `==` will always yield true")
object ExampleTests extends TestSuite{
import fastparse.NoWhitespace._
val tests = Tests{
Expand All @@ -17,6 +19,7 @@ object ExampleTests extends TestSuite{
def parseA[$: P] = P("a")

val Parsed.Success(value, successIndex) = parse("a", parseA(_))

assert(value == (), successIndex == 1)

val f @ Parsed.Failure(label, index, extra) = parse("b", parseA(_))
Expand Down
2 changes: 1 addition & 1 deletion pythonparse/src/pythonparse/Statements.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Statements(indent: Int){
def lastElse = P( (space_indents ~~ kw("else") ~/ ":" ~~ suite).? )
P( firstIf ~~ elifs ~~ lastElse ).map{
case (test, body, elifs, orelse) =>
val (init :+ last) = (test, body) +: elifs
val (init :+ last) = (test, body) +: elifs : @unchecked
val (last_test, last_body) = last
init.foldRight(Ast.stmt.If(last_test, last_body, orelse.toSeq.flatten)){
case ((test, body), rhs) => Ast.stmt.If(test, body, Seq(rhs))
Expand Down

0 comments on commit 7c96397

Please sign in to comment.