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

Disable no-console for CLI config #198

Merged
merged 3 commits into from
Mar 22, 2024
Merged

Disable no-console for CLI config #198

merged 3 commits into from
Mar 22, 2024

Conversation

noahtallen
Copy link
Contributor

@noahtallen noahtallen commented Mar 22, 2024

Edit: I've updated this to just clarify the readme.

I used the CLI config in a different repo (see https://github.com/Automattic/vip-go-utility-scripts/pull/477), but was surprised that using console.log still showed warnings. (The readme also implies that this rule is disabled here: https://github.com/Automattic/eslint-config-wpvip?tab=readme-ov-file#cli)

Any objections to disabling the no-console rule for the CLI preset?

@chriszarate
Copy link
Member

chriszarate commented Mar 22, 2024

The reasoning here is a little aspirational, but it's basically this:

  1. Calling console.* directly is a primitive way to log, both for "regular" applications and for output in CLI contexts. Ideally you are delegating to something else that calls console.* or process.stdout on your behalf, usually with additional context or adornment. Delegation makes mocking easier so that you don't have to mock and restore a global, and it makes expects easier because you catch more primitive input before it has been adorned or formatted.
  2. If we followed the approach of #1, then we still find value in the no-console rule in CLI contexts, to flag accidental debugging logs.

That said, our CLI applications don't really live up to this standard and I think most of them just override it themselves. In general, though, we like to keep the config strict for new projects and to motivate older projects to improve.

This could all be made much more clear, of course, in the README and maybe comments in this preset. If you wanted to add that it would be much appreciated!

@noahtallen
Copy link
Contributor Author

Yeah, I can update the readme :)

Hm, I think I follow. Seems like this preset is more oriented towards customer-facing CLI tools rather than assorted node scripts, which makes sense.

Copy link
Member

@chriszarate chriszarate left a comment

Choose a reason for hiding this comment

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

thanks!!

@noahtallen noahtallen merged commit e953aa5 into trunk Mar 22, 2024
4 checks passed
@noahtallen noahtallen deleted the disable-console-rule branch March 22, 2024 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants