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

feat: adds no-metal-plugins rule to avoid deprecated metal-* imports #61

Merged
merged 3 commits into from
Aug 12, 2019
Merged

feat: adds no-metal-plugins rule to avoid deprecated metal-* imports #61

merged 3 commits into from
Aug 12, 2019

Conversation

jbalsas
Copy link
Contributor

@jbalsas jbalsas commented Aug 8, 2019

This is a naive first pass at a rule for deprecated metal-* imports.

I originally added some other checks like usage of CancellablePromise but I figure that after all, once we remove the import its usages will get flagged in different ways, so there's probably no need to go any further.

DEPRECATED_MODULES.includes(node.source.value)
) {
context.report({
messageId: toCamelCase(`no-${node.source.value}`),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this is overkill? Just did it so we had matching noMetalPromise message ids... but maybe nometalpromise would do as well? 🤷‍♂

Copy link
Contributor

Choose a reason for hiding this comment

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

Doctors say that a bit of overkill from time to time is good for your health! But yeah, you probably could have just used 'no-metal-promise' (etc) as the key. 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or even no-metal-promise 😂

@jbalsas
Copy link
Contributor Author

jbalsas commented Aug 12, 2019

I've force-pushed a commit to also deprecate metal-uri since @julien already removed it from liferay-portal

Copy link
Contributor

@wincent wincent left a comment

Choose a reason for hiding this comment

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

Awesome! To make this actually work you need a couple of extra things — for a full example, see the last PR of this kind that I did:

Bonus:

Even though we haven't fully eliminated all the usages of metal in liferay-portal, we can probably merge this and just add some temporary suppressions as needed. (Which reminds me that when we backport liferay-npm-scripts to All The Places™, that will bring eslint-config-liferay with it, so we'll end up needing some suppressions there too.)

DEPRECATED_MODULES.includes(node.source.value)
) {
context.report({
messageId: toCamelCase(`no-${node.source.value}`),
Copy link
Contributor

Choose a reason for hiding this comment

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

Doctors say that a bit of overkill from time to time is good for your health! But yeah, you probably could have just used 'no-metal-promise' (etc) as the key. 😂


create(context) {
return {
ImportDeclaration(node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To make this bullet-proof, I wonder whether we should also catch require('metal-foo'). That would be CallExpression with callee of name, 'require', and arguments being a Literal of value 'metal-foo' etc.

Copy link
Contributor Author

@jbalsas jbalsas Aug 12, 2019

Choose a reason for hiding this comment

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

We've never used (nor allowed) CommonJS, so I don't think we're likely to get hits on this one...

Maybe on old tests, but I couldn't find any occurrence...

'liferay-portal/no-side-navigation': 'error',
'liferay-portal/no-metal-plugins': 'error',
'liferay-portal/no-explicit-extend': 'error',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops... I'll correct this and force-push

@jbalsas
Copy link
Contributor Author

jbalsas commented Aug 12, 2019

Hey @wincent, I've pushed a couple of commits simplifying the messageId generation and enabling the rule by default.

I don't think we need to care about CommonJS for now as we've never really used it...

Also, regarding how to apply it, I think we might want to fork portal.js to have something like portal_7_1_x.js where we can simply warn or ignore things we won't be willing to change, wdt?

@wincent
Copy link
Contributor

wincent commented Aug 12, 2019

Also, regarding how to apply it, I think we might want to fork portal.js to have something like portal_7_1_x.js where we can simply warn or ignore things we won't be willing to change, wdt?

Yeah, that could work. I guess the question is would you rather do the suppression here by forking, or in liferay-portal by adjusting the .eslintrc.js on the older branch(es)? I'd probably be inclined towards the latter (either way the .eslintrc.js files are going to have to diverge), but it's up to you.

@jbalsas
Copy link
Contributor Author

jbalsas commented Aug 12, 2019

Yeah, that could work. I guess the question is would you rather do the suppression here by forking, or in liferay-portal by adjusting the .eslintrc.js on the older branch(es)? I'd probably be inclined towards the latter (either way the .eslintrc.js files are going to have to diverge), but it's up to you.

Indeed, doing it in .eslintrc will simplify maintenance here... but at the same time, it might force us to coordinate releases on master and 7.1.x every time we add a new rule so we synchronously modify the configuration over there...

I think we can cross that bridge when the moment comes ;)

@wincent
Copy link
Contributor

wincent commented Aug 12, 2019

I think we can cross that bridge when the moment comes ;)

Sounds good.

@wincent wincent merged commit 5a7c1c7 into liferay:master Aug 12, 2019
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.

2 participants