Skip to content

ESLint - Require capture and custom message #3220

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

Merged
merged 11 commits into from
Sep 11, 2024
Merged

Conversation

nitzanyiz
Copy link
Collaborator

Description

  • Added handling for require in our eslint no-direct-import rule.
  • Added custom message to the rules.

Changelog

ESLint - Added require capture to the no-direct-import rule and custom message functionality.

Additional info

MADS-4434

@nitzanyiz nitzanyiz changed the title Feat/eslint catch require ESLint - Require capture and custom message Aug 21, 2024
@nitzanyiz nitzanyiz requested a review from ethanshar August 21, 2024 08:59
@nitzanyiz nitzanyiz added the Important for Next Release PR that must be included in the release version label Aug 21, 2024
@nitzanyiz nitzanyiz requested review from adids1221 and removed request for ethanshar August 21, 2024 09:18
@nitzanyiz nitzanyiz assigned adids1221 and unassigned ethanshar Aug 21, 2024
@nitzanyiz nitzanyiz marked this pull request as ready for review August 21, 2024 09:18
@nitzanyiz nitzanyiz requested review from M-i-k-e-l and removed request for adids1221 August 21, 2024 09:19
@nitzanyiz nitzanyiz assigned M-i-k-e-l and unassigned adids1221 Aug 21, 2024
@nitzanyiz nitzanyiz removed the Important for Next Release PR that must be included in the release version label Aug 21, 2024
@@ -85,8 +87,45 @@ module.exports = {
}
}

function reportDirectRequire(node, rule) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't you use the utils as we've discussed? Did it not work?

Copy link
Collaborator Author

@nitzanyiz nitzanyiz Aug 25, 2024

Choose a reason for hiding this comment

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

I think the utils we saw do a little more than I need. They aggregate the components and variables from everywhere and all I need to do is just prohibit the usage of a library.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It does not sound like a good enough reason to duplicate the code.
Using the util should remove a lot of code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could use the utils some how but the code will be much uglier. It aggregates all the imports and returns an object. Checking the imports after that is kind of ugly because I will need to go over all the keys of the object and check if its in the rules. I guess I could do that but its not clear. I guess thats why it wasn't used in the import declaration before. I'm also not sure it will exactly do what I need and will not capture other cases as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Will changing the usage in the ImportDeclaration will be much different than in the VariableDeclarator? Because you've already used it there.

@M-i-k-e-l M-i-k-e-l assigned nitzanyiz and unassigned M-i-k-e-l Aug 21, 2024
@nitzanyiz nitzanyiz assigned M-i-k-e-l and unassigned nitzanyiz Aug 25, 2024
@M-i-k-e-l M-i-k-e-l assigned nitzanyiz and unassigned M-i-k-e-l Aug 27, 2024
@nitzanyiz nitzanyiz assigned M-i-k-e-l and nitzanyiz and unassigned nitzanyiz and M-i-k-e-l Sep 2, 2024
@nitzanyiz nitzanyiz assigned M-i-k-e-l and unassigned nitzanyiz Sep 5, 2024
@nitzanyiz nitzanyiz closed this Sep 5, 2024
@nitzanyiz nitzanyiz reopened this Sep 5, 2024
@ethanshar ethanshar added the Important for Next Release PR that must be included in the release version label Sep 5, 2024
@@ -85,8 +87,45 @@ module.exports = {
}
}

function reportDirectRequire(node, rule) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will changing the usage in the ImportDeclaration will be much different than in the VariableDeclarator? Because you've already used it there.

@M-i-k-e-l M-i-k-e-l assigned nitzanyiz and unassigned M-i-k-e-l Sep 11, 2024
@nitzanyiz nitzanyiz assigned M-i-k-e-l and unassigned nitzanyiz Sep 11, 2024
@M-i-k-e-l M-i-k-e-l merged commit 880856e into master Sep 11, 2024
1 check passed
@M-i-k-e-l M-i-k-e-l deleted the feat/eslint-catch-require branch September 11, 2024 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Important for Next Release PR that must be included in the release version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants