How to fix (non-trivial) ESLint problems in MDN code snippets #158
Replies: 5 comments 12 replies
-
The various
That doesn't look good—should be transformed to comments if possible. Otherwise we may need to invent some kind of special layout in Yari so we can display the text as a floating box or a two-column layout.
Worse noting that at least one parser (probably Babel?) has a
We should definitely parse most examples as scripts. Also, several general ideas:
|
Beta Was this translation helpful? Give feedback.
-
How about at first we put all the files in ignore list and remove them as the PRs fix them? This way we'll get the ball rolling and the entire effort won't stop because of few un-fixable files. 🙂 [PR3] Chunked block of codeFixing all the blocks will be a huge effort. And they are part of live samples as well.
We don't have to ignore each block. If it's too much we can ignore entire sections or even entire pages. We can put them in [PR5] [PR6] [PR9]If there are few cases then we can disable linting/rule locally. [PR7] with used in strict modeThere shouldn't be many [PR8] JS + hidden to complete live examplesUntil a permanent solution is found we simply need to skip these using [PR10] "raw" objectsWe can mark them as [PR11] Macro added to codeThose in meta pages describing kuma macros shouldn't be marked as Vue and Ember pages are full of these but only few occurrences. We can mark them as The linting can be done without some rules to keep it simple for contributors and keep alive for longer. Some of the rules that we can disable globally: We do not have to enforce all the rules available in ESLint right away. After the syntax errors are fixed, we can tighten the grip few rules at a time depending on how fast we fix the lint rule in content. |
Beta Was this translation helpful? Give feedback.
-
[PR8] js + hiddenThese blocks are not displayed to users. Can we just skip any blocks that have ```js hidden? (and similarly ```js example-bad ) |
Beta Was this translation helpful? Give feedback.
-
I have one new case, "This number literal will lose precision at runtime" https://eslint.org/docs/latest/rules/no-loss-of-precision I don't know if it's trivial fix or not but this is found in pages about Audio. |
Beta Was this translation helpful? Give feedback.
-
There is some friction between exiting If we can not find the common ground between them then, I am just thinking, if possible we could use use Prettier only for embedded languages. And let markdownlint continue linting markdown content. For the migration we are able to run Prettier on a particular language in isolation. |
Beta Was this translation helpful? Give feedback.
-
Hi all!
We have a mid-term goal to use more linters (like Markdownlint, ESLint, or Prettier) on MDN. We would like to use ESLint, a linter for code samples and snippets.
This brings several advantages for our readership:
If we want to run ESLint automatically, we need to clean MDN first, or each PR will scream from detected problems. Even if we end up running ESLint periodically, as we do with Markdownlint, we will have so many potential errors raised that the tool will become useless. In addition, getting better acquainted with this tool is useful: getting to the hassle of setting up the toolchain to hit one problem after the other is not a good methodology.
@lionralfs ran ESLint on web/javascript and web/audio and created PRs to fix them. 🎉 This is amazing, and they solved a lot of errors. See the (large) PRs: mdn/content#18186, mdn/content#18191, mdn/content#18307, mdn/content#18424, and mdn/content#18442.
This great work uncovered a few problems. We need to solve them if we want to use ESLint automatically. Here is the list of the remaining problems, grouped by category. Note: The id of each group is fixed, so we can refer to it in the discussion that will follow.
Problems to solve
Note: Problems IDs are permanent; you can refer to an issue as PR3, PR12, …
👍 = we have a solution for this problem
✅ = solution implemented
[PR1] Code ellipsis. 👍
...
is used to replace missing code.//...
or/* ... */
and a few variations depending on the languagejsonc
, an extension of JSON with comments.[PR2] Pseudo-code in syntax boxes. 👍
delete()
delete(name)
delete(property)
delete(key)
delete()
continue()
delete(name)
delete(name)
delete(font)
delete(value)
delete(name/options)
delete(cacheName)
delete(request)
class
as arg namejssyntax
, that we'll apply on syntax boxes and tell ESLint to ignore them.[PR3] Chunked block of code.
[PR4] GLSL block of code 👍
[PR5] Return outside of a function
return
return
return
return
return
[PR6] Method without surrounding class
class
structure (that is not necessary defined earlier).[PR7]
with
used in strict modewith
with
with
in strict modewith
async
/await
, so not running it in that mode leads to other problems; strict mode is good: we want our code to be ready for strict mode. Obviously, when we speak aboutwith
, we want to avoid linting in strict mode.[PR8] JS + hidden to complete live examples
[PR9] Loose
case
blockscase
blocks(all throughout this file), loosecase
block[PR10] "raw" objects
Parsing error: Unexpected token :
[PR11] Macro added to code ✅
{{deprecated_inline}}
inside code block[PR12] Code diffs 👍
cc/ @lionralfs, @OnkarRuikar, @Josh-Cena, @Rumyra, @schalkneethling, @wbamberg, @Elchi3
Beta Was this translation helpful? Give feedback.
All reactions