Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
break;
}
case ts.SyntaxKind.VariableStatement:
// skip 'declare' keywords
if (tsutils.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword)) {
return;
}
break;
case ts.SyntaxKind.Parameter:
case ts.SyntaxKind.PropertyDeclaration:
handleDeclaredVariable(node as ts.ParameterDeclaration | ts.PropertyDeclaration);
break;
case ts.SyntaxKind.VariableDeclaration:
handleVariableDeclaration(node as ts.VariableDeclaration);
}
return ts.forEachChild(node, cb);
});
ts.forEachChild(parentNode, child => {
var item, code;
var name = ((child.name && child.name.getText) ?
child.name.getText() : child.name) ||
"";
var idParts = (parent && parent.id) ?
[parent.id, name] : [name];
var id = idParts.join(".");
switch (child.kind) {
case ts.SyntaxKind.ModuleDeclaration:
// create namespace item (unless already known)
item = { id, name, isNamespace: true };
code = "namespace " + name;
break;
case ts.SyntaxKind.ClassDeclaration:
// create class item
item = { id, name, isClass: true };
code = "class " + getClassCode(child);
break;
case ts.SyntaxKind.InterfaceDeclaration:
// create interface item
item = { id, name, isInterface: true };
code = "interface " + getClassCode(child);
break;
case ts.SyntaxKind.Constructor:
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.FunctionDeclaration:
case ts.SyntaxKind.ConstructSignature:
case ts.SyntaxKind.MethodSignature:
case ts.SyntaxKind.CallSignature:
// determine if this item is static
}
break;
case ts.SyntaxKind.JSDocReturnTag:
case ts.SyntaxKind.JSDocParameterTag: {
var _a = tag, typeExpression = _a.typeExpression, comment = _a.comment;
if (typeExpression !== undefined) {
ctx.addFailureAtNode(typeExpression, Rule.FAILURE_STRING_REDUNDANT_TYPE);
}
if (comment === undefined || comment === "") {
// Redundant if no documentation
ctx.addFailureAtNode(tag.tagName, Rule.FAILURE_STRING_NO_COMMENT(tag.tagName.text));
}
break;
}
default:
throw new Error("Unexpected tag kind: " + ts.SyntaxKind[tag.kind]);
}
}
}
.map(range => {
const { pos, kind, end } = range;
return text.substring(
pos + 2,
kind === ts.SyntaxKind.SingleLineCommentTrivia ? end : end - 2,
);
})
.join("\n");
function getDeclarationDomain(node) {
switch (node.parent.kind) {
case ts.SyntaxKind.TypeParameter:
case ts.SyntaxKind.InterfaceDeclaration:
case ts.SyntaxKind.TypeAliasDeclaration:
return 2;
case ts.SyntaxKind.ClassDeclaration:
case ts.SyntaxKind.ClassExpression:
return 2 | 4;
case ts.SyntaxKind.EnumDeclaration:
return 7;
case ts.SyntaxKind.NamespaceImport:
case ts.SyntaxKind.ImportClause:
return 7 | 8;
case ts.SyntaxKind.ImportEqualsDeclaration:
case ts.SyntaxKind.ImportSpecifier:
return node.parent.name === node
? 7 | 8
: undefined;
case ts.SyntaxKind.ModuleDeclaration:
return 1;
case ts.SyntaxKind.Parameter:
if (node.parent.parent.kind === ts.SyntaxKind.IndexSignature)
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as tsutils from "tsutils";
import * as ts from "typescript";
import * as Lint from "../index";
const OPTION_FUNCTION_DECLARATION = "check-function-declaration";
const OPTION_FUNCTION_EXPRESSION = "check-function-expression";
const OPTION_ARROW_FUNCTION = "check-arrow-function";
const OPTION_METHOD_DECLARATION = "check-method-declaration";
const KIND_FOR_OPTION: { [arg: string]: number } = {
[OPTION_FUNCTION_DECLARATION]: ts.SyntaxKind.FunctionDeclaration,
[OPTION_FUNCTION_EXPRESSION]: ts.SyntaxKind.FunctionExpression,
[OPTION_ARROW_FUNCTION]: ts.SyntaxKind.ArrowFunction,
[OPTION_METHOD_DECLARATION]: ts.SyntaxKind.MethodDeclaration,
};
type EnabledSyntaxKinds = ReadonlySet;
function parseOptions(ruleArguments: string[]): EnabledSyntaxKinds {
if (ruleArguments.length === 0) {
ruleArguments = Object.keys(KIND_FOR_OPTION);
}
const enabledKinds = new Set();
for (const arg of ruleArguments) {
enabledKinds.add(KIND_FOR_OPTION[arg]);
}
node.getChildren().forEach((child) => {
if (child.kind === ts.SyntaxKind.OpenBraceToken) {
openBrace = child;
} else if (child.kind === ts.SyntaxKind.SyntaxList) {
body = child;
} else if (child.kind === ts.SyntaxKind.CloseBraceToken) {
closeBrace = child;
}
});
function isNodeExported(node) {
return (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Export) !== 0 || (!!node.parent && node.parent.kind === ts.SyntaxKind.SourceFile);
}
case ts.SyntaxKind.JsxSpreadAttribute : return ("-" +"JsxSpreadAttribute: " + node.getText());
case ts.SyntaxKind.JsxExpression : return ("-" +"JsxExpression: " + node.getText());
case ts.SyntaxKind.CaseClause : return ("-" +"CaseClause: " + node.getText());
case ts.SyntaxKind.DefaultClause : return ("-" +"DefaultClause: " + node.getText());
case ts.SyntaxKind.HeritageClause : return ("-" +"HeritageClause: " + node.getText());
case ts.SyntaxKind.CatchClause : return ("-" +"CatchClause: " + node.getText());
case ts.SyntaxKind.PropertyAssignment : return ("-" +"PropertyAssignment: " + node.getText());
case ts.SyntaxKind.ShorthandPropertyAssignment : return ("-" +"ShorthandPropertyAssignment: " + node.getText());
case ts.SyntaxKind.SpreadAssignment : return ("-" +"SpreadAssignment: " + node.getText());
case ts.SyntaxKind.EnumMember : return ("-" +"EnumMember: " + node.getText());
case ts.SyntaxKind.SourceFile : return ("-" +"SourceFile: " + node.getText());
case ts.SyntaxKind.Bundle : return ("-" +"Bundle: " + node.getText());
case ts.SyntaxKind.JSDocTypeExpression : return ("-" +"JSDocTypeExpression: " + node.getText());
case ts.SyntaxKind.JSDocAllType : return ("-" +"JSDocAllType: " + node.getText());
case ts.SyntaxKind.JSDocUnknownType : return ("-" +"JSDocUnknownType: " + node.getText());
case ts.SyntaxKind.JSDocNullableType : return ("-" +"JSDocNullableType: " + node.getText());
case ts.SyntaxKind.JSDocNonNullableType : return ("-" +"JSDocNonNullableType: " + node.getText());
case ts.SyntaxKind.JSDocOptionalType : return ("-" +"JSDocOptionalType: " + node.getText());
case ts.SyntaxKind.JSDocFunctionType : return ("-" +"JSDocFunctionType: " + node.getText());
case ts.SyntaxKind.JSDocVariadicType : return ("-" +"JSDocVariadicType: " + node.getText());
case ts.SyntaxKind.JSDocComment : return ("-" +"JSDocComment: " + node.getText());
case ts.SyntaxKind.JSDocTypeLiteral : return ("-" +"JSDocTypeLiteral: " + node.getText());
case ts.SyntaxKind.JSDocTag : return ("-" +"JSDocTag: " + node.getText());
case ts.SyntaxKind.JSDocAugmentsTag : return ("-" +"JSDocAugmentsTag: " + node.getText());
case ts.SyntaxKind.JSDocClassTag : return ("-" +"JSDocClassTag: " + node.getText());
case ts.SyntaxKind.JSDocParameterTag : return ("-" +"JSDocParameterTag: " + node.getText());
case ts.SyntaxKind.JSDocReturnTag : return ("-" +"JSDocReturnTag: " + node.getText());
case ts.SyntaxKind.JSDocTypeTag : return ("-" +"JSDocTypeTag: " + node.getText());
case ts.SyntaxKind.JSDocTemplateTag : return ("-" +"JSDocTemplateTag: " + node.getText());
case ts.SyntaxKind.JSDocTypedefTag : return ("-" +"JSDocTypedefTag: " + node.getText());
case ts.SyntaxKind.JSDocPropertyTag : return ("-" +"JSDocPropertyTag: " + node.getText());
case ts.SyntaxKind.SyntaxList : return ("-" +"SyntaxList: " + node.getText());
function isEmpty(node) {
var initializer = node === undefined ? undefined : node.initializer;
if (initializer === undefined) {
return true;
}
if (TypeGuard_1.isStringLiteral(initializer)) {
return initializer.text.trim() === '';
}
if (initializer.expression !== undefined) {
var expression = initializer.expression;
if (expression.kind === ts.SyntaxKind.Identifier) {
return expression.getText() === 'undefined';
}
if (expression.kind === ts.SyntaxKind.NullKeyword) {
return true;
}
}
return false;
}
exports.isEmpty = isEmpty;