Skip to content

Commit

Permalink
rename all mention of 'errors' to 'diagnostics'
Browse files Browse the repository at this point in the history
  • Loading branch information
lrlna committed Jul 13, 2022
1 parent bac7c91 commit 4defb6a
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 97 deletions.
72 changes: 51 additions & 21 deletions crates/apollo-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ impl ApolloCompiler {
validator.validate().into()
}

// pub fn syntax_errors(&self) -> Vec<ApolloDiagnostic> {
// self.db.syntax_errors()
// }
pub fn syntax_errors(&self) -> Vec<ApolloDiagnostic> {
self.db.syntax_errors()
}

pub fn definitions(&self) -> Arc<Vec<ast::Definition>> {
self.db.definitions()
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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();

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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<String> = directives
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/apollo-compiler/src/validation/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
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."
)),
}));
}
Expand Down
8 changes: 4 additions & 4 deletions crates/apollo-compiler/src/validation/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
};

pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
let mut errors = Vec::new();
let mut diagnostics = Vec::new();

// An Enum type must define one or more unique enum values.
//
Expand All @@ -22,7 +22,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {

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(),
Expand All @@ -46,7 +46,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
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(),
Expand All @@ -55,5 +55,5 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
}
}

errors
diagnostics
}
8 changes: 4 additions & 4 deletions crates/apollo-compiler/src/validation/input_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
};

pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
let mut errors = Vec::new();
let mut diagnostics = Vec::new();

// Input Object Definitions must have unique names.
//
Expand All @@ -21,7 +21,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {

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(),
Expand Down Expand Up @@ -58,7 +58,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
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(),
Expand All @@ -74,5 +74,5 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
}
}

errors
diagnostics
}
56 changes: 28 additions & 28 deletions crates/apollo-compiler/src/validation/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};

pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
let mut errors = Vec::new();
let mut diagnostics = Vec::new();

// Interface definitions must have unique names.
//
Expand All @@ -25,7 +25,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {

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(),
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
.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(),
Expand Down Expand Up @@ -95,7 +95,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
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(),
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
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(),
Expand Down Expand Up @@ -169,7 +169,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
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(),
Expand Down Expand Up @@ -212,7 +212,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
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(),
Expand All @@ -227,7 +227,7 @@ pub fn check(db: &dyn SourceDatabase) -> Vec<ApolloDiagnostic> {
}
}

errors
diagnostics
}

#[cfg(test)]
Expand All @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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)
}
}
}
Loading

0 comments on commit 4defb6a

Please sign in to comment.