diff --git a/.changeset/metal-pillows-report.md b/.changeset/metal-pillows-report.md new file mode 100644 index 0000000000..4e217cb085 --- /dev/null +++ b/.changeset/metal-pillows-report.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: false negatives on second run for cache and `severity` option diff --git a/lib/__tests__/standalone-cache.test.js b/lib/__tests__/standalone-cache.test.js index 45c629041c..7766a5f610 100644 --- a/lib/__tests__/standalone-cache.test.js +++ b/lib/__tests__/standalone-cache.test.js @@ -119,6 +119,30 @@ describe('standalone cache', () => { expect(cache.getKey(newFileDest)).toBeUndefined(); }); + it('warning files are not cached', async () => { + await fs.copyFile(invalidFile, newFileDest); + + const { errored, results } = await standalone( + getConfig({ + config: { + rules: { 'block-no-empty': [true, { severity: 'warning' }] }, + }, + }), + ); + + expect(errored).toBe(false); + + // cache is discarded because config changed + expect(results.some((file) => isChanged(file, validFile))).toBe(true); + expect(results.some((file) => isChanged(file, newFileDest))).toBe(true); + + const { cache } = fCache.createFromFile(expectedCacheFilePath); + + expect(typeof cache.getKey(validFile)).toBe('object'); + expect(cache.getKey(validFile)).toBeTruthy(); + expect(cache.getKey(newFileDest)).toBeUndefined(); + }); + it('files with syntax errors are not cached', async () => { await fs.copyFile(syntaxErrorFile, newFileDest); diff --git a/lib/lintPostcssResult.js b/lib/lintPostcssResult.js index 23d0f75e5f..0cde1a0af9 100644 --- a/lib/lintPostcssResult.js +++ b/lib/lintPostcssResult.js @@ -20,6 +20,7 @@ function lintPostcssResult(stylelintOptions, postcssResult, config) { postcssResult.stylelint.customMessages = {}; postcssResult.stylelint.ruleMetadata = {}; postcssResult.stylelint.stylelintError = false; + postcssResult.stylelint.stylelintWarning = false; postcssResult.stylelint.quiet = config.quiet; postcssResult.stylelint.config = config; diff --git a/lib/lintSource.js b/lib/lintSource.js index bd101d4a61..01029a2070 100644 --- a/lib/lintSource.js +++ b/lib/lintSource.js @@ -116,6 +116,7 @@ function createEmptyStylelintPostcssResult() { disabledRanges: {}, ignored: true, stylelintError: false, + stylelintWarning: false, }; } diff --git a/lib/standalone.js b/lib/standalone.js index b74659ab7d..5f2781ab91 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -216,7 +216,10 @@ async function standalone({ cache: useCache, }); - if (postcssResult.stylelint.stylelintError && useCache) { + if ( + (postcssResult.stylelint.stylelintError || postcssResult.stylelint.stylelintWarning) && + useCache + ) { debug(`${absoluteFilepath} contains linting errors and will not be cached.`); stylelint._fileCache.removeEntry(absoluteFilepath); } diff --git a/lib/utils/report.js b/lib/utils/report.js index a84ae5e808..befcd739c5 100644 --- a/lib/utils/report.js +++ b/lib/utils/report.js @@ -78,6 +78,10 @@ module.exports = function report(problem) { result.stylelint.stylelintError = true; } + if (!result.stylelint.stylelintWarning && severity === 'warning') { + result.stylelint.stylelintWarning = true; + } + /** @type {import('stylelint').WarningOptions} */ const warningProperties = { severity, diff --git a/types/stylelint/index.d.ts b/types/stylelint/index.d.ts index 1a12c44f81..bb1c7681ab 100644 --- a/types/stylelint/index.d.ts +++ b/types/stylelint/index.d.ts @@ -104,6 +104,7 @@ declare module 'stylelint' { disabledWarnings?: DisabledWarning[]; ignored?: boolean; stylelintError?: boolean; + stylelintWarning?: boolean; disableWritingFix?: boolean; config?: Config; ruleDisableFix?: boolean;