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

Implement default "never" option for check-line-alignment rule: linting inside comments block spaces/tab to single space #483

Closed
jperocho opened this issue Jan 17, 2020 · 7 comments

Comments

@jperocho
Copy link

jperocho commented Jan 17, 2020

Just a question if this plugin has a rule to check for multiple spaces or tabs inside a comment block?

 /**
 * Some jsdocs for a function
 * @param   {String}   argument string - string
 * @param   {Object}   property        - property object
 * @returns {Function} callback        - callback
 */

Thanks in advance.

@brettz9
Copy link
Collaborator

brettz9 commented Jan 23, 2020

Not currently. One can use regexes on the description portion using match-description, but that wouldn't catch whitespace before or after the tag name, type, or (parameter) name (or default value) or within the type.

@l1bbcsg
Copy link
Contributor

l1bbcsg commented Jan 24, 2020

This is quite complex given the lack of concrete syntax tree or parsers that can produce one for JSDoc.
Regular expressions will quickly turn into a mess if edge cases and more scenarios were to be implemented.

Neither Doctrine, nor comment-parser can do what espee does for js, namely tokenize input and keep information about all whitespaces and non-syntax important stuff.
When we previously discussed this in my company, we figured we're going to need to write a new JSDoc parser that either keeps track of tokens or builds a concrete syntax tree, but it wasn't the task we had time for.
This would allow all kinds of validation of JSDoc codestyle – indentation, whitespace placement, you name it.

Some attempt were made in eslint-plugin-interfaced however, particularly JSDocTokenizer and some helper functions. And jsdoc-type-spacing is an example of a rule that validates whitespaces.

@yvele
Copy link

yvele commented Feb 24, 2020

What about the use case where we want to disable multi space alignment in JSDoc? Does that feature requires complex parsing?

Something that fixes:

/**
 * @param   {string}   foo   This is foo.
 * @param   {object}   bar   This is bar.
 * @returns {boolean}        This is the returned value.
 */

to:

/**
 * @param {string} foo This is foo.
 * @param {object} bar This is bar.
 * @returns {boolean} This is the returned value.
 */

The rule may be very specific like

"jsdoc/no-aligment" : "error"

Or a more configurable rule similar to https://eslint.org/docs/rules/key-spacing but it looks lke we are limited by the JSDoc parser.

So.. can we at least have a simple rule to disallow multi space alignment?

PS: As a workaround can we have a generic match regex that applies to a whole JSDoc line? 🤔 with a custom message and fix of course.

@brettz9
Copy link
Collaborator

brettz9 commented Feb 24, 2020

@yvele : I think based on the title of the issue that that's what the original poster intended for the rule, though there could conceivably be a rule which automatically added whitespace with alignment. I'd be personally open to a whole-line regex solution as an interim solution if someone could put a PR together, though it'd be great as @l1bbcsg suggests if we could get AST for jsdoc, or at least build on comment-parser further to allow full round-tripping.

@brettz9 brettz9 changed the title Linting inside comments block spaces/tab to single space Implement default "never" option for check-line-alignment rule: linting inside comments block spaces/tab to single space Sep 14, 2020
@brettz9
Copy link
Collaborator

brettz9 commented Sep 14, 2020

I've renamed this issue to reflect the fact that we've made space for this functionality within a new rule check-line-alignment, but currently the implementation is only able to do the opposite. The "always" option will do the opposite, but the functionality for this issue should provide the "never" option and is even reserved already as the default behavior. At such time as it may be implemented, we can also add this rule to the "recommended" rules.

@gajus
Copy link
Owner

gajus commented Jan 11, 2021

🎉 This issue has been resolved in version 31.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Jan 11, 2021
@brettz9
Copy link
Collaborator

brettz9 commented Jan 11, 2021

I've gone ahead and implemented the "never" behavior as @renatho previously implemented "always" behavior.

It'd probably be better if we switched internally for the "always" behavior to the new comment-parser tokens in place of our custom regexes, and we don't have any specified behavior for alignment of multi-line descriptions, but the main behavior is now available in v31.0.2. Thanks for the report and to @renatho for getting the feature going!

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

No branches or pull requests

5 participants