Skip to content

Commit

Permalink
fix: don't warn usage of stylelint 14.x-label (#278)
Browse files Browse the repository at this point in the history
Fixes #275
  • Loading branch information
adalinesimonian committed Oct 27, 2021
1 parent 1933a36 commit 5445b1c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
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

0 comments on commit 5445b1c

Please sign in to comment.