Skip to content

Commit f46d911

Browse files
committed
feat: css Linter Language service integration
1 parent 5c995c2 commit f46d911

File tree

6 files changed

+126
-8
lines changed

6 files changed

+126
-8
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@fortawesome/fontawesome-free": "^6.1.2",
9292
"@highlightjs/cdn-assets": "^11.5.1",
9393
"@phcode/fs": "^3.0.0",
94-
"@phcode/language-support": "^1.0.5",
94+
"@phcode/language-support": "^1.0.6",
9595
"@pixelbrackets/gfm-stylesheet": "^1.1.0",
9696
"@prettier/plugin-php": "^0.22.2",
9797
"@uiw/file-icons": "^1.3.2",
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
* Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved.
6+
*
7+
* This program is free software: you can redistribute it and/or modify it
8+
* under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
19+
*
20+
*/
21+
22+
// Parts of this file is adapted from https://github.com/cfjedimaster/brackets-jshint
23+
24+
/**
25+
* Provides JSLint results via the core linting extension point
26+
*/
27+
define(function (require, exports, module) {
28+
29+
// Load dependent modules
30+
const CodeInspection = brackets.getModule("language/CodeInspection"),
31+
Strings = brackets.getModule("strings"),
32+
IndexingWorker = brackets.getModule("worker/IndexingWorker");
33+
34+
IndexingWorker.loadScriptInWorker(`${module.uri}/../worker/css-worker.js`);
35+
36+
function getTypeFromSeverity(sev) {
37+
switch (sev) {
38+
case 1: return CodeInspection.Type.ERROR;
39+
case 2: return CodeInspection.Type.WARNING;
40+
default: return CodeInspection.Type.META;
41+
}
42+
}
43+
44+
/**
45+
* Run JSLint on the current document. Reports results to the main UI. Displays
46+
* a gold star when no errors are found.
47+
*/
48+
async function lintOneFile(text, fullPath) {
49+
return new Promise((resolve)=>{
50+
IndexingWorker.execPeer("cssLint", {
51+
text,
52+
cssMode: "CSS",
53+
filePath: fullPath
54+
}).then(lintResult =>{
55+
if (lintResult && lintResult.length) {
56+
lintResult = lintResult.map(function (lintError) {
57+
return {
58+
pos: { line: lintError.range.start.line, ch: lintError.range.start.character },
59+
message: `${lintError.message} (${lintError.code})`,
60+
type: getTypeFromSeverity(lintError.severity)
61+
};
62+
});
63+
64+
resolve({ errors: lintResult });
65+
}
66+
resolve();
67+
});
68+
});
69+
}
70+
71+
// Register for JS files
72+
CodeInspection.register("css", {
73+
name: Strings.CSS_LINT_NAME,
74+
scanFileAsync: lintOneFile
75+
});
76+
});

src/extensions/default/CSSCodeHints/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ define(function (require, exports, module) {
3535
CSSProperties = require("text!CSSProperties.json"),
3636
properties = JSON.parse(CSSProperties);
3737

38+
require("./css-lint");
3839

3940
const cssWideKeywords = ['initial', 'inherit', 'unset', 'var()', 'calc()'];
4041

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
14+
* for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
18+
*
19+
*/
20+
21+
/*global Phoenix, WorkerComm, CSSLanguageService*/
22+
23+
(function () {
24+
function cssLint(params) {
25+
return CSSLanguageService.validateCSS(params.text, params.cssMode, params.filePath, {
26+
duplicateProperties: "warning",
27+
zeroUnits: "warning",
28+
emptyRules: "warning",
29+
unknownProperties: "warning",
30+
ieHack: "warning",
31+
propertyIgnoredDueToDisplay: "warning",
32+
fontFaceProperties: "warning",
33+
unknownVendorSpecificProperties: "warning"
34+
});
35+
}
36+
37+
WorkerComm.setExecHandler("cssLint", cssLint);
38+
}());

src/nls/root/strings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,9 @@ define({
876876
// extensions/default/JSLint
877877
"JSHINT_NAME": "JSHint",
878878

879+
// extension css code hints
880+
"CSS_LINT_NAME": "CSS Lint",
881+
879882
// Features/QuickView and quick view extensions
880883
"CMD_ENABLE_QUICK_VIEW": "Quick View on Hover",
881884
"CMD_ENABLE_SELECTION_VIEW": "Selection View",

0 commit comments

Comments
 (0)