How to use the tslint.RuleFailure function in tslint

To help you get started, we’ve selected a few tslint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github w11k / ngx-componentdestroyed / src / tslint / w11kRxjsAngularSubscribeTakeuntilRule.ts View on Github external
propertyAccessExpressions.forEach(node => {
                const propertyAccessExpression = node as ts.PropertyAccessExpression; // .subscribe
                const type = typeChecker.getTypeAtLocation(propertyAccessExpression.expression);
                if (couldBeType(type, "Observable")) {
                    const {name} = propertyAccessExpression;

                    const objWithSubscribeExpression = propertyAccessExpression.expression as ts.CallExpression;
                    const beforeSubscribeExpression = objWithSubscribeExpression.expression as ts.PropertyAccessExpression;

                    if (beforeSubscribeExpression === undefined
                        || beforeSubscribeExpression.name === undefined
                        || beforeSubscribeExpression.name.escapedText !== "pipe") {
                        failures.push(new Lint.RuleFailure(
                            sourceFile,
                            name.getStart(),
                            name.getStart() + name.getWidth(),
                            "Missing `.pipe(...)` before .subscribe()",
                            this.ruleName
                        ));
                        return;
                    }

                    let pipeCallArguments = objWithSubscribeExpression.arguments;
                    let missingTakeUntil = false;
                    if (pipeCallArguments.length === 0) {
                        missingTakeUntil = true;
                    } else {
                        const lastArg = pipeCallArguments[pipeCallArguments.length - 1] as ts.CallExpression;
                        const takeUntilCall = lastArg.expression as ts.Identifier;
github angular / angular / packages / core / schematics / migrations / google3 / rendererToRenderer2Rule.ts View on Github external
private _getHelpersFailure(
      helpersToAdd: Set, sourceFile: ts.SourceFile,
      printer: ts.Printer): RuleFailure {
    const helpers: Replacement[] = [];
    const endOfFile = sourceFile.endOfFileToken;

    helpersToAdd.forEach(helperName => {
      helpers.push(new Replacement(
          endOfFile.getStart(), endOfFile.getWidth(), getHelper(helperName, sourceFile, printer)));
    });

    // Add a failure at the end of the file which we can use as an anchor to insert the helpers.
    return new RuleFailure(
        sourceFile, endOfFile.getStart(), endOfFile.getStart() + 1,
        'File should contain Renderer helper functions. Run tslint with --fix to generate them.',
        this.ruleName, helpers);
  }
}
github angular / components / src / lib / schematics / update / rules / switchStylesheetInputNamesRule.ts View on Github external
this.replaceNamesInStylesheet(stylesheet, stylesheet.getFullText()).forEach(replacement => {
      const fix = replacement.replacement;
      const ruleFailure = new RuleFailure(stylesheet, fix.start + 1, fix.end + 1,
          replacement.message, this.getRuleName(), fix);
      this.addFailure(ruleFailure);
    });
  }
github angular / angular / packages / core / schematics / migrations / missing-injectable / google3 / tslint_update_recorder.ts View on Github external
updateObjectLiteral(node: ts.ObjectLiteralExpression, newText: string): void {
    this.failures.push(new RuleFailure(
        this.sourceFile, node.getStart(), node.getEnd(),
        `Object literal needs to be updated to: ${newText}`, this.ruleName,
        Replacement.replaceFromTo(node.getStart(), node.getEnd(), newText)));
  }
github microsoft / tslint-microsoft-contrib / noUselessFilesRule.js View on Github external
Rule.prototype.apply = function (sourceFile) {
        var ruleFailures = [];
        var fileContent = sourceFile.getFullText().trim();
        var fileContentNoComments = sourceFile.getText().trim();
        if (fileContent.length === 0) {
            ruleFailures.push(new Lint.RuleFailure(sourceFile, 0, 0, FAILURE_STRING_EMPTY, this.getOptions().ruleName));
        }
        else if (fileContentNoComments.length === 0) {
            ruleFailures.push(new Lint.RuleFailure(sourceFile, 0, 0, FAILURE_STRING_COMMENTS, this.getOptions().ruleName));
        }
        return ruleFailures;
    };
    Rule.metadata = {
github fimbullinter / wotan / packages / bifrost / src / index.ts View on Github external
public format(fileName: string, summary: FileSummary): undefined {
            let sourceFile: ts.SourceFile | undefined;
            for (let i = 0; i < summary.fixes; ++i)
                this.fixed.push(new TSLint.RuleFailure(getSourceFile(), 0, 0, '', '', TSLint.Replacement.appendText(0, '')));
            if (summary.failures.length === 0)
                return;
            this.failures.push(
                ...summary.failures.map((f) => {
                    const failure = new TSLint.RuleFailure(
                        getSourceFile(),
                        f.start.position,
                        f.end.position,
                        f.message,
                        f.ruleName,
                        f.fix && f.fix.replacements.map((r) => new TSLint.Replacement(r.start, r.end - r.start, r.text)));
                    failure.setRuleSeverity(f.severity);
                    return failure;
                }),
            );
            return;
github angular / components / src / lib / schematics / update / rules / switchTemplateExportAsNamesRule.ts View on Github external
this.replaceNamesInTemplate(template, template.getFullText()).forEach(replacement => {
      const fix = replacement.replacement;
      const ruleFailure = new RuleFailure(template, fix.start + 1, fix.end + 1,
          replacement.message, this.getRuleName(), fix);
      this.addFailure(ruleFailure);
    });
  }
github angular / components / src / lib / schematics / update / rules / switchTemplateCssNamesRule.ts View on Github external
this.replaceNamesInTemplate(template, template.getText()).forEach(replacement => {
      const fix = replacement.replacement;
      const ruleFailure = new RuleFailure(template.getSourceFile(), fix.start, fix.end,
          replacement.message, this.getRuleName(), fix);
      this.addFailure(ruleFailure);
    });
  }
github angular / components / src / lib / schematics / update / rules / switchTemplateAttributeSelectorsRule.ts View on Github external
this.replaceNamesInTemplate(template, template.getText()).forEach(replacement => {
      const fix = replacement.replacement;
      const ruleFailure = new RuleFailure(template.getSourceFile(), fix.start, fix.end,
          replacement.message, this.getRuleName(), fix);
      this.addFailure(ruleFailure);
    });
  }
github microsoft / tslint-microsoft-contrib / src / noUselessFilesRule.ts View on Github external
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
        const ruleFailures: Lint.RuleFailure[] = [];

        const fileContent = sourceFile.getFullText().trim();
        const fileContentNoComments = sourceFile.getText().trim();

        if (fileContent.length === 0) {
            //This file only contains whitespace characters, a totally empty & useless file
            ruleFailures.push(new Lint.RuleFailure(sourceFile, 0, 0, FAILURE_STRING_EMPTY, this.getOptions().ruleName));
        } else if (fileContentNoComments.length === 0) {
            //This file only contains code comments, not empty but completely useless
            ruleFailures.push(new Lint.RuleFailure(sourceFile, 0, 0, FAILURE_STRING_COMMENTS, this.getOptions().ruleName));
        }
        return ruleFailures;
    }
}