當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript issue.issueFrom函數代碼示例

本文整理匯總了TypeScript中linting/issue.issueFrom函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript issueFrom函數的具體用法?TypeScript issueFrom怎麽用?TypeScript issueFrom使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了issueFrom函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: noConstantLambdas

export default function noConstantLambdas(node: ts.Node, checker: ts.TypeChecker): Issue | void {
    if (isArrowFunction(node)) {
        const body = node.body;

        if (isIdentifier(body)) {
            return isUndefined(body)
                ? issueFrom(body, 'undefined returned', 'no-undefined-lambdas')
                : verifyIdentifier(body, checker);
        }

        if (isStringLiteral(body) || isNumericLiteral(body) || isNullLiteral(body)) {
            return issueFrom(body, 'literal returned', 'no-literal-lambdas');
        }

    }
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:16,代碼來源:rule.ts

示例2: noUndeclaredSymbols

export default function noUndeclaredSymbols(node: ts.Node, checker: ts.TypeChecker): Issue | void {
    if (isIdentifier(node)) {
        const symbol = checker.getSymbolAtLocation(node);
        if (symbol === undefined) {
            return issueFrom(node, 'undeclared', 'undeclared');
        }
    }
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:8,代碼來源:rule.ts

示例3: noExportImport

export default function noExportImport(node: ts.Node): Issue | void {
    if (isImportEqualsDeclaration(node)) {
        if (node.modifiers !== undefined && node.modifiers.length > 0) {
            const modifier = node.modifiers[0];
            if (modifier.getText() === 'export') {
                return issueFrom(modifier, 'no export import', 'no-export-import');
            }
        }
    }
};
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:10,代碼來源:rule.ts

示例4: toNoPrimitiveToSelf

export default function toNoPrimitiveToSelf(node: ts.Node, checker: ts.TypeChecker): Issue | void {
    if (isCallExpression(node)) {
        if (isIdentifier(node.expression)) {
            if (node.arguments.length > 1) {
            } else if (node.arguments.length > 0) {
                if (node.expression.text === 'String') {
                    const argument = node.arguments[0]!;
                    const expressionType = checker.getTypeAtLocation(argument);
                    if (expressionType.flags & ts.TypeFlags.String) {
                        return issueFrom(node, 'string to string conversion', 'string-to-string');
                    }
                } else if (node.expression.text === 'Number') {
                    return issueFrom(node, 'number conversion', 'something-to-number');
                } else if (node.expression.text === 'Boolean') {
                    return issueFrom(node, 'boolean conversion', 'something-to-boolean');
                }
            }
        }
    }
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:20,代碼來源:rule.ts

示例5: toBadComment

export default function toBadComment(node: ts.Node, _: ts.TypeChecker, _config: Config): Issue | void {
    const identifier = nameIdentifierOutOf(node);
    if (identifier !== undefined && identifier.parent !== undefined) {
        const fragments = ba.insteadEach(leadingCommentsStrippedOutOf(identifier.parent), normalize);
        const name = normalize(identifier.text);
        const found = ba.firstThatOutOf(fragments, fragment => fragment === name);
        if (found !== undefined) {
            return issueFrom(node, 'useless comment', 'useless-comment');
        }
    }
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:11,代碼來源:rule.ts

示例6: verifyIdentifier

function verifyIdentifier(node: ts.Identifier, checker: ts.TypeChecker): Issue | void {
    if (node.parent === undefined) return;
    if (isVariableDeclaration(node.parent) && node.parent.initializer === node) return;

    const symbol = checker.getSymbolAtLocation(node);
    if (symbol === undefined) return fail('Unable to get symbol.');
    const declared = symbol.getDeclarations();
    if (declared === undefined) return fail('There is no declaration.');
    if (declared.length < 1) return fail('There are ' + declared.length + ' declarations.');
    const declaration = declared[0];
    if (isVariableDeclaration(declaration) && hasConstModifier(declaration)) {
        return issueFrom(node, 'const returned', 'no-const-lambdas');
    }
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:14,代碼來源:rule.ts

示例7: toNoUnnecessaryAnnotations

export default function toNoUnnecessaryAnnotations(node: ts.Node, checker: ts.TypeChecker): Issue | void {
    if (isVariableDeclaration(node)) {
        if (node.initializer !== undefined && node.type !== undefined) {

            const typeNodeBackup = node.type;
            node.type = undefined;

            const expressionType = checker.getTypeAtLocation(node.initializer);
            node.type = typeNodeBackup;

            const declaredType = checker.getTypeAtLocation(node.type);
            if (expressionType.id === declaredType.id) {
                return issueFrom(node, 'unnecessary type annotation', 'unnecessary-annotation');
            }
        }
    }
}
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:17,代碼來源:rule.ts

示例8: issueFrom

 identifier => rule.regex.test(identifier.text)
     ? bl.add(issues, issueFrom(node, rule.message, 'invalid-name'))
     : issues,
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:3,代碼來源:rule.ts

示例9: noThrow

export default function noThrow(node: ts.Node): Issue | void {
    if (isThrowStatement(node)) {
        return issueFrom(node, 'no throw', 'no-throw');
    }
};
開發者ID:aleksey-bykov,項目名稱:rules,代碼行數:5,代碼來源:rule.ts


注:本文中的linting/issue.issueFrom函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。