mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-02 18:11:04 +08:00
This CL adds the eslint-plugin-jsdoc plugin and enables just one rule, `jsdoc/check-alignment`, which ensures that all the lines in a comment are correctly aligned. For example: ``` /** * foo * bar */ ``` Would fail the check and be corrected to: ``` /** * foo * bar */ ``` DISABLE_THIRD_PARTY_CHECK=deliberate install + use of eslint-plugin-jsdoc node_module Bug: none Change-Id: I969983cd550653654a334ede3409b8c850467245 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4110906 Commit-Queue: Andres Olivares <andoli@chromium.org> Reviewed-by: Andres Olivares <andoli@chromium.org> Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
582 lines
10 KiB
JavaScript
582 lines
10 KiB
JavaScript
const { default: getParser } = require('../../lib/parser/index.cjs');
|
|
|
|
test('fenced description', () => {
|
|
const parsed = getParser({ spacing: 'preserve' })(`
|
|
/**
|
|
* @example "" \`\`\`ts
|
|
@transient()
|
|
class Foo { }
|
|
\`\`\`
|
|
*/`);
|
|
|
|
const source = [
|
|
{
|
|
number: 1,
|
|
source: ' /**',
|
|
tokens: {
|
|
start: ' ',
|
|
delimiter: '/**',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 2,
|
|
source: ' * @example "" ```ts',
|
|
tokens: {
|
|
start: ' ',
|
|
delimiter: '*',
|
|
postDelimiter: ' ',
|
|
tag: '@example',
|
|
postTag: ' ',
|
|
name: '""',
|
|
postName: ' ',
|
|
type: '',
|
|
postType: '',
|
|
description: '```ts',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 3,
|
|
source: '@transient()',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '@transient()',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 4,
|
|
source: 'class Foo { }',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: 'class Foo { }',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 5,
|
|
source: '```',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '```',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 6,
|
|
source: ' */',
|
|
tokens: {
|
|
start: ' ',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '',
|
|
end: '*/',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
];
|
|
|
|
expect(parsed).toEqual([
|
|
{
|
|
description: '',
|
|
tags: [
|
|
{
|
|
tag: 'example',
|
|
name: '',
|
|
type: '',
|
|
optional: false,
|
|
description: '```ts\n@transient()\nclass Foo { }\n```',
|
|
problems: [],
|
|
source: source.slice(1),
|
|
},
|
|
],
|
|
source,
|
|
problems: [],
|
|
},
|
|
]);
|
|
});
|
|
|
|
test('fenced one-liner', () => {
|
|
const parsed = getParser({ spacing: 'preserve' })(
|
|
'/** @example "" ```ts @transient() class Foo { } ```*/'
|
|
);
|
|
|
|
const source = [
|
|
{
|
|
number: 0,
|
|
source: '/** @example "" ```ts @transient() class Foo { } ```*/',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '/**',
|
|
postDelimiter: ' ',
|
|
tag: '@example',
|
|
postTag: ' ',
|
|
name: '""',
|
|
postName: ' ',
|
|
type: '',
|
|
postType: '',
|
|
description: '```ts @transient() class Foo { } ```',
|
|
end: '*/',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
];
|
|
|
|
expect(parsed).toEqual([
|
|
{
|
|
description: '',
|
|
tags: [
|
|
{
|
|
tag: 'example',
|
|
name: '',
|
|
type: '',
|
|
optional: false,
|
|
description: '```ts @transient() class Foo { } ```',
|
|
problems: [],
|
|
source,
|
|
},
|
|
],
|
|
source,
|
|
problems: [],
|
|
},
|
|
]);
|
|
});
|
|
|
|
test('multiple fences', () => {
|
|
const parsed = getParser({ spacing: 'preserve' })(`
|
|
/**
|
|
* @example "" \`\`\`ts
|
|
@one
|
|
\`\`\`
|
|
text
|
|
\`\`\`
|
|
@two
|
|
\`\`\`
|
|
*/`);
|
|
|
|
const source = [
|
|
{
|
|
number: 1,
|
|
source: ' /**',
|
|
tokens: {
|
|
start: ' ',
|
|
delimiter: '/**',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 2,
|
|
source: ' * @example "" ```ts',
|
|
tokens: {
|
|
start: ' ',
|
|
delimiter: '*',
|
|
postDelimiter: ' ',
|
|
tag: '@example',
|
|
postTag: ' ',
|
|
name: '""',
|
|
postName: ' ',
|
|
type: '',
|
|
postType: '',
|
|
description: '```ts',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 3,
|
|
source: '@one',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '@one',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 4,
|
|
source: '```',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '```',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 5,
|
|
source: 'text',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: 'text',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 6,
|
|
source: '```',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '```',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 7,
|
|
source: '@two',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '@two',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 8,
|
|
source: '```',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '```',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 9,
|
|
source: ' */',
|
|
tokens: {
|
|
start: ' ',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '',
|
|
end: '*/',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
];
|
|
|
|
expect(parsed).toEqual([
|
|
{
|
|
description: '',
|
|
tags: [
|
|
{
|
|
tag: 'example',
|
|
name: '',
|
|
type: '',
|
|
optional: false,
|
|
description: '```ts\n@one\n```\ntext\n```\n@two\n```',
|
|
source: source.slice(1),
|
|
problems: [],
|
|
},
|
|
],
|
|
source,
|
|
problems: [],
|
|
},
|
|
]);
|
|
});
|
|
|
|
test('custom fences', () => {
|
|
const parsed = getParser({ spacing: 'preserve', fence: '###' })(`
|
|
/**
|
|
* @example "" ###ts
|
|
@one
|
|
###
|
|
text
|
|
###
|
|
@two
|
|
###
|
|
*/`);
|
|
|
|
const source = [
|
|
{
|
|
number: 1,
|
|
source: ' /**',
|
|
tokens: {
|
|
start: ' ',
|
|
delimiter: '/**',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 2,
|
|
source: ' * @example "" ###ts',
|
|
tokens: {
|
|
start: ' ',
|
|
delimiter: '*',
|
|
postDelimiter: ' ',
|
|
tag: '@example',
|
|
postTag: ' ',
|
|
name: '""',
|
|
postName: ' ',
|
|
type: '',
|
|
postType: '',
|
|
description: '###ts',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 3,
|
|
source: '@one',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '@one',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 4,
|
|
source: '###',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '###',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 5,
|
|
source: 'text',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: 'text',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 6,
|
|
source: '###',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '###',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 7,
|
|
source: '@two',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '@two',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 8,
|
|
source: '###',
|
|
tokens: {
|
|
start: '',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '###',
|
|
end: '',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
{
|
|
number: 9,
|
|
source: ' */',
|
|
tokens: {
|
|
start: ' ',
|
|
delimiter: '',
|
|
postDelimiter: '',
|
|
tag: '',
|
|
postTag: '',
|
|
name: '',
|
|
postName: '',
|
|
type: '',
|
|
postType: '',
|
|
description: '',
|
|
end: '*/',
|
|
lineEnd: '',
|
|
},
|
|
},
|
|
];
|
|
|
|
expect(parsed).toEqual([
|
|
{
|
|
description: '',
|
|
tags: [
|
|
{
|
|
tag: 'example',
|
|
name: '',
|
|
type: '',
|
|
optional: false,
|
|
description: '###ts\n@one\n###\ntext\n###\n@two\n###',
|
|
source: source.slice(1),
|
|
problems: [],
|
|
},
|
|
],
|
|
source,
|
|
problems: [],
|
|
},
|
|
]);
|
|
});
|