Skip to content

Commit

Permalink
Sort schema enums (#3595)
Browse files Browse the repository at this point in the history
* Sort enums in json schema

* Black

* Sort schema keys with same indenting as .editorconfig

* Fix typo

* Build schemas

* Generate html schema docs

* Update changelog

* Regenerate licenses

* Adapt launch.json to debug build.py

* Update docs

* Changes after regenerating test classes
  • Loading branch information
echoix authored May 31, 2024
1 parent 28d17bd commit f4dbe62
Show file tree
Hide file tree
Showing 13 changed files with 115,402 additions and 64,275 deletions.
25 changes: 19 additions & 6 deletions .automation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ def generate_flavor_documentation(flavor_id, flavor, linters_tables_md):
def dump_as_json(value: Any, empty_value: str) -> str:
if not value:
return empty_value
# Covert any value to string with JSON
# Convert any value to string with JSON
# Don't indent since markdown table supports single line only
result = json.dumps(value, indent=None, sort_keys=True)
return f"`{result}`"
Expand Down Expand Up @@ -2350,7 +2350,7 @@ def add_in_config_schema_file(variables):
json_schema["properties"] = json_schema_props
if updated is True:
with open(CONFIG_JSON_SCHEMA, "w", encoding="utf-8") as outfile:
json.dump(json_schema, outfile, indent=4, sort_keys=True)
json.dump(json_schema, outfile, indent=2, sort_keys=True)
outfile.write("\n")


Expand All @@ -2367,7 +2367,7 @@ def remove_in_config_schema_file(variables):
json_schema["properties"] = json_schema_props
if updated is True:
with open(CONFIG_JSON_SCHEMA, "w", encoding="utf-8") as outfile:
json.dump(json_schema, outfile, indent=4, sort_keys=True)
json.dump(json_schema, outfile, indent=2, sort_keys=True)
outfile.write("\n")


Expand Down Expand Up @@ -2707,7 +2707,7 @@ def generate_json_schema_enums():
with open(DESCRIPTOR_JSON_SCHEMA, "r", encoding="utf-8") as json_file:
json_schema = json.load(json_file)
json_schema["definitions"]["enum_flavors"]["enum"] = ["all_flavors"] + list(
flavors.keys()
sorted(set(list(flavors.keys())))
)
with open(DESCRIPTOR_JSON_SCHEMA, "w", encoding="utf-8") as outfile:
json.dump(json_schema, outfile, indent=2, sort_keys=True)
Expand All @@ -2724,6 +2724,14 @@ def generate_json_schema_enums():
json_schema["definitions"]["enum_linter_keys"]["enum"] = [x.name for x in linters]
# Deprecated linters
json_schema["definitions"]["enum_linter_keys"]["enum"] += DEPRECATED_LINTERS

# Sort:
json_schema["definitions"]["enum_descriptor_keys"]["enum"] = sorted(
set(json_schema["definitions"]["enum_descriptor_keys"]["enum"])
)
json_schema["definitions"]["enum_linter_keys"]["enum"] = sorted(
set(json_schema["definitions"]["enum_linter_keys"]["enum"])
)
with open(CONFIG_JSON_SCHEMA, "w", encoding="utf-8") as outfile:
json.dump(json_schema, outfile, indent=2, sort_keys=True)
outfile.write("\n")
Expand Down Expand Up @@ -3352,17 +3360,22 @@ def update_workflow_linters(file_path, linters):


if __name__ == "__main__":
logging_format = (
"[%(levelname)s] %(message)s"
if "CI" in os.environ
else "%(asctime)s [%(levelname)s] %(message)s"
)
try:
logging.basicConfig(
force=True,
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
format=logging_format,
handlers=[logging.StreamHandler(sys.stdout)],
)
except ValueError:
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
format=logging_format,
handlers=[logging.StreamHandler(sys.stdout)],
)
config.init_config("build")
Expand Down
2 changes: 1 addition & 1 deletion .automation/generated/linter-licenses.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"markdownlint": "MIT",
"misspell": "MIT",
"mypy": "Other",
"npm-groovy-lint": "GPL-3.0",
"npm-groovy-lint": "MIT",
"npm-package-json-lint": "MIT",
"perlcritic": "Other",
"php": "Other",
Expand Down
17 changes: 14 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@
"type": "node"
},
{
"name": "Python : CurrentFile",
"type": "python",
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python Debugger: Build MegaLinter files",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/.automation/build.py",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceFolder}"
}
}
]
}
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l

- Doc
- Handle disabled_reason property in descriptors
- Sort enums in json schema, by @echoix in <https://github.com/oxsecurity/megalinter/pull/3595>

- Flavors

Expand Down
2 changes: 1 addition & 1 deletion docs/all_linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
| [**markdown-table-formatter**](https://github.com/nvuillam/markdown-table-formatter){target=_blank} | 1.6.0 | [MIT](licenses/markdown-table-formatter.md) | [![GitHub stars](https://img.shields.io/github/stars/nvuillam/markdown-table-formatter?cacheSeconds=3600)](https://github.com/nvuillam/markdown-table-formatter){target=_blank} | [MARKDOWN](descriptors/markdown_markdown_table_formatter.md) | :white_circle: | [Repository](https://github.com/nvuillam/markdown-table-formatter){target=_blank} |
| [**markdownlint**](https://github.com/DavidAnson/markdownlint){target=_blank} | 0.41.0 | [MIT](licenses/markdownlint.md) | [![GitHub stars](https://img.shields.io/github/stars/DavidAnson/markdownlint?cacheSeconds=3600)](https://github.com/DavidAnson/markdownlint){target=_blank} | [MARKDOWN](descriptors/markdown_markdownlint.md) | :white_circle: | [Repository](https://github.com/DavidAnson/markdownlint){target=_blank} |
| [**mypy**](https://github.com/python/mypy){target=_blank} | 1.10.0 | [MIT](licenses/mypy.md) | [![GitHub stars](https://img.shields.io/github/stars/python/mypy?cacheSeconds=3600)](https://github.com/python/mypy){target=_blank} | [PYTHON](descriptors/python_mypy.md) | <!-- --> | [Repository](https://github.com/python/mypy){target=_blank} |
| [**npm-groovy-lint**](https://github.com/nvuillam/npm-groovy-lint){target=_blank} | 14.6.0 | [GPL-3.0](licenses/npm-groovy-lint.md) | [![GitHub stars](https://img.shields.io/github/stars/nvuillam/npm-groovy-lint?cacheSeconds=3600)](https://github.com/nvuillam/npm-groovy-lint){target=_blank} | [GROOVY](descriptors/groovy_npm_groovy_lint.md) | :heart: | [MegaLinter reference](https://nvuillam.github.io/npm-groovy-lint/#mega-linter){target=_blank} |
| [**npm-groovy-lint**](https://github.com/nvuillam/npm-groovy-lint){target=_blank} | 14.6.0 | [MIT](licenses/npm-groovy-lint.md) | [![GitHub stars](https://img.shields.io/github/stars/nvuillam/npm-groovy-lint?cacheSeconds=3600)](https://github.com/nvuillam/npm-groovy-lint){target=_blank} | [GROOVY](descriptors/groovy_npm_groovy_lint.md) | :heart: | [MegaLinter reference](https://nvuillam.github.io/npm-groovy-lint/#mega-linter){target=_blank} |
| [**npm-package-json-lint**](https://github.com/tclindner/npm-package-json-lint){target=_blank} | 7.1.0 | [MIT](licenses/npm-package-json-lint.md) | [![GitHub stars](https://img.shields.io/github/stars/tclindner/npm-package-json-lint?cacheSeconds=3600)](https://github.com/tclindner/npm-package-json-lint){target=_blank} | [JSON](descriptors/json_npm_package_json_lint.md) | :heart: | [MegaLinter reference](https://npmpackagejsonlint.org/docs/integrations#megalinter){target=_blank} |
| [**perlcritic**](https://github.com/Perl-Critic/Perl-Critic){target=_blank} | 1.152 | [Other](licenses/perlcritic.md) | [![GitHub stars](https://img.shields.io/github/stars/Perl-Critic/Perl-Critic?cacheSeconds=3600)](https://github.com/Perl-Critic/Perl-Critic){target=_blank} | [PERL](descriptors/perl_perlcritic.md) | :white_circle: | [Repository](https://github.com/Perl-Critic/Perl-Critic){target=_blank} |
| [**phpcs**](https://github.com/PHPCSStandards/PHP_CodeSniffer){target=_blank} | 3.10.1 | [BSD-3-Clause](licenses/phpcs.md) | [![GitHub stars](https://img.shields.io/github/stars/PHPCSStandards/PHP_CodeSniffer?cacheSeconds=3600)](https://github.com/PHPCSStandards/PHP_CodeSniffer){target=_blank} | [PHP](descriptors/php_phpcs.md) | :white_circle: | [Repository](https://github.com/PHPCSStandards/PHP_CodeSniffer){target=_blank} |
Expand Down
Loading

0 comments on commit f4dbe62

Please sign in to comment.