BenoitZugmeyer / eslint-plugin-html

An ESLint plugin to extract and lint scripts from HTML files.
ISC License
430 stars 51 forks source link

Parsing a PHP file raises an error: Unexpected token #51

Closed mateiacd closed 7 years ago

mateiacd commented 7 years ago

When I test eslint index.php

I get the following error 16:38 error Parsing error: Unexpected token e

The index.php is this and is also attached in a zip file

<!DOCTYPE html> <html> <head> <title>PHP test</title>

<?php $my_array = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"purple"); ?>

<script type="text/javascript">

function OnLoadPage() { var x = "<?php echo $my_array["e"]; ?>"; alert("OnLoadPage '" + x+ "' "); } </script>

</head>

<body onload="OnLoadPage();"> </body>

`

index.zip

mateiacd commented 7 years ago

I found the solution. In my .php file, I replaced the quotes surrounding "e" with single quotes 'e' and now it's ok. var x = "<?php echo $my_array['e']; ?>";

BenoitZugmeyer commented 7 years ago

Nice!

As a side note, you should probably use json_encode when printing PHP variables in a <script> tag.

wowcut commented 7 years ago

Besides the other issue I opened today I have this problem too - it woud be nice if this plugin would not produce errors with that kind of ugly code, but simply report it as another problem.