refactor: switch off position for remark, it is reduce size of tests and check on position (#1369)

This commit is contained in:
Anton 2021-04-16 18:18:06 +03:00 committed by GitHub
parent 061b906425
commit f2fa522070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 279 additions and 14183 deletions

View File

@ -1563,51 +1563,13 @@ Array [
Object {
"children": Array [
Object {
"position": Object {
"end": Object {
"column": 19,
"line": 1,
"offset": 18,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "Bananas are yellow",
},
],
"position": Object {
"end": Object {
"column": 19,
"line": 1,
"offset": 18,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 19,
"line": 1,
"offset": 18,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"examples": Array [],
@ -1665,51 +1627,13 @@ Array [
Object {
"children": Array [
Object {
"position": Object {
"end": Object {
"column": 20,
"line": 1,
"offset": 19,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "Carrots are awesome",
},
],
"position": Object {
"end": Object {
"column": 20,
"line": 1,
"offset": 19,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 20,
"line": 1,
"offset": 19,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"examples": Array [],
@ -1767,51 +1691,13 @@ Array [
Object {
"children": Array [
Object {
"position": Object {
"end": Object {
"column": 15,
"line": 1,
"offset": 14,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "Apples are red",
},
],
"position": Object {
"end": Object {
"column": 15,
"line": 1,
"offset": 14,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 15,
"line": 1,
"offset": 14,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"examples": Array [],
@ -2110,51 +1996,13 @@ Array [
Object {
"children": Array [
Object {
"position": Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "test",
},
],
"position": Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"examples": Array [],
@ -2190,18 +2038,6 @@ Array [
Object {
"description": Object {
"children": Array [],
"position": Object {
"end": Object {
"column": 1,
"line": 1,
"offset": 0,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"title": "returns",
@ -2251,51 +2087,13 @@ Array [
Object {
"children": Array [
Object {
"position": Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "test",
},
],
"position": Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"examples": Array [],
@ -2331,18 +2129,6 @@ Array [
Object {
"description": Object {
"children": Array [],
"position": Object {
"end": Object {
"column": 1,
"line": 1,
"offset": 0,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"title": "returns",
@ -2387,51 +2173,13 @@ Array [
Object {
"children": Array [
Object {
"position": Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "test",
},
],
"position": Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 5,
"line": 1,
"offset": 4,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"examples": Array [],
@ -2467,18 +2215,6 @@ Array [
Object {
"description": Object {
"children": Array [],
"position": Object {
"end": Object {
"column": 1,
"line": 1,
"offset": 0,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"title": "returns",

View File

@ -9,51 +9,13 @@ Array [
Object {
"children": Array [
Object {
"position": Position {
"end": Object {
"column": 3,
"line": 1,
"offset": 2,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "hi",
},
],
"position": Position {
"end": Object {
"column": 3,
"line": 1,
"offset": 2,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 3,
"line": 1,
"offset": 2,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"errors": Array [],
@ -118,49 +80,11 @@ exports[`build 3`] = `
\\"children\\": [
{
\\"type\\": \\"text\\",
\\"value\\": \\"hi\\",
\\"position\\": {
\\"start\\": {
\\"line\\": 1,
\\"column\\": 1,
\\"offset\\": 0
},
\\"end\\": {
\\"line\\": 1,
\\"column\\": 3,
\\"offset\\": 2
},
\\"indent\\": []
}
\\"value\\": \\"hi\\"
}
],
\\"position\\": {
\\"start\\": {
\\"line\\": 1,
\\"column\\": 1,
\\"offset\\": 0
},
\\"end\\": {
\\"line\\": 1,
\\"column\\": 3,
\\"offset\\": 2
},
\\"indent\\": []
}
]
}
],
\\"position\\": {
\\"start\\": {
\\"line\\": 1,
\\"column\\": 1,
\\"offset\\": 0
},
\\"end\\": {
\\"line\\": 1,
\\"column\\": 3,
\\"offset\\": 2
}
}
]
},
\\"tags\\": [],
\\"loc\\": {

File diff suppressed because it is too large Load Diff

View File

@ -8,52 +8,14 @@ Array [
Object {
"children": Array [
Object {
"position": Position {
"end": Object {
"column": 16,
"line": 1,
"offset": 15,
},
"indent": Array [],
"start": Object {
"column": 3,
"line": 1,
"offset": 2,
},
},
"type": "text",
"value": "The Snowflake",
},
],
"depth": 1,
"position": Position {
"end": Object {
"column": 16,
"line": 1,
"offset": 15,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "heading",
},
],
"position": Object {
"end": Object {
"column": 1,
"line": 2,
"offset": 16,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"kind": "note",
@ -94,52 +56,14 @@ Array [
Object {
"children": Array [
Object {
"position": Position {
"end": Object {
"column": 16,
"line": 1,
"offset": 15,
},
"indent": Array [],
"start": Object {
"column": 3,
"line": 1,
"offset": 2,
},
},
"type": "text",
"value": "The Snowflake",
},
],
"depth": 1,
"position": Position {
"end": Object {
"column": 16,
"line": 1,
"offset": 15,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "heading",
},
],
"position": Object {
"end": Object {
"column": 1,
"line": 2,
"offset": 16,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"kind": "note",

View File

@ -334,51 +334,13 @@ Array [
Object {
"children": Array [
Object {
"position": Position {
"end": Object {
"column": 28,
"line": 1,
"offset": 27,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "renamed destructuring param",
},
],
"position": Position {
"end": Object {
"column": 28,
"line": 1,
"offset": 27,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 28,
"line": 1,
"offset": 27,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"lineNumber": 2,

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
const remark = require('remark');
const parse = require('../../../src/parsers/javascript');
const remarkParse = remark().use({ settings: { position: false } }).parse;
function toComments(source, filename, opts) {
source = typeof source === 'string' ? source : '(' + source.toString() + ')';
@ -12,41 +13,41 @@ function toComments(source, filename, opts) {
);
}
test('parse - leading comment', function() {
test('parse - leading comment', function () {
expect(
toComments(function() {
toComments(function () {
/** one */
/** two */
function two() {}
}).map(function(c) {
}).map(function (c) {
return c.description;
})
).toEqual([remark().parse('one'), remark().parse('two')]);
).toEqual([remarkParse('one'), remarkParse('two')]);
});
test('parse - trailing comment', function() {
test('parse - trailing comment', function () {
expect(
toComments(function() {
toComments(function () {
/** one */
function one() {}
/** two */
}).map(function(c) {
}).map(function (c) {
return c.description;
})
).toEqual([remark().parse('one'), remark().parse('two')]);
).toEqual([remarkParse('one'), remarkParse('two')]);
});
test('parse - unknown tag', function() {
test('parse - unknown tag', function () {
expect(
toComments(function() {
toComments(function () {
/** @unknown */
})[0].tags[0].title
).toBe('unknown');
});
test('parse - error', function() {
test('parse - error', function () {
expect(
toComments(function() {
toComments(function () {
/** @param {foo */
})[0].errors
).toEqual([
@ -55,7 +56,7 @@ test('parse - error', function() {
]);
});
test('parse - document exported', function() {
test('parse - document exported', function () {
expect(
toComments(
`
@ -85,7 +86,7 @@ test('parse - document exported', function() {
).toBe(2);
});
test('parse - constructor comments', function() {
test('parse - constructor comments', function () {
expect(
toComments(`
class Test {

View File

@ -1,7 +1,7 @@
const sort = require('../../src/sort');
const path = require('path');
test('sort stream alphanumeric', function() {
test('sort stream alphanumeric', function () {
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const banana = { context: { sortKey: 'c' }, name: 'bananas' };
@ -11,7 +11,7 @@ test('sort stream alphanumeric', function() {
expect(sort([carrot, apples, banana])).toEqual([apples, carrot, banana]);
});
test('sort stream with configuration', function() {
test('sort stream with configuration', function () {
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const bananas = { context: { sortKey: 'c' }, name: 'bananas' };
@ -23,7 +23,7 @@ test('sort stream with configuration', function() {
).toEqual([carrot, bananas, apples]);
});
test('sort stream with configuration and a section', function() {
test('sort stream with configuration and a section', function () {
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const bananas = { context: { sortKey: 'c' }, name: 'bananas' };
@ -43,49 +43,11 @@ test('sort stream with configuration and a section', function() {
children: [
{
type: 'text',
value: 'here lies bananas',
position: {
start: {
line: 1,
column: 1,
offset: 0
},
end: {
line: 1,
column: 18,
offset: 17
},
indent: []
}
value: 'here lies bananas'
}
],
position: {
start: {
line: 1,
column: 1,
offset: 0
},
end: {
line: 1,
column: 18,
offset: 17
},
indent: []
}
]
}
],
position: {
start: {
line: 1,
column: 1,
offset: 0
},
end: {
line: 1,
column: 18,
offset: 17
}
}
]
},
kind: 'note',
path: [
@ -103,7 +65,7 @@ test('sort stream with configuration and a section', function() {
).toEqual([carrot, sectionMarkdown, bananas, apples]);
});
test('sort an already-sorted stream containing a section/description', function() {
test('sort an already-sorted stream containing a section/description', function () {
// this happens in the 'serve' task
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
@ -123,49 +85,11 @@ test('sort an already-sorted stream containing a section/description', function(
children: [
{
type: 'text',
value: 'here lies bananas',
position: {
start: {
line: 1,
column: 1,
offset: 0
},
end: {
line: 1,
column: 18,
offset: 17
},
indent: []
}
value: 'here lies bananas'
}
],
position: {
start: {
line: 1,
column: 1,
offset: 0
},
end: {
line: 1,
column: 18,
offset: 17
},
indent: []
}
]
}
],
position: {
start: {
line: 1,
column: 1,
offset: 0
},
end: {
line: 1,
column: 18,
offset: 17
}
}
]
},
kind: 'note',
path: [
@ -185,7 +109,7 @@ test('sort an already-sorted stream containing a section/description', function(
expect(sortTwice).toEqual([carrot, sectionMarkdown, bananas, apples]);
});
test('sort toc with files', function() {
test('sort toc with files', function () {
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const bananas = { context: { sortKey: 'c' }, name: 'bananas' };
@ -202,7 +126,7 @@ test('sort toc with files', function() {
).toMatchSnapshot();
});
test('sort toc with files absolute path', function() {
test('sort toc with files absolute path', function () {
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const bananas = { context: { sortKey: 'c' }, name: 'bananas' };
@ -218,7 +142,7 @@ test('sort toc with files absolute path', function() {
).toMatchSnapshot();
});
test('sort toc with files absolute path', function() {
test('sort toc with files absolute path', function () {
const apples = {
context: { sortKey: 'a' },
name: 'apples',

View File

@ -60,8 +60,8 @@
"stream-array": "^1.1.2",
"strip-json-comments": "^2.0.1",
"tiny-lr": "^1.1.0",
"unist-builder": "^1.0.2",
"unist-util-visit": "^1.3.0",
"unist-builder": "^2.0.3",
"unist-util-visit": "^2.0.3",
"vfile": "^4.0.0",
"vfile-reporter": "^6.0.0",
"vfile-sort": "^2.1.0",
@ -71,7 +71,6 @@
"yargs": "^15.3.1"
},
"devDependencies": {
"babel-core": "^7.0.0-bridge.0",
"chdir": "0.0.0",
"cz-conventional-changelog": "2.1.0",
"documentation-schema": "0.0.1",

View File

@ -10,7 +10,9 @@ const inlineTokenizer = require('./inline_tokenizer');
* @private
*/
function parseMarkdown(string) {
return remark().use(inlineTokenizer).parse(string);
return remark()
.use({ plugins: [inlineTokenizer], settings: { position: false } })
.parse(string);
}
module.exports = parseMarkdown;

View File

@ -1695,11 +1695,6 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
babel-core@^7.0.0-bridge.0:
version "7.0.0-bridge.0"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
integrity sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==
babel-jest@^26.6.3:
version "26.6.3"
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-26.6.3.tgz#d87d25cb0037577a0c89f82e5755c5d293c01056"
@ -7682,14 +7677,7 @@ unique-stream@^2.0.2:
json-stable-stringify-without-jsonify "^1.0.1"
through2-filter "^3.0.0"
unist-builder@^1.0.2:
version "1.0.4"
resolved "https://registry.yarnpkg.com/unist-builder/-/unist-builder-1.0.4.tgz#e1808aed30bd72adc3607f25afecebef4dd59e17"
integrity sha512-v6xbUPP7ILrT15fHGrNyHc1Xda8H3xVhP7/HAIotHOhVPjH5dCXA097C3Rry1Q2O+HbOLCao4hfPB+EYEjHgVg==
dependencies:
object-assign "^4.1.0"
unist-builder@^2.0.0:
unist-builder@^2.0.0, unist-builder@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/unist-builder/-/unist-builder-2.0.3.tgz#77648711b5d86af0942f334397a33c5e91516436"
integrity sha512-f98yt5pnlMWlzP539tPc4grGMsFaQQlP/vM396b00jngsiINumNmsY8rkXjfoi1c6QaM8nQ3vaGDuoKWbe/1Uw==
@ -7699,11 +7687,6 @@ unist-util-generated@^1.0.0:
resolved "https://registry.yarnpkg.com/unist-util-generated/-/unist-util-generated-1.1.6.tgz#5ab51f689e2992a472beb1b35f2ce7ff2f324d4b"
integrity sha512-cln2Mm1/CZzN5ttGK7vkoGw+RZ8VcUH6BtGbq98DDtRGquAAOXig1mrBQYelOwMXYS8rK+vZDyyojSjp7JX+Lg==
unist-util-is@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-3.0.0.tgz#d9e84381c2468e82629e4a5be9d7d05a2dd324cd"
integrity sha512-sVZZX3+kspVNmLWBPAB6r+7D9ZgAFPNWm66f7YNb420RlQSbn+n8rG8dGZSkrER7ZIXGQYNm5pqC3v3HopH24A==
unist-util-is@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-4.1.0.tgz#976e5f462a7a5de73d94b706bac1b90671b57797"
@ -7728,13 +7711,6 @@ unist-util-stringify-position@^2.0.0:
dependencies:
"@types/unist" "^2.0.2"
unist-util-visit-parents@^2.0.0:
version "2.1.2"
resolved "https://registry.yarnpkg.com/unist-util-visit-parents/-/unist-util-visit-parents-2.1.2.tgz#25e43e55312166f3348cae6743588781d112c1e9"
integrity sha512-DyN5vD4NE3aSeB+PXYNKxzGsfocxp6asDc2XXE3b0ekO2BaRUpBicbbUygfSvYfUz1IkmjFR1YF7dPklraMZ2g==
dependencies:
unist-util-is "^3.0.0"
unist-util-visit-parents@^3.0.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/unist-util-visit-parents/-/unist-util-visit-parents-3.1.1.tgz#65a6ce698f78a6b0f56aa0e88f13801886cdaef6"
@ -7743,14 +7719,7 @@ unist-util-visit-parents@^3.0.0:
"@types/unist" "^2.0.0"
unist-util-is "^4.0.0"
unist-util-visit@^1.3.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-1.4.1.tgz#4724aaa8486e6ee6e26d7ff3c8685960d560b1e3"
integrity sha512-AvGNk7Bb//EmJZyhtRUnNMEpId/AZ5Ph/KUpTI09WHQuDZHKovQ1oEv3mfmKpWKtoMzyMC4GLBm1Zy5k12fjIw==
dependencies:
unist-util-visit-parents "^2.0.0"
unist-util-visit@^2.0.0:
unist-util-visit@^2.0.0, unist-util-visit@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-2.0.3.tgz#c3703893146df47203bb8a9795af47d7b971208c"
integrity sha512-iJ4/RczbJMkD0712mGktuGpm/U4By4FfDonL7N/9tATGIF4imikjOuagyMY53tnZq3NP6BcmlrHhEKAfGWjh7Q==