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

Make most variants of module.exports = { ... } fixable #208

Closed

Conversation

papandreou
Copy link

@papandreou papandreou commented Mar 4, 2020

I need a codemod-like way to convert module.exports = { foo: ... } to exports.foo = ... statements. Seems like that can be achieved by making the exports-style rule fixable when in exports mode.

TODO:

  • See if comments before, between and after the properties can somehow be preserved

@papandreou papandreou marked this pull request as ready for review March 4, 2020 23:36
@mysticatea mysticatea self-requested a review March 5, 2020 01:22
Both work and satisfy the linter
Seems like in-between comments are only attached to one of the nodes
@papandreou
Copy link
Author

@mysticatea, is this something you would consider supporting in the plugin? 🌞

@papandreou
Copy link
Author

@mysticatea, ping?

@papandreou
Copy link
Author

I've applied this fixing mode to a code base with 3k+ source files without breaking anything 🤗

Copy link
Owner

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

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

I apologize for my late response. Thank you for your work!

Almost LGTM. But I have a concern. If you keep the motivation on this, would you fix a deprecated method?

fixedValue = `async ${fixedValue}`
}
}
const comments = sourceCode.getComments(property)
Copy link
Owner

Choose a reason for hiding this comment

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

sourceCode.getComments() method has been deprecated since ESLint v4.0.0 (https://github.com/eslint/eslint/blob/caeb223c4f7b0b6fe35e5348ae0df4c6446b5bed/docs/user-guide/migrating-to-4.0.0.md#-ast-nodes-no-longer-have-comment-properties). Would you fix it with the new methods?

Copy link
Author

Choose a reason for hiding this comment

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

Absolutely, fixed in 8d7cec4

I had no idea, I was just playing around with it in the debugger to discover how to get to the comments :)

@papandreou
Copy link
Author

@mysticatea, does it look OK to you now? 🙏

@papandreou
Copy link
Author

@mysticatea, ping? 🙇

@papandreou
Copy link
Author

@mysticatea, would be really nice to get this merged 🙏 🤗

@papandreou
Copy link
Author

@mysticatea, ping? 🙏

@papandreou
Copy link
Author

@ota-meshi @kevinoid, maybe one of you can help get this landed? 🙏

@kevinoid
Copy link
Contributor

kevinoid commented Dec 8, 2021

I'd be happy to help. Unfortunately, I'm not sure what I could do. I'm not currently affiliated in this project beyond having created a few issues and a PR in the past.

@papandreou
Copy link
Author

@kevinoid, oh, I saw your name on some commits to master and assumed that you were more involved. Sorry!

aladdin-add pushed a commit to eslint-community/eslint-plugin-n that referenced this pull request Apr 25, 2022
* Make the exports style fixable under some circumstances

* Handle generators

* Preserve comments from inside the object literal

* Consistent semicolons in fixed output

* Test that we only replace top-level module.exports = {...}

* Also replace module.exports.foo references

* Split fixing code into two functions to avoid exceeding the complexity budget

* Also fix shorthand property occurrences

* Make helper functions

* Return undefined instead of []

Both work and satisfy the linter

* Simplify a bit

Seems like in-between comments are only attached to one of the nodes

* Don't use SourceCode#getComments (deprecated)

mysticatea#208 (comment)

* Be more defensive and try to match the patterns that we do want to fix
#17 (comment)

* Return null instead of undefined
#17 (comment)
#17 (comment)
#17 (comment)

* Add a few more test cases
#17 (comment)
@papandreou
Copy link
Author

Landed in eslint-plugin-n now: eslint-community#17

Feel free to pick this up if eslint-plugin-node gets resurrected. I'll close this PR for now to clear it from my list :)

@papandreou papandreou closed this Apr 25, 2022
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

Successfully merging this pull request may close these issues.

None yet

3 participants