From 04c3e5ceeee1b5df09e748c20b66189b08785772 Mon Sep 17 00:00:00 2001 From: MartinNuc Date: Thu, 29 Aug 2024 20:24:56 +0200 Subject: [PATCH] Remove case sensitivity for collocate fragment spreads --- src/rule-must-colocate-fragment-spreads.js | 10 +----- test/must-colocate-fragment-spreads.js | 42 +++++++++++++--------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/rule-must-colocate-fragment-spreads.js b/src/rule-must-colocate-fragment-spreads.js index e9c3d91..1619751 100644 --- a/src/rule-must-colocate-fragment-spreads.js +++ b/src/rule-must-colocate-fragment-spreads.js @@ -103,10 +103,6 @@ function getGraphQLFragmentSpreads(graphQLAst) { return fragmentSpreads; } -function isFirstLetterUppercase(word) { - return /^\p{Lu}/u.test(word); -} - function getGraphQLFragmentDefinitionName(graphQLAst) { let name = null; visit(graphQLAst, { @@ -171,11 +167,7 @@ function checkColocation(context) { ImportDeclaration(node) { if (node.importKind === 'value') { node.specifiers.forEach(specifier => { - if ( - allowNamedImports && - specifier.imported && - isFirstLetterUppercase(specifier.imported.name) - ) { + if (allowNamedImports && specifier.imported) { foundImportedModules.push({ type: 'namedImport', value: specifier.imported.name diff --git a/test/must-colocate-fragment-spreads.js b/test/must-colocate-fragment-spreads.js index a101eff..6877508 100644 --- a/test/must-colocate-fragment-spreads.js +++ b/test/must-colocate-fragment-spreads.js @@ -14,7 +14,7 @@ const RuleTester = eslint.RuleTester; const ruleTester = new RuleTester({ parser: require.resolve('babel-eslint'), - parserOptions: {ecmaVersion: 6, sourceType: 'module'} + parserOptions: { ecmaVersion: 6, sourceType: 'module' } }); function unusedFieldsWarning(fragment) { @@ -48,39 +48,49 @@ ruleTester.run( ...component_fragment }\`; `, - options: [{allowNamedImports: true}] + options: [{ allowNamedImports: true }] }, - ` + { + code: ` + import { useHook } from '@some/module'; + + graphql\`fragment foo on Page { + ...useHook + }\`; + `, + options: [{ allowNamedImports: true }] + }, + ` const Component = require('../shared/component.js'); graphql\`fragment foo on Page { ...component_fragment }\`; `, - ` + ` const Component = import('../shared/component.js'); graphql\`fragment foo on Page { ...component_fragment }\`; `, - ` + ` import { Component } from './nested/componentModule.js'; graphql\`fragment foo on Page { ...componentModule_fragment }\`; `, - ` + ` import { Component } from './component-module.js'; graphql\`fragment foo on Page { ...componentModuleFragment }\`; `, - ` + ` import { Component } from './component-module.js'; graphql\`query Root { ...componentModuleFragment }\`; `, - ` + ` graphql\`fragment foo1 on Page { name }\`; @@ -88,7 +98,7 @@ ruleTester.run( ...foo1 }\`; `, - ` + ` graphql\`mutation { page_unlike(data: $input) { ...component_fragment @@ -97,23 +107,23 @@ ruleTester.run( } }\` `, - ` + ` graphql\`fragment foo on Page { ...Fragment @relay(mask: false) }\`; `, - ` + ` graphql\`fragment foo on Page { ...Fragment @module(name: "ComponentName.react") }\`; `, - '\ + '\ const getOperation = (reference) => {\ return import(`./src/__generated__/${reference}`);\ };\ ', - '\ + '\ const getOperation = (reference) => {\ return import(reference);\ };\ ', - ` + ` graphql\`fragment foo on Page { # eslint-disable-next-line @productboard/relay/must-colocate-fragment-spreads ...unused1 @@ -139,7 +149,7 @@ ruleTester.run( ...component_fragment }\`; `, - options: [{allowNamedImports: true}], + options: [{ allowNamedImports: true }], errors: [ { message: unusedFieldsWarning('component_fragment'), @@ -154,7 +164,7 @@ ruleTester.run( ...component_fragment }\`; `, - options: [{allowNamedImports: false}], + options: [{ allowNamedImports: false }], errors: [ { message: unusedFieldsWarning('component_fragment'),