8000 Merge pull request #82 from nschonni/add-editorconfig · CSSLint/parser-lib@8aac15c · GitHub
Skip to content

Commit 8aac15c

Browse files
committed
Merge pull request #82 from nschonni/add-editorconfig
Add EditorConfig for spacing
2 parents 448ce9a + 55b5747 commit 8aac15c

26 files changed

+853
-843
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; See http://EditorConfig.org for supported IDEs
2+
3+
root = true ; top-most EditorConfig file
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = false

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To use the CSS parser in a Node.js script, include it at the beginning:
1919
```js
2020
var parserlib = require("./node-parserlib");
2121
```
22-
22+
2323
### Rhino
2424

2525
To use the CSS parser in a Rhino script, include it at the beginning:
@@ -32,7 +32,7 @@ load("parserlib.js");
3232
To use the CSS parser on an HTML page, you can either include the entire library on your page:
3333
```html
3434
<script src="parserlib.js"></script>
35-
```
35+
```
3636
Or include it as its component parts, the ParserLib core and the CSS parser:
3737
```html
3838
<script src="parserlib-core.js"></script>
@@ -46,7 +46,7 @@ Basic usage
4646
You can create a new instance of the parser by using the following code:
4747
```js
4848
var parser = new parserlib.css.Parser();
49-
```
49+
```
5050
The constructor accepts an options object that specifies additional features the parser should use. The available options are:
5151

5252
* `starHack` - set to true to treat properties with a leading asterisk as if the asterisk wasn't there. Default is false.
@@ -61,7 +61,7 @@ var parser = new parserlib.css.Parser({ starHack: true, underscoreHack: true });
6161
You can then parse a string of CSS code by passing into the `parse()` method:
6262
```js
6363
parser.parse(someCSSText);
64-
```
64+
```
6565
The `parse()` method throws an error if a non-recoverable syntax error occurs, otherwise it finishes silently. This method does not return a value nor does it build up an abstract syntax tree (AST) for you, it simply parses the CSS text and fires events at important moments along the parse.
6666

6767
Note: The `parseStyleSheet()` method is provided for compatibility with SAC-based APIs but does the exact same thing as `parse()`.
@@ -87,7 +87,7 @@ The `parserlib.css.MediaQuery` type represents all parts of a media query. Each
8787
For example, consider the following media query:
8888
```css
8989
only screen and (max-device-width: 768px) and (orientation:portrait)
90-
```
90+
```
9191
A corresponding object would have the following values:
9292

9393
* `modifier` = "only"
@@ -126,7 +126,7 @@ li.selected > a:hover
126126
```
127127
This selector has three parts: `li.selected`, `>`, and `a:hover`. The first part is a `SelectorPart`, the second is a `Combinator`, and the third is a `SelectorPart`. Each `SelectorPart` is made up of an optional element name followed by an ID, class, attribute condition, pseudo class, and/or pseudo element.
128128

129-
Each instance of `parserlib.css.SelectorPart` has an `elementName` property, which represents the element name as a `parserlib.css.SelectorSubPart` object or `null` if there isn't one, and a `modifiers` property, which is an array of `parserlib.css.SelectorSubPart` objects. Each `SelectorSubPart` object represents the smallest individual piece of a selector and has a `type` property indicating the type of subpart, "elementName", "class", "attribute", "pseudo", "id", "not". If the `type` is "not", then the `args` property contains an array of `SelectorPart` arguments that were passed to `not()`.
129+
Each instance of `parserlib.css.SelectorPart` has an `elementName` property, which represents the element name as a `parserlib.css.SelectorSubPart` object or `null` if there isn't one, and a `modifiers` property, which is an array of `parserlib.css.SelectorSubPart` objects. Each `SelectorSubPart` object represents the smallest individual piece of a selector and has a `type` property indicating the type of subpart, "elementName", "class", "attribute", "pseudo", "id", "not". If the `type` is "not", then the `args` property contains an array of `SelectorPart` arguments that were passed to `not()`.
130130

131131
Each instance of `parserlib.css.Combinator` has an additional `type` property that indicates the type of combinator: "descendant", "child", "sibling", or "adjacent-sibling".
132132

@@ -195,7 +195,7 @@ parser.addListener("endfontface", function(event){
195195
});
196196
```
197197
### `startpage` and `endpage` events
198-
198+
199199
The `startpage` event fires when `@page` is encountered and the `endfontface` event fires just after the closing right brace (`}`) is encountered after `@page`. The `event` object has two properties: `id`, which is the page ID, and `pseudo`, which is the page pseudo class. Example:
200200
```js
201201
parser.addListener("startpage", function(event){
@@ -207,7 +207,7 @@ parser.addListener("endpage", function(event){
207207
});
208208
```
209209
### `startpagemargin` and `endpagemargin` events
210-
210+
211211
The `startpagemargin` event fires when a page margin directive (such as `@top-left`) is encountered and the `endfontface` event fires just after the closing right brace (`}`) is encountered after the page margin. The `event` object has a `margin` property, which contains the actual page margin encountered. Example:
212212
```js
213213
parser.addListener("startpagemargin", function(event){
@@ -220,7 +220,7 @@ parser.addListener("endpagemargin", function(event){
220220
});
221221
```
222222
### `startmedia` and `endmedia` events
223-
223+
224224
The `startmedia` event fires when `@media` is encountered and the `endmedia` event fires just after the closing right brace (`}`) is encountered after `@media`. The `event` object has one property, `media`, which is an array of `parserlib.css.MediaQuery` objects. Example:
225225
```js
226226
parser.addListener("startpagemargin", function(event){
@@ -233,7 +233,7 @@ parser.addListener("endpagemargin", function(event){
233233
});
234234
```
235235
### `startkeyframes` and `endkeyframes` events
236-
236+
237237
The `startkeyframes` event fires when `@keyframes` (or any vendor prefixed version) is encountered and the `endkeyframes` event fires just after the closing right brace (`}`) is encountered after `@keyframes`. The `event` object has one property, `name`, which is the name of the animation. Example:
238238
```js
239239
parser.addListener("startkeyframes", function(event){
@@ -246,23 +246,23 @@ parser.addListener("endkeyframes", function(event){
246246
});
247247
```
248248
### `startrule` and `endrule` events
249-
250-
The `startrule` event fires just after all selectors on a rule have been parsed and the `endrule` event fires just after the closing right brace (`}`) is encountered for the rule. The `event` object has one additional property, `selectors`, which is an array of `parserlib.css.Selector` objects. Example:
251-
```js
249+
250+
The `startrule` event fires just after all selectors on a rule have been parsed and the `endrule` event fires just after the closing right brace (`}`) is encountered for the rule. The `event` object has one additional property, `selectors`, which is an array of `parserlib.css.Selector` objects. Example:
251+
```js
252252
parser.addListener("startrule", function(event){
253253
console.log("Starting rule with " + event.selectors.length + " selector(s)");
254-
254+
255255
for (var i=0,len=event.selectors.length; i < len; i++){
256256
var selector = event.selectors[i];
257-
257+
258258
console.log(" Selector #1 (" + selector.line + "," + selector.col + ")");
259-
259+
260260
for (var j=0,count=selector.parts.length; j < count; j++){
261261
console.log(" Unit #" + (j+1));
262-
262+
263263
if (selector.parts[j] instanceof parserlib.css.SelectorPart){
264264
console.log(" Element name: " + selector.parts[j].elementName);
265-
265+
266266
for (var k=0; k < selector.parts[j].modifiers.length; k++){
267267
console.log(" Modifier: " + selector.parts[j].modifiers[k]);
268268
}

src/css/Combinator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* @class Combinator
66
* @extends parserlib.util.SyntaxUnit
77
* @constructor
8-
* @param {String} text The text representation of the unit.
8+
* @param {String} text The text representation of the unit.
99
* @param {int} line The line of text on which the unit resides.
1010
* @param {int} col The column of text on which the unit resides.
1111
*/
1212
function Combinator(text, line, col){
13-
13+
1414
SyntaxUnit.call(this, text, line, col, Parser.COMBINATOR_TYPE);
1515

1616
/**
@@ -19,7 +19,7 @@ function Combinator(text, line, col){
1919
* @property type
2020
*/
2121
this.type = "unknown";
22-
22+
2323
//pretty simple
2424
if (/^\s+$/.test(text)){
2525
this.type = "descendant";

src/css/MediaFeature.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @param {SyntaxUnit} value The value of the feature or null if none.
1010
*/
1111
function MediaFeature(name, value){
12-
12+
1313
SyntaxUnit.call(this, "(" + name + (value !== null ? ":" + value : "") + ")", name.startLine, name.startCol, Parser.MEDIA_FEATURE_TYPE);
1414

1515
/**

src/css/MediaQuery.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* @param {int} col The column of text on which the unit resides.
1313
*/
1414
function MediaQuery(modifier, mediaType, features, line, col){
15-
16-
SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
15+
16+
SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
1717

1818
/**
1919
* The media modifier ("not" or "only")
@@ -27,8 +27,8 @@ function MediaQuery(modifier, mediaType, features, line, col){
2727
* @type String
2828
* @property mediaType
2929
*/
30-
this.mediaType = mediaType;
31-
30+
this.mediaType = mediaType;
31+
3232
/**
3333
* The parts that make up the selector.
3434
* @type Array

src/css/PropertyName.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* @class PropertyName
66
* @extends parserlib.util.SyntaxUnit
77
* @constructor
8-
* @param {String} text The text representation of the unit.
8+
* @param {String} text The text representation of the unit.
99
* @param {String} hack The type of IE hack applied ("*", "_", or null).
1010
* @param {int} line The line of text on which the unit resides.
1111
* @param {int} col The column of text on which the unit resides.
1212
*/
1313
function PropertyName(text, hack, line, col){
14-
14+
1515
SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_NAME_TYPE);
1616

1717
/**

src/css/PropertyValue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
function PropertyValue(parts, line, col){
1515

1616
SyntaxUnit.call(this, parts.join(" "), line, col, Parser.PROPERTY_VALUE_TYPE);
17-
17+
1818
/**
1919
* The parts that make up the selector.
2020
* @type Array
2121
* @property parts
2222
*/
2323
this.parts = parts;
24-
24+
2525
}
2626

2727
PropertyValue.prototype = new SyntaxUnit();

src/css/PropertyValueIterator.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,37 @@
99
*/
1010
function PropertyValueIterator(value){
1111

12-
/**
12+
/**
1313
* Iterator value
1414
* @type int
1515
* @property _i
1616
* @private
1717
*/
1818
this._i = 0;
19-
19+
2020
/**
2121
* The parts that make up the value.
2222
* @type Array
2323
* @property _parts
2424
* @private
2525
*/
2626
this._parts = value.parts;
27-
27+
2828
/**
2929
* Keeps track of bookmarks along the way.
3030
* @type Array
3131
* @property _marks
3232
* @private
3333
*/
3434
this._marks = [];
35-
35+
3636
/**
3737
* Holds the original property value.
3838
* @type parserlib.css.PropertyValue
3939
* @property value
4040
*/
4141
this.value = value;
42-
42+
4343
}
4444

4545
/**
@@ -104,7 +104,7 @@ PropertyValueIterator.prototype.next = function(){
104104
/**
105105
* Returns the previous part of the property value or null if there is no
106106
* previous part.
107-
* @return {parserlib.css.PropertyValuePart} The previous part of the
107+
* @return {parserlib.css.PropertyValuePart} The previous part of the
108108
* property value or null if there is no next part.
109109
* @method previous
110110
*/

src/css/PropertyValuePart.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
function PropertyValuePart(text, line, col){
1414

1515
SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_VALUE_PART_TYPE);
16-
16+
1717
/**
1818
* Indicates the type of value unit.
1919
* @type String
@@ -22,18 +22,18 @@ function PropertyValuePart(text, line, col){
2222
this.type = "unknown";
2323

2424
//figure out what type of data it is
25-
25+
2626
var temp;
27-
27+
2828
//it is a measurement?
2929
if (/^([+\-]?[\d\.]+)([a-z]+)$/i.test(text)){ //dimension
3030
this.type = "dimension";
3131
this.value = +RegExp.$1;
3232
this.units = RegExp.$2;
33-
33+
3434
//try to narrow down
3535
switch(this.units.toLowerCase()){
36-
36+
3737
case "em":
3838
case "rem":
3939
case "ex":
@@ -49,32 +49,32 @@ function PropertyValuePart(text, line, col){
4949
case "vm":
5050
this.type = "length";
5151
break;
52-
52+
5353
case "deg":
5454
case "rad":
5555
case "grad":
5656
this.type = "angle";
5757
break;
58-
58+
5959
case "ms":
6060
case "s":
6161
this.type = "time";
6262
break;
63-
63+
6464
case "hz":
6565
case "khz":
6666
this.type = "frequency";
6767
break;
68-
68+
6969
case "dpi":
7070
case "dpcm":
7171
this.type = "resolution";
7272
break;
73-
73+
7474
//default
75-
75+
7676
}
77-
77+
7878
} else if (/^([+\-]?[\d\.]+)%$/i.test(text)){ //percentage
7979
this.type = "percentage";
8080
this.value = +RegExp.$1;
@@ -84,18 +84,18 @@ function PropertyValuePart(text, line, col){
8484
} else if (/^([+\-]?[\d\.]+)$/i.test(text)){ //number
8585
this.type = "number";
8686
this.value = +RegExp.$1;
87-
87+
8888
} else if (/^#([a-f0-9]{3,6})/i.test(text)){ //hexcolor
8989
this.type = "color";
9090
temp = RegExp.$1;
9191
if (temp.length == 3){
9292
this.red = parseInt(temp.charAt(0)+temp.charAt(0),16);
9393
this.green = parseInt(temp.charAt(1)+temp.charAt(1),16);
94-
this.blue = parseInt(temp.charAt(2)+temp.charAt(2),16);
94+
this.blue = parseInt(temp.charAt(2)+temp.charAt(2),16);
9595
} else {
9696
this.red = parseInt(temp.substring(0,2),16);
9797
this.green = parseInt(temp.substring(2,4),16);
98-
this.blue = parseInt(temp.substring(4,6),16);
98+
this.blue = parseInt(temp.substring(4,6),16);
9999
}
100100
} else if (/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i.test(text)){ //rgb() color with absolute numbers
101101
this.type = "color";
@@ -118,18 +118,18 @@ function PropertyValuePart(text, line, col){
118118
this.red = +RegExp.$1 * 255 / 100;
119119
this.green = +RegExp.$2 * 255 / 100;
120120
this.blue = +RegExp.$3 * 255 / 100;
121-
this.alpha = +RegExp.$4;
121+
this.alpha = +RegExp.$4;
122122
} else if (/^hsl\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)){ //hsl()
123123
this.type = "color";
124124
this.hue = +RegExp.$1;
125125
this.saturation = +RegExp.$2 / 100;
126-
this.lightness = +RegExp.$3 / 100;
126+
this.lightness = +RegExp.$3 / 100;
127127
} else if (/^hsla\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)){ //hsla() color with percentages
128128
this.type = "color";
129129
this.hue = +RegExp.$1;
130130
this.saturation = +RegExp.$2 / 100;
131-
this.lightness = +RegExp.$3 / 100;
132-
this.alpha = +RegExp.$4;
131+
this.lightness = +RegExp.$3 / 100;
132+
this.alpha = +RegExp.$4;
133133
} else if (/^url\(["']?([^\)"']+)["']?\)/i.test(text)){ //URI
134134
this.type = "uri";
135135
this.uri = RegExp.$1;
@@ -145,7 +145,7 @@ function PropertyValuePart(text, line, col){
145145
temp = Colors[text.toLowerCase()].substring(1);
146146
this.red = parseInt(temp.substring(0,2),16);
147147
this.green = parseInt(temp.substring(2,4),16);
148-
this.blue = parseInt(temp.substring(4,6),16);
148+
this.blue = parseInt(temp.substring(4,6),16);
149149
} else if (/^[\,\/]$/.test(text)){
150150
this.type = "operator";
151151
this.value = text;

0 commit comments

Comments
 (0)