github-pages-deploy-action/node_modules/eslint-plugin-jsdoc/dist/rules/checkValues.js

110 lines
3.7 KiB
JavaScript
Raw Normal View History

2020-03-31 20:40:00 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _semver = _interopRequireDefault(require("semver"));
var _spdxExpressionParse = _interopRequireDefault(require("spdx-expression-parse"));
var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = (0, _iterateJsdoc.default)(({
utils,
report,
context
}) => {
const options = context.options[0] || {};
const _options$allowedLicen = options.allowedLicenses,
allowedLicenses = _options$allowedLicen === void 0 ? null : _options$allowedLicen,
_options$allowedAutho = options.allowedAuthors,
allowedAuthors = _options$allowedAutho === void 0 ? null : _options$allowedAutho,
_options$licensePatte = options.licensePattern,
licensePattern = _options$licensePatte === void 0 ? '([^\n]*)' : _options$licensePatte;
utils.forEachPreferredTag('version', (jsdocParameter, targetTagName) => {
const version = jsdocParameter.description.trim();
if (!version) {
report(`Missing JSDoc @${targetTagName}.`, null, jsdocParameter);
} else if (!_semver.default.valid(version)) {
report(`Invalid JSDoc @${targetTagName}: "${jsdocParameter.description}".`, null, jsdocParameter);
}
});
utils.forEachPreferredTag('since', (jsdocParameter, targetTagName) => {
const version = jsdocParameter.description.trim();
if (!version) {
report(`Missing JSDoc @${targetTagName}.`, null, jsdocParameter);
} else if (!_semver.default.valid(version)) {
report(`Invalid JSDoc @${targetTagName}: "${jsdocParameter.description}".`, null, jsdocParameter);
}
});
utils.forEachPreferredTag('license', (jsdocParameter, targetTagName) => {
const licenseRegex = new RegExp(licensePattern, 'g');
const match = jsdocParameter.description.match(licenseRegex);
const license = match && match[1] || match[0];
if (!license.trim()) {
report(`Missing JSDoc @${targetTagName}.`, null, jsdocParameter);
} else if (allowedLicenses) {
if (allowedLicenses !== true && !allowedLicenses.includes(license)) {
report(`Invalid JSDoc @${targetTagName}: "${license}"; expected one of ${allowedLicenses.join(', ')}.`, null, jsdocParameter);
}
} else {
try {
(0, _spdxExpressionParse.default)(license);
} catch (error) {
report(`Invalid JSDoc @${targetTagName}: "${license}"; expected SPDX expression: https://spdx.org/licenses/.`, null, jsdocParameter);
}
}
});
utils.forEachPreferredTag('author', (jsdocParameter, targetTagName) => {
const author = jsdocParameter.description;
if (!author.trim()) {
report(`Missing JSDoc @${targetTagName}.`, null, jsdocParameter);
} else if (allowedAuthors) {
if (!allowedAuthors.includes(author)) {
report(`Invalid JSDoc @${targetTagName}: "${jsdocParameter.description}"; expected one of ${allowedAuthors.join(', ')}.`, null, jsdocParameter);
}
}
});
}, {
iterateAllJsdocs: true,
meta: {
schema: [{
additionalProperties: false,
properties: {
allowedAuthors: {
items: {
type: 'string'
},
type: 'array'
},
allowedLicenses: {
anyOf: [{
items: {
type: 'string'
},
type: 'array'
}, {
type: 'boolean'
}]
},
licensePattern: {
type: 'string'
}
},
type: 'object'
}],
type: 'suggestion'
}
});
exports.default = _default;
module.exports = exports.default;
//# sourceMappingURL=checkValues.js.map