SublimeLinter / SublimeLinter-xmllint

SublimeLinter 3 plugin for XML, using xmllint.
MIT License
29 stars 6 forks source link

XML linter with schema validation #4

Closed jtojnar closed 6 years ago

jtojnar commented 10 years ago

I wanted SublimeLinter to automatically validate XML against XSD, but this AFAIK isn’t possible so I made a wrapper for xmllint utility to find XSD file in source code and pass it as argument to xmllint. Because XSD paths can be relative I had to change linter to pass path instead of content so I could detect XSD file path.

Currently the wrapper is quite stupid but it can be changed when I come across something that doesn’t work.

Based on SublimeLinter/SublimeLinter-xmllint@3e855400a5f47c8b4989cc06081a3781af443a79 Tested with xmllint: using libxml version 20901 and Python 2.7.6

https://gist.github.com/jtojnar/5851893

This feature should be probably implemented into libxml but I am posting it here as it is faster solution than filing a patch.

dmaglio commented 9 years ago

how to test this fork?

jtojnar commented 9 years ago

Just replace respective files in your plugin directory. Should be still compatible.

dmaglio commented 9 years ago

the first file, "liinter.py" it's an error or it's correct?

jtojnar commented 9 years ago

Yes, sorry. Updated the gist with instructions and python 3 compatibility. It doesn’t display some errors though, not sure why (they are displayed in console when lint debug is enabled). I usually use this tool around July so I currently lack will to further debug it.

dmaglio commented 9 years ago
SublimeLinter: xmllint output:
  File "/usr/bin/xmllintschema", line 25
    print('-:' + str(schemaline) + ': Schema file does not exist', file=sys.stderr)
                                                                       ^
SyntaxError: invalid syntax 
jtojnar commented 9 years ago

Do you use python 3 (Sublime 3)?

dmaglio commented 9 years ago

yes

Il giorno mar 31 mar 2015 alle 10:05, Jan Tojnar notifications@github.com ha scritto:

Do you use python 3 (Sublime 3)?

— Reply to this email directly or view it on GitHub.

jtojnar commented 9 years ago

This error is thrown by python 2. You can try the previous revision.

dmaglio commented 9 years ago

Nothing....

SublimeLinter: xmllint output:
Traceback (most recent call last):
  File "/usr/bin/xmllintschema", line 11, in <module>
    with open(sys.argv[-1], 'r') as f:
IOError: [Errno 2] No such file or directory: '-'

Il giorno mar 31 mar 2015 alle 11:27, Jan Tojnar notifications@github.com ha scritto:

This error is thrown by python 2. You can try the previous revision.

— Reply to this email directly or view it on GitHub.

jtojnar commented 9 years ago

Have you also changed linter.py accordingly?

dmaglio commented 9 years ago

Yes, now work without error but don't show error in sublime... if i try to use xmllintschema into console work correctly

Il giorno mar 31 mar 2015 alle 11:33, Jan Tojnar notifications@github.com ha scritto:

Have you also changed linter.py accordingly?

— Reply to this email directly or view it on GitHub.

jtojnar commented 9 years ago

Do you use 'Save Only' linter mode? The problem with this linter is that file path is passed to xmllint (it is needed to figure out the path to schema file) and it has no way to see unsaved changes :( Only way to fix this is integrating xmlllintschema to linter.py.

dmaglio commented 9 years ago

my lint mode is background. this is my preferences:

{
    "user": {
        "debug": true,
        "delay": 0.25,
        "error_color": "D02000",
        "gutter_theme": 
"Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
        "gutter_theme_excludes": [],
        "lint_mode": "background",
        "linters": {
            "htmltidy": {
                "@disable": false,
                "args": [],
                "excludes": []
            },
            "php": {
                "@disable": false,
                "args": [],
                "excludes": []
            },
            "xmllint": {
                "@disable": false,
                "args": [],
                "excludes": []
            }
        },
        "mark_style": "outline",
        "no_column_highlights_line": false,
        "passive_warnings": false,
        "paths": {
            "linux": [],
            "osx": [],
            "windows": []
        },
        "python_paths": {
            "linux": [],
            "osx": [],
            "windows": []
        },
        "rc_search_limit": 3,
        "shell_timeout": 10,
        "show_errors_on_save": false,
        "show_marks_in_minimap": true,
        "syntax_map": {
            "html": "html",
            "html (django)": "html",
            "html (rails)": "html",
            "html 5": "html",
            "php": "html",
            "python django": "python",
            "xml": "xml"
        },
        "warning_color": "DDB700",
        "wrap_find": true
    }
}

Il giorno mar 31 mar 2015 alle 11:44, Jan Tojnar notifications@github.com ha scritto:

Do you use 'Save Only' linter mode? The problem with this linter is that file path is passed to xmllint (it is needed to figure out the path to schema file) and it has no way to see unsaved changes :( Only way to fix this is integrating xmlllintschema to linter.py.

— Reply to this email directly or view it on GitHub.

jtojnar commented 9 years ago

OK, created fork with xmllintschema incorporated in the plugin. Just replace linter.py

dmaglio commented 9 years ago

Perfect, work correctly :)

Il giorno mar 31 mar 2015 alle 14:52, Jan Tojnar notifications@github.com ha scritto:

OK, created fork with xmllintschema incorporated in the plugin. Just replace linter.py

— Reply to this email directly or view it on GitHub.

Pendrokar commented 9 years ago

@jtojnar your fork works great, except the errors that are found when validating against the XSD schema pop up only in SublimeLinter's "Show all errors" not when having the cursor over the line that has the error.

It seems it is because the formatting of such errors is a bit different from simple XML validation. SublimeLinter is only able to get the line. My regex is rusty, will survive with just "Show all errors".

jtojnar commented 9 years ago

For me it displays the error even when cursor is on the line. schema error Though I discovered different bug: when there is an error in schema, the error is displayed on the same line in the validated file.

Pendrokar commented 9 years ago

Forgot to note, I'm on Windows. Perhaps that is the reason why it is happening to me.

jtojnar commented 9 years ago

Weird. What do you see in the console when you enable debug in SublimeLinter config?

Pendrokar commented 9 years ago

Ah I see, it is because there are two errors on a single line, any other one line error shows correctly: -:16: element PersonalityTraits: Schemas validity error : Element 'PersonalityTraits': [facet 'enumeration'] The value 'Aggressives' is not an element of the set {'... -:16: element PersonalityTraits: Schemas validity error : Element 'PersonalityTraits': 'Aggressives' is not a valid value of the atomic type 'PersonalityTypes'.

jeffery9 commented 8 years ago

when i set args for xmllint, sublime report

SublimeLinter: xmllint: account_assert_test.xml ['c:\cygwin\bin\xmllint.exe', '--noout', '--relaxng e:\odoo.rng', '-'] SublimeLinter: xmllint output: Unknown option --relaxng e:\odoo.rng

but when i run it out of sublime, it worked,

C:\Users\w541>xmllint --noout --relaxng e:\odoo.rng e:\odoo\addons\account\account_assert_test.xml e:\odoo\addons\account\account_assert_test.xml validates

jtojnar commented 8 years ago

@jeffery9 Try using '--relaxng', 'e:\odoo.rng' otherwise it might be enclosed in quotation marks and considered one option.

jeffery9 commented 8 years ago

@jtojnar thanks, it worked.

braver commented 6 years ago

Sorry for letting this sit here so long. I don't think we'll be incorporating this into the plugin, but feel free to publish the fork.