-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Add no-console-spaces
rule
#191
Add no-console-spaces
rule
#191
Conversation
|
The other question is if we should worry about someone shadowing In any case, I'll start plugging away at your requests. 😄 |
Nah. That's an edge-case. Would be nice to solve eventually, but can be a follow-up. |
Can you rebase from master? I just added back linting (It was previously removed because of problems with ESLint 4). And then run |
rules/no-console-spaces.js
Outdated
const methods = [ | ||
'log', | ||
'warn', | ||
'error', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many more log methods: https://developers.google.com/web/tools/chrome-devtools/console/console-reference We only need to support the ones that accept multiple arguments.
You might (or may not) find these useful: |
rules/no-console-spaces.js
Outdated
const methods = [ | ||
'log', | ||
'warn', | ||
'error', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many more log methods: https://developers.google.com/web/tools/chrome-devtools/console/console-reference We only need to support the ones that accept multiple arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added debug
and info
. The only other multi-parameter is group
which isn't really the same. I can add that as well if you want.
a6055d7
to
b03822d
Compare
@sindresorhus Updated PR.
Let me know if you want any other changes. |
@sindresorhus gentle bump in case the earlier notification got lost in the wind. |
docs/rules/no-console-spaces.md
Outdated
@@ -0,0 +1,38 @@ | |||
# Do not include spaces in `console.log` parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too generic. Should be something more like:
Do not include leading/trailing space in
console.log
parameters.
rules/no-console-spaces.js
Outdated
return value; | ||
} | ||
|
||
// Find exactly one leading or tailing space |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo, trailing
rules/no-console-spaces.js
Outdated
} | ||
|
||
// Find exactly one leading or tailing space | ||
return value.replace(/^ ?((?! ).*?[^ ]) ?$/, '$1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like using .startsWith()
/.endsWith()
and then .slice(1)
or .slice(-1)
would be simpler and more readable.
Sorry about the delay. This got lost in a tab somewhere. |
I don't think these should be failures:
They are not really mistake. The mistake is not realizing multiple arguments are joined with a space. Meaning, these should not be failures either:
|
@sindresorhus No worries. I made the changes requested but travis is failing due to the following:
|
This is looking great now. Thanks for your patience. I think we ended up with something really good :) |
A few questions:
I chose to use
.trim()
to apply the fix. This removes all whitespace -- including\t
and\n
. In theory we could expose a setting to chose what values to remove but then we'd probably want to upgrade to something like lodash.trim.Similarly,
.trim()
also removes preceding whitespace. There could be a setting to switch totrimEnd
instead?This implementation explicitly ignores template literals. It wouldn't be a big deal to add them but the previous decision to remove
\n
makes some of the fixes awkward. Maybe we want to include template literals in the fix but ignore multiline literals?I assumed this rule should be enabled in the recommended config.
Any other documentation examples and / or tests I should include?
Thoughts on the rule name? I personally prefer
no-console-spaces
orno-console-whitespace
because I don't like prepositions in names when they can be avoided.Fixes #175.