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

Fix false negatives on second run for cache and severity option #6384

Merged
merged 10 commits into from Oct 6, 2022
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