<p></p>
<h3 dir="auto">Problem</h3>
<p dir="auto">When I'm refactoring, or when I'm reading pull requests, it's often unclear to me if particular html class names are still required.</p>
<p dir="auto">For example, in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1430552142" data-permission-text="Title is private" data-url="https://github.com/openstreetmap/openstreetmap-website/issues/3779" data-hovercard-type="pull_request" data-hovercard-url="/openstreetmap/openstreetmap-website/pull/3779/hovercard" href="https://github.com/openstreetmap/openstreetmap-website/pull/3779">#3779</a> the CSS rules for <code class="notranslate">.loader</code> were removed, but the class was still left in the html code in the .erb templates in the PR. I had to dig around to find out that there is still JavaScript code that needs those classes to remain.</p>
<p dir="auto">It's a particular problem because our JavaScript code is only lightly tested, so it's quite easy to break things by accidentally removing a class that's no longer required for CSS, without realising that it's also used by JavaScript.</p>
<h3 dir="auto">Description</h3>
<p dir="auto">I think that we should follow the convention to prefix all the classes used in our Javascript with <code class="notranslate">js-</code>. I've seen this done elsewhere, and recommended elsewhere too. Github has a nice explanation in their eslint rule that enforces this on their codebase:</p>
<p dir="auto"><a href="https://github.com/github/eslint-plugin-github/blob/main/docs/rules/js-class-name.md">https://github.com/github/eslint-plugin-github/blob/main/docs/rules/js-class-name.md</a></p>
<p dir="auto">I'd like to hear any feedback from other developers who think this is either a good or bad idea, before I implement it. My intention would be to implement this across all of our JavaScript code, and then introduce an eslint rule like the one above to help enforce the convention.</p>
<h3 dir="auto">Screenshots</h3>
<p dir="auto"><em>No response</em></p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/issues/3801">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLIOVPLP7A435S4LZUTWIUBVFANCNFSM6AAAAAASCM525A">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLOKIFMITCGAYCA24VTWIUBVFA5CNFSM6AAAAAASCM525CWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHFNCPLFE.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/issues/3801</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/issues/3801",
"url": "https://github.com/openstreetmap/openstreetmap-website/issues/3801",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>