Skip to content

Instantly share code, notes, and snippets.

@phenomnomnominal
Created March 11, 2019 11:11
Show Gist options
  • Save phenomnomnominal/55b427505d9e3667cb6b31dcea43734f to your computer and use it in GitHub Desktop.
Save phenomnomnominal/55b427505d9e3667cb6b31dcea43734f to your computer and use it in GitHub Desktop.
const FAILURE_MESSAGE = 'Found magic `loadChildren` string. Use a function with `import` instead.';
export class Rule extends Rules.AbstractRule {
public apply(sourceFile: SourceFile): Array<RuleFailure> {
// ...
// Try to fix indentation in replacement:
const { character } = sourceFile.getLineAndCharacterOfPosition(result.getStart());
fix = fix.replace(/\n/g, `\n${' '.repeat(character)}`);
const replacement = new Replacement(valueNode.getStart(), valueNode.getWidth(), fix);
return new RuleFailure(sourceFile, result.getStart(), result.getEnd(), FAILURE_MESSAGE, this.ruleName, replacement);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment