Skip to content

Commit fc679a7

Browse files
committed
Upgrade lint
1 parent 1a5ebba commit fc679a7

File tree

9 files changed

+50
-46
lines changed

9 files changed

+50
-46
lines changed

.eslintrc

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ var walk = require('./walk');
33
var stringify = require('./stringify');
44

55
function ValueParser(value) {
6-
if (!(this instanceof ValueParser)) {
7-
return new ValueParser(value);
6+
if (this instanceof ValueParser) {
7+
this.nodes = parse(value);
8+
return this;
89
}
9-
this.nodes = parse(value);
10+
return new ValueParser(value);
1011
}
1112

1213
ValueParser.prototype.toString = function () {

lib/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports = function (input) {
8181
pos = next + 1;
8282
code = value.charCodeAt(pos);
8383

84-
//Comments
84+
// Comments
8585
} else if (code === slash && value.charCodeAt(pos + 1) === star) {
8686
token = {
8787
type: 'comment',

lib/stringify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ function stringify(nodes) {
2727

2828
if (Array.isArray(nodes)) {
2929
result = '';
30-
for (var i = nodes.length - 1; ~i; i -= 1) {
30+
for (i = nodes.length - 1; ~i; i -= 1) {
3131
result = stringifyNode(nodes[i]) + result;
3232
}
3333
return result;
3434
}
3535
return stringifyNode(nodes);
36-
};
36+
}
3737

3838
module.exports = stringify;

lib/unit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function (value) {
1313
while (pos < length) {
1414
code = value.charCodeAt(pos);
1515

16-
if (48 <= code && code <= 57) {
16+
if (code >= 48 && code <= 57) {
1717
number += value[pos];
1818
containsNumber = true;
1919
} else if (code === dot) {

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,23 @@
77
"lib"
88
],
99
"devDependencies": {
10-
"eslint": "^1.1.0",
10+
"eslint": "^2.1.0",
11+
"eslint-config-postcss": "^2.0.0",
1112
"tap-spec": "^4.1.0",
1213
"tape": "^4.2.0"
1314
},
1415
"scripts": {
15-
"test": "eslint lib test && tape test/*.js | tap-spec"
16+
"test": "tape test/*.js | tap-spec",
17+
"posttest": "eslint ."
18+
},
19+
"eslintConfig": {
20+
"extends": "postcss/es5",
21+
"rules": {
22+
"max-len": 0,
23+
"no-bitwise": 0,
24+
"complexity": 0,
25+
"no-use-before-define": 0
26+
}
1627
},
1728
"author": "Bogdan Chadkin <trysound@yandex.ru>",
1829
"license": "MIT",

test/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
var test = require('tape');
22
var parser = require('..');
33

4-
test('ValueParser', function (t) {
5-
t.test('i/o', function (t) {
4+
test('ValueParser', function (tp) {
5+
tp.test('i/o', function (t) {
66
var tests = [
77
' rgba( 34 , 45 , 54, .5 ) ',
88
'w1 w2 w6 \n f(4) ( ) () \t "s\'t" \'st\\"2\''
@@ -14,7 +14,7 @@ test('ValueParser', function (t) {
1414
});
1515
});
1616

17-
t.test('walk', function (t) {
17+
tp.test('walk', function (t) {
1818
t.plan(4);
1919
var result;
2020

@@ -32,7 +32,7 @@ test('ValueParser', function (t) {
3232
{ type: 'function', sourceIndex: 6, value: 'fn2', before: ' ', after: '', nodes: [
3333
{ type: 'function', sourceIndex: 11, value: 'fn3', before: '', after: '', nodes: [] }
3434
] },
35-
{ type: 'function', sourceIndex: 11, value: 'fn3', before: '', after: '', nodes: [] },
35+
{ type: 'function', sourceIndex: 11, value: 'fn3', before: '', after: '', nodes: [] }
3636
], 'should process all functions');
3737

3838

@@ -45,13 +45,14 @@ test('ValueParser', function (t) {
4545
return false;
4646
}
4747
}
48+
return true;
4849
});
4950

5051
t.deepEqual(result, [
5152
{ type: 'function', sourceIndex: 0, value: 'fn', before: ' ', after: '', nodes: [] },
5253
{ type: 'function', sourceIndex: 6, value: 'fn2', before: ' ', after: '', nodes: [
5354
{ type: 'function', sourceIndex: 11, value: 'fn3', before: '', after: '', nodes: [] }
54-
] },
55+
] }
5556
], 'shouldn\'t process functions after falsy callback');
5657

5758

@@ -66,10 +67,10 @@ test('ValueParser', function (t) {
6667

6768
t.deepEqual(result, [
6869
{ type: 'function', sourceIndex: 0, value: 'fn', before: ' ', after: '', nodes: [] },
69-
{ type: 'space', sourceIndex: 5, value: ' '},
70+
{ type: 'space', sourceIndex: 5, value: ' ' },
7071
{ type: 'word', sourceIndex: 6, value: 'fn2', before: ' ', after: '', nodes: [
7172
{ type: 'function', sourceIndex: 11, value: 'fn3', before: '', after: '', nodes: [] }
72-
] },
73+
] }
7374
], 'shouldn\'t process nodes with defined non-function type');
7475

7576

@@ -85,7 +86,7 @@ test('ValueParser', function (t) {
8586
{ type: 'function', sourceIndex: 5, value: 'fn3', before: '', after: '', nodes: [] },
8687
{ type: 'function', sourceIndex: 0, value: 'fn2', before: ' ', after: '', nodes: [
8788
{ type: 'function', sourceIndex: 5, value: 'fn3', before: '', after: '', nodes: [] }
88-
] },
89+
] }
8990
], 'should process all functions with reverse mode');
9091
});
9192
});

test/parse.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ var tests = [{
194194
fixture: ' \\"word\\\'\\ \\\t ',
195195
expected: [
196196
{ type: 'space', sourceIndex: 0, value: ' ' },
197-
{ type: 'word', sourceIndex: 1, value: '\\"word\\\'\\ \\\t'},
197+
{ type: 'word', sourceIndex: 1, value: '\\"word\\\'\\ \\\t' },
198198
{ type: 'space', sourceIndex: 13, value: ' ' }
199199
]
200200
}, {
@@ -206,7 +206,7 @@ var tests = [{
206206
{ type: 'word', sourceIndex: 5, value: 'italic' },
207207
{ type: 'space', sourceIndex: 11, value: ' ' },
208208
{ type: 'word', sourceIndex: 12, value: '12px' },
209-
{ type: 'div', sourceIndex: 16, value: '/' , before: ' \t ', after: '' },
209+
{ type: 'div', sourceIndex: 16, value: '/', before: ' \t ', after: '' },
210210
{ type: 'word', sourceIndex: 20, value: '3' },
211211
{ type: 'space', sourceIndex: 21, value: ' ' },
212212
{ type: 'string', sourceIndex: 22, value: 'Open Sans', quote: '\'' },
@@ -215,7 +215,7 @@ var tests = [{
215215
{ type: 'div', sourceIndex: 40, value: ',', before: '', after: ' ' },
216216
{ type: 'string', sourceIndex: 42, value: 'Helvetica Neue', quote: '"' },
217217
{ type: 'div', sourceIndex: 58, value: ',', before: '', after: ' ' },
218-
{ type: 'word', sourceIndex: 60, value: 'sans-serif' },
218+
{ type: 'word', sourceIndex: 60, value: 'sans-serif' }
219219
]
220220
}, {
221221
message: 'should correctly proceess color value',
@@ -226,7 +226,7 @@ var tests = [{
226226
{ type: 'div', sourceIndex: 8, value: ',', before: '', after: ' ' },
227227
{ type: 'word', sourceIndex: 10, value: '439' },
228228
{ type: 'div', sourceIndex: 13, value: ',', before: ' ', after: ' ' },
229-
{ type: 'word', sourceIndex: 16, value: '29' },
229+
{ type: 'word', sourceIndex: 16, value: '29' }
230230
] }
231231
]
232232
}, {
@@ -260,7 +260,7 @@ var tests = [{
260260
message: 'should correctly process nested calc functions',
261261
fixture: 'calc(((768px - 100vw) / 2) - 15px)',
262262
expected: [
263-
{type: 'function', sourceIndex: 0, value: 'calc', before: '', after: '', nodes: [
263+
{ type: 'function', sourceIndex: 0, value: 'calc', before: '', after: '', nodes: [
264264
{ type: 'function', sourceIndex: 5, value: '', before: '', after: '', nodes: [
265265
{ type: 'function', sourceIndex: 6, value: '', before: '', after: '', nodes: [
266266
{ type: 'word', sourceIndex: 7, value: '768px' },
@@ -315,7 +315,7 @@ var tests = [{
315315
{ type: 'div', sourceIndex: 12, value: ',', before: '', after: ' ' },
316316
{ type: 'function', sourceIndex: 14, value: 'fn3', before: '', after: '', nodes: [
317317
{ type: 'word', sourceIndex: 18, value: '.2' }
318-
] },
318+
] }
319319
] },
320320
{ type: 'div', sourceIndex: 22, value: ',', before: '', after: ' ' },
321321
{ type: 'function', sourceIndex: 24, value: 'fn4', before: '', after: '', nodes: [
@@ -324,7 +324,7 @@ var tests = [{
324324
{ type: 'div', sourceIndex: 35, value: ',', before: '', after: '' },
325325
{ type: 'word', sourceIndex: 36, value: '.2' }
326326
] },
327-
{ type: 'div', sourceIndex: 39, value: ',', before: '', after: ' '},
327+
{ type: 'div', sourceIndex: 39, value: ',', before: '', after: ' ' },
328328
{ type: 'word', sourceIndex: 41, value: 'fn6' }
329329
] }
330330
]
@@ -381,7 +381,7 @@ var tests = [{
381381
{ type: 'div', sourceIndex: 16, value: ',', before: '', after: ' ' },
382382
{ type: 'function', sourceIndex: 18, value: 'url', before: '', after: '', nodes: [
383383
{ type: 'word', sourceIndex: 22, value: 'http://website.com/img.jpg' }
384-
] },
384+
] }
385385
]
386386
}, {
387387
message: 'should parse empty url',
@@ -393,15 +393,15 @@ var tests = [{
393393
message: 'should parse comments',
394394
fixture: '/*before*/ 1px /*between*/ 1px /*after*/',
395395
expected: [
396-
{ type: 'comment', sourceIndex: 0, value: 'before'},
396+
{ type: 'comment', sourceIndex: 0, value: 'before' },
397397
{ type: 'space', sourceIndex: 10, value: ' ' },
398398
{ type: 'word', sourceIndex: 11, value: '1px' },
399399
{ type: 'space', sourceIndex: 14, value: ' ' },
400-
{ type: 'comment', sourceIndex: 15, value: 'between'},
400+
{ type: 'comment', sourceIndex: 15, value: 'between' },
401401
{ type: 'space', sourceIndex: 26, value: ' ' },
402402
{ type: 'word', sourceIndex: 27, value: '1px' },
403403
{ type: 'space', sourceIndex: 30, value: ' ' },
404-
{ type: 'comment', sourceIndex: 31, value: 'after'},
404+
{ type: 'comment', sourceIndex: 31, value: 'after' }
405405
]
406406
}, {
407407
message: 'should parse comments inside functions',
@@ -415,44 +415,44 @@ var tests = [{
415415
{ type: 'word', sourceIndex: 12, value: '55' },
416416
{ type: 'div', sourceIndex: 14, value: ',', before:'', after: ' ' },
417417
{ type: 'word', sourceIndex: 16, value: '0' },
418-
{ type: 'comment', sourceIndex: 17, value: ',.5'}
418+
{ type: 'comment', sourceIndex: 17, value: ',.5' }
419419
] }
420420
]
421421
}, {
422422
message: 'should parse comments at the end of url functions with quoted first argument',
423423
fixture: 'url( "/demo/bg.png" /*comment*/ )',
424424
expected: [
425425
{ type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [
426-
{ type: 'string', sourceIndex: 5, value: '/demo/bg.png', quote:'"'},
426+
{ type: 'string', sourceIndex: 5, value: '/demo/bg.png', quote:'"' },
427427
{ type: 'space', sourceIndex: 19, value: ' ' },
428-
{ type: 'comment', sourceIndex: 20, value: 'comment'}
428+
{ type: 'comment', sourceIndex: 20, value: 'comment' }
429429
] }
430430
]
431431
}, {
432432
message: 'should not parse comments at the start of url function with unquoted first argument',
433433
fixture: 'url( /*comment*/ /demo/bg.png )',
434434
expected: [
435435
{ type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [
436-
{ type: 'word', sourceIndex: 5, value: '/*comment*/ /demo/bg.png'},
436+
{ type: 'word', sourceIndex: 5, value: '/*comment*/ /demo/bg.png' }
437437
] }
438438
]
439439
}, {
440440
message: 'should not parse comments at the end of url function with unquoted first argument',
441441
fixture: 'url( /demo/bg.png /*comment*/ )',
442442
expected: [
443443
{ type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [
444-
{ type: 'word', sourceIndex: 5, value: '/demo/bg.png /*comment*/'},
444+
{ type: 'word', sourceIndex: 5, value: '/demo/bg.png /*comment*/' }
445445
] }
446446
]
447447
}, {
448448
message: 'should parse unclosed comments',
449449
fixture: '/*comment*/ 1px /* unclosed ',
450450
expected: [
451-
{ type: 'comment', sourceIndex: 0, value: 'comment'},
451+
{ type: 'comment', sourceIndex: 0, value: 'comment' },
452452
{ type: 'space', sourceIndex: 11, value: ' ' },
453453
{ type: 'word', sourceIndex: 12, value: '1px' },
454454
{ type: 'space', sourceIndex: 15, value: ' ' },
455-
{ type: 'comment', sourceIndex: 16, value: ' unclosed ', unclosed:true}
455+
{ type: 'comment', sourceIndex: 16, value: ' unclosed ', unclosed:true }
456456

457457
]
458458
}];

test/unit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var tests = [{
3030
test('Unit', function (t) {
3131
t.plan(tests.length);
3232

33-
tests.forEach(function (test) {
34-
t.deepEqual(unit(test.fixture), test.expected);
33+
tests.forEach(function (item) {
34+
t.deepEqual(unit(item.fixture), item.expected);
3535
});
3636
});

0 commit comments

Comments
 (0)