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

Adding silent option to suppress warnings #57

Merged
merged 2 commits into from
May 30, 2017
Merged

Conversation

iansu
Copy link
Contributor

@iansu iansu commented May 27, 2017

I'm using this in a site generator and the project being built may or may not have a .env file. Since that file is optional I don't want to display the warning about not being able to load the .env file.

I also suppressed the deprecation warning for consistency although I'm not sure it's a good idea in that case. I did not suppress the exception when a value is missing from the .env file since that's an error and not a warning.

@mrsteele
Copy link
Owner

Hey @iansu thanks for the PR. This is actually a really good use-case and I think appropriate for what you mentioned.

Could I make a small request to the PR?

I was wondering if instead of calling console.warn directly, we could make some log function that gets the silent variable passed to it? That way we could let the log function determine if it needs to be called. Something like follows:

/**
 * Logs a message if 'silent' is falsy.
 * @param {String} msg - The message.
 * @param {Bool=} silent - If the message should not happen.
 */
const log = (msg, silent) => !silent && console.warn(msg)

That way elsewhere we can just do: log("Something bad happened", options.silent) instead of wrapping every single log request with that if statement.

Great idea though for sure!

@iansu
Copy link
Contributor Author

iansu commented May 29, 2017

@mrsteele That sounds like a good change. As far as the name of the function, should it be warn instead of log? It's only used for warnings and it calls console.warn. Let me know and I'll update the pull request later today.

@mrsteele
Copy link
Owner

@iansu Yeah the nomenclature of that function doesn't matter too much to me. I'll lean on your discretion for that 😉 .

@codecov
Copy link

codecov bot commented May 30, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@99beda6). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##             master    #57   +/-   ##
=======================================
  Coverage          ?   100%           
=======================================
  Files             ?      1           
  Lines             ?     35           
  Branches          ?      0           
=======================================
  Hits              ?     35           
  Misses            ?      0           
  Partials          ?      0
Impacted Files Coverage Δ
src/index.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99beda6...e5572ce. Read the comment docs.

@iansu
Copy link
Contributor Author

iansu commented May 30, 2017

@mrsteele Pull request updated.

@mrsteele
Copy link
Owner

Awesome! thanks @iansu for the contribution!

@mrsteele mrsteele merged commit fc11e45 into mrsteele:master May 30, 2017
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

2 participants