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

Cop idea: check descriptions for accidental spaces #1144

Closed
G-Rath opened this issue Apr 20, 2021 · 1 comment · Fixed by #1164
Closed

Cop idea: check descriptions for accidental spaces #1144

G-Rath opened this issue Apr 20, 2021 · 1 comment · Fixed by #1164
Labels

Comments

@G-Rath
Copy link
Contributor

G-Rath commented Apr 20, 2021

I'm actually a bit surprised that not only is this not already a rule, I can't find any mention of anything close to it in any issue or PR - so I could be missing something really big, but in case I'm not here goes nothing...

Over in eslint-plugin-jest we have a rule called valid-title which does checks against it/test and describe descriptions (jest doesn't have context) for things like blank titles (similar to RSpec/ExampleWithoutDescription), duplicate titles (similar to RSpec/RepeatedExampleGroupDescription), and prefixing titles with the test method name (similar to RSpec/ExampleWording)

However, it also checks for accidental spaces in titles, which there doesn't seem to be any cop for!
Specifically, the rule looks for leading and trailing whitespace, and provides an autofix to remove them when found.

I can't think of a situation where you'd want to have this space, and so think this could a good addition for rubocop-rspec; maybe RSpec/ExampleSpacing, or as an extension to the existing RSpec/ExampleWording?

I actually think it would be fair to check for double spaces in titles too, but I think there's slightly higher chance of valid titles having that? (but tbh my go-to example of something like it 'treats " " as valid' would probably be better written as it 'treats multiple spaces as valid' anyway).

I'm happy to have a go at implementing this if people think it'd make a good cop :)

@pirj
Copy link
Member

pirj commented Apr 20, 2021

Do you mean something like?

it " has  excessive   spacing  " do

This should apply to example group, shared group and example wording, right? I don't think that "docstring" is a commonly-used name for it, but AFAIR it is how RSpec calls it internally [1, 2]. Maybe RSpec/ExcessiveDocstringSpacing? See rubocop/rubocop#7077 for cop naming guidelines and practices.

If you're up for it - sure, a PR is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants