aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/rules/completedDocsRule.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/tslint/lib/rules/completedDocsRule.js
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/tslint/lib/rules/completedDocsRule.js')
-rw-r--r--node_modules/tslint/lib/rules/completedDocsRule.js236
1 files changed, 134 insertions, 102 deletions
diff --git a/node_modules/tslint/lib/rules/completedDocsRule.js b/node_modules/tslint/lib/rules/completedDocsRule.js
index 6107859a6..515ca257d 100644
--- a/node_modules/tslint/lib/rules/completedDocsRule.js
+++ b/node_modules/tslint/lib/rules/completedDocsRule.js
@@ -17,12 +17,14 @@
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
+var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
var utils_1 = require("../utils");
exports.ALL = "all";
exports.ARGUMENT_CLASSES = "classes";
exports.ARGUMENT_ENUMS = "enums";
+exports.ARGUMENT_ENUM_MEMBERS = "enum-members";
exports.ARGUMENT_FUNCTIONS = "functions";
exports.ARGUMENT_INTERFACES = "interfaces";
exports.ARGUMENT_METHODS = "methods";
@@ -58,100 +60,101 @@ var Rule = (function (_super) {
}
return Requirement.constructRequirements(ruleArguments);
};
- return Rule;
-}(Lint.Rules.TypedRule));
-Rule.FAILURE_STRING_EXIST = "Documentation must exist for ";
-Rule.defaultArguments = [
- exports.ARGUMENT_CLASSES,
- exports.ARGUMENT_FUNCTIONS,
- exports.ARGUMENT_METHODS,
- exports.ARGUMENT_PROPERTIES,
-];
-Rule.ARGUMENT_DESCRIPTOR_BLOCK = {
- properties: (_a = {},
- _a[exports.DESCRIPTOR_VISIBILITIES] = {
- enum: [
- exports.ALL,
- exports.VISIBILITY_EXPORTED,
- exports.VISIBILITY_INTERNAL,
- ],
- type: "string",
- },
- _a),
- type: "object",
-};
-Rule.ARGUMENT_DESCRIPTOR_CLASS = {
- properties: (_b = {},
- _b[exports.DESCRIPTOR_LOCATIONS] = {
- enum: [
- exports.ALL,
- exports.LOCATION_INSTANCE,
- exports.LOCATION_STATIC,
- ],
- type: "string",
- },
- _b[exports.DESCRIPTOR_PRIVACIES] = {
- enum: [
- exports.ALL,
- exports.PRIVACY_PRIVATE,
- exports.PRIVACY_PROTECTED,
- exports.PRIVACY_PUBLIC,
- ],
- type: "string",
- },
- _b),
- type: "object",
-};
-/* tslint:disable:object-literal-sort-keys */
-Rule.metadata = {
- ruleName: "completed-docs",
- description: "Enforces documentation for important items be filled out.",
- optionsDescription: (_c = ["\n `true` to enable for [\"", "\", \"", "\", \"", "\", \"", "\"],\n or an array with each item in one of two formats:\n\n * `string` to enable for that type\n * `object` keying types to when their documentation is required:\n * `\"", "\"` and `\"", "\"` may specify:\n * `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * All other types may specify `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n\n Types that may be enabled are:\n\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`"], _c.raw = ["\n \\`true\\` to enable for [\"", "\", \"", "\", \"", "\", \"", "\"],\n or an array with each item in one of two formats:\n\n * \\`string\\` to enable for that type\n * \\`object\\` keying types to when their documentation is required:\n * \\`\"", "\"\\` and \\`\"", "\"\\` may specify:\n * \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * All other types may specify \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n\n Types that may be enabled are:\n\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`"], Lint.Utils.dedent(_c, exports.ARGUMENT_CLASSES, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_METHODS, exports.ARGUMENT_PROPERTIES, exports.ARGUMENT_METHODS, exports.ARGUMENT_PROPERTIES, exports.DESCRIPTOR_PRIVACIES, exports.ALL, exports.PRIVACY_PRIVATE, exports.PRIVACY_PROTECTED, exports.PRIVACY_PUBLIC, exports.DESCRIPTOR_LOCATIONS, exports.ALL, exports.LOCATION_INSTANCE, exports.LOCATION_STATIC, exports.DESCRIPTOR_VISIBILITIES, exports.ALL, exports.VISIBILITY_EXPORTED, exports.VISIBILITY_INTERNAL, exports.ARGUMENT_CLASSES, exports.ARGUMENT_ENUMS, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_INTERFACES, exports.ARGUMENT_METHODS, exports.ARGUMENT_NAMESPACES, exports.ARGUMENT_PROPERTIES, exports.ARGUMENT_TYPES, exports.ARGUMENT_VARIABLES)),
- options: {
- type: "array",
- items: {
- anyOf: [
- {
- enum: Rule.defaultArguments,
- type: "string",
- },
- {
- type: "object",
- properties: (_d = {},
- _d[exports.ARGUMENT_CLASSES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_ENUMS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_FUNCTIONS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_INTERFACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_METHODS] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
- _d[exports.ARGUMENT_NAMESPACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_PROPERTIES] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
- _d[exports.ARGUMENT_TYPES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d[exports.ARGUMENT_VARIABLES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
- _d),
- },
- ],
+ Rule.FAILURE_STRING_EXIST = "Documentation must exist for ";
+ Rule.defaultArguments = [
+ exports.ARGUMENT_CLASSES,
+ exports.ARGUMENT_FUNCTIONS,
+ exports.ARGUMENT_METHODS,
+ exports.ARGUMENT_PROPERTIES,
+ ];
+ Rule.ARGUMENT_DESCRIPTOR_BLOCK = {
+ properties: (_a = {},
+ _a[exports.DESCRIPTOR_VISIBILITIES] = {
+ enum: [
+ exports.ALL,
+ exports.VISIBILITY_EXPORTED,
+ exports.VISIBILITY_INTERNAL,
+ ],
+ type: "string",
+ },
+ _a),
+ type: "object",
+ };
+ Rule.ARGUMENT_DESCRIPTOR_CLASS = {
+ properties: (_b = {},
+ _b[exports.DESCRIPTOR_LOCATIONS] = {
+ enum: [
+ exports.ALL,
+ exports.LOCATION_INSTANCE,
+ exports.LOCATION_STATIC,
+ ],
+ type: "string",
+ },
+ _b[exports.DESCRIPTOR_PRIVACIES] = {
+ enum: [
+ exports.ALL,
+ exports.PRIVACY_PRIVATE,
+ exports.PRIVACY_PROTECTED,
+ exports.PRIVACY_PUBLIC,
+ ],
+ type: "string",
+ },
+ _b),
+ type: "object",
+ };
+ /* tslint:disable:object-literal-sort-keys */
+ Rule.metadata = {
+ ruleName: "completed-docs",
+ description: "Enforces documentation for important items be filled out.",
+ optionsDescription: (_c = ["\n `true` to enable for [\"", "\", \"", "\", \"", "\", \"", "\"],\n or an array with each item in one of two formats:\n\n * `string` to enable for that type\n * `object` keying types to when their documentation is required:\n * `\"", "\"` and `\"", "\"` may specify:\n * `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * All other types may specify `\"", "\"`:\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n\n Types that may be enabled are:\n\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`\n * `\"", "\"`"], _c.raw = ["\n \\`true\\` to enable for [\"", "\", \"", "\", \"", "\", \"", "\"],\n or an array with each item in one of two formats:\n\n * \\`string\\` to enable for that type\n * \\`object\\` keying types to when their documentation is required:\n * \\`\"", "\"\\` and \\`\"", "\"\\` may specify:\n * \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * All other types may specify \\`\"", "\"\\`:\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n\n Types that may be enabled are:\n\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`\n * \\`\"", "\"\\`"], Lint.Utils.dedent(_c, exports.ARGUMENT_CLASSES, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_METHODS, exports.ARGUMENT_PROPERTIES, exports.ARGUMENT_METHODS, exports.ARGUMENT_PROPERTIES, exports.DESCRIPTOR_PRIVACIES, exports.ALL, exports.PRIVACY_PRIVATE, exports.PRIVACY_PROTECTED, exports.PRIVACY_PUBLIC, exports.DESCRIPTOR_LOCATIONS, exports.ALL, exports.LOCATION_INSTANCE, exports.LOCATION_STATIC, exports.DESCRIPTOR_VISIBILITIES, exports.ALL, exports.VISIBILITY_EXPORTED, exports.VISIBILITY_INTERNAL, exports.ARGUMENT_CLASSES, exports.ARGUMENT_ENUMS, exports.ARGUMENT_ENUM_MEMBERS, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_INTERFACES, exports.ARGUMENT_METHODS, exports.ARGUMENT_NAMESPACES, exports.ARGUMENT_PROPERTIES, exports.ARGUMENT_TYPES, exports.ARGUMENT_VARIABLES)),
+ options: {
+ type: "array",
+ items: {
+ anyOf: [
+ {
+ enum: Rule.defaultArguments,
+ type: "string",
+ },
+ {
+ type: "object",
+ properties: (_d = {},
+ _d[exports.ARGUMENT_CLASSES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _d[exports.ARGUMENT_ENUMS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _d[exports.ARGUMENT_ENUM_MEMBERS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _d[exports.ARGUMENT_FUNCTIONS] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _d[exports.ARGUMENT_INTERFACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _d[exports.ARGUMENT_METHODS] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
+ _d[exports.ARGUMENT_NAMESPACES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _d[exports.ARGUMENT_PROPERTIES] = Rule.ARGUMENT_DESCRIPTOR_CLASS,
+ _d[exports.ARGUMENT_TYPES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _d[exports.ARGUMENT_VARIABLES] = Rule.ARGUMENT_DESCRIPTOR_BLOCK,
+ _d),
+ },
+ ],
+ },
},
- },
- optionExamples: [
- true,
- [true, exports.ARGUMENT_ENUMS, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_METHODS],
- [
+ optionExamples: [
true,
- (_e = {},
- _e[exports.ARGUMENT_ENUMS] = true,
- _e[exports.ARGUMENT_FUNCTIONS] = (_f = {},
- _f[exports.DESCRIPTOR_VISIBILITIES] = [exports.VISIBILITY_EXPORTED],
- _f),
- _e[exports.ARGUMENT_METHODS] = (_g = {},
- _g[exports.DESCRIPTOR_LOCATIONS] = exports.LOCATION_INSTANCE,
- _g[exports.DESCRIPTOR_PRIVACIES] = [exports.PRIVACY_PUBLIC, exports.PRIVACY_PROTECTED],
- _g),
- _e),
+ [true, exports.ARGUMENT_ENUMS, exports.ARGUMENT_FUNCTIONS, exports.ARGUMENT_METHODS],
+ [
+ true,
+ (_e = {},
+ _e[exports.ARGUMENT_ENUMS] = true,
+ _e[exports.ARGUMENT_FUNCTIONS] = (_f = {},
+ _f[exports.DESCRIPTOR_VISIBILITIES] = [exports.VISIBILITY_EXPORTED],
+ _f),
+ _e[exports.ARGUMENT_METHODS] = (_g = {},
+ _g[exports.DESCRIPTOR_LOCATIONS] = exports.LOCATION_INSTANCE,
+ _g[exports.DESCRIPTOR_PRIVACIES] = [exports.PRIVACY_PUBLIC, exports.PRIVACY_PROTECTED],
+ _g),
+ _e),
+ ],
],
- ],
- type: "style",
- typescriptOnly: false,
-};
+ type: "style",
+ typescriptOnly: false,
+ };
+ return Rule;
+}(Lint.Rules.TypedRule));
exports.Rule = Rule;
var Requirement = (function () {
// tslint:disable-next-line no-object-literal-type-assertion
@@ -256,6 +259,12 @@ var CompletedDocsWalker = (function (_super) {
this.checkNode(node, exports.ARGUMENT_ENUMS);
_super.prototype.visitEnumDeclaration.call(this, node);
};
+ CompletedDocsWalker.prototype.visitEnumMember = function (node) {
+ // Enum members don't have modifiers, so use the parent
+ // enum declaration when checking the requirements.
+ this.checkNode(node, exports.ARGUMENT_ENUM_MEMBERS, node.parent);
+ _super.prototype.visitEnumMember.call(this, node);
+ };
CompletedDocsWalker.prototype.visitFunctionDeclaration = function (node) {
this.checkNode(node, exports.ARGUMENT_FUNCTIONS);
_super.prototype.visitFunctionDeclaration.call(this, node);
@@ -281,16 +290,36 @@ var CompletedDocsWalker = (function (_super) {
_super.prototype.visitTypeAliasDeclaration.call(this, node);
};
CompletedDocsWalker.prototype.visitVariableDeclaration = function (node) {
- this.checkNode(node, exports.ARGUMENT_VARIABLES);
+ this.checkVariable(node);
_super.prototype.visitVariableDeclaration.call(this, node);
};
- CompletedDocsWalker.prototype.checkNode = function (node, nodeType) {
+ CompletedDocsWalker.prototype.checkVariable = function (node) {
+ // Only check variables in variable declaration lists
+ // and not variables in catch clauses and for loops.
+ var list = node.parent;
+ if (!tsutils_1.isVariableDeclarationList(list)) {
+ return;
+ }
+ var statement = list.parent;
+ if (!tsutils_1.isVariableStatement(statement)) {
+ return;
+ }
+ // Only check variables at the namespace/module-level or file-level
+ // and not variables declared inside functions and other things.
+ switch (statement.parent.kind) {
+ case ts.SyntaxKind.SourceFile:
+ case ts.SyntaxKind.ModuleBlock:
+ this.checkNode(node, exports.ARGUMENT_VARIABLES, statement);
+ }
+ };
+ CompletedDocsWalker.prototype.checkNode = function (node, nodeType, requirementNode) {
+ if (requirementNode === void 0) { requirementNode = node; }
var name = node.name;
if (name === undefined) {
return;
}
var requirement = this.requirements.get(nodeType);
- if (requirement === undefined || !requirement.shouldNodeBeDocumented(node)) {
+ if (requirement === undefined || !requirement.shouldNodeBeDocumented(requirementNode)) {
return;
}
var symbol = this.getTypeChecker().getSymbolAtLocation(name);
@@ -298,17 +327,20 @@ var CompletedDocsWalker = (function (_super) {
return;
}
var comments = symbol.getDocumentationComment();
- this.checkComments(node, nodeType, comments);
+ this.checkComments(node, this.describeNode(nodeType), comments, requirementNode);
+ };
+ CompletedDocsWalker.prototype.describeNode = function (nodeType) {
+ return nodeType.replace("-", " ");
};
- CompletedDocsWalker.prototype.checkComments = function (node, nodeDescriptor, comments) {
+ CompletedDocsWalker.prototype.checkComments = function (node, nodeDescriptor, comments, requirementNode) {
if (comments.map(function (comment) { return comment.text; }).join("").trim() === "") {
- this.addDocumentationFailure(node, nodeDescriptor);
+ this.addDocumentationFailure(node, nodeDescriptor, requirementNode);
}
};
- CompletedDocsWalker.prototype.addDocumentationFailure = function (node, nodeType) {
+ CompletedDocsWalker.prototype.addDocumentationFailure = function (node, nodeType, requirementNode) {
var start = node.getStart();
var width = node.getText().split(/\r|\n/g)[0].length;
- var description = this.describeDocumentationFailure(node, nodeType);
+ var description = this.describeDocumentationFailure(requirementNode, nodeType);
this.addFailureAt(start, width, description);
};
CompletedDocsWalker.prototype.describeDocumentationFailure = function (node, nodeType) {
@@ -324,9 +356,9 @@ var CompletedDocsWalker = (function (_super) {
var alias = CompletedDocsWalker.modifierAliases[description];
return alias !== undefined ? alias : description;
};
+ CompletedDocsWalker.modifierAliases = {
+ export: "exported",
+ };
return CompletedDocsWalker;
}(Lint.ProgramAwareRuleWalker));
-CompletedDocsWalker.modifierAliases = {
- export: "exported",
-};
var _a, _b, _c, _d, _e, _f, _g;