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

feat(lint): add checkHtmlElements option for useSelfClosingElements #3697

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

abidjappie
Copy link
Contributor

@abidjappie abidjappie commented Aug 22, 2024

Summary

Fix #3364

This PR implements the checkHtmlElements option provided by Eslint Stylistic jsx-self-closing-comp (as html).

By setting checkHtmlElements to false, it will not enforce this rule on html elements.

Implementation

It checks whether the JsxOpeningElement contains a JsxName i.e. it is not a JsxReferenceIdentifier etc. and assumes that it is a valid html element implicitly. If this assumption does not hold, we may need an alternative implementation.

Limitations

This does not cover the void element case - i.e. it will not automatically lint the void element correctly. It simply disables the rule.

Test Plan

Added the validCheckHtmlElementsFalse and invalidCheckHtmlElementsFalse test cases.

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Aug 22, 2024
@abidjappie abidjappie marked this pull request as draft August 22, 2024 09:59
@abidjappie abidjappie changed the title feat: implement the html option for useSelfClosingElements as provide… feat(lint): implement the html option for useSelfClosingElements Aug 22, 2024
@abidjappie abidjappie changed the title feat(lint): implement the html option for useSelfClosingElements feat(lint): add the html option for useSelfClosingElements Aug 22, 2024
@abidjappie abidjappie changed the title feat(lint): add the html option for useSelfClosingElements feat(lint): add html option for useSelfClosingElements Aug 22, 2024
Copy link

codspeed-hq bot commented Aug 22, 2024

CodSpeed Performance Report

Merging #3697 will degrade performances by 6.24%

Comparing abidjappie:feat/style-use-self-closing-elements-html-option (9e5086a) with main (ecf1f16)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 105 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main abidjappie:feat/style-use-self-closing-elements-html-option Change
dojo_11880045762646467684.js[cached] 7.9 ms 8.4 ms -6.24%
react.production.min_3378072959512366797.js[uncached] 2.2 ms 2.1 ms +6.12%

@abidjappie abidjappie marked this pull request as ready for review August 22, 2024 10:38
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution.

A couple of important things should be addressed:

  • Documentation; I left various tips
  • Changelog line for CHANGELOG.md

/// {
/// "//":"...",
/// "options": {
/// "html": true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, the name html is not descriptive enough. A name should be explanatory enough so users can understand what it does just by reading it.

I think we should name it checkHtmlElements, what do you think?

Regarding the structure of the docs, it should be like this:

### Options

#### `nameOfTheOoption`

Default: `true`

<Explanation of the option> (e.g. This option allows to control whether this rule should check HTML elements or not)

<Explanation of an example> (e.g. In the following example, when the option is set to `false`, this happens)

```json
{
	"//": "example of the configuration"
}
```

```jsx,ignore
// example of code that will pass, use the `ignore` directive in the code block, so the codegen won't execute the code
<img src="something.png" >
```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I think we can proceed with checkHtmlElements!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in c633de8

Please let me know if it's acceptable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A possible alternative name: ignoreHtmlElements.
This has the advantage to make its default false.

#[derive(Clone, Debug, Deserialize, Deserializable, Eq, PartialEq, Serialize)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct UseSelfClosingElementsOptions {
pub html: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options must be documented. The documentation will be part of the configuration JSON schema, this means that users will be able to see the description when their IDE will autocomplete the option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I'll add the documentation too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in c633de8

Please let me know if it's acceptable.

@ematipico
Copy link
Member

@abidjappie, are you still interested in bringing this feature to the finish line?

@abidjappie
Copy link
Contributor Author

@ematipico sorry, I'll have a look at this one this week!

@abidjappie abidjappie force-pushed the feat/style-use-self-closing-elements-html-option branch from 6961fdc to c633de8 Compare September 24, 2024 04:58
@abidjappie
Copy link
Contributor Author

I still need to investigate how to do the CHANGELOG.md line 🙇 🙇

@github-actions github-actions bot added the A-Changelog Area: changelog label Sep 24, 2024
@abidjappie
Copy link
Contributor Author

I still need to investigate how to do the CHANGELOG.md line 🙇 🙇

Updated 👍

@abidjappie abidjappie force-pushed the feat/style-use-self-closing-elements-html-option branch from 95c434e to 3604605 Compare September 24, 2024 13:08
@abidjappie abidjappie force-pushed the feat/style-use-self-closing-elements-html-option branch from 3604605 to 9e5086a Compare September 25, 2024 01:09
@abidjappie abidjappie changed the title feat(lint): add html option for useSelfClosingElements feat(lint): add checkHtmlElements option for useSelfClosingElements Sep 25, 2024
///
/// ## Options
///
/// #### `checkHtmlElements`
Copy link
Member

@unvalley unvalley Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits

Suggested change
/// #### `checkHtmlElements`
/// ### `checkHtmlElements`

///
/// This option allows you to specify whether or not to check native HTML elements.
///
/// In the following example, when the option is set to "false", it will not self close native HTML elements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggestion because the following example is set to true.

Suggested change
/// In the following example, when the option is set to "false", it will not self close native HTML elements.
/// In the following example, when the option is set to "true", it will check for self-closing native HTML elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Linter Area: linter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

💅 lint/style/useSelfClosingElements false positive error
4 participants