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

Convert DOM manipulation bans into a custom rule #123

Open
Josehower opened this issue May 6, 2022 · 1 comment
Open

Convert DOM manipulation bans into a custom rule #123

Josehower opened this issue May 6, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@Josehower
Copy link
Contributor

Josehower commented May 6, 2022

Currently, we are using no-restricted-syntax config blocks to preventively ban querySelector querySeletorAll and getElementById. One of the issues with this is the warning messages don't allow us to add clickable links to the description of the error:

One way to solve this Is moving these checks into a new custom ESLint rule:

/** Currently it is not possible to use markdown links inside of the eslint warn/error message.
* related links:
* - https:/microsoft/vscode/issues/54272
* - https:/microsoft/vscode-eslint/issues/418
* - https:/microsoft/vscode/issues/11847
*/
{
selector:
"ExpressionStatement CallExpression[callee.object.name='document'][callee.property.name='querySelector']",
message: `Using document.querySelector() can give unexpected results, especially if multiple elements match the query (for example, when the component is used more than once); as a piece of advice, use State or Refs instead
https:/reactjs/reactjs.org/issues/4626#issuecomment-1117535930`,
},
{
selector:
"ExpressionStatement CallExpression[callee.object.name='document'][callee.property.name='querySelectorAll']",
message: `Using document.querySelectorAll() can give unexpected results, especially if multiple elements match the query (for example, when the component is used more than once); as a piece of advice, use State or Refs instead
https:/reactjs/reactjs.org/issues/4626#issuecomment-1117535930`,
},
{
selector:
"ExpressionStatement CallExpression[callee.object.name='document'][callee.property.name='getElementById']",
message: `Using document.getElementById() can give unexpected results, especially if multiple elements match the query (for example, when the component is used more than once); as a piece of advice, use State or Refs instead
https:/reactjs/reactjs.org/issues/4626#issuecomment-1117535930`,
},

@Josehower Josehower added documentation Improvements or additions to documentation enhancement New feature or request labels May 6, 2022
@Josehower
Copy link
Contributor Author

Handover Comment for the PR:

What work has been done

  • Initial research about the issue and documentation

What work is still open

  • Do a new search about the state of the issue
  • Create a Plan on how to implement changes that fix the issue

who to take over

This Issue will be taken over either for @ProchaLu or @Eprince-hub

Where to start

The best place to start would be checking the following issue in vs code:

See if there is a new workaround found by the community.

Other details that you know that are not captured already in the issue / PR

If at any point the issue microsoft/vscode#54272 is solved, this issue would be able to be solved right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant