-
Notifications
You must be signed in to change notification settings - Fork 51
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
no_unused_vars
triggered wrongly
#61
Comments
Hi, thanks for the report. Sadly, I have no idea how linting JS in HTML attributes could work... I can't think of a way to feed it to ESLint. I'm open to suggestions. |
How about parse onXXX attributes and transform into a fake JS segment? Then hack the messages from ESLint. |
@BenoitZugmeyer To parse attributes you have to use something like this const parser = new htmlparser.Parser(
{
...
onattribute(name, value) {
const cdata = []
if (/^javascript:/i.test(value)) {
const end = parser.endIndex - 1 // idk if quote is included
chunks.push({
type: "inlineScript",
start: end - value.length + 10, // not sure about those values
end,
cdata,
})
} else if (/^on/i.test(name)) {
const end = parser.endIndex - 1 // idk if quote is included
chunks.push({
type: "inlineScript",
start: end - value.length,
end,
cdata,
})
}
},
... after parsing html event attributes you will have to make rule thats triggers context.markVariableAsUsed(name) see https://eslint.org/docs/developer-guide/working-with-rules#the-context-object |
Superseded by #123 |
Hi,
I have a file with the following structure, in which I get the following error:
Clearly,
checkSubmit
is used as a listener. Maybe the html is ignored by the plugin, even though it may have an impact on rules like this one.Thanks!
The text was updated successfully, but these errors were encountered: