diff options
Diffstat (limited to '.github')
-rwxr-xr-x | .github/generate.py | 134 | ||||
-rwxr-xr-x | .github/main.py | 31 | ||||
m--------- | .github/nvim_doc_tools | 0 | ||||
-rwxr-xr-x | .github/pre-commit | 4 | ||||
-rwxr-xr-x | .github/pre-push | 7 |
5 files changed, 1 insertions, 175 deletions
diff --git a/.github/generate.py b/.github/generate.py deleted file mode 100755 index f317534..0000000 --- a/.github/generate.py +++ /dev/null @@ -1,134 +0,0 @@ -import os -import os.path -import re -from dataclasses import dataclass -from functools import lru_cache -from typing import Dict, List - -from nvim_doc_tools import (Vimdoc, VimdocSection, generate_md_toc, indent, - parse_functions, read_nvim_json, render_md_api, - render_vimdoc_api, replace_section, wrap) - -HERE = os.path.dirname(__file__) -ROOT = os.path.abspath(os.path.join(HERE, os.path.pardir)) -README = os.path.join(ROOT, "README.md") -DOC = os.path.join(ROOT, "doc") -VIMDOC = os.path.join(DOC, "conform.txt") -OPTIONS = os.path.join(ROOT, "tests", "options_doc.lua") - - -@dataclass -class Formatter: - name: str - description: str - url: str - - -@lru_cache -def get_all_formatters() -> List[Formatter]: - names = sorted( - [ - os.path.splitext(file)[0] - for file in os.listdir(os.path.join(ROOT, "lua", "conform", "formatters")) - ] - ) - formatters = [] - for name in names: - meta = read_nvim_json(f'require("conform.formatters.{name}").meta') - formatters.append(Formatter(name, **meta)) - return formatters - - -def update_formatter_list(): - formatter_lines = ["\n"] - for formatter in get_all_formatters(): - formatter_lines.append( - f"- [{formatter.name}]({formatter.url}) - {formatter.description}\n" - ) - replace_section( - README, - r"^<!-- FORMATTERS -->$", - r"^<!-- /FORMATTERS -->$", - formatter_lines, - ) - - -def update_options(): - option_lines = ["\n", "```lua\n"] - with open(OPTIONS, "r", encoding="utf-8") as f: - option_lines.extend(f.readlines()) - option_lines.extend(["```\n", "\n"]) - replace_section( - README, - r"^<!-- OPTIONS -->$", - r"^<!-- /OPTIONS -->$", - option_lines, - ) - - -def add_md_link_path(path: str, lines: List[str]) -> List[str]: - ret = [] - for line in lines: - ret.append(re.sub(r"(\(#)", "(" + path + "#", line)) - return ret - - -def update_md_api(): - funcs = parse_functions(os.path.join(ROOT, "lua", "conform", "init.lua")) - lines = ["\n"] + render_md_api(funcs, 3)[:-1] # trim last newline - replace_section( - README, - r"^<!-- API -->$", - r"^<!-- /API -->$", - lines, - ) - - -def update_readme_toc(): - toc = ["\n"] + generate_md_toc(README) + ["\n"] - replace_section( - README, - r"^<!-- TOC -->$", - r"^<!-- /TOC -->$", - toc, - ) - - -def gen_options_vimdoc() -> VimdocSection: - section = VimdocSection("Options", "conform-options", ["\n", ">lua\n"]) - with open(OPTIONS, "r", encoding="utf-8") as f: - section.body.extend(indent(f.readlines(), 4)) - section.body.append("<\n") - return section - - -def gen_formatter_vimdoc() -> VimdocSection: - section = VimdocSection("Formatters", "conform-formatters", ["\n"]) - for formatter in get_all_formatters(): - line = f"`{formatter.name}` - {formatter.description}\n" - section.body.extend(wrap(line, sub_indent=len(formatter.name) + 3)) - return section - - -def generate_vimdoc(): - doc = Vimdoc("conform.txt", "conform") - funcs = parse_functions(os.path.join(ROOT, "lua", "conform", "init.lua")) - doc.sections.extend( - [ - gen_options_vimdoc(), - VimdocSection("API", "conform-api", render_vimdoc_api("conform", funcs)), - gen_formatter_vimdoc(), - ] - ) - - with open(VIMDOC, "w", encoding="utf-8") as ofile: - ofile.writelines(doc.render()) - - -def main() -> None: - """Update the README""" - update_formatter_list() - update_options() - update_md_api() - update_readme_toc() - generate_vimdoc() diff --git a/.github/main.py b/.github/main.py deleted file mode 100755 index 4dffddf..0000000 --- a/.github/main.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import sys - -HERE = os.path.dirname(__file__) -ROOT = os.path.abspath(os.path.join(HERE, os.path.pardir)) -DOC = os.path.join(ROOT, "doc") - - -def main() -> None: - """Generate docs""" - sys.path.append(HERE) - parser = argparse.ArgumentParser(description=main.__doc__) - parser.add_argument("command", choices=["generate", "lint"]) - args = parser.parse_args() - if args.command == "generate": - import generate - - generate.main() - elif args.command == "lint": - from nvim_doc_tools import lint_md_links - - files = [os.path.join(ROOT, "README.md")] + [ - os.path.join(DOC, file) for file in os.listdir(DOC) if file.endswith(".md") - ] - lint_md_links.main(ROOT, files) - - -if __name__ == "__main__": - main() diff --git a/.github/nvim_doc_tools b/.github/nvim_doc_tools deleted file mode 160000 -Subproject 3432f0308c96ad95b7337c68b5f143c6b991630 diff --git a/.github/pre-commit b/.github/pre-commit index 49ee249..240abeb 100755 --- a/.github/pre-commit +++ b/.github/pre-commit @@ -1,5 +1,3 @@ #!/bin/bash set -e -luacheck lua tests - -stylua --check . +make lint diff --git a/.github/pre-push b/.github/pre-push deleted file mode 100755 index d117589..0000000 --- a/.github/pre-push +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -e -luacheck lua tests - -stylua --check . - -lua-typecheck lua |