From 5a2a1c33d75dd4bd9fdc11c4cf4b1fa9945032c1 Mon Sep 17 00:00:00 2001 From: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com> Date: Mon, 23 Oct 2023 15:00:04 +0200 Subject: [PATCH] Add support for Sass syntax (#4306) --- package-lock.json | 57 ++++++++++++++++++- package.json | 2 + packages/css/tests/analysis/analyzer.test.ts | 17 ++++++ .../css/tests/analysis/fixtures/file.sass | 3 + 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 packages/css/tests/analysis/fixtures/file.sass diff --git a/package-lock.json b/package-lock.json index ad59889a231..7ffad747d79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "express", "functional-red-black-tree", "htmlparser2", + "jsx-ast-utils", "lodash.clone", "module-alias", "postcss-html", @@ -65,11 +66,12 @@ "express": "4.18.2", "functional-red-black-tree": "1.0.1", "htmlparser2": "9.0.0", - "jsx-ast-utils": "^3.3.5", + "jsx-ast-utils": "3.3.5", "lodash.clone": "4.5.0", "module-alias": "2.2.3", "postcss-html": "0.36.0", "postcss-less": "6.0.0", + "postcss-sass": "0.5.0", "postcss-scss": "4.0.6", "postcss-syntax": "0.36.2", "postcss-value-parser": "4.2.0", @@ -6396,6 +6398,20 @@ "inBundle": true, "license": "MIT" }, + "node_modules/gonzales-pe": { + "version": "4.3.0", + "resolved": "https://repox.jfrog.io/repox/api/npm/npm/gonzales-pe/-/gonzales-pe-4.3.0.tgz", + "integrity": "sha512-otgSPpUmdWJ43VXyiNgEYE4luzHCL2pz4wQ0OnDluC6Eg4Ko3Vexy/SrSynglw/eR+OhkzmqFCZa/OFa/RgAOQ==", + "dependencies": { + "minimist": "^1.2.5" + }, + "bin": { + "gonzales": "bin/gonzales.js" + }, + "engines": { + "node": ">=0.6.0" + } + }, "node_modules/gopd": { "version": "1.0.1", "inBundle": true, @@ -9176,6 +9192,11 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://repox.jfrog.io/repox/api/npm/npm/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==" + }, "node_modules/minimist-options": { "version": "4.1.0", "inBundle": true, @@ -9982,6 +10003,18 @@ "postcss": "^8.3.3" } }, + "node_modules/postcss-sass": { + "version": "0.5.0", + "resolved": "https://repox.jfrog.io/repox/api/npm/npm/postcss-sass/-/postcss-sass-0.5.0.tgz", + "integrity": "sha512-qtu8awh1NMF3o9j/x9j3EZnd+BlF66X6NZYl12BdKoG2Z4hmydOt/dZj2Nq+g0kfk2pQy3jeYFBmvG9DBwynGQ==", + "dependencies": { + "gonzales-pe": "^4.3.0", + "postcss": "^8.2.14" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, "node_modules/postcss-scss": { "version": "4.0.6", "funding": [ @@ -16168,6 +16201,14 @@ "globjoin": { "version": "0.1.4" }, + "gonzales-pe": { + "version": "4.3.0", + "resolved": "https://repox.jfrog.io/repox/api/npm/npm/gonzales-pe/-/gonzales-pe-4.3.0.tgz", + "integrity": "sha512-otgSPpUmdWJ43VXyiNgEYE4luzHCL2pz4wQ0OnDluC6Eg4Ko3Vexy/SrSynglw/eR+OhkzmqFCZa/OFa/RgAOQ==", + "requires": { + "minimist": "^1.2.5" + } + }, "gopd": { "version": "1.0.1", "requires": { @@ -17799,6 +17840,11 @@ "brace-expansion": "^1.1.7" } }, + "minimist": { + "version": "1.2.8", + "resolved": "https://repox.jfrog.io/repox/api/npm/npm/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==" + }, "minimist-options": { "version": "4.1.0", "requires": { @@ -18233,6 +18279,15 @@ "version": "6.0.0", "requires": {} }, + "postcss-sass": { + "version": "0.5.0", + "resolved": "https://repox.jfrog.io/repox/api/npm/npm/postcss-sass/-/postcss-sass-0.5.0.tgz", + "integrity": "sha512-qtu8awh1NMF3o9j/x9j3EZnd+BlF66X6NZYl12BdKoG2Z4hmydOt/dZj2Nq+g0kfk2pQy3jeYFBmvG9DBwynGQ==", + "requires": { + "gonzales-pe": "^4.3.0", + "postcss": "^8.2.14" + } + }, "postcss-scss": { "version": "4.0.6", "requires": {} diff --git a/package.json b/package.json index 3dd1a40d7bf..0143b390428 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "module-alias": "2.2.3", "postcss-html": "0.36.0", "postcss-less": "6.0.0", + "postcss-sass": "0.5.0", "postcss-scss": "4.0.6", "postcss-syntax": "0.36.2", "postcss-value-parser": "4.2.0", @@ -130,6 +131,7 @@ "module-alias", "postcss-html", "postcss-less", + "postcss-sass", "postcss-scss", "postcss-syntax", "postcss-value-parser", diff --git a/packages/css/tests/analysis/analyzer.test.ts b/packages/css/tests/analysis/analyzer.test.ts index be4d57fac3d..5431946f4cf 100644 --- a/packages/css/tests/analysis/analyzer.test.ts +++ b/packages/css/tests/analysis/analyzer.test.ts @@ -50,6 +50,23 @@ describe('analyzeCSS', () => { }); }); + it('should analyze sass syntax', async () => { + const filePath = path.join(__dirname, 'fixtures', 'file.sass'); + await expect( + analyzeCSS( + await input(filePath, undefined, [ + { key: 'selector-pseudo-element-no-unknown', configurations: [] }, + ]), + ), + ).resolves.toEqual({ + issues: [ + expect.objectContaining({ + ruleId: 'selector-pseudo-element-no-unknown', + }), + ], + }); + }); + it('should analyze less syntax', async () => { const filePath = path.join(__dirname, 'fixtures', 'file.less'); await expect(analyzeCSS(await input(filePath, undefined, rules))).resolves.toEqual({ diff --git a/packages/css/tests/analysis/fixtures/file.sass b/packages/css/tests/analysis/fixtures/file.sass new file mode 100644 index 00000000000..9434c072386 --- /dev/null +++ b/packages/css/tests/analysis/fixtures/file.sass @@ -0,0 +1,3 @@ +a + &::pseudo + color: red