-
Notifications
You must be signed in to change notification settings - Fork 889
Adding "allow-declarations" to only-arrow-functions #1452
Adding "allow-declarations" to only-arrow-functions #1452
Conversation
This allows traditional standalone function declarations.
I still get some small amount of amusement from tslint rules failing a PR to tslint. Will fix. |
@@ -337,6 +337,7 @@ Core rules are included in the `tslint` package. | |||
* `one-variable-per-declaration` disallows multiple variable definitions in the same statement. | |||
* `"ignore-for-loop"` allows multiple variable definitions in for loop statement. | |||
* `only-arrow-functions` disallows traditional `function () { ... }` declarations, preferring `() => { ... }` arrow lambdas. | |||
* `"allow-declarations"` allows standalone function declarations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed how the README works, could you remove this change?
You'll need to remerge develop (sorry, I introduced conflicts!) Also, could you rename |
Also fixed up rule specifiers as per project guidelines.
Otherwise it's all fixed. Edit: I had neglected to push the test renames until 8/9. It should be fixed. |
@@ -41,7 +55,9 @@ export class Rule extends Lint.Rules.AbstractRule { | |||
|
|||
class OnlyArrowFunctionsWalker extends Lint.RuleWalker { | |||
public visitFunctionDeclaration(node: ts.FunctionDeclaration) { | |||
this.addFailure(this.createFailure(node.getStart(), "function".length, Rule.FAILURE_STRING)); | |||
if (this.getOptions().indexOf(OPTION_ALLOW_DECLARATIONS) === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can just be this.hasOption(OPTION_ALLOW_DECLARATIONS)
I see we were making comments / changes at the same time! 😀 |
Tests appear to be failing... I'll have to get to that later today. |
@@ -55,7 +55,7 @@ export class Rule extends Lint.Rules.AbstractRule { | |||
|
|||
class OnlyArrowFunctionsWalker extends Lint.RuleWalker { | |||
public visitFunctionDeclaration(node: ts.FunctionDeclaration) { | |||
if (this.getOptions().indexOf(OPTION_ALLOW_DECLARATIONS) === -1) { | |||
if (this.hasOption(OPTION_ALLOW_DECLARATIONS)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad, I should have suggested !this.hasOption
, I think the logic got inverted here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can confirm.
Merged! |
This allows standalone function declarations:
...but still disallows function expressions inline:
Fixes #1449.