Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
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);
}
}
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);
});
}
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)));
}
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 = {
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;
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);
});
}
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);
});
}
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);
});
}
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;
}
}