From a2a6cb9a18df98e4000c6aba58e82c11fcca4007 Mon Sep 17 00:00:00 2001 From: Carlos Liarte Navarro Date: Thu, 4 Apr 2019 11:02:32 +0200 Subject: [PATCH] Add implementation of package linting rule and tests --- .../core/proto/validate/ProtoLint.java | 18 ++++++++++++++++++ .../core/proto/validate/ValidationResults.java | 1 + .../anemos/metastore/invalid/invalid.proto | 9 +++++++++ .../anemos/metastore/v1alpha1/report.proto | 1 + .../anemos/metastore/v1alpha1/rules.proto | 1 + 5 files changed, 30 insertions(+) create mode 100644 core/src/test/proto/anemos/metastore/invalid/invalid.proto diff --git a/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java b/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java index c732d1c..85364f3 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java @@ -166,4 +166,22 @@ private boolean isPascalCase(String fieldName) { return true; } +<<<<<<< HEAD +======= + public void lintOnPackage(Descriptors.Descriptor ref) { + Descriptors.FileDescriptor fileDescriptor = proto.getFileDescriptorByFileName(ref.getFile().getName()); + String protoPackageName = fileDescriptor.getPackage(); + String fileName = ref.getFile().getFullName(); + fileName = fileName.substring(0, fileName.lastIndexOf("/")).replace("/", "."); + if(!fileName.equals(protoPackageName)){ + results.addResult(fileDescriptor, RuleInfo.newBuilder() + .setLintRule(LintRule.LINT_PACKAGE_NAME_SHOULD_BE_VALID) + .setCode(String.format("L%d/00", LintRule.LINT_PACKAGE_NAME_SHOULD_BE_VALID_VALUE)) + .build() + ); + } + } + + +>>>>>>> f5c7aac... Add implementation of package linting rule and tests } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java index 0daf04f..c0fb61d 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java @@ -269,4 +269,5 @@ public void addPatch(ChangeInfo patch) { this.patch = patch; } } + } diff --git a/core/src/test/proto/anemos/metastore/invalid/invalid.proto b/core/src/test/proto/anemos/metastore/invalid/invalid.proto new file mode 100644 index 0000000..9f37ad0 --- /dev/null +++ b/core/src/test/proto/anemos/metastore/invalid/invalid.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +import "google/protobuf/empty.proto"; + +package anemos.metastore.invalid.test; + +option java_package = "io.anemos.metastore.invalid"; + +message InvalidMessage {} diff --git a/proto/src/main/proto/anemos/metastore/v1alpha1/report.proto b/proto/src/main/proto/anemos/metastore/v1alpha1/report.proto index 3e4e07e..54a80e3 100644 --- a/proto/src/main/proto/anemos/metastore/v1alpha1/report.proto +++ b/proto/src/main/proto/anemos/metastore/v1alpha1/report.proto @@ -173,3 +173,4 @@ message RuleInfo { //message SchemaDiff { // repeated RuleInfo rules = 1; //} + diff --git a/proto/src/main/proto/anemos/metastore/v1alpha1/rules.proto b/proto/src/main/proto/anemos/metastore/v1alpha1/rules.proto index 14692e0..61c23e8 100644 --- a/proto/src/main/proto/anemos/metastore/v1alpha1/rules.proto +++ b/proto/src/main/proto/anemos/metastore/v1alpha1/rules.proto @@ -28,3 +28,4 @@ enum LintRule { LINT_GENERAL_CUSTOM = 60000; } +