mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 17:57:36 +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>
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.getJoiner = void 0;
|
|
|
|
const primitives_1 = require("../../primitives.cjs");
|
|
/**
|
|
* Makes no changes to `spec.lines[].tokens` but joins them into `spec.description`
|
|
* following given spacing srtategy
|
|
* @param {Spacing} spacing tells how to handle the whitespace
|
|
* @param {BlockMarkers} markers tells how to handle comment block delimitation
|
|
*/
|
|
|
|
|
|
function descriptionTokenizer(spacing = 'compact', markers = primitives_1.Markers) {
|
|
const join = getJoiner(spacing);
|
|
return spec => {
|
|
spec.description = join(spec.source, markers);
|
|
return spec;
|
|
};
|
|
}
|
|
|
|
exports.default = descriptionTokenizer;
|
|
|
|
function getJoiner(spacing) {
|
|
if (spacing === 'compact') return compactJoiner;
|
|
if (spacing === 'preserve') return preserveJoiner;
|
|
return spacing;
|
|
}
|
|
|
|
exports.getJoiner = getJoiner;
|
|
|
|
function compactJoiner(lines, markers = primitives_1.Markers) {
|
|
return lines.map(({
|
|
tokens: {
|
|
description
|
|
}
|
|
}) => description.trim()).filter(description => description !== '').join(' ');
|
|
}
|
|
|
|
const lineNo = (num, {
|
|
tokens
|
|
}, i) => tokens.type === '' ? num : i;
|
|
|
|
const getDescription = ({
|
|
tokens
|
|
}) => (tokens.delimiter === '' ? tokens.start : tokens.postDelimiter.slice(1)) + tokens.description;
|
|
|
|
function preserveJoiner(lines, markers = primitives_1.Markers) {
|
|
if (lines.length === 0) return ''; // skip the opening line with no description
|
|
|
|
if (lines[0].tokens.description === '' && lines[0].tokens.delimiter === markers.start) lines = lines.slice(1); // skip the closing line with no description
|
|
|
|
const lastLine = lines[lines.length - 1];
|
|
if (lastLine !== undefined && lastLine.tokens.description === '' && lastLine.tokens.end.endsWith(markers.end)) lines = lines.slice(0, -1); // description starts at the last line of type definition
|
|
|
|
lines = lines.slice(lines.reduce(lineNo, 0));
|
|
return lines.map(getDescription).join('\n');
|
|
}
|
|
//# sourceMappingURL=description.cjs.map
|