Skip to content

Commit

Permalink
Remove case sensitivity for collocate fragment spreads
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNuc committed Aug 29, 2024
1 parent b573618 commit 04c3e5c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
10 changes: 1 addition & 9 deletions src/rule-must-colocate-fragment-spreads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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
Expand Down
42 changes: 26 additions & 16 deletions test/must-colocate-fragment-spreads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -48,47 +48,57 @@ 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
}\`;
graphql\`fragment foo2 on Page {
...foo1
}\`;
`,
`
`
graphql\`mutation {
page_unlike(data: $input) {
...component_fragment
Expand All @@ -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
Expand All @@ -139,7 +149,7 @@ ruleTester.run(
...component_fragment
}\`;
`,
options: [{allowNamedImports: true}],
options: [{ allowNamedImports: true }],
errors: [
{
message: unusedFieldsWarning('component_fragment'),
Expand All @@ -154,7 +164,7 @@ ruleTester.run(
...component_fragment
}\`;
`,
options: [{allowNamedImports: false}],
options: [{ allowNamedImports: false }],
errors: [
{
message: unusedFieldsWarning('component_fragment'),
Expand Down

0 comments on commit 04c3e5c

Please sign in to comment.