@@ -75,6 +75,7 @@ describe(`web worker CSS Language tests`, async function () {
7575 } ) ;
7676
7777 /**
78+ * // todo these tests
7879 * - "compatibleVendorPrefixes": Unnecessary vendor prefixes checker.
7980 * - "vendorPrefix": Warns on missing vendor prefixes.
8081 * - "boxModel": Warns if CSS box model is potentially misused.
@@ -91,6 +92,48 @@ describe(`web worker CSS Language tests`, async function () {
9192 * - "idSelector": Advises against using ID selectors for styling.
9293 */
9394
95+ /**
96+ * Best defaults to use:
97+ * duplicateProperties: "warning"
98+ * zeroUnits: "warning"
99+ * emptyRules: "warning"
100+ * // leave default
101+ * importStatement: none
102+ * boxModel: none
103+ */
104+
105+ it ( "should validate css boxModel" , async function ( ) {
106+ const cssValidationData = await ( await fetch ( "test-files/cssValidationData.json" ) ) . json ( ) ;
107+ messageFromWorker = null ;
108+ const text = `.box {
109+ width: 300px;
110+ padding: 50px;
111+ border: 5px solid black;
112+ }` ;
113+ worker . postMessage ( {
114+ command : `validateCSS` , text, cssMode : "CSS" , filePath : "file:///c.css" , lintSettings : {
115+ boxModel : "warning"
116+ }
117+ } ) ;
118+ let output = await waitForWorkerMessage ( `validateCSS` , 1000 ) ;
119+ const symbols = output . diag ;
120+ expect ( symbols ) . to . deep . equal ( cssValidationData [ "boxModel" ] ) ;
121+ } ) ;
122+
123+ it ( "should not validate css boxModel by default" , async function ( ) {
124+ messageFromWorker = null ;
125+ const text = `.box {
126+ width: 300px;
127+ padding: 50px;
128+ border: 5px solid black;
129+ }` ;
130+ worker . postMessage ( {
131+ command : `validateCSS` , text, cssMode : "CSS" , filePath : "file:///c.css" } ) ;
132+ let output = await waitForWorkerMessage ( `validateCSS` , 1000 ) ;
133+ const symbols = output . diag ;
134+ expect ( symbols ) . to . deep . equal ( [ ] ) ;
135+ } ) ;
136+
94137 it ( "should validate css zeroUnits" , async function ( ) {
95138 const cssValidationData = await ( await fetch ( "test-files/cssValidationData.json" ) ) . json ( ) ;
96139 messageFromWorker = null ;
@@ -105,6 +148,15 @@ describe(`web worker CSS Language tests`, async function () {
105148 expect ( symbols ) . to . deep . equal ( cssValidationData [ "zeroUnits" ] ) ;
106149 } ) ;
107150
151+ it ( "should not validate css zeroUnits by default" , async function ( ) {
152+ messageFromWorker = null ;
153+ const text = `.box { width: 0px;}` ;
154+ worker . postMessage ( { command : `validateCSS` , text, cssMode : "CSS" , filePath : "file:///c.css" } ) ;
155+ let output = await waitForWorkerMessage ( `validateCSS` , 1000 ) ;
156+ const symbols = output . diag ;
157+ expect ( symbols ) . to . deep . equal ( [ ] ) ;
158+ } ) ;
159+
108160 it ( "should validate css duplicateProperties" , async function ( ) {
109161 const cssValidationData = await ( await fetch ( "test-files/cssValidationData.json" ) ) . json ( ) ;
110162 messageFromWorker = null ;
@@ -119,6 +171,16 @@ describe(`web worker CSS Language tests`, async function () {
119171 expect ( symbols ) . to . deep . equal ( cssValidationData [ "duplicateProperties" ] ) ;
120172 } ) ;
121173
174+ it ( "should not validate css duplicateProperties by default" , async function ( ) {
175+ messageFromWorker = null ;
176+ const text = `.box { color: red; color: blue; }` ;
177+ worker . postMessage ( {
178+ command : `validateCSS` , text, cssMode : "CSS" , filePath : "file:///c.css" } ) ;
179+ let output = await waitForWorkerMessage ( `validateCSS` , 1000 ) ;
180+ const symbols = output . diag ;
181+ expect ( symbols ) . to . deep . equal ( [ ] ) ;
182+ } ) ;
183+
122184 it ( "should validate css importStatement" , async function ( ) {
123185 const cssValidationData = await ( await fetch ( "test-files/cssValidationData.json" ) ) . json ( ) ;
124186 messageFromWorker = null ;
@@ -131,15 +193,33 @@ describe(`web worker CSS Language tests`, async function () {
131193 expect ( symbols ) . to . deep . equal ( cssValidationData [ "importStatement" ] ) ;
132194 } ) ;
133195
196+ it ( "should not validate css importStatement by default" , async function ( ) {
197+ messageFromWorker = null ;
198+ const text = `@import "a.css"` ;
199+ worker . postMessage ( { command : `validateCSS` , text, cssMode : "CSS" , filePath : "file:///c.css" } ) ;
200+ let output = await waitForWorkerMessage ( `validateCSS` , 1000 ) ;
201+ const symbols = output . diag ;
202+ expect ( symbols ) . to . deep . equal ( [ ] ) ;
203+ } ) ;
204+
134205 it ( "should validate css emptyRules" , async function ( ) {
135206 const cssValidationData = await ( await fetch ( "test-files/cssValidationData.json" ) ) . json ( ) ;
136207 messageFromWorker = null ;
137208 const text = `.box {}` ;
138209 worker . postMessage ( { command : `validateCSS` , text, cssMode : "CSS" , filePath : "file:///c.css" , lintSettings : {
139- compatibleVendorPrefixes : "warning"
210+ emptyRules : "warning"
140211 } } ) ;
141212 let output = await waitForWorkerMessage ( `validateCSS` , 1000 ) ;
142213 const symbols = output . diag ;
143- expect ( symbols ) . to . deep . equal ( cssValidationData [ "compatibleVendorPrefixes" ] ) ;
214+ expect ( symbols ) . to . deep . equal ( cssValidationData [ "emptyRules" ] ) ;
215+ } ) ;
216+ it ( "should validate css emptyRules by default" , async function ( ) {
217+ const cssValidationData = await ( await fetch ( "test-files/cssValidationData.json" ) ) . json ( ) ;
218+ messageFromWorker = null ;
219+ const text = `.box {}` ;
220+ worker . postMessage ( { command : `validateCSS` , text, cssMode : "CSS" , filePath : "file:///c.css" } ) ;
221+ let output = await waitForWorkerMessage ( `validateCSS` , 1000 ) ;
222+ const symbols = output . diag ;
223+ expect ( symbols ) . to . deep . equal ( cssValidationData [ "emptyRules" ] ) ;
144224 } ) ;
145225} ) ;
0 commit comments