Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

New: Add no-var-requires #114

Merged
merged 2 commits into from
Mar 27, 2018
Merged

Conversation

macklinu
Copy link
Collaborator

This PR adds the no-var-requires rule as listed in the description of #5.

Examples of **incorrect** code for this rule:

```ts
require("foo");
Copy link
Collaborator

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.

Copy link
Collaborator Author

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. 👍

]
},
{
code: "require('foo')",
Copy link
Collaborator Author

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.

Copy link

@ajafff ajafff Mar 18, 2018

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.

Copy link
Collaborator Author

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.
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha yeah, I agree 😂

@JamesHenry JamesHenry merged commit 431f463 into bradzacher:master Mar 27, 2018
@JamesHenry
Copy link
Collaborator

Thanks, @macklinu!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants