Skip to content

Commit

Permalink
Fix false negatives on second run for cache and severity option (#6384
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kimulaco committed Oct 6, 2022
1 parent 59d6a3f commit 168b71a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/metal-pillows-report.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: false negatives on second run for cache and `severity` option
24 changes: 24 additions & 0 deletions lib/__tests__/standalone-cache.test.js
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions lib/lintPostcssResult.js
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions lib/lintSource.js
Expand Up @@ -116,6 +116,7 @@ function createEmptyStylelintPostcssResult() {
disabledRanges: {},
ignored: true,
stylelintError: false,
stylelintWarning: false,
};
}

Expand Down
5 changes: 4 additions & 1 deletion lib/standalone.js
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/report.js
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions types/stylelint/index.d.ts
Expand Up @@ -104,6 +104,7 @@ declare module 'stylelint' {
disabledWarnings?: DisabledWarning[];
ignored?: boolean;
stylelintError?: boolean;
stylelintWarning?: boolean;
disableWritingFix?: boolean;
config?: Config;
ruleDisableFix?: boolean;
Expand Down

0 comments on commit 168b71a

Please sign in to comment.