fix: ensure absolute paths are handled correctly with --file
option in next lint
command for lint-staged
compatibility
#69220
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello😊 Thanks for having attention to this issue.
What?
Fixed a bug.
The
next lint
command's--file
option was intended to allow users to lint specific files directly by specifying their paths. However, it only worked with relative paths and did not handle absolute paths correctly. This limitation hindered the flexibility and usability of the linting process.Furthermore,
lint-staged
returns absolute paths when running lint commands on staged files. Without proper handling of these absolute paths, linting was not performed correctly, leading to issues in automated linting workflows.Why?
Environment(results by
next info
)Steps to Reproduce
Make a
js
orjsx
file like below. this makes ESLint error namedno-unused-vars
Run
eslint
andnext lint
to the same file.See screenshot below.
eslint
command works correctly with absolute path. but,next lint
command doesn't work correctly with absolute path.Code Details
pathsToLint
pathsToLint
gets an empty array[]
whenfilesToLint
array is[ 'D:\\Cloud_Git\\web-blog\\src\\app\\test.jsx' ]
passed by--file
option from CLI.The
reduce
Functiond
) infilesToLint
, it combines it withbaseDir
to createcurrDir
.existsSync(currDir)
.res
), and if it does exist, it adds it.Cause of the Issue
join(baseDir, d)
:join
function is used to combine file paths and directory paths.baseDir
isD:\Cloud_Git\web-blog
, thencurrDir
becomesD:\Cloud_Git\web-blog\D:\Cloud_Git\web-blog\src\app\test.jsx
, creating an incorrect path.existsSync(currDir)
:D:\Cloud_Git\web-blog\D:\Cloud_Git\web-blog\src\app\test.jsx
),existsSync
determines that this path does not exist, so it does not add it to theres
array.pathsToLint
ends up being an empty array[]
.How? (Solution)
The code should be modified to use the file path as-is, without combining it with
baseDir
. If a file path is provided, it should be directly included inpathsToLint
.--file
option to properly handle absolute paths. This involved ensuring that absolute paths are correctly interpreted and used by the linting command.The code below is the built code of the modified version.
Closes: I tried to find but No related Issues.
Fixes: I tried to find but No related Issues.