valeryan / vscode-phpsab

Php Sniffer and Beautifier for VS Code
https://marketplace.visualstudio.com/items?itemName=ValeryanM.vscode-phpsab
MIT License
58 stars 12 forks source link

Sniffer doesnt work with associated files. #125

Closed SamTyurenkov closed 5 months ago

SamTyurenkov commented 5 months ago
"files.associations": {
    "*.html": "php"
}

When working with php inside .html templates, sniffer doesnt seem to validate or fix errors.

jonathanbossenger commented 5 months ago

@valeryan, could I check with you here. Is this a similar issue to https://github.com/valeryan/vscode-phpsab/issues/109. I'm not aware of phpcs working on .html files, but I could be mistaken.

valeryan commented 5 months ago

Yes, this is similar to #109 and we are not going to support or add features around deprecated functionality. This extension specifically only activates for php file types when the extension is registered in VSCode.

SamTyurenkov commented 5 months ago

@valeryan @jonathanbossenger

No it is not similar issue.

The difference is - the one you mentioned is about different languages - css or js. While my issue is about working with php language but inside an .html file.

Please reopen, I dont seem to have access rights.

SamTyurenkov commented 5 months ago

Example code: (the only difference is file extension, otherwise its a valid php file)

<!-- html file with regular html markup, but with php embeddings. -->
<div>
Regular html markup
</div>

<?php
//Php code that could be sniffed
$variable = 'hello world';
?>
<!-- html file with regular html markup, but with php embeddings. -->
<div>
Regular html markup
</div>

<?php
//Php code that could be sniffed
$variable = 'hello world';
?>
SamTyurenkov commented 5 months ago

image

in vscode you can choose to treat html files, as PHP files., in the bottom right corner image

valeryan commented 5 months ago

I don't do php anymore but I can't imagine why you would want to invert and embed php in html. However, if you tell VSCode to treat the file as php the extension should activate. Phpcs may not pick that up though. I will look at it but I don't see this working.

SamTyurenkov commented 5 months ago

@valeryan in my projects I dont implement such crazy things, but I have to work with code written by others, and unfortunately I met such a case, where I need those .html files to be sniffed as well.

Some template files of an unpopular CMS.

jonathanbossenger commented 5 months ago

@SamTyurenkov are you able to run phpcs in the terminal against the .html template files?

I just did a quick test using

phpcs -p example-file.html --standard=PSR1

Against an .html file which included the following code

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>
<?php
class my_class(){
    function my_class(){
        return true;
    }
}
?>

</body>
</html>

and none of the expected phpcs errors or warnings were reported.

SamTyurenkov commented 5 months ago

@jonathanbossenger im not near PC right now, but didnt think about it.

Actually I keep forgeting that extension cant do more than actual executable can.

If it cant - sorry, probably close this issue then.

jonathanbossenger commented 5 months ago

Yup, as far as I know that is the case, so I'll close this out.