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(basic): prefer non global object of node #159

Merged
merged 2 commits into from Apr 3, 2023

Conversation

zanminkian
Copy link
Contributor

@zanminkian zanminkian commented Mar 23, 2023

Description

Ban using Buffer and process object without import.

Why: These two objects can only be used in Node. Browser and other runtime (like Deno) have no such objects. Before using them, if we have require or import statement, we can quickly migrate the Node script to browser or Deno by replacing the require('node:process') to another object.

If we don't enforce these rules, we have to check manually, like global searching.

Linked Issues

Additional context

@antfu
Copy link
Owner

antfu commented Mar 23, 2023

I am not so sure. As we are using process.env.NODE_ENV a lot in front-end to do conditional env logic.

@zanminkian
Copy link
Contributor Author

Your opinion is reasonable.

I think, mounting Buffer object and process object to global object is a design mistake. It make me difficult to migrate my Node code to Deno. I think all the Node apis (like fs and child_process and Buffer ...) should be required to use.

Maybe we can ban the Buffer first?

@antfu antfu merged commit 502f6b0 into antfu:main Apr 3, 2023
@DanSnow
Copy link

DanSnow commented Apr 3, 2023

Just a quick question. From what I understand, eslint-plugin-n is a maintained version of eslint-plugin-node, and the rules from eslint-plugin-node are available in eslint-plugin-n, which includes the prefer-global rule. May I ask why eslint-plugin-node is being used instead of eslint-plugin-n in this case?

@antfu
Copy link
Owner

antfu commented Apr 3, 2023

Oh I didn't know, thanks. PR welcome to improve it!

chrisbbreuer added a commit to ow3org/eslint-config that referenced this pull request Apr 8, 2023
commit 5240f68
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Tue Apr 4 08:56:34 2023 +0200

    chore: release v0.38.4

commit 79c8de5
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Tue Apr 4 08:56:29 2023 +0200

    chore: update deps

commit 3f13db7
Author: 曾明健 <hellozmj@qq.com>
Date:   Tue Apr 4 14:55:00 2023 +0800

    refactor: remove `eslint-plugin-node` (antfu#162)

commit 7a5daf6
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Mon Apr 3 17:19:24 2023 +0200

    chore: update lock

commit 79b63bc
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Mon Apr 3 14:43:41 2023 +0200

    chore: enable hoist

commit 60002c3
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Mon Apr 3 14:42:06 2023 +0200

    chore: release v0.38.3

commit 502f6b0
Author: 曾明健 <hellozmj@qq.com>
Date:   Mon Apr 3 20:41:41 2023 +0800

    feat(basic): prefer non global object of node (antfu#159)

    Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>

commit d1cd722
Author: 曾明健 <hellozmj@qq.com>
Date:   Mon Apr 3 20:30:54 2023 +0800

    feat(basic): new line after import (antfu#161)

commit d2150ee
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Thu Mar 30 11:02:49 2023 +0200

    fix(top-level-function): narrow warning range

commit d3c3e1b
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Thu Mar 30 10:57:04 2023 +0200

    chore: update lock

commit 3963633
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Thu Mar 30 10:53:40 2023 +0200

    chore: release v0.38.2

commit e919334
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Thu Mar 30 10:53:36 2023 +0200

    chore: format

commit e8d73f7
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Thu Mar 30 10:51:35 2023 +0200

    chore: release v0.38.1

commit 3a74c8e
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Thu Mar 30 10:51:29 2023 +0200

    fix(top-level-function): support async function

commit 3fa8617
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Thu Mar 30 01:08:42 2023 +0200

    test: add more test case

commit ebbc1a7
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Wed Mar 29 15:52:45 2023 +0200

    chore: rebuild lock file

commit 417b60c
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Wed Mar 29 15:47:19 2023 +0200

    chore: release v0.38.0

commit 9768ccd
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Wed Mar 29 15:47:03 2023 +0200

    chore: update deps

commit 87d26fb
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Wed Mar 29 15:46:16 2023 +0200

    feat: enforce to use function declaration on top-level

commit e17d2f8
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Fri Mar 24 10:08:38 2023 +0100

    docs: update

commit 4ef978a
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Fri Mar 24 10:01:44 2023 +0100

    refactor: rename folders

commit ab850b0
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Sat Mar 18 22:01:51 2023 +0100

    chore: release v0.37.0

commit 7632765
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Sat Mar 18 22:01:39 2023 +0100

    feat: upgrade deps, support typescript 5.0

commit d3c1119
Author: Ivan Demchuk <ivan.demchuk@gmail.com>
Date:   Thu Mar 16 12:34:58 2023 +0200

    feat: enable `vue/no-unused-refs` (antfu#158)
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