Enforce alignment of JSDoc comments

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>
This commit is contained in:
Jack Franklin
2022-12-21 12:30:47 +00:00
committed by Devtools-frontend LUCI CQ
parent ecd1fd2921
commit fd72c071cc
908 changed files with 69808 additions and 9491 deletions
+25
View File
@@ -0,0 +1,25 @@
import { Block, Tokens } from '../primitives';
export type Stringifier = (block: Block) => string;
function join(tokens: Tokens): string {
return (
tokens.start +
tokens.delimiter +
tokens.postDelimiter +
tokens.tag +
tokens.postTag +
tokens.type +
tokens.postType +
tokens.name +
tokens.postName +
tokens.description +
tokens.end +
tokens.lineEnd
);
}
export default function getStringifier(): Stringifier {
return (block: Block): string =>
block.source.map(({ tokens }) => join(tokens)).join('\n');
}
+68
View File
@@ -0,0 +1,68 @@
import { Block, Tokens } from '../primitives';
import { isSpace } from '../util';
interface Width {
line: number;
start: number;
delimiter: number;
postDelimiter: number;
tag: number;
postTag: number;
name: number;
postName: number;
type: number;
postType: number;
description: number;
end: number;
lineEnd: number;
}
const zeroWidth = {
line: 0,
start: 0,
delimiter: 0,
postDelimiter: 0,
tag: 0,
postTag: 0,
name: 0,
postName: 0,
type: 0,
postType: 0,
description: 0,
end: 0,
lineEnd: 0,
};
const headers = { lineEnd: 'CR' };
const fields = Object.keys(zeroWidth);
const repr = (x: string) => (isSpace(x) ? `{${x.length}}` : x);
const frame = (line: string[]) => '|' + line.join('|') + '|';
const align = (width: Width, tokens: Tokens): string[] =>
Object.keys(tokens).map((k) => repr(tokens[k]).padEnd(width[k]));
export default function inspect({ source }: Block): string {
if (source.length === 0) return '';
const width: Width = { ...zeroWidth };
for (const f of fields) width[f] = (headers[f] ?? f).length;
for (const { number, tokens } of source) {
width.line = Math.max(width.line, number.toString().length);
for (const k in tokens)
width[k] = Math.max(width[k], repr(tokens[k]).length);
}
const lines: string[][] = [[], []];
for (const f of fields) lines[0].push((headers[f] ?? f).padEnd(width[f]));
for (const f of fields) lines[1].push('-'.padEnd(width[f], '-'));
for (const { number, tokens } of source) {
const line = number.toString().padStart(width.line);
lines.push([line, ...align(width, tokens)]);
}
return lines.map(frame).join('\n');
}