eslint-plugin-relay
Advanced tools
Comparing version
{ | ||
"name": "eslint-plugin-relay", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"description": "ESLint plugin for Relay.", | ||
@@ -5,0 +5,0 @@ "main": "eslint-plugin-relay", |
@@ -24,4 +24,4 @@ # eslint-plugin-relay [](https://travis-ci.org/relayjs/eslint-plugin-relay) [](http://badge.fury.io/js/eslint-plugin-relay) | ||
'relay/generated-flow-types': 'warn', | ||
'no-future-added-value': 'warn', | ||
'unused-fields': 'warn' | ||
'relay/no-future-added-value': 'warn', | ||
'relay/unused-fields': 'warn' | ||
}, | ||
@@ -28,0 +28,0 @@ plugins: ['relay'] |
@@ -22,4 +22,4 @@ /** | ||
if (node.kind === 'Field' && !ignoreLevel) { | ||
const fieldName = (node.alias || node.name).value; | ||
fieldNames[fieldName] = true; | ||
const nameNode = node.alias || node.name; | ||
fieldNames[nameNode.value] = nameNode; | ||
} | ||
@@ -53,3 +53,3 @@ if (node.kind === 'OperationDefinition') { | ||
walkAST(graphQLAst); | ||
return Object.keys(fieldNames); | ||
return fieldNames; | ||
} | ||
@@ -135,21 +135,15 @@ | ||
const queriedFields = getGraphQLFieldNames(graphQLAst); | ||
const unusedFields = queriedFields.filter( | ||
field => !foundMemberAccesses[field] && !isPageInfoField(field) | ||
); | ||
if (unusedFields.length === 0) { | ||
return; | ||
for (const field in queriedFields) { | ||
if (!foundMemberAccesses[field] && !isPageInfoField(field)) { | ||
context.report({ | ||
node: templateLiteral, | ||
loc: utils.getLoc(context, templateLiteral, queriedFields[field]), | ||
message: | ||
`This queries for the field \`${field}\` but this file does ` + | ||
'not seem to use it directly. If a different file needs this ' + | ||
'information that file should export a fragment and colocate ' + | ||
'the query for the data with the usage.' | ||
}); | ||
} | ||
} | ||
const whatsUnused = | ||
unusedFields.length === 1 | ||
? 'field `' + unusedFields[0] + '`' | ||
: 'fields `' + unusedFields.join('`, `') + '`'; | ||
context.report( | ||
templateLiteral, | ||
'It looks like this queries for the ' + | ||
whatsUnused + | ||
' but this ' + | ||
'file is not using it directly. If a different file needs this ' + | ||
'information that file should export a fragment and colocate the ' + | ||
'query for the data with the usage.' | ||
); | ||
}); | ||
@@ -156,0 +150,0 @@ }, |
41353
-0.31%1122
-0.53%