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: don't warn usage of stylelint 14.x-label #278

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/server/modules/__tests__/old-stylelint-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,32 @@ describe('OldStylelintWarningModule', () => {
expect(mockContext.connection.window.showWarningMessage).not.toHaveBeenCalled();
});

test('if Stylelint version is 14.x with a label, should not warn', async () => {
getWorkspaceFolder.mockResolvedValue('/path');
findPackageRoot.mockResolvedValue('/path/node_modules/stylelint');
mockContext.resolveStylelint.mockResolvedValue({
stylelint: {},
resolvedPath: '/path/node_modules/stylelint',
});
mockContext.options.validate = ['bar'];
fs.readFile.mockResolvedValue('{"version": "14.0.0-sdk"}');

const module = new OldStylelintWarningModule(getParams(true));

module.onInitialize(/** @type {any} */ ({ capabilities: {} }));

module.onDidRegisterHandlers();

const handler = mockContext.documents.onDidOpen.mock.calls[0][0];

await handler({
document: { uri: 'foo', languageId: 'bar' },
});

expect(mockContext.resolveStylelint).toHaveBeenCalledTimes(1);
expect(mockContext.connection.window.showWarningMessage).not.toHaveBeenCalled();
});

test('without openDocument support, if Stylelint version is less than 14.x, should warn and provide link to migration guide', async () => {
getWorkspaceFolder.mockResolvedValue('/path');
findPackageRoot.mockResolvedValue('/path/node_modules/stylelint');
Expand Down
14 changes: 11 additions & 3 deletions src/server/modules/old-stylelint-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,18 @@ class OldStylelintWarningModule {

const stylelintVersion = await this.#getStylelintVersion(document);

if (!stylelintVersion) {
return undefined;
}

try {
return stylelintVersion && semver.lt(stylelintVersion, '14.0.0')
? stylelintVersion
: undefined;
const coerced = semver.coerce(stylelintVersion);

if (!coerced) {
throw new Error(`Could not coerce version "${stylelintVersion}"`);
}

return semver.lt(coerced, '14.0.0') ? stylelintVersion : undefined;
} catch (error) {
this.#logger?.debug('Stylelint version could not be parsed', {
uri: document.uri,
Expand Down