Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chris Potter <chris@reactioncommerce.com>
- Loading branch information
Chris Potter
committed
Jun 12, 2019
1 parent
08052d4
commit 777df00
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
.reaction/graphql-linter/rules/description_fields_capitalized.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.DescriptionsAreCapitalized = DescriptionsAreCapitalized; | ||
|
||
var _validation_error = require("graphql-schema-linter/lib/validation_error"); | ||
var schema = require('graphql/utilities/buildASTSchema'); | ||
|
||
function DescriptionsAreCapitalized(configuration, context) { | ||
return { | ||
FieldDefinition(node, key, parent, path, ancestors) { | ||
var description = schema.getDescription(node, { | ||
commentDescriptions: configuration.getCommentDescriptions(), | ||
}) | ||
if (description && description[0] === description[0].toUpperCase()) { | ||
return; | ||
} | ||
|
||
const fieldName = node.name.value; | ||
const parentName = ancestors[ancestors.length - 1].name.value; | ||
|
||
context.reportError( | ||
new _validation_error.ValidationError( | ||
'descriptions-are-capitalized', | ||
`The description for field \`${parentName}.${fieldName}\` should be capitalized.`, | ||
[node] | ||
) | ||
); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters