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

feat(linter/node): implement no-new-require #6165

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jelly
Copy link
Contributor

@jelly jelly commented Sep 29, 2024

No description provided.

Copy link

graphite-app bot commented Sep 29, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added the A-linter Area - Linter label Sep 29, 2024
Copy link

codspeed-hq bot commented Sep 29, 2024

CodSpeed Performance Report

Merging #6165 will not alter performance

Comparing jelly:no-new-require (f7b04d7) with main (f2ac584)

Summary

✅ 29 untouched benchmarks

@DonIsaac DonIsaac added the C-enhancement Category - New feature or request label Sep 30, 2024

let pass = vec![
"var appHeader = require('app-header')",
"var AppHeader = new (require('app-header'))",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why should this be allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what the original rule allows as well, if we want to be more strict I would be happy to implement that behaviour.

"var appHeader = require('app-header')",
"var AppHeader = new (require('app-header'))",
"var AppHeader = new (require('headers').appHeader)",
"var AppHeader = require('app-header'); var appHeader = new AppHeader();",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please add a pass case for new require('foo')()

fn no_new_require(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected use of new with require")
.with_label(span)
.with_help("Initialise the constructor separate from the import statement")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This message is a little confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My idea was to inform the user to move the new call to a newline, any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants