Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected identifier error STRING_LITERAL when defining Refined Regex #366

Open
vasigorc opened this issue Mar 16, 2022 · 0 comments
Open

Comments

@vasigorc
Copy link

We use Scala refined library to narrow down basic/primitive types and to make illegal states unrepresentable.

For some basic stuff it has been ok, but when we try to use regex rules for narrowed String definitions, we get these errors:

[info] scalastyle using config /Users/vasilegorcinschi/company/company-app/project/scalastyle_config.xml
[error] /Users/vasilegorcinschi/company/company-app/src/main/scala/io/company/util/amqp/Exchanges.scala: Expected identifier, but got Token(STRING_LITERAL,"company(\\.[a-z_]{1,30}){1,3}",263,"company(\\.[a-z_]{1,30}){1,3}")

☝️ and 👇 I have replaced our company application names.

This is the source code for which the error is thrown:

package io.company.util.amqp

import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.string.MatchesRegex

private[company] object Exchanges {

  type ExchangeTypeR = String Refined MatchesRegex["company(\\.[a-z_]{1,30}){1,3}"]

  sealed abstract class Exchange(val exchangeName: ExchangeTypeR) {
    override def toString: String = exchangeName.value
  }
  final case object InboundCommandExchange extends Exchange("company.inbound.command_exchange")
  final case object CommandExchange extends Exchange("company.outbound.command_exchange")
  ...

This error breaks our builds and we are not sure how to address it. Please assist.

Scalastyle version from plugins.sbt:

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")

Scala version: 2.13.8
sbt version: 1.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant