diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 841960669..fa4bb1bf9 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,2 +1,5 @@ # Scala Steward: Reformat with scalafmt 3.7.17 64d75796ea0483a6708ad2ada181eea9256e6bdd + +# Scala Steward: Reformat with scalafmt 3.10.7 +094d8602fd0dd6794e2ee330820d302442c4924a diff --git a/.scalafmt.conf b/.scalafmt.conf index fbb3927f9..d9029470b 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,3 +1,3 @@ -version=3.7.17 +version=3.10.7 runner.dialect = scala213 maxColumn = 100 diff --git a/apps/checker/app/matchers/LanguageToolMatcher.scala b/apps/checker/app/matchers/LanguageToolMatcher.scala index 47daf2bc2..473269c48 100644 --- a/apps/checker/app/matchers/LanguageToolMatcher.scala +++ b/apps/checker/app/matchers/LanguageToolMatcher.scala @@ -109,7 +109,7 @@ class LanguageToolFactory( private def getLTRulesFromXML(rules: List[LTRuleXML]): Try[List[AbstractPatternRule]] = rules match { case Nil => Success(Nil) - case r => { + case r => { val loader = new PatternRuleLoader() getXMLStreamFromLTRules(rules) flatMap { xmlStream => { @@ -173,7 +173,9 @@ class LanguageToolFactory( additionalMessage: String = "" ) = new Exception( - s"Error applying LanguageTool rule `${ruleId}`: ${e.getMessage} ${if (additionalMessage.nonEmpty) additionalMessage + s"Error applying LanguageTool rule `${ruleId}`: ${e.getMessage} ${if ( + additionalMessage.nonEmpty + ) additionalMessage else ""}".trim, e ) diff --git a/apps/checker/app/services/MatcherPool.scala b/apps/checker/app/services/MatcherPool.scala index 1e12594fa..3025f6feb 100644 --- a/apps/checker/app/services/MatcherPool.scala +++ b/apps/checker/app/services/MatcherPool.scala @@ -282,7 +282,7 @@ class MatcherPool( private def getMatchesForJob(job: MatcherPoolJob): Future[(MatcherPoolJob, List[RuleMatch])] = { val maybeMatchesForJob = for { matchers <- job match { - case categoryJob: MatcherPoolCategoryJob => getMatchersForJob(categoryJob) + case categoryJob: MatcherPoolCategoryJob => getMatchersForJob(categoryJob) case singleMatcherJob: MatcherPoolSingleMatcherJob => Success(List(singleMatcherJob.matcher)) } @@ -378,7 +378,7 @@ class MatcherPool( */ private def getApplicableCategories(query: Check) = (query.categoryIds, query.excludeCategoryIds) match { - case (Some(ids), _) if ids.nonEmpty => ids + case (Some(ids), _) if ids.nonEmpty => ids case (_, Some(excludeIds)) if excludeIds.nonEmpty => getCurrentCategories.map(_.id).filter(!excludeIds.contains(_)) case _ => getCurrentCategories.map(_.id) diff --git a/apps/checker/app/services/MatcherProvisionerService.scala b/apps/checker/app/services/MatcherProvisionerService.scala index fcb9e7bfe..c14fdb10e 100644 --- a/apps/checker/app/services/MatcherProvisionerService.scala +++ b/apps/checker/app/services/MatcherProvisionerService.scala @@ -76,7 +76,7 @@ class MatcherProvisionerService( bucketRuleResource.getRulesLastModified match { case Right(date) if date.compareTo(lastModified) > 0 => updateRulesFromBucket() case Right(_) => logger.info("No rule update needed") - case Left(error) => + case Left(error) => logger.error(s"Could not get last modified from S3", error) cloudWatchClient.putMetric(Metrics.RulesNotFound) } diff --git a/apps/common-lib/src/main/scala/com/gu/typerighter/lib/AppSetup.scala b/apps/common-lib/src/main/scala/com/gu/typerighter/lib/AppSetup.scala index 398b2d889..1fd1c6c3a 100644 --- a/apps/common-lib/src/main/scala/com/gu/typerighter/lib/AppSetup.scala +++ b/apps/common-lib/src/main/scala/com/gu/typerighter/lib/AppSetup.scala @@ -38,7 +38,7 @@ object AppSetup { } val config = ConfigurationLoader.load(identity, credsV2) { - case identity: AwsIdentity => SSMConfigurationLocation.default(identity) + case identity: AwsIdentity => SSMConfigurationLocation.default(identity) case development: DevIdentity => SSMConfigurationLocation(s"/DEV/flexible/${development.app}", region) } diff --git a/apps/common-lib/src/main/scala/com/gu/typerighter/model/CheckerRule.scala b/apps/common-lib/src/main/scala/com/gu/typerighter/model/CheckerRule.scala index 43dc95505..f3e867e2e 100644 --- a/apps/common-lib/src/main/scala/com/gu/typerighter/model/CheckerRule.scala +++ b/apps/common-lib/src/main/scala/com/gu/typerighter/model/CheckerRule.scala @@ -169,7 +169,7 @@ object LTRule { rule.patternTokens.getOrElse(List[PatternToken]()).map(PatternToken.toLT).asJava val language = Languages.getLanguageForShortCode(rule.languageShortcode.getOrElse("en-GB")) val message = rule.suggestions match { - case Nil => rule.message + case Nil => rule.message case suggestions => val ruleMessage = if (rule.message == "") "" else rule.message + ". " ruleMessage.concat( diff --git a/apps/common-lib/src/main/scala/com/gu/typerighter/model/RuleMatch.scala b/apps/common-lib/src/main/scala/com/gu/typerighter/model/RuleMatch.scala index edb2fb62a..101ab8227 100644 --- a/apps/common-lib/src/main/scala/com/gu/typerighter/model/RuleMatch.scala +++ b/apps/common-lib/src/main/scala/com/gu/typerighter/model/RuleMatch.scala @@ -63,7 +63,7 @@ case class RuleMatch( /** Map the range this match applies to through the given ranges, adjusting its range accordingly. */ def mapThroughSkippedRanges(skipRanges: List[TextRange]): RuleMatch = skipRanges match { - case Nil => this + case Nil => this case skipRanges => { val (newMatch, _) = skipRanges.foldLeft((this, List.empty[TextRange]))((acc, range) => acc match { diff --git a/apps/rule-manager/app/controllers/RulesController.scala b/apps/rule-manager/app/controllers/RulesController.scala index a67eff395..39599cb8a 100644 --- a/apps/rule-manager/app/controllers/RulesController.scala +++ b/apps/rule-manager/app/controllers/RulesController.scala @@ -32,7 +32,7 @@ class RulesController( def refresh = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to refresh rules") - case true => + case true => val maybeWrittenRules = for { dbRules <- sheetsRuleResource .getRules() @@ -53,7 +53,7 @@ class RulesController( def refreshDictionaryRules() = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to refresh dictionary rules") - case true => + case true => val wordsOrError = dictionaryResource.getDictionaryWords() val wordsToNotPublish = dictionaryResource.getWordsToNotPublish() @@ -85,7 +85,7 @@ class RulesController( def get(id: Int) = APIAuthAction { RuleManager.getAllRuleData(id) match { - case None => NotFound("Rule not found matching ID") + case None => NotFound("Rule not found matching ID") case Some(allRuleData) => Ok(Json.toJson(allRuleData)) } @@ -94,7 +94,7 @@ class RulesController( def publish(id: Int) = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to publish rules") - case true => + case true => PublishRuleForm.form .bindFromRequest() .fold( @@ -102,7 +102,7 @@ class RulesController( reason => { DbRuleDraft.find(id) match { case None => NotFound - case _ => + case _ => RuleManager .publishRule(id, request.user.email, reason, bucketRuleResource) match { case Right(result) => Ok(Json.toJson(result)) @@ -118,7 +118,7 @@ class RulesController( { hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to create rules") - case true => + case true => CreateRuleForm.form .bindFromRequest() .fold( @@ -140,7 +140,7 @@ class RulesController( def update(id: Int) = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to edit rules") - case true => + case true => UpdateRuleForm.form .bindFromRequest() .fold( @@ -171,7 +171,7 @@ class RulesController( def batchUpdate() = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to edit rules") - case true => + case true => BatchUpdateRuleForm.form .bindFromRequest() .fold( @@ -205,7 +205,7 @@ class RulesController( def unpublish(id: Int): Action[AnyContent] = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to unpublish rules") - case true => + case true => RuleManager.unpublishRule(id, request.user.email, bucketRuleResource) match { case Left(e: Throwable) => InternalServerError(e.getMessage) case Right(allRuleData) => Ok(Json.toJson(allRuleData)) @@ -216,7 +216,7 @@ class RulesController( def archive(id: Int): Action[AnyContent] = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to archive rules") - case true => + case true => RuleManager.archiveRule(id, request.user.email) match { case Left(e: Throwable) => InternalServerError(e.getMessage) case Right(allRuleData) => Ok(Json.toJson(allRuleData)) @@ -227,7 +227,7 @@ class RulesController( def unarchive(id: Int): Action[AnyContent] = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to unarchive rules") - case true => + case true => RuleManager.unarchiveRule(id, request.user.email) match { case Left(e: Throwable) => InternalServerError(e.getMessage) case Right(allRuleData) => Ok(Json.toJson(allRuleData)) @@ -238,7 +238,7 @@ class RulesController( def discardChanges(id: Int) = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to edit rules") - case true => + case true => revertDraftRule(id, request.user.email) match { case Left(throwable) => InternalServerError(throwable.getMessage) case Right(data) => Ok(Json.toJson(data)) @@ -283,7 +283,7 @@ class RulesController( def csvImport() = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to edit rules") - case true => + case true => val rules = for { formData <- request.body.asMultipartFormData.toRight("No form data found in request") file <- formData.file("file").toRight("No file found in request") @@ -307,7 +307,7 @@ class RulesController( def archiveRulesByTag() = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to edit rules") - case true => + case true => val rules = for { formData <- request.body.asMultipartFormData.toRight("No form data found in request") tag = formData.dataParts.get("tag").flatMap(_.headOption) diff --git a/apps/rule-manager/app/controllers/TagsController.scala b/apps/rule-manager/app/controllers/TagsController.scala index 09f37e031..84a52e12e 100644 --- a/apps/rule-manager/app/controllers/TagsController.scala +++ b/apps/rule-manager/app/controllers/TagsController.scala @@ -34,7 +34,7 @@ class TagsController( def get(id: Int) = APIAuthAction { Tags.find(id) match { - case None => NotFound("Tag not found matching ID") + case None => NotFound("Tag not found matching ID") case Some(tag) => Ok(Json.toJson(tag)) } @@ -42,7 +42,7 @@ class TagsController( def delete(id: Int) = APIAuthAction { Tags.find(id) match { - case None => NotFound("Tag not found matching ID") + case None => NotFound("Tag not found matching ID") case Some(tag) => RuleTagDraft.destroyForTag(tag.id.get) RuleTagLive.destroyForTag(tag.id.get) @@ -55,7 +55,7 @@ class TagsController( { hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to create tags") - case true => + case true => TagForm.form .bindFromRequest() .fold( @@ -77,7 +77,7 @@ class TagsController( def update(id: Int) = APIAuthAction { implicit request => hasPermission(request.user, PermissionDefinition("manage_rules", "typerighter")) match { case false => Unauthorized("You don't have permission to edit rules") - case true => + case true => TagForm.form .bindFromRequest() .fold( diff --git a/apps/rule-manager/app/db/DbRuleDraft.scala b/apps/rule-manager/app/db/DbRuleDraft.scala index 869b4fed5..2f410df2f 100644 --- a/apps/rule-manager/app/db/DbRuleDraft.scala +++ b/apps/rule-manager/app/db/DbRuleDraft.scala @@ -270,7 +270,7 @@ object DbRuleDraft extends SQLSyntaxSupport[DbRuleDraft] { val condition = searchClause.toList ++ tagFilterClause.toList ++ ruleTypeFilterClause.toList match { - case Nil => sqls.empty + case Nil => sqls.empty case clauses => sqls"WHERE ${sqls.join(clauses, sqls"AND")}" } @@ -452,7 +452,7 @@ object DbRuleDraft extends SQLSyntaxSupport[DbRuleDraft] { find(id) match { case Some(rule) => Success(rule) - case None => + case None => Failure( new Exception( s"Attempted to create a rule with id $id, but no result found attempting to read it back" diff --git a/apps/rule-manager/app/db/DbRuleLive.scala b/apps/rule-manager/app/db/DbRuleLive.scala index 40026e751..01fd0e114 100644 --- a/apps/rule-manager/app/db/DbRuleLive.scala +++ b/apps/rule-manager/app/db/DbRuleLive.scala @@ -249,7 +249,7 @@ object DbRuleLive extends SQLSyntaxSupport[DbRuleLive] { findRevision(generatedKey.get, liveRule.revisionId) match { case Some(rule) => rule - case None => + case None => throw new Exception( s"Attempted to create a rule with id $generatedKey, but no result found attempting to read it back" ) diff --git a/apps/rule-manager/app/db/RuleTagDraft.scala b/apps/rule-manager/app/db/RuleTagDraft.scala index b30d1ea6e..d4d821271 100644 --- a/apps/rule-manager/app/db/RuleTagDraft.scala +++ b/apps/rule-manager/app/db/RuleTagDraft.scala @@ -58,7 +58,7 @@ object RuleTagDraft extends SQLSyntaxSupport[RuleTagDraft] { }.update().apply() find(ruleId, tagId) match { case Some(rule) => Success(rule) - case None => + case None => Failure( new Exception( s"Attempted to create a tag with id $generatedKey, but no result found attempting to read it back" diff --git a/apps/rule-manager/app/db/RuleTagLive.scala b/apps/rule-manager/app/db/RuleTagLive.scala index ee3f28d40..f8c6c8387 100644 --- a/apps/rule-manager/app/db/RuleTagLive.scala +++ b/apps/rule-manager/app/db/RuleTagLive.scala @@ -79,7 +79,7 @@ object RuleTagLive extends SQLSyntaxSupport[RuleTagLive] { }.update().apply() find(externalId, revisionId, tagId) match { case Some(ruleTagLive) => Success(ruleTagLive) - case None => + case None => Failure( new Exception( s"Attempted to create a RuleTagLive with id $tagId, but no result found attempting to read it back" diff --git a/apps/rule-manager/app/db/Tags.scala b/apps/rule-manager/app/db/Tags.scala index ed93fba87..702be1c63 100644 --- a/apps/rule-manager/app/db/Tags.scala +++ b/apps/rule-manager/app/db/Tags.scala @@ -89,7 +89,7 @@ object Tags extends SQLSyntaxSupport[Tag] { }.updateAndReturnGeneratedKey().apply() find(generatedKey.toInt) match { case Some(rule) => Success(rule) - case None => + case None => Failure( new Exception( s"Attempted to create a tag with id $generatedKey, but no result found attempting to read it back" diff --git a/apps/rule-manager/app/model/CheckerRuleForm.scala b/apps/rule-manager/app/model/CheckerRuleForm.scala index a58b55c6c..239bf83ac 100644 --- a/apps/rule-manager/app/model/CheckerRuleForm.scala +++ b/apps/rule-manager/app/model/CheckerRuleForm.scala @@ -19,7 +19,7 @@ import scala.xml.XML object RegexRuleForm { val regexConstraint: Constraint[String] = Constraint("constraints.regexcheck") { regexStr => Try(regexStr.r) match { - case Success(_) => Valid + case Success(_) => Valid case Failure(exception) => Invalid( Seq(ValidationError(s"Error parsing the regular expression: ${exception.getMessage()}")) @@ -58,7 +58,7 @@ object RegexRuleForm { object LTRuleXMLForm { val xmlConstraint: Constraint[String] = Constraint("constraints.xmlcheck") { xmlStr => Try(XML.loadString(xmlStr)) match { - case Success(_) => Valid + case Success(_) => Valid case Failure(exception) => Invalid(Seq(ValidationError(s"Error parsing the XML: ${exception.getMessage()}"))) } diff --git a/apps/rule-manager/app/model/CreateRuleForm.scala b/apps/rule-manager/app/model/CreateRuleForm.scala index c710f63be..ca09e510f 100644 --- a/apps/rule-manager/app/model/CreateRuleForm.scala +++ b/apps/rule-manager/app/model/CreateRuleForm.scala @@ -12,7 +12,7 @@ object CreateRuleForm { case RuleType.languageToolCore => Nil case RuleType.languageToolXML => Nil case RuleType.dictionary => Nil - case _ => + case _ => Seq( ValidationError( s"RuleType must be one of \"${RuleType.regex}\", \"${RuleType.languageToolXML}\", \"${RuleType.languageToolCore}\" or \"${RuleType.dictionary}\"" diff --git a/apps/rule-manager/app/model/UpdateRuleForm.scala b/apps/rule-manager/app/model/UpdateRuleForm.scala index c55b2df4f..8123701f5 100644 --- a/apps/rule-manager/app/model/UpdateRuleForm.scala +++ b/apps/rule-manager/app/model/UpdateRuleForm.scala @@ -13,7 +13,7 @@ object UpdateRuleForm { case Some(RuleType.languageToolCore) => Nil case Some(RuleType.languageToolXML) => Nil case Some(RuleType.dictionary) => Nil - case _ => + case _ => Seq( ValidationError( s"RuleType must be one of \"${RuleType.regex}\", \"${RuleType.languageToolXML}\", \"${RuleType.languageToolCore}\" or \"${RuleType.dictionary}\"" diff --git a/apps/rule-manager/app/service/DictionaryResource.scala b/apps/rule-manager/app/service/DictionaryResource.scala index 74622abc1..b00314a0e 100644 --- a/apps/rule-manager/app/service/DictionaryResource.scala +++ b/apps/rule-manager/app/service/DictionaryResource.scala @@ -43,7 +43,7 @@ class DictionaryResource(s3: S3Client, bucketName: String, stage: String) { }) words match { - case Success(words) => Right(words) + case Success(words) => Right(words) case Failure(exception) => Left(Seq(FormError("dictionary-parse-error", exception.getMessage))) } diff --git a/apps/rule-manager/app/utils/Dictionary.scala b/apps/rule-manager/app/utils/Dictionary.scala index d24b2308e..cfe289bad 100644 --- a/apps/rule-manager/app/utils/Dictionary.scala +++ b/apps/rule-manager/app/utils/Dictionary.scala @@ -24,7 +24,7 @@ object Dictionary { def lemmaOrInflListToText(node: Node): Set[String] = { node match { - case node if node.label == "lemma" => Set(node.text) + case node if node.label == "lemma" => Set(node.text) case node if node.label == "infl_list" => node.child.filter(_.label == "infl").map(_.text).toSet case _ => Set.empty diff --git a/apps/rule-manager/test/db/RuleManagerSpec.scala b/apps/rule-manager/test/db/RuleManagerSpec.scala index 375fb613c..00f49ca2b 100644 --- a/apps/rule-manager/test/db/RuleManagerSpec.scala +++ b/apps/rule-manager/test/db/RuleManagerSpec.scala @@ -291,7 +291,7 @@ class RuleManagerSpec extends FixtureAnyFlatSpec with Matchers with AutoRollback RuleManager.publishRule(ruleToPublish.id.get, user, reason, bucketRuleResource) RuleManager.publishRule(ruleToPublish.id.get, user, reason, bucketRuleResource) match { - case Right(_) => fail("This rule should not be publishable") + case Right(_) => fail("This rule should not be publishable") case Left(formErrors) => formErrors.head.message should include( "has not changed" @@ -304,7 +304,7 @@ class RuleManagerSpec extends FixtureAnyFlatSpec with Matchers with AutoRollback RuleManager.archiveRule(ruleToPublish.id.get, user) RuleManager.publishRule(ruleToPublish.id.get, user, reason, bucketRuleResource) match { - case Right(_) => fail("This rule should not be publishable") + case Right(_) => fail("This rule should not be publishable") case Left(formErrors) => formErrors.length shouldBe 1 formErrors.head.message should be("Only unarchived rules can be published") @@ -331,7 +331,7 @@ class RuleManagerSpec extends FixtureAnyFlatSpec with Matchers with AutoRollback val ruleToPublish = createPublishableRule RuleManager.publishRule(ruleToPublish.id.get, user, reason, bucketRuleResource) RuleManager.parseDraftRuleForPublication(ruleToPublish.id.get, "reason") match { - case Right(_) => fail("This rule should not be publishable") + case Right(_) => fail("This rule should not be publishable") case Left(formErrors) => formErrors.length shouldBe 1 formErrors.head.message should include("has not changed") @@ -344,7 +344,7 @@ class RuleManagerSpec extends FixtureAnyFlatSpec with Matchers with AutoRollback RuleManager.archiveRule(ruleToPublish.id.get, user) RuleManager.parseDraftRuleForPublication(ruleToPublish.id.get, "reason") match { - case Right(_) => fail("This rule should not be publishable") + case Right(_) => fail("This rule should not be publishable") case Left(formErrors) => formErrors.length shouldBe 1 formErrors.head.message should be("Only unarchived rules can be published") @@ -355,7 +355,7 @@ class RuleManagerSpec extends FixtureAnyFlatSpec with Matchers with AutoRollback val ruleToPublish = createPublishableRule RuleManager.getAllRuleData(ruleToPublish.id.get) match { - case None => fail("Rule should exist") + case None => fail("Rule should exist") case Some(allRuleData) => allRuleData.draft shouldMatchTo ruleToPublish allRuleData.live shouldMatchTo List.empty @@ -521,7 +521,7 @@ class RuleManagerSpec extends FixtureAnyFlatSpec with Matchers with AutoRollback fail(s"Unexpected error on unpublishing id: ${ruleToUnpublish.id.get}: ${e.getMessage}") case Right(allRuleData) => allRuleData match { - case None => fail("Expected rule data to be returned") + case None => fail("Expected rule data to be returned") case Some(allRuleData) => allRuleData.draft.isPublished shouldBe false allRuleData.draft.revisionId shouldBe >(ruleToUnpublish.revisionId)