-
-
Notifications
You must be signed in to change notification settings - Fork 939
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
Fix ignoreFiles
being evaluated case-sensitively on Windows
#5594
Comments
Thanks for the report. Labelling as ready to implement. |
stylelint is using process.cwd() , which can potentially return lower-case in environments. I think we should avoid using process.cwd() direct values or indexing keys. It creates a lot of potential issues with caching. Here we can see it can store the same config twice with using upper-case drive path in Case: ./.stylelintrc.json {
"processors": ["stylelint-processor-styled-components"],
"extends": ["stylelint-config-standard-scss", "stylelint-config-styled-components"],
"rules": {
"selector-type-case": ["lower", { "ignoreTypes": ["/^\\$\\w+/"] }],
"selector-type-no-unknown": [true, { "ignoreTypes": ["/-styled-mixin/", "/^\\$\\w+/"] }],
"value-keyword-case": ["lower", { "ignoreKeywords": ["dummyValue"] }],
"declaration-colon-newline-after": null
},
"overrides": [{
"files": ["./**/*.js"],
"customSyntax": "postcss-scss"
}]
} ./foo.js const foo = styled.div`
.bar {
line-height: 1em // CssSyntaxError missing semi-colon
}
`; ./stylelint-runner-exception.js import { logResult, logError } from './lintLogger';
await stylelint.lint({ codeFilename: 'C:\\Path\\to\\project\foo.js' }).then(logResult).catch(logError);
// exception from stylelint-processor-styled-component in logs e.g. Cannot access property "3" of undefined... instead of reporting missing semi-colon
// debugging details:
// calls getConfigForFile(stylelint._options.configFile); // searchPath defaulted to process.cwd()
// calls augmentConfigFull(config); // See https://github.com/stylelint/stylelint/blob/29acc54ef08174a6b0caa69d093b9e3bd3ba897f/lib/augmentConfig.js#L82
// - calls addProcessorFunctions, processorCache misses.
// - Require and add processor to cache from config
// linting begins with lintSource
// will fetch config again to check for ignore files. See line https://github.com/stylelint/stylelint/blob/a7d6e5651a7e43a7978c18798fa88e4fc2473c8f/lib/lintSource.js#L51
// calls getConfigForFile((stylelint._options.configFile || inputFilePath); // configFile is undefined
// calls augmentConfigFull(config);
// - calls addProcessorFunctions, processorCache misses.
// - Require and add processor to cache from config
console.log(Array.from(stylelint._specifiedConfigCache.keys())) // has both upper and lower case caches. Each config has their own caches, processors, plugins, etc!
/*
* [
* 'c:\\Path\\to\\project\\.stylelintrc.json',
* 'C:\\Path\\to\\project\\.stylelintrc.json'
* ]
*/
console.log(stylelint._specifiedConfigCache.get('C:\\Path\\to\\project\.stylelintrc.json') === stylelint._specifiedConfigCache.get('c:\\Path\\to\\project\.stylelintrc.json'));
// false ./stylelint-runner-no-exeception1.js import { logResult, logError } from './lintLogger';
await stylelint.lint({ configFile: 'C:\\Path\\to\\project\.stylelintrc.json', codeFilename: 'C:\\Path\\to\\project\foo.js' }).then(logResult).catch(logError);;
// logs the semi-colon error. Works!
console.log(Array.from(stylelint._specifiedConfigCache.keys()))
/*
* [
* 'C:\\Path\\to\\project\\.stylelintrc.json'
* ]
*/ ./stylelint-runner-no-exception2.js import { logResult, logError } from './lintLogger';
await stylelint.lint({ codeFilename: 'c:\\Path\\to\\project\foo.js' }).then(logResult).catch(logError);
// also works
console.log(Array.from(stylelint._specifiedConfigCache.keys()))
/*
* [
* 'c:\\Path\\to\\project\\.stylelintrc.json'
* ]
*/ |
This issue is older than one month. Please ask before opening a pull request, as it may no longer be relevant. |
What about using an util to normalize the paths? e.g. return path
.resolve(folder)
.split(path.sep)
.join("/")
.replace(/^([a-z]):/, (_, driveLetter) => driveLetter.toLowerCase() + ":"); |
Can we use Line 186 in 5d907dd
|
Nop it doesn't lowercase the drive letter. related: nodejs/node-v0.x-archive@016e084 |
Can we reproduce this bug in our CI? If yes, it seems that we can write a patch using |
// TODO: Remove once fixed upstream
test('should upper-case drive letters on Windows (Stylelint bug #5594)', async () => { |
Nice. It seems possible to bring the test case from |
Tested on Stylelint 14
ignoreFiles
is evaluated case-sensitively on Windows, leading to a few issues downstream in vscode-stylelint. I stumbled into this while migrating from the deprecated vscode-languageserver URI API to the new vscode-uri API. The new API generates lowercase drive letters for paths instead of uppercase letters as the old API did.Let's say the project is in
C:\Users\Adaline\Code\my-project
. Suppose that there is a file namedshould-be-ignored.css
and the Stylelint config is:If you pass
C:\Users\Adaline\Code\my-project\should-be-ignored.css
to Stylelint, it ignores the file, as it should. But if you passc:\...\should-be-ignored.css
or any other case of any part of the path, Stylelint doesn't ignore it even though it can read the file correctly using the differently-cased path.Node.js's API's behaviour, for reference, correctly sees these paths as equal on Windows:
I haven't checked any other config properties or functionality, so I'm unaware if there are other cases of this behaviour elsewhere in the project.
The text was updated successfully, but these errors were encountered: