3

I have installed Sublimelinter through this site: SublimeLinter 3. I'm on a debian machine.

I basically have installed the following plugins: SublimeLinter 3, SublimeLinter-html-tidy, SublimeLinter-csslint, SublimeLinter-jshint and SublimeLinter-php. Everything works fine if I'm writing only PHP or only JavaScript on a file. But when I develop JavaScript that has some PHP code in it, I get some errors on the lines that has the PHP code.

Is this supposed to happen? Is there a way where the SublimeLinter detects what is JavaScript and what is PHP in the same file? So that it doesn't show the PHP linter errors if the sublime text syntax is set to JavaScript.

Here is a screenshot of my Sublime Text: enter image description here

alexandre1985
  • 1,056
  • 3
  • 13
  • 31

1 Answers1

1

I think that's possible if you use a linter that has more than one "selector": then it can lint embedded languages (see the Sublime Linter documentation). But that should probably happen automatically wherever possible.

Have you identified which linter the undesirable errors come from? If your file is a php file, then the php linter may be the culprit, if it can only understand php code and thus misinterprets the Javascript code. I think what you want is only possible if the php linter is programmed to do so.

Cerberus
  • 246
  • 2
  • 16
  • I have opened a issue on GitHub of php and jshint linters and I think that the culprit is jshint linter (javascript) – alexandre1985 Sep 01 '16 at 14:03
  • @alexandre1985: I've looked at https://github.com/SublimeLinter/SublimeLinter-jshint/blob/master/linter.py, and it says: `syntax = ('javascript', 'html', 'javascriptnext')`. I think that means that it will not operate on php files at all? Are you sure the errors are coming from Jshint: have you tested what happens when you disable Jshint temporarily? – Cerberus Sep 01 '16 at 14:29
  • if you look at the image that I posted and see the bottom right corner you can see that my syntax is Javascript – alexandre1985 Sep 01 '16 at 15:05
  • @alexandre1985: Oh! I missed that! Yes, then one would expect it to be possible. And it says "php" when you click somewhere else in the code? – Cerberus Sep 01 '16 at 15:11
  • I don't know if it says php if I click somewhere else in the code. Can you explain better what do you want me to do and where can I read it? – alexandre1985 Sep 01 '16 at 15:33
  • In Issues of jshint on GitHub there are more people that says the same; that jshint should not throw errors on php code. So I guess the problem is on the jshint linter – alexandre1985 Sep 01 '16 at 15:36
  • @alexandre1985: True: Jshint should either ignore embedded code (like things in a string), or properly parse it using rules appropriate for the embedded language. – Cerberus Sep 01 '16 at 18:03