Is there a option to disable `Parsing error: Identifier '' has already been declared`
hasezoey opened this issue · comments
Currently i am trying to add this plugin to a project, but the project makes use of the following examples, and separating them out into their own code blocks would not look as good in the documentation.
I have already tried to search eslint options, but couldnt find anything to disable this error (already tried "no-redeclare": "off"
, but seems to only allow var
re-declaration not const
or let
or variants (like import))
Examples:
showcasing how the package can be imported
const pkg = require("pkg");
import pkg from "pkg";
showcasing different files, or also different versions on how stuff can be written
// file a
const t = "hello";
export default t;
// file b
const t = "something else";
// file c
const fileA = require("a")
const fileB = require("b")
const t = pkg.someFunction();
t.someOtherFunction();
// can also be written
const t = pkg.someFunction().someOtherFunction();
Sorry we lost track of this. Can you please create a minimal reproduction case that we can run? It's not clear from the description how to reproduce what you're describing.
It's not clear from the description how to reproduce what you're describing.
from what i can tell, i have provided reproduction examples already, though now i notice i have not noted down exactly which line errors
Can you please create a minimal reproduction case that we can run?
sure
Reproduction Repository & branch
weirdly, the same code is in a .js
file, where eslint does not error, but the same code in a markdown block does error with the plugin with the error 9:7 error Parsing error: Identifier 't' has already been declared
Hi @hasezoey, thanks for the issue. I could reproduce the issue you were facing.
const pkg = require("pkg");
import pkg from "pkg";
This is illegal JS code and if allowed to pass linting I feel would beat the purpose of using a linter altogether. I think this is why there is no option to disable the Parsing error: Identifier '' has already been declared
even though it can be useful for documentation.
You could maybe use the <!-- eslint-skip -->
option to skip parsing an entire code block.
// this will be skipped
<!-- eslint-skip -->
```js
const pkg = require("pkg");
import pkg from "pkg";
```
// not this
```js
// file a
const t = "hello";
export default t;
```
Hope this helps.
You could maybe use the option to skip parsing an entire code block.
i know that this way exists, but i opened the issue because i think it is pretty common to have those kinds of code blocks (at least in documentation) and separating them into their own code-blocks just does not look great most of the time (especially if they are one-liners)
This is illegal JS code and if allowed to pass linting I feel would beat the purpose of using a linter altogether
true, but wouldnt it be good to have something like allowRedefinitonOfConstants
? but i dont know if this plugin could do this and would instead have to be opened at eslint directly
but i dont know if this plugin could do this and would instead have to be opened at eslint directly
The plugin extracts JS code from .md
files and then passes it to ESLint for linting.
wouldnt it be good to have something like allowRedefinitonOfConstants?
I don't think an option like allowRedefinitonOfConstants
in ESLint would be ideal. The @eslint/eslint-tsc folks will have a better idea.
I second that allowRedefinitonOfConstants
defeats the purpose of const
and having a linter altogether. By using <!-- eslint-skip -->
you get to bypass the rule for this rare (imho) occasions.
Thanks @Rec0iL99 for the analysis.
So the problem here is actually not a linting problem, it's a parsing problem. JavaScript simply does not allow redeclaration of let
or const
scoped variables at the parsing level. So this error is actually being thrown before ESLint is even able to start linting and we can't override it.
I think it may be worth filing an issue on Acorn (https://github.com/acornjs/acorn/issues). It seems like it should at least be telling you the name of the identifier that was already declared, not just empty quotes.
It seems like it should at least be telling you the name of the identifier that was already declared, not just empty quotes.
it does, i just made it empty to be for a generic issue title (not about a specific identifier)
Ah okay. It's always best to use the actual error message you see to avoid confusion. :)