当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript tsutils.forEachComment函数代码示例

本文整理汇总了TypeScript中tsutils.forEachComment函数的典型用法代码示例。如果您正苦于以下问题:TypeScript forEachComment函数的具体用法?TypeScript forEachComment怎么用?TypeScript forEachComment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了forEachComment函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: if

    return this.applyWithFunction(sourceFile, (ctx: Lint.WalkContext<any>) => {
      utils.forEachComment(ctx.sourceFile, (file, {pos, end}) => {
        const commentText = file.substring(pos, end);

        // TODO(crisbeto): remove this check once most of the pending
        // PRs start using `breaking-change`.
        if (commentText.indexOf(DELETION_TARGET) > -1) {
          ctx.addFailure(pos, end, `${DELETION_TARGET} has been replaced with ${BREAKING_CHANGE}.`);
          return;
        }

        const hasBreakingChange = commentText.indexOf(BREAKING_CHANGE) > -1;

        if (!hasBreakingChange && commentText.indexOf('@deprecated') > -1) {
          ctx.addFailure(pos, end, `@deprecated marker has to have a ${BREAKING_CHANGE}.`);
        } if (hasBreakingChange) {
          const version = commentText.match(/\d+\.\d+\.\d+/);

          if (!version) {
            ctx.addFailure(pos, end, `${BREAKING_CHANGE} must have a version.`);
          } else if (this._hasExpired(packageVersion, version[0])) {
            ctx.addFailure(pos, end, `Breaking change at ${version[0]} is due to be deleted. ` +
                                     `Current version is ${packageVersion}.`);
          }
        }
      });
    });
开发者ID:OkBayat,项目名称:material2,代码行数:27,代码来源:breakingChangeRule.ts

示例2: getDisableMap

/**
 * The map will have an array of TextRange for each disable of a rule in a file.
 * (It will have no entry if the rule is never disabled, meaning all arrays are non-empty.)
 */
function getDisableMap(
    sourceFile: ts.SourceFile,
    failingRules: Set<string>,
): ReadonlyMap<string, ts.TextRange[]> {
    const map = new Map<string, ts.TextRange[]>();

    utils.forEachComment(sourceFile, (fullText, comment) => {
        const commentText =
            comment.kind === ts.SyntaxKind.SingleLineCommentTrivia
                ? fullText.substring(comment.pos + 2, comment.end)
                : fullText.substring(comment.pos + 2, comment.end - 2);
        const parsed = parseComment(commentText);
        if (parsed !== undefined) {
            const { rulesList, isEnabled, modifier } = parsed;
            const switchRange = getSwitchRange(modifier, comment, sourceFile);
            if (switchRange !== undefined) {
                const rulesToSwitch =
                    rulesList === "all"
                        ? Array.from(failingRules)
                        : rulesList.filter(r => failingRules.has(r));
                for (const ruleToSwitch of rulesToSwitch) {
                    switchRuleState(ruleToSwitch, isEnabled, switchRange.pos, switchRange.end);
                }
            }
        }
    });

    return map;

    function switchRuleState(
        ruleName: string,
        isEnable: boolean,
        start: number,
        end: number,
    ): void {
        const disableRanges = map.get(ruleName);

        if (isEnable) {
            if (disableRanges !== undefined) {
                const lastDisable = disableRanges[disableRanges.length - 1];
                if (lastDisable.end === -1) {
                    lastDisable.end = start;
                    if (end !== -1) {
                        // Disable it again after the enable range is over.
                        disableRanges.push({ pos: end, end: -1 });
                    }
                }
            }
        } else {
            // disable
            if (disableRanges === undefined) {
                map.set(ruleName, [{ pos: start, end }]);
            } else if (disableRanges[disableRanges.length - 1].end !== -1) {
                disableRanges.push({ pos: start, end });
            }
        }
    }
}
开发者ID:JoshuaKGoldberg,项目名称:tslint,代码行数:62,代码来源:enableDisableRules.ts

示例3: getEnableDisableRuleMap

    public getEnableDisableRuleMap() {
        utils.forEachComment(this.sourceFile, (fullText, comment) => {
            const commentText = comment.kind === ts.SyntaxKind.SingleLineCommentTrivia
                ? fullText.substring(comment.pos + 2, comment.end)
                : fullText.substring(comment.pos + 2, comment.end - 2);
            return this.handleComment(commentText, comment);
        });

        return this.enableDisableRuleMap;
    }
开发者ID:mark-buer,项目名称:tslint,代码行数:10,代码来源:enableDisableRules.ts

示例4: visitSourceFile

  visitSourceFile(sourceFile: ts.SourceFile) {
    utils.forEachComment(sourceFile, (text, commentRange) => {
      const isTodoComment = text.substring(commentRange.pos, commentRange.end).includes('TODO:');

      if (commentRange.kind === ts.SyntaxKind.MultiLineCommentTrivia && isTodoComment) {
        this.addFailureAt(commentRange.pos, commentRange.end - commentRange.pos, ERROR_MESSAGE);
      }
    });

    super.visitSourceFile(sourceFile);
  }
开发者ID:angular,项目名称:preboot,代码行数:11,代码来源:noExposedTodoRule.ts

示例5: visitSourceFile

  visitSourceFile(sourceFile: ts.SourceFile) {
    utils.forEachComment(sourceFile, (fullText, commentRange) => {
      const htmlIsEscaped =
        this._parseForHtml(fullText.substring(commentRange.pos, commentRange.end));
      if (commentRange.kind === ts.SyntaxKind.MultiLineCommentTrivia && !htmlIsEscaped) {
        this.addFailureAt(commentRange.pos, commentRange.end - commentRange.pos, ERROR_MESSAGE);
      }
    });

    super.visitSourceFile(sourceFile);
  }
开发者ID:Nodarii,项目名称:material2,代码行数:11,代码来源:noUnescapedHtmlTagRule.ts

示例6: if

    return this.applyWithFunction(sourceFile, (ctx: Lint.WalkContext<any>) => {
      utils.forEachComment(ctx.sourceFile, (file, {pos, end}) => {
        const commentText = file.substring(pos, end);
        const hasDeletionTarget = commentText.indexOf('@deletion-target') > -1;

        if (!hasDeletionTarget && commentText.indexOf('@deprecated') > -1) {
          ctx.addFailure(pos, end, '@deprecated marker has to have a @deletion-target.');
        } if (hasDeletionTarget) {
          const version = commentText.match(/\d+\.\d+\.\d+/);

          if (!version) {
            ctx.addFailure(pos, end, '@deletion-target must have a version.');
          } else if (this._hasExpired(packageVersion, version[0])) {
            ctx.addFailure(pos, end, `Deletion target at ${version[0]} is due to be deleted. ` +
              `Current version is ${packageVersion}.`);
          }
        }
      });
    });
开发者ID:marffox,项目名称:flex-layout,代码行数:19,代码来源:deletionTargetRule.ts

示例7: if

    return this.applyWithFunction(sourceFile, (ctx: Lint.WalkContext<any>) => {
      utils.forEachComment(ctx.sourceFile, (file, {pos, end}) => {
        const commentText = file.substring(pos, end);

        // TODO(crisbeto): remove this check once most of the pending
        // PRs start using `breaking-change`.
        if (commentText.indexOf(DELETION_TARGET) > -1) {
          ctx.addFailure(pos, end, `${DELETION_TARGET} has been replaced with ${BREAKING_CHANGE}.`);
          return;
        }

        const hasBreakingChange = commentText.indexOf(BREAKING_CHANGE) > -1;

        if (!hasBreakingChange && commentText.indexOf('@deprecated') > -1) {
          ctx.addFailure(pos, end, `@deprecated marker has to have a ${BREAKING_CHANGE}.`);
        } if (hasBreakingChange && !/\d+\.\d+\.\d+/.test(commentText)) {
          ctx.addFailure(pos, end, `${BREAKING_CHANGE} must have a version.`);
        }
      });
    });
开发者ID:Nodarii,项目名称:material2,代码行数:20,代码来源:requireBreakingChangeVersionRule.ts


注:本文中的tsutils.forEachComment函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。