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

More auto fixing #40

Open
daedalus28 opened this issue Oct 4, 2017 · 0 comments
Open

More auto fixing #40

daedalus28 opened this issue Oct 4, 2017 · 0 comments

Comments

@daedalus28
Copy link
Contributor

// 0. Pattern
// Duplicated lines in branches, e.g. in if/else statements

// 1. Pattern
// Factoring out common code in branches, sometimes inverting if statements
// 1. Input
if (data.metrics) {
  data.metrics.categories = _.getOr(0, 'length', data.categories)
} else {
  data.metrics = user.organization.metrics
  data.metrics.categories = _.getOr(0, 'length', data.categories)
}
// 1. Output
if (!data.metrics) 
  data.metrics = user.organization.metrics
data.metrics.categories = _.getOr(0, 'length', data.categories)


// 2. Pattern
// Collapsing if assignments to `||` assignments
// 2. Input
if (!data.metrics) 
  data.metrics = user.organization.metrics
// 2. Output
data.metrics = data.metrics || user.organization.metrics
data.metrics.categories = _.getOr(0, 'length', data.categories)
@daedalus28 daedalus28 changed the title Moar auto fixing Moar auto fixin' Oct 4, 2017
@daedalus28 daedalus28 changed the title Moar auto fixin' More auto fixing Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant