Closed johannes-z closed 7 years ago
Oh hrmm. Yeah I think that maybe standard --fix
might not have support for html files. Adding html
to the extensions array should attempt to pipe the contents of the view through the formatting command, but will abort the format if the command doesn't return 0.
That's what I suspected. But this also means that it's either the responsibility of standard-format
or sublime-standard-format
to handle html files correctly, right? Are there any plans or should I post this issue on standard-format
.
What would be nice as some sort of work around is a standard format: current selection
. Then I could just select the tags content, format, and be done with it.
Actually the sublime linter works perfectly fine with script
tags. It requires the syntax (.sublime-syntax
) to set the scope:source.js
though. I just updated another syntax and the linter works for the other syntax as well. Maybe I can take a look at it and do a pull request, but my python sucks.
From the SublimeLinter\lint\linter.py
# If a linter can be used with embedded code, you need to tell SublimeLinter
# which portions of the source code contain the embedded code by specifying
# the embedded scope selectors. This attribute maps syntax names
# to embedded scope selectors.
#
# For example, the HTML syntax uses the scope `source.js.embedded.html`
# for embedded JavaScript. To allow a JavaScript linter to lint that embedded
# JavaScript, you would set this attribute to {'html': 'source.js.embedded.html'}.
selectors = {}
This is how the standard linter does it:
syntax = ('javascript', 'html', 'javascriptnext', 'javascript 6to5', 'javascript (babel)', 'vue')
selectors = {
'html': 'source.js.embedded.html',
'vue': 'source.js.embedded.html'
}
The SublimeLinter
provides an interface vor both the syntax and the selectors. StandardFormat
could use similar variables and only pass the scope's content to standard --fix
I never released this! Gah doing that now.
OK it is done!
I'm not sure if this is an issue with
sublime-standard-format
or it's dependencies, but the formatting doesn't work for me in.html
files with ascript
tag. If I extract thescript
tag content to another file, save the file with a.js
extension and then run the formatter, it works as expected. There is no error output when I try to run the formatter on a.html
file.I even explicitly added
.html
extensions as such:"extensions": ["js", "html"]
. Is there another option for html script tags?