-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow formatting xml files when cli_lint_mode is file
- Loading branch information
Showing
6 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<note> | ||
<to>Tove</to> | ||
<from>Jani<from> | ||
<heading>Reminder</heading> | ||
<body>Don't forget me this weekend!</body> | ||
<note> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<note> | ||
<to>Tove</to> | ||
<from>Jani</from> | ||
<heading>Reminder</heading> | ||
<body>Don't forget me this weekend!</body> | ||
</note> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Use XmlLint to lint xml files | ||
http://xmlsoft.org/xmllint.html | ||
""" | ||
import os | ||
|
||
from megalinter import Linter, config | ||
|
||
|
||
class XmlLintLinter(Linter): | ||
# Build the CLI command to call to lint a file | ||
def build_lint_command(self, file=None): | ||
cmd = super().build_lint_command(file) | ||
|
||
if ( | ||
self.apply_fixes is True | ||
and self.cli_lint_fix_arg_name is not None | ||
and config.get("XML_XMLLINT_AUTOFORMAT", "false") == "true" | ||
): | ||
if self.cli_lint_mode == "file": | ||
os.environ["XMLLINT_INDENT"] = config.get("XML_XMLLINT_INDENT", " ") | ||
|
||
cmd += f" {self.cli_lint_fix_arg_name} --output {file}" | ||
else: | ||
raise KeyError( | ||
f"You can not apply_fixes with cli_lint_mode {self.cli_lint_mode}" | ||
) | ||
return cmd |