@@ -65,48 +65,37 @@ var CSSLint = (function(){
65
65
} ;
66
66
67
67
/**
68
- * Returns a ruleset configuration object with all current rules, modified by inline embedded rules.
68
+ * Returns a ruleset object based on embedded rules.
69
69
* @param {String } text A string of css containing embedded rules.
70
- * @return A ruleset object.
70
+ * @param {Object } ruleset A ruleset object to modify.
71
+ * @return {Object } A ruleset object.
71
72
* @method getEmbeddedRuleset
72
73
*/
73
- api . getEmbeddedRuleset = function ( text ) {
74
+ function applyEmbeddedRuleset ( text , ruleset ) {
74
75
var valueMap ,
75
- ruleset = this . getRuleset ( ) ,
76
76
embedded = text && text . match ( embeddedRuleset ) ,
77
77
rules = embedded && embedded [ 1 ] ;
78
78
79
- if ( ! rules ) {
80
- return ruleset ;
79
+ if ( rules ) {
80
+ valueMap = {
81
+ "true" : 2 , // true is error
82
+ "false" : 0 , // false is ignore
83
+ "2" : 2 ,
84
+ "1" : 1 ,
85
+ "0" : 0
86
+ } ;
87
+
88
+ rules . toLowerCase ( ) . split ( "," ) . forEach ( function ( rule ) {
89
+ var pair = rule . split ( ":" ) ,
90
+ property = pair [ 0 ] || "" ,
91
+ value = pair [ 1 ] || "" ;
92
+
93
+ ruleset [ property . trim ( ) ] = valueMap [ value . trim ( ) ] ;
94
+ } ) ;
81
95
}
82
96
83
- valueMap = {
84
- 'true' : 2 , // true is error
85
- 'false' : 0 , // false is ignore
86
- '2' : 2 ,
87
- '1' : 1 ,
88
- '0' : 0
89
- } ;
90
-
91
- rules . toLowerCase ( ) . split ( ',' ) . forEach ( function ( rule ) {
92
- var pair = rule . split ( ':' ) ,
93
- property = ( pair [ 0 ] || '' ) . trim ( ) , // normalize properties
94
- value = valueMap [ ( pair [ 1 ] || '' ) . trim ( ) ] ; // normalize values
95
-
96
- if ( ! ruleset . hasOwnProperty ( property ) ) {
97
- return ;
98
- }
99
-
100
- if ( ! value ) {
101
- delete ruleset [ property ] ;
102
- return ;
103
- }
104
-
105
- ruleset [ property ] = value ;
106
- } ) ;
107
-
108
97
return ruleset ;
109
- } ;
98
+ }
110
99
111
100
//-------------------------------------------------------------------------
112
101
// Formatters
@@ -190,20 +179,19 @@ var CSSLint = (function(){
190
179
// normalize line endings
191
180
lines = text . replace ( / \n \r ? / g, "$split$" ) . split ( '$split$' ) ;
192
181
193
- // always perfer file-level rulesets
194
- if ( embeddedRuleset . test ( text ) ) {
195
- ruleset = this . getEmbeddedRuleset ( text ) ;
196
- }
197
-
198
182
if ( ! ruleset ) {
199
183
ruleset = this . getRuleset ( ) ;
200
184
}
201
185
186
+ if ( embeddedRuleset . test ( text ) ) {
187
+ ruleset = applyEmbeddedRuleset ( text , ruleset ) ;
188
+ }
189
+
202
190
reporter = new Reporter ( lines , ruleset ) ;
203
191
204
192
ruleset . errors = 2 ; //always report parsing errors as errors
205
193
for ( i in ruleset ) {
206
- if ( ruleset . hasOwnProperty ( i ) ) {
194
+ if ( ruleset . hasOwnProperty ( i ) && ruleset [ i ] ) {
207
195
if ( rules [ i ] ) {
208
196
rules [ i ] . init ( parser , reporter ) ;
209
197
}
0 commit comments