regex - 用于 scalastyle 的自定义正则表达式以捕获丢失的空格
问题描述
我想为 scalastyle 编写一个自定义正则表达式,以便它可以捕获开发人员在运算符之前和之后忘记空格的情况,但正则表达式不应该捕获字符串中的任何内容。让我们看看例子:
val asdf123=sdf // should be catched
val as = sd // shouldn't be watched
val a /=10 // should be
def check() =as // should be
def check= { // should be
val isEqual = a == b // shouldn't
val b += 2 // shouldn't
val e = true!=false //should
val a = 2!=3 //dhould
val a = 2 != 3 // shouldn't
val a = 2 <= 3 // shouldn't
val a = b&&s // should
val a = b % s // shouldn't
val a/= s // should
val a /= b // shouldn't
def validateSeq[T](input: Seq[T], validationFunc: (T =>Option[Message])*): Either[ValidationError, Seq[T]] = { // should, because of =>Option
val url = "/docs/swagger-ui/index.html?url=/docs/swagger" // shouldn't because =/ is inside string
"Access-Control-Allow-Credentials" // shouldn't
这是我到目前为止所拥有的,但它不能正确处理字符串:
([a-zA-Z0-9]+([-+&<>!=\/&%]+)[a-zA-Z0-9]|[a-zA-Z0-9]([-+&<>!=\/&%]+)|([-+&<>!=\/&%]+)[a-zA-Z0-9])
解决方案
推荐阅读
- ruby-on-rails - 未初始化的常量 SessionsController::User
- jquery - jQuery - 检查 URL 是否包含各种可能的字符串之一
- git - 无法构建 Maven 项目 Jenkins 管道
- excel - 最佳方法 - 使用具有多个最终用户的 VBA 从 Excel 将记录写入 Oracle
- javascript - 添加到购物车路线 node.js
- javascript - 使用 Jasmine 测试链式承诺而不返回承诺
- django - 无法使用 DRF 在 Django 模板中显示图像
- wpf - 在本地/直接设置控件的(触发)属性时,ControlTemplate/Style 触发器不起作用
- javascript - Vue.js - 在另一个数组中显示嵌套数组的详细信息
- c - 如何反转C中的句子?