Skip to content

Commit 533d123

Browse files
authored
Fix issues with Windows paths (#442)
1 parent 1d85025 commit 533d123

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

.changeset/tall-keys-divide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
Fix issues with Windows paths

packages/plugin/src/rules/unique-fragment-name.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GraphQLESLintRule } from '../types';
2-
import { requireSiblingsOperations } from '../utils';
2+
import { normalizePath, requireSiblingsOperations } from '../utils';
33

44
const UNIQUE_FRAGMENT_NAME = 'UNIQUE_FRAGMENT_NAME';
55

@@ -61,7 +61,9 @@ const rule: GraphQLESLintRule<[], false> = {
6161
const siblingFragments = siblings.getFragment(fragmentName);
6262

6363
const conflictingFragments = siblingFragments.filter(
64-
f => f.document.name?.value === fragmentName && f.filePath !== context.getFilename()
64+
f =>
65+
f.document.name?.value === fragmentName &&
66+
normalizePath(f.filePath) !== normalizePath(context.getFilename())
6567
);
6668

6769
if (conflictingFragments.length > 0) {

packages/plugin/src/rules/unique-operation-name.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GraphQLESLintRule } from '../types';
2-
import { requireSiblingsOperations } from '../utils';
2+
import { normalizePath, requireSiblingsOperations } from '../utils';
33

44
const UNIQUE_OPERATION_NAME = 'UNIQUE_OPERATION_NAME';
55

@@ -65,7 +65,9 @@ const rule: GraphQLESLintRule<[], false> = {
6565
const siblingOperations = siblings.getOperation(operationName);
6666

6767
const conflictingOperations = siblingOperations.filter(
68-
f => f.document.name?.value === operationName && f.filePath !== context.getFilename()
68+
f =>
69+
f.document.name?.value === operationName &&
70+
normalizePath(f.filePath) !== normalizePath(context.getFilename())
6971
);
7072

7173
if (conflictingOperations.length > 0) {

packages/plugin/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ export function checkForEslint(token: Token, rawNode: DocumentNode): boolean {
104104
if (token.kind !== 'Comment') {
105105
return false;
106106
}
107-
const string = rawNode.loc?.source.body.substring(token.start+1, token.start+8);
107+
const string = rawNode.loc?.source.body.substring(token.start + 1, token.start + 8);
108108
if (string.toLocaleLowerCase().includes('eslint')) {
109109
return true;
110110
}
111111
return false;
112112
}
113+
114+
export const normalizePath = (path: string): string => (path || '').replace(/\\/g, '/');

0 commit comments

Comments
 (0)