Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} else {
replacements.push(new Lint.Replacement(exprEnd + 1, 0, ' '));
}
// Handling the left side of the pipe
if (exprText[exprText.length - 1] === ' ') {
let ignoreSpace = 1;
while (exprText[exprText.length - 1 - ignoreSpace] === ' ') {
ignoreSpace += 1;
}
if (ignoreSpace > 1) {
replacements.push(new Lint.Replacement(exprEnd - ignoreSpace, ignoreSpace, ' '));
}
} else {
if (!parentheses) {
replacements.push(new Lint.Replacement(exprEnd, 0, ' '));
}
}
if (replacements.length) {
context.addFailureAt(
ast.exp.span.end - 1,
3,
'The pipe operator should be surrounded by one space on each side, i.e. " | ".',
replacements
);
}
super.visitPipe(ast, context);
return null;
}
visitor.missingInjectablePipes.forEach(data => {
const {pipeDecorator, importDeclarationMissingImport} = data;
const fixes = [new Replacement(
pipeDecorator.getStart(), pipeDecorator.getWidth(),
`@${INJECTABLE_DECORATOR_NAME}()\n${pipeDecorator.getText()}`)];
if (importDeclarationMissingImport) {
const namedImports = getNamedImports(importDeclarationMissingImport);
// Add another fix that'll add the missing import.
if (namedImports) {
fixes.push(new Replacement(
namedImports.getStart(), namedImports.getWidth(),
printer.printNode(
ts.EmitHint.Unspecified, addImport(namedImports, INJECTABLE_DECORATOR_NAME),
sourceFile)));
}
}
const cb = (node: ts.Node): void => {
if (utils.isBinaryExpression(node) &&
node.operatorToken.kind === ts.SyntaxKind.PercentToken &&
utils.isNumericLiteral(node.right) &&
node.right.text === '2') {
// TODO if this is part of a comparison with a negative value, this failure would be a false positive
const start = node.operatorToken.getStart(sourceFile);
this.addFailure(start, node.right.end, FAILURE_STRING, [
new Lint.Replacement(start, 1, '&'),
new Lint.Replacement(node.right.end - 1, 1, '1'),
]);
}
return ts.forEachChild(node, cb);
};
return ts.forEachChild(sourceFile, cb);
// "let" to "const" or not? For now we change to const if at least one variable is invalid.
let addFix = true;
for (const variableDeclarationNode of declarationList.declarations) {
if (
!Ignore.shouldIgnore(
variableDeclarationNode,
ctx.options,
ctx.sourceFile
)
) {
invalidVariableDeclarationNodes.push(
createInvalidNode(
variableDeclarationNode,
addFix
? [
new Lint.Replacement(
declarationList.getStart(ctx.sourceFile),
"let".length,
"const"
)
]
: []
)
);
addFix = false;
}
}
return { invalidNodes: invalidVariableDeclarationNodes };
}
return { invalidNodes: [] };
}
function getReadonlyKeywordFix(
node: ts.ArrayTypeNode | ts.TupleTypeNode,
ctx: Lint.WalkContext
): Lint.Replacement[] {
// Nested shorthand syntax array?
if (utils.isArrayTypeNode(node.parent)) {
return [
new Lint.Replacement(node.getStart(ctx.sourceFile), 0, "(readonly "),
new Lint.Replacement(node.end, 0, ")")
];
}
return [new Lint.Replacement(node.getStart(ctx.sourceFile), 0, "readonly ")];
}
return;
}
if (pattern.import) {
importList
.filter(token => new RegExp(pattern.import).test(token.getText()))
.forEach(token =>
ctx.addFailureAtNode(
token,
pattern.message || `Using '${token.getText()}' from '${fromStringText}' is banned.`
)
);
} else {
let fix;
if (pattern.fix) {
fix = new Lint.Replacement(
fromStringToken.getStart(),
fromStringToken.getWidth(),
`'${fromStringText.replace(new RegExp(pattern.from), pattern.fix)}'`
);
}
ctx.addFailureAtNode(fromStringToken, pattern.message || `Importing from '${fromStringText} is banned.`, fix);
}
}
});
}
location: 'start' | 'end',
fixTo: string,
position: number,
absolutePosition: number,
lengthFix: number
) => {
const { length } = subMatch;
if (length === 1) {
return;
}
const errorText = length === 0 ? 'Missing' : 'Extra';
context.addFailureAt(
position,
length + lengthFix,
`${errorText} whitespace in interpolation ${location}; expecting ${InterpolationOpen} expr ${InterpolationClose}`,
[new Lint.Replacement(absolutePosition, length + lengthFix, fixTo)]
);
};
function getReadonlyArrayFix(
node: ts.ArrayTypeNode,
ctx: Lint.WalkContext
): Lint.Replacement[] {
return [
new Lint.Replacement(node.getStart(ctx.sourceFile), 0, "ReadonlyArray<"),
new Lint.Replacement(node.end - 2, 2, ">")
];
}
.map(start => new Replacement(start, selector.replace.length, selector.replaceWith))
.forEach(replacement => replacements.push({replacement, failureMessage}));
export function replaceTagName(tagName: JsxTagNameExpression, newTagName: string) {
return new Replacement(tagName.getFullStart(), tagName.getFullWidth(), newTagName);
}