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


TypeScript tslint.RuleFailure類代碼示例

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


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

示例1: analyze

    ts.forEachChild(sourceFile, function analyze(node) {
      if (ts.isPropertyAssignment(node) &&
          (ts.isIdentifier(node.name) || ts.isStringLiteral(node.name)) &&
          node.name.text === 'loadChildren' &&
          ts.isStringLiteral(node.initializer)) {
        const valueNode = node.initializer;
        const parts = valueNode.text.split(LOAD_CHILDREN_SPLIT);
        const path = parts[0];
        const moduleName = parts[1] || 'default';

        let fix = `() => import('${path}').then(m => m.${moduleName})`;

        // Try to fix indentation in replacement:
        const { character } = ast.getLineAndCharacterOfPosition(node.getStart());
        fix = fix.replace(/\n/g, `\n${' '.repeat(character)}`);

        const replacement = new Replacement(valueNode.getStart(), valueNode.getWidth(), fix);
        const start = node.getStart();
        const end = node.getEnd();

        const change = new RuleFailure(ast, start, end, FAILURE_MESSAGE, ruleName, replacement);
        change.setRuleSeverity('warning');
        changes.push(change);
      }

      ts.forEachChild(node, analyze);
    });
開發者ID:angular,項目名稱:angular-cli,代碼行數:27,代碼來源:noLazyModulePathsRule.ts

示例2: super

        super('no-require-imports', function (this: Formatter, failure: RuleFailure): void {
            const fileName: string = failure.getFileName();
            const fileContents: string = this.readFile(fileName);
            const start: number = failure.getStartPosition().getPosition();
            const end: number = failure.getEndPosition().getPosition();

            let importStartIndex = fileContents.lastIndexOf('\n', start) + 1;
            if (importStartIndex === -1) {
                importStartIndex = 0;
            }
            const importEndIndex = fileContents.indexOf('\n', end);

            const leftSide: string = fileContents.substring(0, importStartIndex);
            const middle: string = fileContents.substring(importStartIndex, importEndIndex).trim();
            const rightSide: string = fileContents.substring(importEndIndex);

            let newImport: string = middle.replace(
                /import\s+(.*)\s+=\s*require\(((.|\s)*)\);/m,
                'import {$1} from $2;');
            newImport = newImport.replace(/from \n/, 'from\n'); // clean up some spacing
            const newContent: string = leftSide + newImport + rightSide;

            this.writeFile(fileName, newContent);
            /* tslint:disable:no-console */
            console.log('Automatically converting require-style import to an ES6 import. Please re-compile and re-lint: ' + fileName);
            /* tslint:enable:no-console */
        });
開發者ID:iclanton,項目名稱:tslint-microsoft-contrib,代碼行數:27,代碼來源:fixNoRequireImportsFormatter.ts

示例3: formatFailure

 private formatFailure(failure: RuleFailure): string {
     const fileName: string = failure.getFileName();
     const failureString: string = failure.getFailure();
     const ruleName: string = failure.getRuleName();
     const lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
     const positionTuple = '[' + (lineAndCharacter.line + 1) + ', ' + (lineAndCharacter.character + 1) + ']';
     return '(' + ruleName + ') ' + fileName + positionTuple + ': ' + failureString;
 }
開發者ID:iclanton,項目名稱:tslint-microsoft-contrib,代碼行數:8,代碼來源:BaseFormatter.ts

示例4: createFailure

export function createFailure(
  sourceFile: ts.SourceFile,
  start: number,
  end: number,
  failure: string,
  ruleName: string,
  fix?: Fix,
  ruleSeverity: RuleSeverity = "warning",
) {
  const rule = new RuleFailure(sourceFile, start, end, failure, ruleName, fix);
  rule.setRuleSeverity(ruleSeverity);
  return rule;
}
開發者ID:ThaNarie,項目名稱:tslint-teamcity-reporter,代碼行數:13,代碼來源:utils.ts

示例5: super

        super('no-var-keyword', function (this: Formatter, failure: RuleFailure): void {
            const fileName: string = failure.getFileName();
            const fileContents: string = this.readFile(fileName);
            const end: number = failure.getEndPosition().getPosition();

            let leftSide: string = fileContents.substring(0, end);
            leftSide = leftSide.replace(/var$/, 'let');
            const rightSide: string = fileContents.substring(end);
            const newContent: string = leftSide + rightSide;

            this.writeFile(fileName, newContent);
            /* tslint:disable:no-console */
            console.log('Automatically converting var to let. Please re-compile and re-lint: ' + fileName);
            /* tslint:enable:no-console */
        });
開發者ID:iclanton,項目名稱:tslint-microsoft-contrib,代碼行數:15,代碼來源:fixNoVarKeywordFormatter.ts


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