comment-parser 0.3.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,139 +1,130 @@
1
- var fs = require('fs');
2
- var expect = require('chai').expect;
3
- var parse = require('../index');
1
+ /* eslint no-unused-vars:off */
2
+ var expect = require('chai').expect
3
+ var parse = require('./parse')
4
4
 
5
- describe('parse() with custom tag parsers', function() {
6
-
7
- function parsed(func, opts) {
8
- var str = func.toString();
9
- return parse(str.slice(
10
- str.indexOf('{') + 1,
11
- str.lastIndexOf('}')
12
- ).trim(), opts);
13
- }
14
-
15
- function sample() {
5
+ describe('parse() with custom tag parsers', function () {
6
+ function sample () {
16
7
  /**
17
8
  * @tag {type} name description
18
9
  */
19
- var a;
10
+ var a
20
11
  }
21
12
 
22
- it('should use `opts.parsers`', function() {
13
+ it('should use `opts.parsers`', function () {
23
14
  var parsers = [
24
- function everything(str) {
15
+ function everything (str) {
25
16
  return {
26
- source : str,
27
- data : {
28
- tag : 'tag',
29
- type : 'type',
30
- name : 'name',
31
- optional : false,
32
- description : 'description'
17
+ source: str,
18
+ data: {
19
+ tag: 'tag',
20
+ type: 'type',
21
+ name: 'name',
22
+ optional: false,
23
+ description: 'description'
33
24
  }
34
- };
25
+ }
35
26
  }
36
- ];
27
+ ]
37
28
 
38
- expect(parsed(sample, {parsers: parsers})[0])
29
+ expect(parse(sample, {parsers: parsers})[0])
39
30
  .to.eql({
40
- line : 0,
41
- description : '',
42
- source : '@tag {type} name description',
31
+ line: 1,
32
+ description: '',
33
+ source: '@tag {type} name description',
43
34
  tags: [{
44
- tag : 'tag',
45
- type : 'type',
46
- name : 'name',
47
- description : 'description',
48
- optional : false,
49
- source : '@tag {type} name description',
50
- line : 1
35
+ tag: 'tag',
36
+ type: 'type',
37
+ name: 'name',
38
+ description: 'description',
39
+ optional: false,
40
+ source: '@tag {type} name description',
41
+ line: 2
51
42
  }]
52
- });
53
- });
43
+ })
44
+ })
54
45
 
55
- it('should merge parsers result', function() {
46
+ it('should merge parsers result', function () {
56
47
  var parsers = [
57
- function parser1(str) {
48
+ function parser1 (str) {
58
49
  return {
59
- source : '',
60
- data : {tag: 'tag'},
61
- };
50
+ source: '',
51
+ data: {tag: 'tag'}
52
+ }
62
53
  },
63
- function parser2(str) {
54
+ function parser2 (str) {
64
55
  return {
65
- source : '',
66
- data : {type: 'type'},
67
- };
56
+ source: '',
57
+ data: {type: 'type'}
58
+ }
68
59
  },
69
- function parser3(str) {
60
+ function parser3 (str) {
70
61
  return {
71
- source : '',
72
- data : {
73
- name : 'name',
74
- description : 'description'
75
- },
76
- };
62
+ source: '',
63
+ data: {
64
+ name: 'name',
65
+ description: 'description'
66
+ }
67
+ }
77
68
  }
78
- ];
69
+ ]
79
70
 
80
- expect(parsed(sample, {parsers: parsers})[0])
71
+ expect(parse(sample, {parsers: parsers})[0])
81
72
  .to.eql({
82
- line : 0,
83
- description : '',
84
- source : '@tag {type} name description',
73
+ line: 1,
74
+ description: '',
75
+ source: '@tag {type} name description',
85
76
  tags: [{
86
- tag : 'tag',
87
- type : 'type',
88
- name : 'name',
89
- description : 'description',
90
- optional : false,
91
- source : '@tag {type} name description',
92
- line : 1
77
+ tag: 'tag',
78
+ type: 'type',
79
+ name: 'name',
80
+ description: 'description',
81
+ optional: false,
82
+ source: '@tag {type} name description',
83
+ line: 2
93
84
  }]
94
- });
95
- });
85
+ })
86
+ })
96
87
 
97
- it('should catch parser exceptions and populate `errors` field', function() {
88
+ it('should catch parser exceptions and populate `errors` field', function () {
98
89
  var parsers = [
99
- function parser1(str) {
90
+ function parser1 (str) {
100
91
  return {
101
- source : '',
102
- data : {tag: 'tag'}
103
- };
92
+ source: '',
93
+ data: {tag: 'tag'}
94
+ }
104
95
  },
105
- function parser2(str) {
106
- throw new Error('error 1');
96
+ function parser2 (str) {
97
+ throw new Error('error 1')
107
98
  },
108
- function parser3(str) {
109
- throw new Error('error 2');
99
+ function parser3 (str) {
100
+ throw new Error('error 2')
110
101
  },
111
- function parser4(str) {
102
+ function parser4 (str) {
112
103
  return {
113
- source : '',
114
- data : {name: 'name'}
115
- };
116
- },
117
- ];
104
+ source: '',
105
+ data: {name: 'name'}
106
+ }
107
+ }
108
+ ]
118
109
 
119
- expect(parsed(sample, {parsers: parsers})[0])
110
+ expect(parse(sample, {parsers: parsers})[0])
120
111
  .to.eql({
121
- line : 0,
122
- description : '',
123
- source : '@tag {type} name description',
112
+ line: 1,
113
+ description: '',
114
+ source: '@tag {type} name description',
124
115
  tags: [{
125
- tag : 'tag',
126
- type : '',
127
- name : 'name',
128
- description : '',
129
- optional : false,
130
- source : '@tag {type} name description',
131
- errors : [
116
+ tag: 'tag',
117
+ type: '',
118
+ name: 'name',
119
+ description: '',
120
+ optional: false,
121
+ source: '@tag {type} name description',
122
+ errors: [
132
123
  'parser2: error 1',
133
124
  'parser3: error 2'
134
125
  ],
135
- line : 1
126
+ line: 2
136
127
  }]
137
- });
138
- });
139
- });
128
+ })
129
+ })
130
+ })
@@ -1,56 +1,55 @@
1
-
2
- var fs = require('fs');
3
- var stream = require('readable-stream');
1
+ /* eslint no-unused-vars:off */
2
+ var fs = require('fs')
3
+ var path = require('path')
4
+ var stream = require('readable-stream')
4
5
  var expect = require('chai').expect
5
- var parse = require('../index');
6
-
7
- describe('File parsing', function() {
8
-
9
- it('should parse the file by path', function(done) {
10
- parse.file(__dirname + '/fixtures/sample.js', function(err, parsed) {
11
- if (err) { done(err); }
6
+ var parse = require('../index')
12
7
 
13
- expect(parsed)
14
- .to.be.an('array');
8
+ describe('File parsing', function () {
9
+ it('should parse the file by path', function (done) {
10
+ parse.file(path.resolve(__dirname, 'fixtures/sample.js'), function (err, parsed) {
11
+ if (err) { done(err) }
15
12
 
16
- expect(parsed.length)
17
- .to.eq(4);
13
+ expect(parsed)
14
+ .to.be.an('array')
18
15
 
19
- expect(parsed[0].description)
20
- .to.eq('File description');
16
+ expect(parsed.length)
17
+ .to.eq(4)
21
18
 
22
- expect(parsed[1].tags[0].tag)
23
- .to.eq('class');
19
+ expect(parsed[0].description)
20
+ .to.eq('File description')
24
21
 
25
- expect(parsed[2].tags[0].tag)
26
- .to.eq('property');
22
+ expect(parsed[1].tags[0].tag)
23
+ .to.eq('class')
27
24
 
28
- expect(parsed[3].tags[0].tag)
29
- .to.eq('method');
25
+ expect(parsed[2].tags[0].tag)
26
+ .to.eq('property')
30
27
 
31
- done();
32
- });
33
- });
28
+ expect(parsed[3].tags[0].tag)
29
+ .to.eq('method')
34
30
 
35
- it('should path the error if file dows not exist', function(done) {
36
- parse.file('does/not/exists', function(err, parsed) {
37
- expect(err)
38
- .to.be.instanceof(Error);
39
- done();
40
- });
41
- });
31
+ done()
32
+ })
33
+ })
42
34
 
43
- it('should return `Transform` stream', function(done) {
35
+ it('should path the error if file dows not exist', function (done) {
36
+ parse.file('does/not/exists', function (err, parsed) {
37
+ expect(err)
38
+ .to.be.instanceof(Error)
39
+ done()
40
+ })
41
+ })
44
42
 
45
- var count = 0;
43
+ it('should return `Transform` stream', function (done) {
44
+ var count = 0
46
45
 
47
- var readable = fs.createReadStream(__dirname + '/fixtures/sample.js', {encoding: 'utf8'});
46
+ var readable = fs.createReadStream(path.resolve(__dirname, 'fixtures/sample.js'), {encoding: 'utf8'})
48
47
 
49
- var writable = new stream.Writable({objectMode: true});
50
- writable._write = function(data, encoding, done) {
51
- count++;
52
- done();
53
- };
48
+ var writable = new stream.Writable({objectMode: true})
49
+ writable._write = function (data, encoding, done) {
50
+ count++
51
+ done()
52
+ }
54
53
 
55
54
  readable
56
55
  .on('error', done)
@@ -58,11 +57,11 @@ describe('File parsing', function() {
58
57
  .on('error', done)
59
58
  .pipe(writable)
60
59
  .on('error', done)
61
- .on('finish', function() {
60
+ .on('finish', function () {
62
61
  expect(count)
63
- .to.eq(4);
62
+ .to.eq(4)
64
63
 
65
- done();
66
- });
67
- });
68
- });
64
+ done()
65
+ })
66
+ })
67
+ })
@@ -10,7 +10,7 @@
10
10
  * @param {Int} coords.x
11
11
  * @param {Int} coords.y
12
12
  */
13
- function Point(options) {
13
+ function Point (options) {
14
14
 
15
15
  }
16
16
 
@@ -18,19 +18,19 @@ function Point(options) {
18
18
  * This should be skipped
19
19
  */
20
20
 
21
- /**
22
- * Tells if point was ever initilized with coordinates
23
- * @property {Boolean} [initilized=false]
24
- */
25
- Point.prototype.initilized = false;
21
+ /**
22
+ * Tells if point was ever initilized with coordinates
23
+ * @property {Boolean} [initilized=false]
24
+ */
25
+ Point.prototype.initilized = false
26
26
 
27
- /**
28
- * Moves point by x,y
29
- * @method move
30
- * @param {Object} [by]
31
- * @param {Int} by.x
32
- * @param {Int} by.y
33
- */
34
- Point.prototype.move = function(by) {
27
+ /**
28
+ * Moves point by x,y
29
+ * @method move
30
+ * @param {Object} [by]
31
+ * @param {Int} by.x
32
+ * @param {Int} by.y
33
+ */
34
+ Point.prototype.move = function (by) {
35
35
 
36
- }
36
+ }
package/tests/parse.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Source lines numeration:
3
+ *
4
+ * 0 function() {
5
+ * 1 // source with comments
6
+ * 2 }
7
+ *
8
+ */
9
+
10
+ var parse = require('../index')
11
+
12
+ module.exports = function (func, opts) {
13
+ var str = func.toString()
14
+ return parse(str.slice(
15
+ str.indexOf('{') + 1,
16
+ str.lastIndexOf('}')
17
+ ), opts)
18
+ }