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 the no-else-return ESLint rule #7935

Merged
merged 1 commit into from
Jan 9, 2017
Merged

Enable the no-else-return ESLint rule #7935

merged 1 commit into from
Jan 9, 2017

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Jan 7, 2017

Using else after return is not necessary, and can often lead to unnecessarily cluttered code. By using the no-else-return rule in ESLint we can avoid this pattern, see http://eslint.org/docs/rules/no-else-return.

Please note: This is one ESLint rules that could perhaps be considered a bit too opinionated by some people, so even though I'd like enable it, I understand if others do not.
Easier reviewing with: https://github.com/mozilla/pdf.js/pull/7935/files?w=1.

Copy link
Contributor

@yurydelendik yurydelendik left a comment

Choose a reason for hiding this comment

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

Looks good. I think we need add smarts to the preprocessor, so it would be able to remove statements after throw/return (to remove rest of the // eslint-disable-line no-else-return)?

@@ -283,9 +283,8 @@ function approximateFraction(x) {
// Select closest of the neighbours to x.
if (x_ - a / b < c / d - x_) {
return x_ === x ? [a, b] : [b, a];
} else {
return x_ === x ? [c, d] : [d, c];
Copy link
Contributor

Choose a reason for hiding this comment

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

let's introduce e.g. result local that will store return value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure; I've added a result variable now.

@Snuffleupagus
Copy link
Collaborator Author

I think we need add smarts to the preprocessor, so it would be able to remove statements after throw/return (to remove rest of the // eslint-disable-line no-else-return)?

That'd be nice, but I think it might be better suited for a followup PR.

/botio test

@yurydelendik
Copy link
Contributor

That'd be nice, but I think it might be better suited for a followup PR.

See #7942

}
return (108 / 841) * (x - 4 / 29);
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment was lost somehow: could you add 'result' local here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, it's fixed now!

Using `else` after `return` is not necessary, and can often lead to unnecessarily cluttered code. By using the `no-else-return` rule in ESLint we can avoid this pattern, see http://eslint.org/docs/rules/no-else-return.
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Linux)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/65f8a3f7f9a413d/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/65f8a3f7f9a413d/output.txt

Total script time: 2.24 mins

Published

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Linux)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/fc59d910b062e96/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Windows)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://107.22.172.223:8877/73fc0b230c841e6/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/73fc0b230c841e6/output.txt

Total script time: 25.68 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/fc59d910b062e96/output.txt

Total script time: 26.69 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@timvandermeij timvandermeij merged commit 098acb1 into mozilla:master Jan 9, 2017
@timvandermeij
Copy link
Contributor

Thank you!

@Snuffleupagus Snuffleupagus deleted the eslint_no-else-return branch January 9, 2017 22:40
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants