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

licensePattern configuration accepts any string if pattern match fails #885

Closed
dennismphil opened this issue Apr 26, 2022 · 7 comments
Closed

Comments

@dennismphil
Copy link

dennismphil commented Apr 26, 2022

Scenario 1 (Works as expected)

No licensePattern - Shows error

2022-04-26_10-41-53

Scenario 2 (Not working as expected)

With licensePattern - Shows no error

2022-04-26_10-42-36

Environment

  • Node version: 17.9.0
  • ESLint version 8.12.0
  • eslint-plugin-jsdoc version: 39.2.9
@dennismphil dennismphil changed the title License Pattern do not work as expected licensePattern configuration accepting random strings Apr 26, 2022
@dennismphil dennismphil changed the title licensePattern configuration accepting random strings licensePattern configuration accepts any string if pattern match fails Apr 26, 2022
@brettz9
Copy link
Collaborator

brettz9 commented Apr 26, 2022

Yes, this change was made by design as part of #884.

(The previous behavior had not been documented as such, so I tweaked it to allow for the regex to allow for opting out.)

The match now is intended to capture the area to be validated, so if you want to ensure that missing license patterns are caught, you should design your regex to eagerly match content (e.g., by use of | and/or *).

Closing as that should address though feel free to comment further as needed.

@brettz9 brettz9 closed this as completed Apr 26, 2022
@dennismphil
Copy link
Author

dennismphil commented Apr 26, 2022

@brettz9 Thanks for the response.

Scenario 2: 
Here the pattern to match is provided as "black". The linter is not failing even if the given license block is missing the string "black".

@brettz9 brettz9 reopened this Apr 26, 2022
@brettz9 brettz9 closed this as completed Apr 26, 2022
@brettz9
Copy link
Collaborator

brettz9 commented Apr 26, 2022

The regex is just to find the zone which ought to identify any string area to be checked. If a zone is not found, then it is treated as valid.

@dennismphil
Copy link
Author

How do we enforce a particular string pattern to be present in the license block?

@brettz9
Copy link
Collaborator

brettz9 commented Apr 26, 2022

You should I think be able to use jsdoc/match-description for such.

@dennismphil
Copy link
Author

dennismphil commented Apr 26, 2022

I believe that is for the @description field and not for @license block. 

Feedback: The current implementation of licensePattern is not quite intuitive. One would expect a pattern to match with a given string and fail if it does not match.

The match-description also gives a great example of how the error message is shown when the pattern match fails.

@brettz9
Copy link
Collaborator

brettz9 commented Apr 26, 2022

match-description can be used with specific tags, including @license. Use the tags option.

Regarding the feedback, we can add more descriptive text in the docs, but I believe we need some way to define a zone such that missing matches can pass validation.

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

2 participants