From 2f5b2d5590331fbeff2c910a5ce0f8643443762a Mon Sep 17 00:00:00 2001 From: "Wei-Hsiang (Matt) Wang" Date: Tue, 3 Sep 2024 01:12:55 +0800 Subject: [PATCH 1/2] Add checker for searching unnecessary parentheses in func & meth role (#115) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- sphinxlint/checkers.py | 12 ++++++++++++ sphinxlint/rst.py | 2 ++ 2 files changed, 14 insertions(+) diff --git a/sphinxlint/checkers.py b/sphinxlint/checkers.py index ab54a3ec5..bd4caf8de 100644 --- a/sphinxlint/checkers.py +++ b/sphinxlint/checkers.py @@ -513,3 +513,15 @@ def check_dangling_hyphen(file, lines, options): stripped_line = line.rstrip("\n") if _has_dangling_hyphen(stripped_line): yield lno + 1, "Line ends with dangling hyphen" + + +@checker(".rst", ".po", rst_only=False, enabled=True) +def check_unnecessary_parentheses(filename, lines, options): + """Check for unnecessary parentheses in :func: and :meth: roles. + + Bad: :func:`test()` + Good: :func:`test` + """ + for lno, line in enumerate(lines, start=1): + if match := rst.ROLE_WITH_UNNECESSARY_PARENTHESES_RE.search(line): + yield lno, f"Unnecessary parentheses in {match.group(0).strip()!r}" diff --git a/sphinxlint/rst.py b/sphinxlint/rst.py index 445689813..2b35a9b04 100644 --- a/sphinxlint/rst.py +++ b/sphinxlint/rst.py @@ -280,3 +280,5 @@ def inline_markup_gen(start_string, end_string, extra_allowed_before=""): ) ROLE_MISSING_CLOSING_BACKTICK_RE = re.compile(rf"({ROLE_HEAD}`[^`]+?)[^`]*$") + +ROLE_WITH_UNNECESSARY_PARENTHESES_RE = re.compile(r"(^|\s):(func|meth):`[^`]+\(\)`") From 82e6aec6bf52286db8b64dbf1f68b10b574dc278 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 2 Sep 2024 20:13:24 +0300 Subject: [PATCH 2/2] CI: Move friend projects to own job (#116) --- .github/workflows/deploy.yml | 6 +++--- .github/workflows/lint.yml | 4 ++-- .github/workflows/tests.yml | 9 ++++++--- .pre-commit-config.yaml | 16 +++++++++++++--- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ad847062b..4e86bd358 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,7 +23,7 @@ jobs: with: fetch-depth: 0 - - uses: hynek/build-and-inspect-python-package@v1 + - uses: hynek/build-and-inspect-python-package@v2 # Upload to Test PyPI on every commit on main. release-test-pypi: @@ -40,7 +40,7 @@ jobs: steps: - name: Download packages built by build-and-inspect-python-package - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Packages path: dist @@ -64,7 +64,7 @@ jobs: steps: - name: Download packages built by build-and-inspect-python-package - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Packages path: dist diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index bce5546c8..c274dd071 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: "3.x" - - uses: pre-commit/action@v3.0.0 + - uses: pre-commit/action@v3.0.1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 651f48ae7..71777ee67 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,6 +21,9 @@ jobs: # friend projects below to the latest one python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] os: [ubuntu-latest, macos-latest, windows-latest] + test-set: [base] + include: + - {python-version: "3.13", os: ubuntu-latest, test-set: friend-projects} exclude: # TODO Add Windows when regex wheel available for 3.13 - {os: windows-latest, python-version: "3.13"} @@ -29,7 +32,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} allow-prereleases: true @@ -42,14 +45,14 @@ jobs: pip install -U tox - name: Download more tests from friend projects - if: matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest' + if: matrix.test-set == 'friend-projects' run: sh download-more-tests.sh - name: Tox tests run: | tox -e py - name: Upload coverage - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: flags: ${{ matrix.os }} name: ${{ matrix.os }} Python ${{ matrix.python-version }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d15f4537..dcc51172a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,13 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.2 + rev: v0.6.2 hooks: - id: ruff args: ["--exit-non-zero-on-fix"] - id: ruff-format - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: check-case-conflict - id: check-merge-conflict @@ -19,6 +19,16 @@ repos: - id: trailing-whitespace exclude: tests/fixtures/xfail/trailing-whitespaces.rst + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.29.2 + hooks: + - id: check-github-workflows + + - repo: https://github.com/rhysd/actionlint + rev: v1.7.1 + hooks: + - id: actionlint + - repo: https://github.com/tox-dev/pyproject-fmt rev: 1.7.0 hooks: @@ -26,7 +36,7 @@ repos: additional_dependencies: [tox] - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.16 + rev: v0.19 hooks: - id: validate-pyproject