-
Notifications
You must be signed in to change notification settings - Fork 63
Conversation
docs/rules/no-var-requires.md
Outdated
Examples of **incorrect** code for this rule: | ||
|
||
```ts | ||
require("foo"); |
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 should be allowed IMO since there isn’t an equivalent with the import =
syntax.
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.
Yeah, I could see how introducing this as-is would be a breaking change, since all standalone require()
calls would be flagged by this rule.
I will push up a fix that allows this. If we ultimately want to disallow it before merging, I will just revert the commit. 👍
tests/lib/rules/no-var-requires.js
Outdated
] | ||
}, | ||
{ | ||
code: "require('foo')", |
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.
I believe an unassigned call to require()
is invalid, but I'm not 100% sure about this based on TSLint's no-var-requires
tests. Just calling this out in case anyone has more experience with TSLint's no-var-requires
rule and if this truly an invalid case.
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.
Users can replace require("foo");
with import "foo";
. Hence an error on this require call is expected.
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.
Forgot about that, thanks for pointing that out. I’ll push up a commit next week when I get access to a computer
|
||
## When Not To Use It | ||
|
||
If you don't care about TypeScript module syntax, then you will not need this rule. |
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.
These make me giggle each time.
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.
Haha yeah, I agree 😂
Thanks, @macklinu! |
This PR adds the
no-var-requires
rule as listed in the description of #5.