hmil / tslint-override

TSLint plugin bringing support for the override keyword
MIT License
27 stars 6 forks source link

Add an option to add a new line after jsDoc style fixes #19

Closed mzyil closed 5 years ago

mzyil commented 5 years ago

We would like to have an option for fixer to add a new line after jsdoc style fixing. "/** @override */\n" + indentation instead of just "/** @override */ "

So this:

export class ChildMyClass extends MyClass
{
    /** @override */ public method(parameters: string[]): void {
        parameters.forEach(console.error);
    }
}

becomes this:

export class ChildMyClass extends MyClass
{
    /** @override */
    public method(parameters: string[]): void {
        parameters.forEach(console.error);
    }
}

A crude implementation would be:

else {
    // No Jsdoc found, create a new one with just the tag
    let text = node.getFullText();
    const tokenStart = text.indexOf(node.getText());
    text = text.substr(0, tokenStart);
    const lastNL = text.lastIndexOf("\n");
    const indent = text.substr(lastNL + 1);
    return Lint.Replacement.appendText(node.getStart(), `/** @${this.getKeyword()} */\n` + indent);
}

Checking seems to work OK regardless of the new line.

Is this possible? Thanks!

mzyil commented 5 years ago

@hmil can you give a feedback? Would you accept a PR?

hmil commented 5 years ago

Yes sure, go ahead. 👍