mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
94 lines
3.6 KiB
JavaScript
94 lines
3.6 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
|
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
|
|
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
|
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
|
var _default = (0, _iterateJsdoc.default)(({
|
|
sourceCode,
|
|
utils,
|
|
report,
|
|
context,
|
|
jsdocNode
|
|
}) => {
|
|
const _context$options = _slicedToArray(context.options, 2),
|
|
circumstance = _context$options[0],
|
|
_context$options$ = _context$options[1],
|
|
_context$options$2 = _context$options$ === void 0 ? {} : _context$options$,
|
|
checkProperties = _context$options$2.checkProperties;
|
|
|
|
const always = !circumstance || circumstance === 'always';
|
|
|
|
const checkHyphens = (jsdocTag, targetTagName) => {
|
|
if (!jsdocTag.description) {
|
|
return;
|
|
}
|
|
|
|
if (always) {
|
|
if (!jsdocTag.description.startsWith('-')) {
|
|
report(`There must be a hyphen before @${targetTagName} description.`, fixer => {
|
|
const lineIndex = jsdocTag.line;
|
|
const sourceLines = sourceCode.getText(jsdocNode).split('\n'); // Get start index of description, accounting for multi-line descriptions
|
|
|
|
const description = jsdocTag.description.split('\n')[0];
|
|
const descriptionIndex = sourceLines[lineIndex].lastIndexOf(description);
|
|
const replacementLine = sourceLines[lineIndex].slice(0, descriptionIndex) + '- ' + description;
|
|
sourceLines.splice(lineIndex, 1, replacementLine);
|
|
const replacement = sourceLines.join('\n');
|
|
return fixer.replaceText(jsdocNode, replacement);
|
|
}, jsdocTag);
|
|
}
|
|
} else if (jsdocTag.description.startsWith('-')) {
|
|
report(`There must be no hyphen before @${targetTagName} description.`, fixer => {
|
|
const _$exec = /-\s*/u.exec(jsdocTag.description),
|
|
_$exec2 = _slicedToArray(_$exec, 1),
|
|
unwantedPart = _$exec2[0];
|
|
|
|
const replacement = sourceCode.getText(jsdocNode).replace(jsdocTag.description, jsdocTag.description.slice(unwantedPart.length));
|
|
return fixer.replaceText(jsdocNode, replacement);
|
|
}, jsdocTag);
|
|
}
|
|
};
|
|
|
|
utils.forEachPreferredTag('param', checkHyphens);
|
|
|
|
if (checkProperties) {
|
|
utils.forEachPreferredTag('property', checkHyphens);
|
|
}
|
|
}, {
|
|
iterateAllJsdocs: true,
|
|
meta: {
|
|
fixable: 'code',
|
|
schema: [{
|
|
enum: ['always', 'never'],
|
|
type: 'string'
|
|
}, {
|
|
additionalProperties: false,
|
|
properties: {
|
|
checkProperties: {
|
|
default: false,
|
|
type: 'boolean'
|
|
}
|
|
},
|
|
type: 'object'
|
|
}],
|
|
type: 'layout'
|
|
}
|
|
});
|
|
|
|
exports.default = _default;
|
|
module.exports = exports.default;
|
|
//# sourceMappingURL=requireHyphenBeforeParamDescription.js.map
|