Skip to content

Commit

Permalink
refactor: check more types, conform to lsp spec
Browse files Browse the repository at this point in the history
- Check types for JS files in test and scripts directories
- Update diagnostic code and tests to use codeDescription instead of
  code object type per microsoft/vscode-languageserver-node#601 and LSP
  3.16
  • Loading branch information
adalinesimonian committed Oct 6, 2021
1 parent 8c43e28 commit 82a8a90
Show file tree
Hide file tree
Showing 25 changed files with 309 additions and 284 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const config = {
},
rules: {
'node/no-missing-require': ['error', { allowModules: ['vscode'] }],
'require-jsdoc': 'error',
},
};

Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
},
"devDependencies": {
"@stylelint/prettier-config": "^2.0.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.0.1",
"@types/lodash": "^4.14.151",
"@types/path-is-inside": "^1.0.0",
Expand Down
1 change: 1 addition & 0 deletions scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const rootDir = path.resolve(__dirname, '..');

const args = new Set(process.argv.slice(2));

/** @returns {Promise<void>} */
async function bundle() {
const entryPoints = ['src/index.js', 'src/server.js'];

Expand Down
10 changes: 8 additions & 2 deletions scripts/stylelint-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ if (!version) {

const args = new Set(process.argv.slice(2));

/** Checks if the Stylelint types file is up to date. */
/**
* Checks if the Stylelint types file is up to date.
* @returns {Promise<void>}
*/
const checkTypesVersion = async () => {
try {
const downloadedVersion = (await fs.readFile(typesVersionPath, 'utf8'))?.trim();
Expand All @@ -44,7 +47,10 @@ const checkTypesVersion = async () => {
}
};

/** Downloads the stylelint types file for the currently installed version of Stylelint. */
/**
* Downloads the stylelint types file for the currently installed version of Stylelint.
* @returns {Promise<void>}
*/
const downloadTypes = async () => {
const typesURL = `https://raw.githubusercontent.com/stylelint/stylelint/${version}/types/stylelint/index.d.ts`;

Expand Down
16 changes: 8 additions & 8 deletions src/warnings-to-diagnostics.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ module.exports = function stylelintWarningToVscodeDiagnostic(
*/
const ruleDocUrl = ruleDocUrlProvider(warning.rule);

return Diagnostic.create(
const diagnostic = Diagnostic.create(
Range.create(position, position),
warning.text,
DiagnosticSeverity[warning.severity === 'warning' ? 'Warning' : 'Error'],
// @ts-expect-error -- It is a types bug. DiagnosticCode exists but is not accepted in create argument.
ruleDocUrl
? {
value: warning.rule,
target: ruleDocUrl,
}
: warning.rule,
warning.rule,
'stylelint',
);

if (ruleDocUrl) {
diagnostic.codeDescription = { href: ruleDocUrl };
}

return diagnostic;
};
54 changes: 27 additions & 27 deletions test/lib/stylelint-vscode/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
exports[`stylelintVSCode() should be resolved with diagnostics when it lints CSS successfully 1`] = `
Array [
Object {
"code": Object {
"target": "https://stylelint.io/user-guide/rules/string-quotes",
"value": "string-quotes",
"code": "string-quotes",
"codeDescription": Object {
"href": "https://stylelint.io/user-guide/rules/string-quotes",
},
"message": "Expected single quotes (string-quotes)",
"range": Object {
Expand All @@ -22,9 +22,9 @@ Array [
"source": "stylelint",
},
Object {
"code": Object {
"target": "https://stylelint.io/user-guide/rules/indentation",
"value": "indentation",
"code": "indentation",
"codeDescription": Object {
"href": "https://stylelint.io/user-guide/rules/indentation",
},
"message": "Expected indentation of 0 tabs (indentation)",
"range": Object {
Expand Down Expand Up @@ -172,9 +172,9 @@ Array [
exports[`stylelintVSCode() should support CSS-in-JS 1`] = `
Array [
Object {
"code": Object {
"target": "https://stylelint.io/user-guide/rules/font-weight-notation",
"value": "font-weight-notation",
"code": "font-weight-notation",
"codeDescription": Object {
"href": "https://stylelint.io/user-guide/rules/font-weight-notation",
},
"message": "Expected numeric font-weight notation (font-weight-notation)",
"range": Object {
Expand All @@ -191,9 +191,9 @@ Array [
"source": "stylelint",
},
Object {
"code": Object {
"target": "https://stylelint.io/user-guide/rules/font-weight-notation",
"value": "font-weight-notation",
"code": "font-weight-notation",
"codeDescription": Object {
"href": "https://stylelint.io/user-guide/rules/font-weight-notation",
},
"message": "Expected numeric font-weight notation (font-weight-notation)",
"range": Object {
Expand All @@ -215,9 +215,9 @@ Array [
exports[`stylelintVSCode() with a configuration file should adhere to configuration file settings 1`] = `
Array [
Object {
"code": Object {
"target": "https://stylelint.io/user-guide/rules/length-zero-no-unit",
"value": "length-zero-no-unit",
"code": "length-zero-no-unit",
"codeDescription": Object {
"href": "https://stylelint.io/user-guide/rules/length-zero-no-unit",
},
"message": "Unexpected unit (length-zero-no-unit)",
"range": Object {
Expand All @@ -240,9 +240,9 @@ exports[`stylelintVSCode() with autofix autofix should work if there are errors
Object {
"diagnostics": Array [
Object {
"code": Object {
"target": "https://stylelint.io/user-guide/rules/selector-type-no-unknown",
"value": "selector-type-no-unknown",
"code": "selector-type-no-unknown",
"codeDescription": Object {
"href": "https://stylelint.io/user-guide/rules/selector-type-no-unknown",
},
"message": "Unexpected unknown type selector \\"unknown\\" (selector-type-no-unknown)",
"range": Object {
Expand Down Expand Up @@ -296,9 +296,9 @@ exports[`stylelintVSCode() with customSyntax should work properly if customSynta
Object {
"diagnostics": Array [
Object {
"code": Object {
"target": "https://stylelint.io/user-guide/rules/indentation",
"value": "indentation",
"code": "indentation",
"codeDescription": Object {
"href": "https://stylelint.io/user-guide/rules/indentation",
},
"message": "Expected indentation of 2 spaces (indentation)",
"range": Object {
Expand Down Expand Up @@ -377,9 +377,9 @@ exports[`stylelintVSCode() with reportNeedlessDisables should work properly if r
Object {
"diagnostics": Array [
Object {
"code": Object {
"target": "https://stylelint.io/user-guide/rules/indentation",
"value": "indentation",
"code": "indentation",
"codeDescription": Object {
"href": "https://stylelint.io/user-guide/rules/indentation",
},
"message": "Expected indentation of 4 spaces (indentation)",
"range": Object {
Expand Down Expand Up @@ -490,9 +490,9 @@ exports[`stylelintVSCode() with stylelintPath should work properly if stylelintP
Object {
"diagnostics": Array [
Object {
"code": Object {
"target": "https://stylelint.io/user-guide/rules/indentation",
"value": "indentation",
"code": "indentation",
"codeDescription": Object {
"href": "https://stylelint.io/user-guide/rules/indentation",
},
"message": "Expected indentation of 2 spaces (indentation)",
"range": Object {
Expand Down
Loading

0 comments on commit 82a8a90

Please sign in to comment.