Skip to content

Conversation

yoavain-sundaysky
Copy link
Contributor

@yoavain-sundaysky yoavain-sundaysky commented May 2, 2024

Fix Issue #2276

  • Convert source.filePath to its absolute path to be comparable to importPath/filePath on Windows

🚨 IMPORTANT: Please do not create a Pull Request without creating an issue first.

Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of
the pull request.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant
motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Screenshots/Sandbox (if appropriate/relevant):

Adding links to sandbox or providing screenshots can help us understand more about this PR and take
action on it as appropriate

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can
reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Test Environment:

  • OS:
  • @graphql-eslint/...:
  • NodeJS:

Checklist:

  • I have followed the
    CONTRIBUTING doc and the
    style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose
the solution you did and what alternatives you considered, etc...

@changeset-bot
Copy link

changeset-bot bot commented May 2, 2024

🦋 Changeset detected

Latest commit: 59d7783

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphql-eslint/eslint-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@yoavain-sundaysky
Copy link
Contributor Author

Anyone can review and merge this?

@yoavain-sundaysky
Copy link
Contributor Author

Hey @dotansimha,
Any chance you make this happen?

Copy link
Contributor

@dimaMachina dimaMachina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yoavain-sundaysky, I just set up running Windows on CI and fixed some issues with Windows. Could you add a test with your change?

* Convert `source.filePath` to its absolute path to be comparable to importPath/filePath on Windows
* Convert `source.filePath` to its absolute path to be comparable to importPath/filePath on Windows
@yoavain-sundaysky yoavain-sundaysky force-pushed the fix-2276-require-import-fragment-on-windows branch from ebea6a5 to fabf3c3 Compare November 15, 2024 09:43
@yoavain
Copy link
Contributor

yoavain commented Nov 15, 2024

Hi @yoavain-sundaysky, I just set up running Windows on CI and fixed some issues with Windows. Could you add a test with your change?

Sure, I'll do that

yoavain and others added 2 commits November 15, 2024 15:41
…n-windows

Add require-import-fragment test for relative path on Windows with both delimiter types in input
@yoavain-sundaysky
Copy link
Contributor Author

Added tests.
Had to be creative to create a failing test without the fix.
Tests check that it doesn't matter which delimiter is used, the comparison in working

);

const hasInSiblings = fragmentsFromSiblings.some(
source => source.filePath === importPath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously you added path.resolve(source.filePath) but why?

source.filePath comes from graphql-config and contains slashes according to user's os

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too, but when I printed out the filePath in fragmentsFromSiblings by adding

console.log(fragmentsFromSiblings.map(x=>x.filePath));

I saw this syntax. On Windows.

C:/Dev/my-project/client/logic/experiments/experimentFragment.graphql

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange because I added console log on ci and get backslash on windows

Copy link
Contributor

@dimaMachina dimaMachina Nov 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I commented d9f5b4e and got

IMG_2887

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder maybe it happens when you specify glob syntax for documents? e.g. **/*.gql

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I was right, specifying glob pattern returns forward slash always

image

}

const fragmentInSameFile = fragmentsFromSiblings.some(
source => source.filePath === filePath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, source.filePath comes from graphql-config and contains slashes according to user's OS, and filePath is ESLint's context.filename which also contains slashed according user's OS

Comment on lines -18 to +23
return source;
return {
...source,
// When using glob pattern e.g. `**/*.gql` location contains always forward slashes even on
// Windows
location: path.resolve(location),
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yoavain-sundaysky this is better fix, so other rules will get always os specific slash

@dimaMachina dimaMachina merged commit 3b35bae into graphql-hive:master Nov 16, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants