Skip to content

Commit

Permalink
Use Eq more (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz authored Sep 24, 2023
1 parent 2940343 commit ef8880e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion modules/ast/src/main/scala/playground/smithyql/AST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ object Struct {
)(
getValue: F[Identifier] => Identifier
): Option[F[InputNode[F]]] = value
.find(pair => getValue(pair.identifier).text == name)
.find(pair => getValue(pair.identifier).text === name)
.map(_.value)

}
Expand Down
9 changes: 6 additions & 3 deletions modules/core/src/main/scala/playground/CompilationError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cats.Id
import cats.data.IorNel
import cats.data.NonEmptyList
import cats.implicits._
import cats.kernel.Eq
import playground.CompilationErrorDetails._
import playground.smithyql._
import playground.smithyql.format.Formatter
Expand All @@ -19,8 +20,8 @@ final case class CompilationError(
) {
def deprecated: CompilationError = copy(tags = tags + DiagnosticTag.Deprecated)

def isError: Boolean = severity == DiagnosticSeverity.Error
def isWarning: Boolean = severity == DiagnosticSeverity.Warning
def isError: Boolean = severity === DiagnosticSeverity.Error
def isWarning: Boolean = severity === DiagnosticSeverity.Warning
}

object CompilationError {
Expand Down Expand Up @@ -69,6 +70,8 @@ object DiagnosticSeverity {
case object Warning extends DiagnosticSeverity
case object Error extends DiagnosticSeverity
case object Information extends DiagnosticSeverity

implicit val eq: Eq[DiagnosticSeverity] = Eq.fromUniversalEquals
}

sealed trait DiagnosticTag extends Product with Serializable
Expand Down Expand Up @@ -145,7 +148,7 @@ sealed trait CompilationErrorDetails extends Product with Serializable {
val expectedRemainingString =
if (remainingFields.isEmpty)
""
else if (remainingFields.size == 1)
else if (remainingFields.sizeIs == 1)
s" Expected: ${remainingFields.head}."
else
s" Expected: one of ${remainingFields.mkString(", ")}."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ object QueryCompilerVisitorInternal extends SchemaVisitor[QueryCompiler] {
val presentKeys = struct.value.fields.value.keys

val extraFieldErrors: QueryCompiler.Result[Unit] = presentKeys
.filterNot(field => validFields.contains(field.value.text))
.filterNot(field => validFields.contains_(field.value.text))
.map { unexpectedKey =>
CompilationError.error(
UnexpectedField(remainingValidFields),
Expand Down Expand Up @@ -342,7 +342,7 @@ object QueryCompilerVisitorInternal extends SchemaVisitor[QueryCompiler] {
// todo: should say it's a union
.typeCheck(NodeKind.Struct) { case s @ Struct(_) => s }
.emap {
case s if s.value.fields.value.size == 1 =>
case s if s.value.fields.value.size === 1 =>
val definition = s.value.fields.value.head
val key = definition.identifier

Expand Down Expand Up @@ -462,10 +462,10 @@ object QueryCompilerVisitorInternal extends SchemaVisitor[QueryCompiler] {
total: E => EnumValue[E],
): QueryCompiler[E] = (string, QueryCompiler.pos).tupled.emap { case (name, range) =>
val byValue = values
.find(_.stringValue == name)
.find(_.stringValue === name)

val byName = values
.find(_.name == name)
.find(_.name === name)

(byName, byValue) match {
case (Some(v), _) => v.value.pure[QueryCompiler.Result]
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/playground/IorUtilsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object IorUtilsTests extends FunSuite {
.foreach { testCase =>
test(s"orElseCombine(${testCase.lhs}, ${testCase.rhs})") {
val result = IorUtils.orElseCombine(testCase.lhs, testCase.rhs)
assert(result == testCase.expected)
assert(result === testCase.expected)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@ private[format] object FormattingVisitor extends ASTVisitor[WithSource, Doc] { v
internal +
commentsRHSSep +
commentsRHS
/*
case CommentPosition.After if lines.lengthIs == 1 =>
// one line: we add a space before the comment
Doc.lineOrSpace + internalString
case CommentPosition.After =>
// more lines: we force a hardline before the comments
Doc.hardLine + internalString
}
*/
}

private def printGeneric(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object CompletionProvider {
presentServiceIdentifiers: List[QualifiedIdentifier],
insertBodyStruct: CompletionItem.InsertBodyStruct,
): List[CompletionItem] = {
val needsUseClause = !presentServiceIdentifiers.contains(serviceId)
val needsUseClause = !presentServiceIdentifiers.contains_(serviceId)

val insertUseClause =
if (needsUseClause)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package playground.language

import cats.Id
import cats.implicits._
import cats.kernel.Eq
import playground.ServiceNameExtractor
import playground.TextUtils
import playground.language.CompletionItem.InsertUseClause.NotRequired
Expand Down Expand Up @@ -145,7 +146,7 @@ object CompletionItem {
insertText: InsertText,
schema: Schema[_],
): CompletionItem = {
val isField = kind == CompletionItemKind.Field
val isField = kind === CompletionItemKind.Field

val sortText =
isField match {
Expand Down Expand Up @@ -402,6 +403,8 @@ object CompletionItemKind {
case object Constant extends CompletionItemKind
case object UnionMember extends CompletionItemKind
case object Function extends CompletionItemKind

implicit val eq: Eq[CompletionItemKind] = Eq.fromUniversalEquals
}

object CompletionVisitor extends SchemaVisitor[CompletionResolver] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ case class ParsingFailure(
e: Parser.Expectation,
): String =
e match {
case OneOfStr(_, List(str)) => prep(str)
case OneOfStr(_, strs) => strs.map(prep).mkString_(" OR ")
case InRange(_, 'A', 'Z') => "an uppercase letter"
case InRange(_, 'a', 'z') => "a lowercase letter"
case InRange(_, '0', '9') => "digit"
case InRange(_, from, to) if from == to => prep(from.toString)
case OneOfStr(_, List(str)) => prep(str)
case OneOfStr(_, strs) => strs.map(prep).mkString_(" OR ")
case InRange(_, 'A', 'Z') => "an uppercase letter"
case InRange(_, 'a', 'z') => "a lowercase letter"
case InRange(_, '0', '9') => "digit"
case InRange(_, from, to) if from === to => prep(from.toString)
case InRange(_, from, to) => s"one of ${prep(from.toString)} - ${prep(to.toString)}"
case EndOfString(_, _) => "end of string"
case WithContext(contextStr, underlying) if verbose =>
Expand Down

0 comments on commit ef8880e

Please sign in to comment.