Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Update eslint plugins #4

Merged
merged 10 commits into from
Jan 17, 2017
Merged

Update eslint plugins #4

merged 10 commits into from
Jan 17, 2017

Conversation

ismail-syed
Copy link
Contributor

  • Added eslint-index package to help improve scripts to help find omitted lint rules
  • Added yarn run rules-status and yarn run rules-omitted scripts (output shown below)
  • Removed eslint-find-rules package and script
  • Updated elint-plugins eslint-plugin-flowtype, eslint-plugin-mocha, eslint-plugin-promise, eslint-plugin-react packages
  • Added new rules for eslint-plugin-react and eslint-plugin-promise

screen shot 2017-01-16 at 1 46 35 pm

screen shot 2017-01-16 at 1 46 50 pm

Why lodash/no-single-chain and lodash/prefer-chain are considered 'omitted'.

Joined prefer-chain and no-single-chain into single rule, chaining that also enables disallowing chaining. (685e9e3)

Why babel stuff comes up:
Babel has no CHANGELOG.md, which could be why this isn't getting picked up properly? However, they list it as deprecated on their README.md

@GoodForOneFare
Copy link
Member

/cc @Shopify/javascript - new eslint rules.


// Async/Await Rules

// Prefer await to then() for reading Promise values

Choose a reason for hiding this comment

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

Are we using the babel compiler for this or something else? Their implementation is not what I'd call light weight.

ex:

async function doTheThing() {
  const whatever = await fetch('google.com');
  
  return whatever;
}

transforms to:

var doTheThing = function () {
  var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
    var whatever;
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return fetch('google.com');

          case 2:
            whatever = _context.sent;
            return _context.abrupt('return', whatever);

          case 4:
          case 'end':
            return _context.stop();
        }
      }
    }, _callee, this);
  }));

  return function doTheThing() {
    return _ref.apply(this, arguments);
  };
}();

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

source

It also creates a blocking loop with the while(1) which is kinda scary. It does look like there's a defined exit condition, but it's hard to say from the generated code how many iterations it'll block on.

Copy link
Contributor Author

@ismail-syed ismail-syed Jan 16, 2017

Choose a reason for hiding this comment

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

😳 That does look quite scary.
@GoodForOneFare: Should we keep this as a 'warn', or even have it turned 'off'?

Choose a reason for hiding this comment

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

Given the blocking behaviour, is it even advantageous to encourage the use of await? I feel like it produce a specific behaviour that may be desirable only in specific circumstances (where blocking IO is required)

Copy link

Choose a reason for hiding this comment

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

yeah i have strong feels about preferring await with its current browser support. I'd like to hear some of the justification behind this.

Copy link
Member

Choose a reason for hiding this comment

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

@ismail-syed is just getting started on FED, so these are just his best guesses. Agree that this should be off until browser support is better.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, agreed to turn these two off 👍

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. I think it's too early for async await at this point.

Copy link
Contributor Author

@ismail-syed ismail-syed Jan 16, 2017

Choose a reason for hiding this comment

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

Thanks everyone.
The two await rules are off now.
70af7aa

Copy link

@hzoo hzoo Jan 17, 2017

Choose a reason for hiding this comment

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

Yeah, not using async also would help with removing regeneratorRuntime. Are y'all using babel-polyfill as well?

Alternatives: you can try https://github.com/babel/kneden although needs work since it's not stable yet, https://github.com/MatAtBread/fast-async, or use http://babeljs.io/docs/plugins/transform-async-to-generator if you support browsers that have generators natively. Would recommend https://github.com/babel/babel-preset-env/ for that as well.

Sorry for the random comment haha

Copy link
Member

Choose a reason for hiding this comment

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

@hzoo All of our projects support at least IE11, so we're still stuck without native generators, and I'd rather way for async-await until we can do so based on native generators, rather than any kind of runtime. We're excited to start using babel-preset-env (Shopify/babel-preset-shopify#4), though. Thanks very much for all your hard work on the Babel project!


// Async/Await Rules

// Prefer await to then() for reading Promise values
Copy link
Member

Choose a reason for hiding this comment

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

Yup, agreed to turn these two off 👍

@@ -47,6 +49,8 @@ module.exports = {
'react/prop-types': 'warn',
// Prevent missing React when using JSX
'react/react-in-jsx-scope': 'error',
// Enforce a defaultProps definition for every prop that is not a required prop
'react/require-default-props': 'error',
Copy link
Member

Choose a reason for hiding this comment

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

IMO this rule is not worth it, I think unset values are fine for boolean props (which would default to falsey values anyways), and I kind of prefer specifying defaults in actual JS rather than defaultProps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with 3b6f088.

// Avoid using promises inside of callbacks
'promise/no-promise-in-callback': 'warn',
// Avoid calling cb() inside of a then() (use nodeify] instead)
'promise/no-callback-in-promise': 'warn',
Copy link
Member

Choose a reason for hiding this comment

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

I feel that this rule and the one above are overly strict, I think there are too many valid cases to keep these on.

// Avoid calling cb() inside of a then() (use nodeify] instead)
'promise/no-callback-in-promise': 'warn',
// Avoid creating new promises outside of utility libs (use pify instead)
'promise/avoid-new': 'warn',
Copy link
Member

Choose a reason for hiding this comment

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

Definitely turn this one off, we definitely want people to be free to use new Promise whenever they like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍
70af7aa.

@GoodForOneFare
Copy link
Member

GTG once Chris' comments are addressed. Thank you :)

@GoodForOneFare
Copy link
Member

Oh, could you start a CHANGELOG.md, please? The old JS repo's log has plenty of examples for eslint config bumps.

@wagerfield
Copy link

@ismail-syed the omitted rules you are seeing for babel are there because the plugin has not properly declared it's deprecated rules as being deprecated using ESLint's meta object. Even though they have documented these rules as being deprecated in their README, there is no programatic way of eslint-index deriving that these rules are deprecated.

See here for more information

To remedy this, I have opened an issues with eslint-plugin-babel, so hopefully when these fixes are made—you should no longer see these omitted rules for the babel plugin.

As for the 2 lodash rules, that's got me a little stumped. Are you using the latest version of this plugin? I had a search in the repo and from the change log it looks like these 2 rules were merged into a new chaining rule. The search didn't return any other matches for these 2 rules, so I'm struggling to understand why they are appearing in your omitted list.

Could you please confirm that you have the latest version of eslint-plugin-lodash?

// Avoid nested .then() or .catch() statements
'promise/no-nesting': 'warn',
// Avoid using promises inside of callbacks
'promise/no-promise-in-callback': 'warn',

Choose a reason for hiding this comment

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

When working with any of the node API async methods, it's kind of hard to not do this, if you are using any other library that uses promises.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with 3b6f088

@ismail-syed
Copy link
Contributor Author

@wagerfield That's what I presumed was the reason behind those Babel rules showing up as omitted. Thanks for the clarification.

Regarding eslint-plugin-lodash, I just updated and re-tested locally. An update was sent out today, so a new rule was introduced: import-scope.
I'm on version eslint-plugin-lodash version 2.3.1.

The two rules lodash/no-single-chain and lodash/prefer-chain still show up.

@wagerfield
Copy link

@ismail-syed I will do some further investigations as to why these lodash rules are being outputted.

@ismail-syed
Copy link
Contributor Author

Thanks @wagerfield, appreciate it! 💯

@ismail-syed ismail-syed merged commit 3af205a into master Jan 17, 2017
@ismail-syed ismail-syed deleted the update-eslint-plugins branch January 17, 2017 19:27
@wagerfield
Copy link

@ismail-syed FYI babel/eslint-plugin-babel#119

@ismail-syed
Copy link
Contributor Author

Thanks @wagerfield 👍

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.

8 participants