Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing in pathWithoutExt(filePath) does not work for Windows paths #12507

Closed
thewalla07 opened this issue Oct 29, 2019 · 4 comments
Closed

Parsing in pathWithoutExt(filePath) does not work for Windows paths #12507

thewalla07 opened this issue Oct 29, 2019 · 4 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion auto closed The bot closed this issue bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion formatter Relates to the formatters bundled with ESLint

Comments

@thewalla07
Copy link
Contributor

Environment is Windows 10 Version 1809

Environment Info:

Node version: v10.15.0
npm version: v6.4.1
Local ESLint version: v6.5.1 (Currently used)
Global ESLint version: Not found

What parser (default, Babel-ESLint, etc.) are you using? default (N/A)

Please show your full configuration: (N/A)

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

We run ESLint in Jenkins CI on a Windows host, and get the following type of output from failures
image

Currently, this means we do not know the filepath for the files with errors, only for the ones which passed.

This issue arises as a result of PR #11683. See below:

/**
* Returns a full file path without extension
* @param {string} filePath input file path
* @returns {string} file path without extension
* @private
*/
function pathWithoutExt(filePath) {
return path.posix.join(path.posix.dirname(filePath), path.basename(filePath, path.extname(filePath)));
}

The above code assumes that POSIX filePaths are used, meaning that the function does not work as expected in Windows.

npx eslint home_page.js --format junit

What did you expect to happen?
I expect that in the classname tag below I can see the full path to the file, without the file extension for visualization within Jenkins CI on a Windows host. i.e. C:\path\to\file

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite package="org.eslint" time="0" tests="1" errors="1" name="C:\git\projectdirectory\home_page.js">
<testcase time="0" name="org.eslint.prefer-const" classname="C:\git\projectdirectory\home_page"><failure message="&apos;msg&apos; is never reassigned. Use &apos;const&apos; instead."><![CDATA[line 7, col 17, Error - &apos;msg&apos; is never reassigned. Use &apos;const&apos; instead. (prefer-const)]]></failure></testcase>
</testsuite>
</testsuites>

What actually happened? Please include the actual, raw output from ESLint.
The function above parses filePath incorrectly on Windows. path.posix.dirname('C:\\path\\to\\file.js') resolves to . on Windows, as posix forces an assumption of POSIX style paths.

This results in the following XML, without the full path to the file in the classname attribute:

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite package="org.eslint" time="0" tests="1" errors="1" name="C:\git\projectdirectory\home_page.js">
<testcase time="0" name="org.eslint.prefer-const" classname="home_page"><failure message="&apos;msg&apos; is never reassigned. Use &apos;const&apos; instead."><![CDATA[line 7, col 17, Error - &apos;msg&apos; is never reassigned. Use &apos;const&apos; instead. (prefer-const)]]></failure></testcase>
</testsuite>
</testsuites>

Are you willing to submit a pull request to fix this bug?
Yes.

I would propose a fix where we do not use the posix specific implementation of Node's path library, and we let Node decide which implementation to use based on the underlying OS.

The main question arises in testing. In https://github.com/eslint/eslint/blob/master/tests/lib/cli-engine/formatters/junit.js is it possible to run a test with both POSIX and Windows style paths? My suggestion would be to have the test cases adapt to the current OS, but opinions would be valued here.

@thewalla07 thewalla07 added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Oct 29, 2019
thewalla07 added a commit to thewalla07/eslint that referenced this issue Oct 29, 2019
This commit aims to fix the issues described in eslint#12507 by removing the
assumption that POSIX style filePaths are supplied by messages.

The tests for this are also updated to run on both Windows and POSIX
based systems. The results can be seen by running ESLint with the JUnit
formatter on a Windows system.

Full details can be seen in the issue mentioned above.
thewalla07 added a commit to thewalla07/eslint that referenced this issue Oct 30, 2019
This commit aims to fix the issues described in eslint#12507 by removing the
assumption that POSIX style filePaths are supplied by messages.

The tests for this are also updated to run on both Windows and POSIX
based systems. The results can be seen by running ESLint with the JUnit
formatter on a Windows system.

Full details can be seen in the issue mentioned above.
@thewalla07
Copy link
Contributor Author

Working on this, created PR to fix this issue

@kaicataldo kaicataldo added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion formatter Relates to the formatters bundled with ESLint and removed triage An ESLint team member will look at this issue soon labels Nov 1, 2019
@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label Dec 2, 2019
@eslint-deprecated
Copy link

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that issues failing to reach accepted status after 21 days tend to
never be accepted, and as such, we close those issues.
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

@thewalla07
Copy link
Contributor Author

@kaicataldo any chance this will be reopened, or should the associated PR be abandoned?

@kaicataldo
Copy link
Member

Thanks for the ping. Let me see if I can get some eyes on this PR!

@kaicataldo kaicataldo reopened this Dec 9, 2019
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 22, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jun 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion auto closed The bot closed this issue bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion formatter Relates to the formatters bundled with ESLint
Projects
None yet
Development

No branches or pull requests

2 participants