From 4defb6a7290dac18aae28d25388faf596c140074 Mon Sep 17 00:00:00 2001 From: Irina Shestak Date: Wed, 13 Jul 2022 12:59:00 +0200 Subject: [PATCH] rename all mention of 'errors' to 'diagnostics' --- crates/apollo-compiler/src/lib.rs | 72 +++++++++++++------ .../src/validation/directives.rs | 2 +- .../apollo-compiler/src/validation/enums.rs | 8 +-- .../src/validation/input_object.rs | 8 +-- .../src/validation/interfaces.rs | 56 +++++++-------- crates/apollo-compiler/src/validation/mod.rs | 26 +++---- .../src/validation/operations.rs | 30 ++++---- .../apollo-compiler/src/validation/scalars.rs | 8 +-- .../apollo-compiler/src/validation/schema.rs | 8 +-- .../apollo-compiler/src/validation/unions.rs | 6 +- 10 files changed, 127 insertions(+), 97 deletions(-) diff --git a/crates/apollo-compiler/src/lib.rs b/crates/apollo-compiler/src/lib.rs index a9292f792..f7c331769 100644 --- a/crates/apollo-compiler/src/lib.rs +++ b/crates/apollo-compiler/src/lib.rs @@ -37,9 +37,9 @@ impl ApolloCompiler { validator.validate().into() } - // pub fn syntax_errors(&self) -> Vec { - // self.db.syntax_errors() - // } + pub fn syntax_errors(&self) -> Vec { + self.db.syntax_errors() + } pub fn definitions(&self) -> Arc> { self.db.definitions() @@ -109,9 +109,13 @@ type Query { "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); + let diagnostics = ctx.validate(); + + assert!(diagnostics.is_empty()); - assert!(errors.is_empty()); + for diagnostic in diagnostics { + println!("{}", diagnostic); + } let operations = ctx.operations(); let operation_names: Vec<_> = operations.iter().filter_map(|op| op.name()).collect(); @@ -155,9 +159,13 @@ type Query { "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); + let diagnostics = ctx.validate(); - assert!(errors.is_empty()); + assert!(diagnostics.is_empty()); + + for diagnostic in diagnostics { + println!("{}", diagnostic); + } let operations = ctx.operations(); let fields = operations @@ -198,9 +206,13 @@ type Result { "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); + let diagnostics = ctx.validate(); - assert!(errors.is_empty()); + assert!(diagnostics.is_empty()); + + for diagnostic in diagnostics { + println!("{}", diagnostic); + } } #[test] @@ -215,9 +227,13 @@ scalar URL @specifiedBy(url: "https://tools.ietf.org/html/rfc3986") "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); + let diagnostics = ctx.validate(); - assert!(errors.is_empty()); + assert!(diagnostics.is_empty()); + + for diagnostic in diagnostics { + println!("{}", diagnostic); + } let scalars = ctx.scalars(); @@ -247,12 +263,15 @@ enum Pet { "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); + let diagnostics = ctx.validate(); - assert!(errors.is_empty()); + assert!(diagnostics.is_empty()); - let enums = ctx.enums(); + for diagnostic in diagnostics { + println!("{}", diagnostic); + } + let enums = ctx.enums(); let enum_values: Vec<&str> = enums .iter() .find(|enum_def| enum_def.name() == "Pet") @@ -289,12 +308,15 @@ type SearchQuery { "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); + let diagnostics = ctx.validate(); - assert!(errors.is_empty()); + assert!(diagnostics.is_empty()); - let unions = ctx.unions(); + for diagnostic in diagnostics { + println!("{}", diagnostic); + } + let unions = ctx.unions(); let union_members: Vec<&str> = unions .iter() .find(|def| def.name() == "SearchResult") @@ -340,9 +362,13 @@ type Book @delegateField(name: "pageCount") @delegateField(name: "author") { "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); + let diagnostics = ctx.validate(); - assert!(errors.is_empty()); + assert!(diagnostics.is_empty()); + + for diagnostic in diagnostics { + println!("{}", diagnostic); + } let directives = ctx.directive_definitions(); let locations: Vec = directives @@ -380,9 +406,13 @@ input Point2D { "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); + let diagnostics = ctx.validate(); - assert!(errors.is_empty()); + assert!(diagnostics.is_empty()); + + for diagnostic in diagnostics { + println!("{}", diagnostic); + } let input_objects = ctx.input_objects(); let fields: Vec<&str> = input_objects diff --git a/crates/apollo-compiler/src/validation/directives.rs b/crates/apollo-compiler/src/validation/directives.rs index 3d92b8cce..1808eb159 100644 --- a/crates/apollo-compiler/src/validation/directives.rs +++ b/crates/apollo-compiler/src/validation/directives.rs @@ -31,7 +31,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { original_definition: (prev_offset, prev_node_len).into(), redefined_definition: (current_offset, current_node_len).into(), help: Some(format!( - "`{name}` must only be defined once in this document." + "`{name} must only be defined once in this document." )), })); } diff --git a/crates/apollo-compiler/src/validation/enums.rs b/crates/apollo-compiler/src/validation/enums.rs index 8f489cf85..79807748c 100644 --- a/crates/apollo-compiler/src/validation/enums.rs +++ b/crates/apollo-compiler/src/validation/enums.rs @@ -7,7 +7,7 @@ use crate::{ }; pub fn check(db: &dyn SourceDatabase) -> Vec { - let mut errors = Vec::new(); + let mut diagnostics = Vec::new(); // An Enum type must define one or more unique enum values. // @@ -22,7 +22,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { let current_offset: usize = enum_value.ast_node(db).text_range().start().into(); let current_node_len: usize = enum_value.ast_node(db).text_range().len().into(); - errors.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { + diagnostics.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { ty: "enum".into(), name: value.into(), src: db.input_string(()).to_string(), @@ -46,7 +46,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { let len: usize = enum_value.ast_node(db).text_range().len().into(); if value.to_uppercase() != value { - errors.push(ApolloDiagnostic::CapitalizedValue(CapitalizedValue { + diagnostics.push(ApolloDiagnostic::CapitalizedValue(CapitalizedValue { ty: value.into(), src: db.input_string(()).to_string(), value: (offset, len).into(), @@ -55,5 +55,5 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { } } - errors + diagnostics } diff --git a/crates/apollo-compiler/src/validation/input_object.rs b/crates/apollo-compiler/src/validation/input_object.rs index 01c1c5634..f52972bac 100644 --- a/crates/apollo-compiler/src/validation/input_object.rs +++ b/crates/apollo-compiler/src/validation/input_object.rs @@ -7,7 +7,7 @@ use crate::{ }; pub fn check(db: &dyn SourceDatabase) -> Vec { - let mut errors = Vec::new(); + let mut diagnostics = Vec::new(); // Input Object Definitions must have unique names. // @@ -21,7 +21,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { let current_offset: usize = input_object.ast_node(db).text_range().start().into(); let current_node_len: usize = input_object.ast_node(db).text_range().len().into(); - errors.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { + diagnostics.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { ty: "input object".into(), name: name.into(), src: db.input_string(()).to_string(), @@ -58,7 +58,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { let current_node_len: usize = field.ast_node(db).unwrap().text_range().len().into(); - errors.push(ApolloDiagnostic::UniqueField(UniqueField { + diagnostics.push(ApolloDiagnostic::UniqueField(UniqueField { field: field_name.into(), src: db.input_string(()).to_string(), original_field: (prev_offset, prev_node_len).into(), @@ -74,5 +74,5 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { } } - errors + diagnostics } diff --git a/crates/apollo-compiler/src/validation/interfaces.rs b/crates/apollo-compiler/src/validation/interfaces.rs index 96bbd8adb..19fefa7aa 100644 --- a/crates/apollo-compiler/src/validation/interfaces.rs +++ b/crates/apollo-compiler/src/validation/interfaces.rs @@ -11,7 +11,7 @@ use crate::{ }; pub fn check(db: &dyn SourceDatabase) -> Vec { - let mut errors = Vec::new(); + let mut diagnostics = Vec::new(); // Interface definitions must have unique names. // @@ -25,7 +25,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { let current_offset: usize = interface.ast_node(db).text_range().start().into(); let current_node_len: usize = interface.ast_node(db).text_range().len().into(); - errors.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { + diagnostics.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { ty: "interface".into(), name: name.into(), src: db.input_string(()).to_string(), @@ -67,7 +67,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { .start() .into(); let len: usize = implements_interface.ast_node(db).text_range().len().into(); - errors.push(ApolloDiagnostic::RecursiveDefinition(RecursiveDefinition { + diagnostics.push(ApolloDiagnostic::RecursiveDefinition(RecursiveDefinition { message: format!("{} interface cannot implement itself", i_name), definition: (offset, len).into(), src: db.input_string(()).to_string(), @@ -95,7 +95,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { let current_offset: usize = field.ast_node(db).text_range().start().into(); let current_node_len: usize = field.ast_node(db).text_range().len().into(); - errors.push(ApolloDiagnostic::UniqueField(UniqueField { + diagnostics.push(ApolloDiagnostic::UniqueField(UniqueField { field: field_name.into(), src: db.input_string(()).to_string(), original_field: (prev_offset, prev_node_len).into(), @@ -134,7 +134,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { for undefined in diff { let offset = undefined.node.text_range().start().into(); let len: usize = undefined.node.text_range().len().into(); - errors.push(ApolloDiagnostic::UndefinedDefinition(UndefinedDefinition { + diagnostics.push(ApolloDiagnostic::UndefinedDefinition(UndefinedDefinition { ty: undefined.name.clone(), src: db.input_string(()).to_string(), definition: (offset, len).into(), @@ -169,7 +169,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { for undefined in transitive_diff { let offset = undefined.node.text_range().start().into(); let len: usize = undefined.node.text_range().len().into(); - errors.push(ApolloDiagnostic::TransitiveImplementedInterfaces( + diagnostics.push(ApolloDiagnostic::TransitiveImplementedInterfaces( TransitiveImplementedInterfaces { missing_interface: undefined.name.clone(), src: db.input_string(()).to_string(), @@ -212,7 +212,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { let super_offset = interface.ast_node(db).text_range().start().into(); let super_len: usize = interface.ast_node(db).text_range().len().into(); - errors.push(ApolloDiagnostic::MissingField(MissingField { + diagnostics.push(ApolloDiagnostic::MissingField(MissingField { ty: missing_field.name.clone(), src: db.input_string(()).to_string(), current_definition: (current_offset, current_len).into(), @@ -227,7 +227,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { } } - errors + diagnostics } #[cfg(test)] @@ -250,11 +250,11 @@ interface NamedEntity { "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); - assert_eq!(errors.len(), 1); + let diagnostics = ctx.validate(); + assert_eq!(diagnostics.len(), 1); - for error in errors { - println!("{}", error) + for diagnostic in diagnostics { + println!("{}", diagnostic) } } @@ -278,11 +278,11 @@ interface NamedEntity { } "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); - assert_eq!(errors.len(), 1); + let diagnostics = ctx.validate(); + assert_eq!(diagnostics.len(), 1); - for error in errors { - println!("{}", error) + for diagnostic in diagnostics { + println!("{}", diagnostic) } } @@ -300,11 +300,11 @@ interface NamedEntity implements NamedEntity { } "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); - assert_eq!(errors.len(), 1); + let diagnostics = ctx.validate(); + assert_eq!(diagnostics.len(), 1); - for error in errors { - println!("{}", error) + for diagnostic in diagnostics { + println!("{}", diagnostic) } } @@ -318,11 +318,11 @@ interface NamedEntity implements NewEntity { } "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); - assert_eq!(errors.len(), 1); + let diagnostic = ctx.validate(); + assert_eq!(diagnostic.len(), 1); - for error in errors { - println!("{}", error) + for diagnostic in diagnostic { + println!("{}", diagnostic) } } @@ -348,11 +348,11 @@ interface Image implements Resource & Node { } "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); - // assert_eq!(errors.len(), 1); + let diagnostics = ctx.validate(); + assert_eq!(diagnostics.len(), 1); - for error in errors { - println!("{}", error) + for diagnostic in diagnostics { + println!("{}", diagnostic) } } } diff --git a/crates/apollo-compiler/src/validation/mod.rs b/crates/apollo-compiler/src/validation/mod.rs index cb98fb6e8..1ec2c953f 100644 --- a/crates/apollo-compiler/src/validation/mod.rs +++ b/crates/apollo-compiler/src/validation/mod.rs @@ -22,34 +22,34 @@ pub mod unused_variables; pub struct Validator<'a> { db: &'a dyn SourceDatabase, - errors: Vec, + diagnostics: Vec, } impl<'a> Validator<'a> { pub fn new(db: &'a dyn SourceDatabase) -> Self { Self { db, - errors: Vec::new(), + diagnostics: Vec::new(), } } pub fn validate(&mut self) -> &mut [ApolloDiagnostic] { - self.errors.extend(self.db.syntax_errors()); + self.diagnostics.extend(self.db.syntax_errors()); - self.errors.extend(schema::check(self.db)); + self.diagnostics.extend(schema::check(self.db)); - self.errors.extend(scalars::check(self.db)); - self.errors.extend(enums::check(self.db)); - self.errors.extend(unions::check(self.db)); + self.diagnostics.extend(scalars::check(self.db)); + self.diagnostics.extend(enums::check(self.db)); + self.diagnostics.extend(unions::check(self.db)); - self.errors.extend(interfaces::check(self.db)); - self.errors.extend(directives::check(self.db)); - self.errors.extend(input_object::check(self.db)); + self.diagnostics.extend(interfaces::check(self.db)); + self.diagnostics.extend(directives::check(self.db)); + self.diagnostics.extend(input_object::check(self.db)); - self.errors.extend(operations::check(self.db)); - self.errors.extend(unused_variables::check(self.db)); + self.diagnostics.extend(operations::check(self.db)); + self.diagnostics.extend(unused_variables::check(self.db)); - self.errors.as_mut() + self.diagnostics.as_mut() } } diff --git a/crates/apollo-compiler/src/validation/operations.rs b/crates/apollo-compiler/src/validation/operations.rs index 6b6876977..f8c2ec2f1 100644 --- a/crates/apollo-compiler/src/validation/operations.rs +++ b/crates/apollo-compiler/src/validation/operations.rs @@ -8,7 +8,7 @@ use crate::{ // use crate::{diagnostics::ErrorDiagnostic, ApolloDiagnostic, SourceDatabase}; pub fn check(db: &dyn SourceDatabase) -> Vec { - let mut errors = Vec::new(); + let mut diagnostics = Vec::new(); // It is possible to have an unnamed (anonymous) operation definition only // if there is **one** operation definition. // @@ -32,7 +32,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { None }) .collect(); - errors.extend(missing_ident); + diagnostics.extend(missing_ident); } // Operation definitions must have unique names. @@ -47,7 +47,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { let current_offset: usize = op.ast_node(db).text_range().start().into(); let current_node_len: usize = op.ast_node(db).text_range().len().into(); - errors.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { + diagnostics.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { ty: "operation".into(), name: name.into(), src: db.input_string(()).to_string(), @@ -92,7 +92,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { } }) .collect(); - errors.extend(single_root_field); + diagnostics.extend(single_root_field); } // All query, subscription and mutation operations must be against legally @@ -131,7 +131,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { } }) .collect(); - errors.extend(unsupported_ops) + diagnostics.extend(unsupported_ops) } // // * query operation - query root operation @@ -166,7 +166,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { } }) .collect(); - errors.extend(unsupported_ops) + diagnostics.extend(unsupported_ops) } // * mutation operation - mutation root operation @@ -202,10 +202,10 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { } }) .collect(); - errors.extend(unsupported_ops) + diagnostics.extend(unsupported_ops) } - errors + diagnostics } #[cfg(test)] @@ -252,10 +252,10 @@ type Subscription { } "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); + let diagnostics = ctx.validate(); - for err in errors { - println!("{}", err) + for diagnostic in diagnostics { + println!("{}", diagnostic) } } @@ -281,8 +281,8 @@ type Query { } "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); - assert_eq!(errors.len(), 1); + let diagnostics = ctx.validate(); + assert_eq!(diagnostics.len(), 1); } #[test] @@ -307,7 +307,7 @@ type Query { } "#; let ctx = ApolloCompiler::new(input); - let errors = ctx.validate(); - assert!(errors.is_empty()); + let diagnostics = ctx.validate(); + assert!(diagnostics.is_empty()); } } diff --git a/crates/apollo-compiler/src/validation/scalars.rs b/crates/apollo-compiler/src/validation/scalars.rs index 656b1c9cb..8f52c47e3 100644 --- a/crates/apollo-compiler/src/validation/scalars.rs +++ b/crates/apollo-compiler/src/validation/scalars.rs @@ -6,7 +6,7 @@ use crate::{ const BUILT_IN_SCALARS: [&str; 5] = ["Int", "Float", "Boolean", "String", "ID"]; pub fn check(db: &dyn SourceDatabase) -> Vec { - let mut errors = Vec::new(); + let mut diagnostics = Vec::new(); // All built-in scalars must be omitted for brevity. for scalar in db.scalars().iter() { @@ -14,7 +14,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { let offset: usize = scalar.ast_node(db).text_range().start().into(); let len: usize = scalar.ast_node(db).text_range().len().into(); if BUILT_IN_SCALARS.contains(&name) { - errors.push(ApolloDiagnostic::BuiltInScalarDefinition( + diagnostics.push(ApolloDiagnostic::BuiltInScalarDefinition( BuiltInScalarDefinition { scalar: (offset, len).into(), src: db.input_string(()).to_string(), @@ -28,7 +28,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { .iter() .any(|directive| directive.name() == "specifiedBy") { - errors.push(ApolloDiagnostic::ScalarSpecificationURL( + diagnostics.push(ApolloDiagnostic::ScalarSpecificationURL( ScalarSpecificationURL { scalar: (offset, len).into(), src: db.input_string(()).to_string(), @@ -38,5 +38,5 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { } } - errors + diagnostics } diff --git a/crates/apollo-compiler/src/validation/schema.rs b/crates/apollo-compiler/src/validation/schema.rs index cdb71a308..d8149970e 100644 --- a/crates/apollo-compiler/src/validation/schema.rs +++ b/crates/apollo-compiler/src/validation/schema.rs @@ -7,14 +7,14 @@ use crate::{ }; pub fn check(db: &dyn SourceDatabase) -> Vec { - let mut errors = Vec::new(); + let mut diagnostics = Vec::new(); // A GraphQL schema must have a Query root operation. if db.schema().query(db).is_none() { if let Some(node) = db.schema().ast_node(db) { let offset: usize = node.text_range().start().into(); let len: usize = node.text_range().len().into(); - errors.push(ApolloDiagnostic::QueryRootOperationType( + diagnostics.push(ApolloDiagnostic::QueryRootOperationType( QueryRootOperationType { src: db.input_string(()).to_string(), schema: (offset, len).into(), @@ -38,7 +38,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { op_type.ast_node(db).unwrap().text_range().start().into(); let current_node_len: usize = op_type.ast_node(db).unwrap().text_range().len().into(); - errors.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { + diagnostics.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { name: name.clone(), ty: "root operation type definition".into(), src: db.input_string(()).to_string(), @@ -54,5 +54,5 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { } } - errors + diagnostics } diff --git a/crates/apollo-compiler/src/validation/unions.rs b/crates/apollo-compiler/src/validation/unions.rs index 522623766..edc3eb554 100644 --- a/crates/apollo-compiler/src/validation/unions.rs +++ b/crates/apollo-compiler/src/validation/unions.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use crate::{diagnostics::UniqueDefinition, values::UnionMember, ApolloDiagnostic, SourceDatabase}; pub fn check(db: &dyn SourceDatabase) -> Vec { - let mut errors = Vec::new(); + let mut diagnostics = Vec::new(); // A Union type must include one or more unique member types. // @@ -18,7 +18,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { let current_offset: usize = union_member.ast_node(db).text_range().start().into(); let current_node_len: usize = union_member.ast_node(db).text_range().len().into(); - errors.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { + diagnostics.push(ApolloDiagnostic::UniqueDefinition(UniqueDefinition { name: name.into(), ty: "union member".into(), src: db.input_string(()).to_string(), @@ -34,5 +34,5 @@ pub fn check(db: &dyn SourceDatabase) -> Vec { } } - errors + diagnostics }