comment-parser 0.7.2 → 0.7.6

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.
package/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ # This file is for unifying the coding style for different editors and IDEs
2
+ # editorconfig.org
3
+
4
+ root = true
5
+
6
+ [*]
7
+ indent_style = space
8
+ end_of_line = lf
9
+ charset = utf-8
10
+ trim_trailing_whitespace = true
11
+ insert_final_newline = true
12
+ indent_size = 2
@@ -0,0 +1,24 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ branches: [ master ]
7
+
8
+ jobs:
9
+ build:
10
+
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ node-version: [8.x, 10.x, 12.x, 14.x]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v1
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+ - run: npm ci
24
+ - run: npm test
@@ -0,0 +1,18 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "node",
9
+ "request": "launch",
10
+ "name": "Test this",
11
+ "skipFiles": [
12
+ "<node_internals>/**"
13
+ ],
14
+ "program": "${workspaceFolder}/node_modules/.bin/mocha",
15
+ "args": ["${file}"]
16
+ }
17
+ ]
18
+ }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v0.7.6
2
+ - distinct non-critical errors by providing `err.warning`
3
+
4
+ # v0.7.5
5
+ - name parsing fixes
6
+
7
+ # v0.7.4
8
+ - node 8 backward compatibility fixes
9
+
10
+ # v0.7.3
11
+ - make stringify result more close to the source
12
+
1
13
  # v0.7.2
2
14
  - make stringify to start each line with * in multiline comments
3
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comment-parser",
3
- "version": "0.7.2",
3
+ "version": "0.7.6",
4
4
  "description": "Generic JSDoc-like comment parser. ",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -10,16 +10,17 @@
10
10
  "dependencies": {},
11
11
  "devDependencies": {
12
12
  "chai": "^4.2.0",
13
- "eslint": "^6.6.0",
14
- "eslint-config-standard": "^14.1.0",
15
- "eslint-plugin-import": "^2.18.2",
16
- "eslint-plugin-node": "^10.0.0",
13
+ "eslint": "^6.8.0",
14
+ "eslint-config-standard": "^14.1.1",
15
+ "eslint-plugin-import": "^2.20.2",
16
+ "eslint-plugin-node": "^11.1.0",
17
17
  "eslint-plugin-promise": "^4.2.1",
18
18
  "eslint-plugin-standard": "^4.0.1",
19
- "mocha": "^6.2.2",
20
- "nodemon": "^1.19.4",
21
- "nyc": "^14.1.1",
22
- "typescript": "^3.6.4"
19
+ "mocha": "^7.1.2",
20
+ "nodemon": "^2.0.3",
21
+ "nyc": "^15.0.1",
22
+ "readable-stream": "^3.6.0",
23
+ "typescript": "^3.8.3"
23
24
  },
24
25
  "engines": {
25
26
  "node": ">= 6.0.0"
@@ -60,7 +61,8 @@
60
61
  "Evgeny Reznichenko (https://github.com/zxcabs)",
61
62
  "Javier \"Ciberma\" Mora (https://github.com/jhm-ciberman)",
62
63
  "Jordan Harband (https://github.com/ljharb)",
63
- "tengattack (https://github.com/tengattack)"
64
+ "tengattack (https://github.com/tengattack)",
65
+ "Jayden Seric (https://github.com/jaydenseric)"
64
66
  ],
65
67
  "license": "MIT",
66
68
  "bugs": {
package/parser.js CHANGED
@@ -33,13 +33,16 @@ function find (list, filter) {
33
33
  * @returns {object} parsed tag node
34
34
  */
35
35
  function parse_tag (str, parsers) {
36
- if (typeof str !== 'string' || !(/\s*@/).test(str)) { return null }
37
-
38
- const data = parsers.reduce(function (state, parser) {
36
+ const { data } = parsers.reduce(function (state, parser) {
39
37
  let result
40
38
 
41
39
  try {
42
40
  result = parser(state.source, Object.assign({}, state.data))
41
+ if (result && result.data && result.data.warning) {
42
+ state.data.warnings = (state.data.warnings || [])
43
+ .concat(parser.name + ': ' + result.data.warning)
44
+ delete result.data.warning
45
+ }
43
46
  } catch (err) {
44
47
  state.data.errors = (state.data.errors || [])
45
48
  .concat(parser.name + ': ' + err.message)
@@ -54,7 +57,7 @@ function parse_tag (str, parsers) {
54
57
  }, {
55
58
  source: str,
56
59
  data: {}
57
- }).data
60
+ })
58
61
 
59
62
  data.optional = !!data.optional
60
63
  data.type = data.type === undefined ? '' : data.type
@@ -139,7 +142,6 @@ function parse_block (source, opts) {
139
142
 
140
143
  const tags = source.reduce(function (tags, tag) {
141
144
  const tag_node = parse_tag(tag.source, opts.parsers)
142
- if (!tag_node) { return tags }
143
145
 
144
146
  tag_node.line = tag.line
145
147
  tag_node.source = tag.source
@@ -180,6 +182,13 @@ function parse_block (source, opts) {
180
182
  return tags.concat(tag_node)
181
183
  }, [])
182
184
 
185
+ for (const tag of tags) {
186
+ if (!tag.errors && tag.warnings) {
187
+ tag.errors = [...tag.warnings]
188
+ delete tag.warnings
189
+ }
190
+ }
191
+
183
192
  return {
184
193
  tags,
185
194
  line: start,
@@ -218,7 +227,7 @@ function mkextract (opts) {
218
227
  const endPos = line.indexOf(MARKER_END)
219
228
 
220
229
  // if open marker detected and it's not, skip one
221
- if (startPos !== -1 && line.indexOf(MARKER_START_SKIP) !== startPos) {
230
+ if (!chunk && startPos !== -1 && line.indexOf(MARKER_START_SKIP) !== startPos) {
222
231
  chunk = []
223
232
  indent = startPos + MARKER_START.length
224
233
  }
package/parsers.js CHANGED
@@ -13,12 +13,12 @@ function skipws (str) {
13
13
  const PARSERS = {}
14
14
 
15
15
  PARSERS.parse_tag = function parse_tag (str) {
16
- const result = str.match(/^\s*@(\S+)/)
17
- if (!result) { throw new Error('Invalid `@tag`, missing @ symbol') }
16
+ const match = str.match(/^\s*@(\S+)/)
17
+ if (!match) { throw new SyntaxError('Invalid `@tag`, missing @ symbol') }
18
18
 
19
19
  return {
20
- source: result[0],
21
- data: { tag: result[1] }
20
+ source: match[0],
21
+ data: { tag: match[1] }
22
22
  }
23
23
  }
24
24
 
@@ -38,7 +38,7 @@ PARSERS.parse_type = function parse_type (str, data) {
38
38
  if (curlies === 0) { break }
39
39
  }
40
40
 
41
- if (curlies !== 0) { throw new Error('Invalid `{type}`, unpaired curlies') }
41
+ if (curlies !== 0) { throw new SyntaxError('Invalid `{type}`, unpaired curlies') }
42
42
 
43
43
  return {
44
44
  source: str.slice(0, pos),
@@ -68,18 +68,27 @@ PARSERS.parse_name = function parse_name (str, data) {
68
68
  if (brackets === 0 && /\s/.test(str[pos])) { break }
69
69
  }
70
70
 
71
- if (brackets !== 0) { throw new Error('Invalid `name`, unpaired brackets') }
71
+ if (brackets !== 0) { throw new SyntaxError('Invalid `name`, unpaired brackets') }
72
72
 
73
- res = { name: name, optional: false }
73
+ res = { name, optional: false }
74
74
 
75
75
  if (name[0] === '[' && name[name.length - 1] === ']') {
76
76
  res.optional = true
77
77
  name = name.slice(1, -1)
78
78
 
79
- if (name.indexOf('=') !== -1) {
80
- const parts = name.split('=')
81
- name = parts[0]
82
- res.default = parts[1].replace(/^(["'])(.+)(\1)$/, '$2')
79
+ const match = name.match(
80
+ /^\s*([^=]+?)(?:\s*=\s*(.*?))?\s*(?=$)/
81
+ )
82
+
83
+ if (!match) throw new SyntaxError('Invalid `name`, bad syntax')
84
+
85
+ name = match[1]
86
+ if (match[2]) res.default = match[2]
87
+ // We will throw this later after processing other tags (so we
88
+ // will collect enough data for the user to be able to fully recover)
89
+ else if (match[2] === '') {
90
+ res.default = match[2]
91
+ res.warning = 'Empty `name`, bad syntax'
83
92
  }
84
93
  }
85
94
  }
@@ -95,12 +104,12 @@ PARSERS.parse_name = function parse_name (str, data) {
95
104
  PARSERS.parse_description = function parse_description (str, data) {
96
105
  if (data.errors && data.errors.length) { return null }
97
106
 
98
- const result = str.match(/^\s+((.|\s)+)?/)
107
+ const match = str.match(/^\s+((.|\s)+)?/)
99
108
 
100
- if (result) {
109
+ if (match) {
101
110
  return {
102
- source: result[0],
103
- data: { description: result[1] === undefined ? '' : result[1] }
111
+ source: match[0],
112
+ data: { description: match[1] === undefined ? '' : match[1] }
104
113
  }
105
114
  }
106
115
 
package/stringifier.js CHANGED
@@ -33,10 +33,16 @@ const stringifyBlock = exports.stringifyBlock = function stringifyBlock (
33
33
  ) {
34
34
  // block.line
35
35
  const indnt = getIndent(indent)
36
- return (block.description ? `${indnt}${block.description.replace(/^/gm, '* ')}\n${indnt}*\n` : '') +
37
- block.tags.reduce((s, tag) => {
38
- return s + stringifyTag(tag, { indent })
39
- }, '')
36
+
37
+ return (
38
+ block.description
39
+ ? block.description.replace(/^\n/, '').replace(/^(.*)\n?/gm, (n0, descLine) => {
40
+ return `${indnt}*${descLine ? ` ${descLine}` : ''}\n`
41
+ })
42
+ : ''
43
+ ) + block.tags.reduce((s, tag) => {
44
+ return s + stringifyTag(tag, { indent })
45
+ }, '')
40
46
  }
41
47
 
42
48
  const stringifyTag = exports.stringifyTag = function stringifyTag (
@@ -46,11 +52,12 @@ const stringifyTag = exports.stringifyTag = function stringifyTag (
46
52
  const {
47
53
  type, name, optional, description, tag: tagName, default: deflt //, line , source
48
54
  } = tag
55
+
49
56
  return indnt + `* @${tagName}` +
50
57
  (type ? ` {${type}}` : '') +
51
- (name ? ` ${
58
+ (name.trim() ? ` ${
52
59
  optional ? '[' : ''
53
- }${name}${deflt ? `=${deflt}` : ''}${
60
+ }${name.trimRight()}${deflt !== undefined ? `=${deflt}` : ''}${
54
61
  optional ? ']' : ''
55
62
  }` : '') +
56
63
  (description ? ` ${description.replace(/\n/g, '\n' + indnt + '* ')}` : '') + '\n'
package/coverage/base.css DELETED
@@ -1,224 +0,0 @@
1
- body, html {
2
- margin:0; padding: 0;
3
- height: 100%;
4
- }
5
- body {
6
- font-family: Helvetica Neue, Helvetica, Arial;
7
- font-size: 14px;
8
- color:#333;
9
- }
10
- .small { font-size: 12px; }
11
- *, *:after, *:before {
12
- -webkit-box-sizing:border-box;
13
- -moz-box-sizing:border-box;
14
- box-sizing:border-box;
15
- }
16
- h1 { font-size: 20px; margin: 0;}
17
- h2 { font-size: 14px; }
18
- pre {
19
- font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
20
- margin: 0;
21
- padding: 0;
22
- -moz-tab-size: 2;
23
- -o-tab-size: 2;
24
- tab-size: 2;
25
- }
26
- a { color:#0074D9; text-decoration:none; }
27
- a:hover { text-decoration:underline; }
28
- .strong { font-weight: bold; }
29
- .space-top1 { padding: 10px 0 0 0; }
30
- .pad2y { padding: 20px 0; }
31
- .pad1y { padding: 10px 0; }
32
- .pad2x { padding: 0 20px; }
33
- .pad2 { padding: 20px; }
34
- .pad1 { padding: 10px; }
35
- .space-left2 { padding-left:55px; }
36
- .space-right2 { padding-right:20px; }
37
- .center { text-align:center; }
38
- .clearfix { display:block; }
39
- .clearfix:after {
40
- content:'';
41
- display:block;
42
- height:0;
43
- clear:both;
44
- visibility:hidden;
45
- }
46
- .fl { float: left; }
47
- @media only screen and (max-width:640px) {
48
- .col3 { width:100%; max-width:100%; }
49
- .hide-mobile { display:none!important; }
50
- }
51
-
52
- .quiet {
53
- color: #7f7f7f;
54
- color: rgba(0,0,0,0.5);
55
- }
56
- .quiet a { opacity: 0.7; }
57
-
58
- .fraction {
59
- font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
60
- font-size: 10px;
61
- color: #555;
62
- background: #E8E8E8;
63
- padding: 4px 5px;
64
- border-radius: 3px;
65
- vertical-align: middle;
66
- }
67
-
68
- div.path a:link, div.path a:visited { color: #333; }
69
- table.coverage {
70
- border-collapse: collapse;
71
- margin: 10px 0 0 0;
72
- padding: 0;
73
- }
74
-
75
- table.coverage td {
76
- margin: 0;
77
- padding: 0;
78
- vertical-align: top;
79
- }
80
- table.coverage td.line-count {
81
- text-align: right;
82
- padding: 0 5px 0 20px;
83
- }
84
- table.coverage td.line-coverage {
85
- text-align: right;
86
- padding-right: 10px;
87
- min-width:20px;
88
- }
89
-
90
- table.coverage td span.cline-any {
91
- display: inline-block;
92
- padding: 0 5px;
93
- width: 100%;
94
- }
95
- .missing-if-branch {
96
- display: inline-block;
97
- margin-right: 5px;
98
- border-radius: 3px;
99
- position: relative;
100
- padding: 0 4px;
101
- background: #333;
102
- color: yellow;
103
- }
104
-
105
- .skip-if-branch {
106
- display: none;
107
- margin-right: 10px;
108
- position: relative;
109
- padding: 0 4px;
110
- background: #ccc;
111
- color: white;
112
- }
113
- .missing-if-branch .typ, .skip-if-branch .typ {
114
- color: inherit !important;
115
- }
116
- .coverage-summary {
117
- border-collapse: collapse;
118
- width: 100%;
119
- }
120
- .coverage-summary tr { border-bottom: 1px solid #bbb; }
121
- .keyline-all { border: 1px solid #ddd; }
122
- .coverage-summary td, .coverage-summary th { padding: 10px; }
123
- .coverage-summary tbody { border: 1px solid #bbb; }
124
- .coverage-summary td { border-right: 1px solid #bbb; }
125
- .coverage-summary td:last-child { border-right: none; }
126
- .coverage-summary th {
127
- text-align: left;
128
- font-weight: normal;
129
- white-space: nowrap;
130
- }
131
- .coverage-summary th.file { border-right: none !important; }
132
- .coverage-summary th.pct { }
133
- .coverage-summary th.pic,
134
- .coverage-summary th.abs,
135
- .coverage-summary td.pct,
136
- .coverage-summary td.abs { text-align: right; }
137
- .coverage-summary td.file { white-space: nowrap; }
138
- .coverage-summary td.pic { min-width: 120px !important; }
139
- .coverage-summary tfoot td { }
140
-
141
- .coverage-summary .sorter {
142
- height: 10px;
143
- width: 7px;
144
- display: inline-block;
145
- margin-left: 0.5em;
146
- background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
147
- }
148
- .coverage-summary .sorted .sorter {
149
- background-position: 0 -20px;
150
- }
151
- .coverage-summary .sorted-desc .sorter {
152
- background-position: 0 -10px;
153
- }
154
- .status-line { height: 10px; }
155
- /* yellow */
156
- .cbranch-no { background: yellow !important; color: #111; }
157
- /* dark red */
158
- .red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
159
- .low .chart { border:1px solid #C21F39 }
160
- .highlighted,
161
- .highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{
162
- background: #C21F39 !important;
163
- }
164
- /* medium red */
165
- .cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
166
- /* light red */
167
- .low, .cline-no { background:#FCE1E5 }
168
- /* light green */
169
- .high, .cline-yes { background:rgb(230,245,208) }
170
- /* medium green */
171
- .cstat-yes { background:rgb(161,215,106) }
172
- /* dark green */
173
- .status-line.high, .high .cover-fill { background:rgb(77,146,33) }
174
- .high .chart { border:1px solid rgb(77,146,33) }
175
- /* dark yellow (gold) */
176
- .status-line.medium, .medium .cover-fill { background: #f9cd0b; }
177
- .medium .chart { border:1px solid #f9cd0b; }
178
- /* light yellow */
179
- .medium { background: #fff4c2; }
180
-
181
- .cstat-skip { background: #ddd; color: #111; }
182
- .fstat-skip { background: #ddd; color: #111 !important; }
183
- .cbranch-skip { background: #ddd !important; color: #111; }
184
-
185
- span.cline-neutral { background: #eaeaea; }
186
-
187
- .coverage-summary td.empty {
188
- opacity: .5;
189
- padding-top: 4px;
190
- padding-bottom: 4px;
191
- line-height: 1;
192
- color: #888;
193
- }
194
-
195
- .cover-fill, .cover-empty {
196
- display:inline-block;
197
- height: 12px;
198
- }
199
- .chart {
200
- line-height: 0;
201
- }
202
- .cover-empty {
203
- background: white;
204
- }
205
- .cover-full {
206
- border-right: none !important;
207
- }
208
- pre.prettyprint {
209
- border: none !important;
210
- padding: 0 !important;
211
- margin: 0 !important;
212
- }
213
- .com { color: #999 !important; }
214
- .ignore-none { color: #999; font-weight: normal; }
215
-
216
- .wrapper {
217
- min-height: 100%;
218
- height: auto !important;
219
- height: 100%;
220
- margin: 0 auto -48px;
221
- }
222
- .footer, .push {
223
- height: 48px;
224
- }
@@ -1,79 +0,0 @@
1
- /* eslint-disable */
2
- var jumpToCode = (function init() {
3
- // Classes of code we would like to highlight in the file view
4
- var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
5
-
6
- // Elements to highlight in the file listing view
7
- var fileListingElements = ['td.pct.low'];
8
-
9
- // We don't want to select elements that are direct descendants of another match
10
- var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `
11
-
12
- // Selecter that finds elements on the page to which we can jump
13
- var selector =
14
- fileListingElements.join(', ') +
15
- ', ' +
16
- notSelector +
17
- missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
18
-
19
- // The NodeList of matching elements
20
- var missingCoverageElements = document.querySelectorAll(selector);
21
-
22
- var currentIndex;
23
-
24
- function toggleClass(index) {
25
- missingCoverageElements
26
- .item(currentIndex)
27
- .classList.remove('highlighted');
28
- missingCoverageElements.item(index).classList.add('highlighted');
29
- }
30
-
31
- function makeCurrent(index) {
32
- toggleClass(index);
33
- currentIndex = index;
34
- missingCoverageElements.item(index).scrollIntoView({
35
- behavior: 'smooth',
36
- block: 'center',
37
- inline: 'center'
38
- });
39
- }
40
-
41
- function goToPrevious() {
42
- var nextIndex = 0;
43
- if (typeof currentIndex !== 'number' || currentIndex === 0) {
44
- nextIndex = missingCoverageElements.length - 1;
45
- } else if (missingCoverageElements.length > 1) {
46
- nextIndex = currentIndex - 1;
47
- }
48
-
49
- makeCurrent(nextIndex);
50
- }
51
-
52
- function goToNext() {
53
- var nextIndex = 0;
54
-
55
- if (
56
- typeof currentIndex === 'number' &&
57
- currentIndex < missingCoverageElements.length - 1
58
- ) {
59
- nextIndex = currentIndex + 1;
60
- }
61
-
62
- makeCurrent(nextIndex);
63
- }
64
-
65
- return function jump(event) {
66
- switch (event.which) {
67
- case 78: // n
68
- case 74: // j
69
- goToNext();
70
- break;
71
- case 66: // b
72
- case 75: // k
73
- case 80: // p
74
- goToPrevious();
75
- break;
76
- }
77
- };
78
- })();
79
- window.addEventListener('keydown', jumpToCode);