Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable linting for __tests__ #3985

Merged
merged 1 commit into from
Jun 1, 2015
Merged

Enable linting for __tests__ #3985

merged 1 commit into from
Jun 1, 2015

Conversation

bgw
Copy link
Contributor

@bgw bgw commented May 29, 2015

Closes #3971.

After #3968, the next thing we should do is start linting our tests.
Historically we've ignored them due to lack of parser compatibility.
But that shouldn't be a problem anymore. We may want to integrate
https://www.npmjs.com/package/eslint-plugin-react to more aggressively
lint our JSX in tests.

I understand this diff touches a lot of stuff, so I tried to keep it to
a near-minimal set of changes to make eslint happy. If you're wondering
why I changed something, let me know and I'll try to map it up to the
rule that I was fixing it for.

@bgw
Copy link
Contributor Author

bgw commented May 29, 2015

Potential future steps:

  • Enable more of the eslint-plugin-react rules.
  • Make our grunt task smarter to be able to pattern-match __tests__, and provide alternate .eslintrc files for tests and normal code. E.g. I'd propose disabling no-unused-expressions for tests.
  • Fix all of the 80-column warnings (ugh)

@@ -1,8 +1,8 @@
var warning = require('./lib/warning');
warning(
false,
'require("react/addons") is deprecated. ' +
'Access using require("react/addons/{addon}") instead.'
'require(\'react/addons\') is deprecated. ' +
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That isn't actually. My bad regexp codemod caught it, and I figured it wouldn't hurt to change it. Let me know if you want me to revert it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess let's keep it as single quotes in the require but use double quotes for the outer string so we don't need the escapes.

@@ -128,7 +126,7 @@ describe('ReactTransitionGroup', function() {
},
render: function() {
var children = [];
for (var i = 0; i < this.state.count; i++) {
for (let i = 0; i < this.state.count; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't support let internally at FB yet so this can't go in like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's been brought up multiple times that we shouldn't be running these tests internally anyways, so I'll look into that issue before we merge this.

Copy link
Member

Choose a reason for hiding this comment

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

We already don't run the tests internally. But we still lint internally and I wouldn't be surprised if we end up choking on let. Regardless though, let's not introduce the first let here.

@sophiebits
Copy link
Collaborator

This looks pretty good overall.

bgw added a commit to bgw/react that referenced this pull request May 29, 2015
Removes all `/*eslint-disable no-unused-expressions */` comments.

> Instead of disabling this rule, maybe we chould use the `void`
> operator on each place that triggers it (which this rule's docs claim
> doesn't warn). Like `void frag[key];`.

facebook#3985 (comment) @spicyj
bgw added a commit to bgw/react that referenced this pull request May 29, 2015
> Does (x) => x * 2 work here? If so, let's do that – but otherwise this
> is okay.

facebook#3985 (comment) @spicyj
bgw added a commit to bgw/react that referenced this pull request May 29, 2015
env:
browser: true
node: true

globals:
__DEV__: true
# Jest / Jasmine
describe: false
Copy link
Member

Choose a reason for hiding this comment

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

Any difference between true and false here? If not let's be consistent (I don't care what the value is if it works)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To configure global variables inside of a configuration file, use the globals key and indicate the global variables you want to use. Set each global variable name equal to true to allow the variable to be overwritten or false to disallow overwriting.

http://eslint.org/docs/user-guide/configuring.html

EDIT: I can comment something to that effect in the eslintrc if you want.

Copy link
Member

Choose a reason for hiding this comment

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

Ah no, I just didn't realize there was a difference. I might have known back when I first did this (I think there's a test that toggles __DEV__)

bgw added a commit to bgw/react that referenced this pull request Jun 1, 2015
bgw added a commit to bgw/react that referenced this pull request Jun 1, 2015
> For this one, we could just do displayName: 'NamedComponent', inside
> the class spec and drop the var assignment.

facebook#3985 (comment) @spicyj
@bgw
Copy link
Contributor Author

bgw commented Jun 1, 2015

@zpao @spicyj

I think I fixed everything except https://github.com/facebook/react/pull/3985/files#r31360729 , which I'd like an opinion on, and the trailing comma issue, which I'll fix in a later PR, after this one is merged.

I could revert the comma changes I made here and disable the rule right now, but there's not really any point besides slightly shortening the diff.

bgw added a commit to bgw/react that referenced this pull request Jun 1, 2015
Alternatively, we could disable it globally, but this is the only place
it triggers in our code.

> facebook#3985 (diff)
@@ -159,6 +159,7 @@ describe('ReactClass-spec', function() {
}
});

/*eslint-disable no-unused-vars */
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think you need this now?

@sophiebits
Copy link
Collaborator

lgtm – can you fix those two things? Then feel free to squash and merge.

Closes facebook#3971.

> After facebook#3968, the next thing we should do is start linting our tests.
> Historically we've ignored them due to lack of parser compatibility.
> But that shouldn't be a problem anymore. We may want to integrate
> https://www.npmjs.com/package/eslint-plugin-react to more aggressively
> lint our JSX in tests.

I understand this diff touches a lot of stuff, so I tried to keep it to
a near-minimal set of changes to make eslint happy.
bgw added a commit that referenced this pull request Jun 1, 2015
Enable linting for __tests__
@bgw bgw merged commit 13823ec into facebook:master Jun 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint tests
4 participants