Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: replace yamllint with prettier #305

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trim_trailing_whitespace = true
[.editorconfig]
max_line_length = off

[Makefile]
[{Makefile,*.mk}]
indent_style = tab

[{*.py,*.pyi}]
Expand Down
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
- [ ] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [ ] Have you successfully run `tox`?

-----
---
2 changes: 1 addition & 1 deletion .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories:
- title: "Tooling"
label:
- "tooling"
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-template: "- $TITLE @$AUTHOR (#$NUMBER)"
template: |
Special thanks to the contributors that made this release happen: $CONTRIBUTORS
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-renovate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
inputs:
enable_ssh_access:
type: boolean
description: 'Enable ssh access'
description: "Enable ssh access"
required: false
default: false

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
- hotfix/*
- work/check-policy # For development
- work/check-policy # For development

jobs:
policy:
Expand Down
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ repos:
- id: fix-byte-order-marker
- id: mixed-line-ending
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.3"
rev: "v0.8.4"
hooks:
# Run the linter
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
# Run the formatter
- id: ruff-format
- repo: https://github.com/adrienverge/yamllint.git
rev: "v1.35.1"
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "" # Intentionally blank, despite the warning.
hooks:
- id: yamllint
- id: prettier
additional_dependencies:
- prettier@3.4.2
12 changes: 0 additions & 12 deletions .yamllint.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ PROJECT=starcraft
include common.mk

.PHONY: format
format: format-ruff format-codespell ## Run all automatic formatters
format: format-ruff format-codespell format-prettier ## Run all automatic formatters

.PHONY: lint
lint: lint-ruff lint-codespell lint-mypy lint-pyright lint-shellcheck lint-yaml lint-docs lint-twine ## Run all linters
lint: lint-ruff lint-codespell lint-mypy lint-prettier lint-pyright lint-shellcheck lint-docs lint-twine ## Run all linters

.PHONY: pack
pack: pack-pip ## Build all packages
Expand Down
28 changes: 23 additions & 5 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ ifneq ($(OS),Windows_NT)
OS := $(shell uname)
endif
ifdef CI
APT := apt-get --yes
APT := apt-get --yes
else
APT := apt-get
endif

PRETTIER=npm exec --package=prettier -- prettier
PRETTIER_FILES=**.yaml **.yml **.json **.json5 **.css **.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a bit sad that prettier does not support reStructuredText (nor any of the community plugins). That would be great to have one because we tend to mess our .rst files (currently the README.rst looks wrong on GitHub).
Did you look into it? (I took a very quick look and did not find anything serious)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did for unrelated reasons. There's no prettier plugin for it, but docstrfmt looks promising. For the particular use case of our README though, it gives:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've raised this as a question for the new year: #308

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the README, it's possible that we'll be enforcing GFM formatting on them in the near future, so that particular concern is probably not worth stressing about.


.DEFAULT_GOAL := help

.ONESHELL:
Expand Down Expand Up @@ -82,6 +85,10 @@ format-ruff: install-ruff ##- Automatically format with ruff
format-codespell: ##- Fix spelling issues with codespell
uv run codespell --toml pyproject.toml --write-changes $(SOURCES)

.PHONY: format-prettier
format-prettier: install-npm ##- Format files with prettier
$(PRETTIER) --write $(PRETTIER_FILES)

.PHONY: lint-ruff
lint-ruff: install-ruff ##- Lint with ruff
ifneq ($(CI),)
Expand Down Expand Up @@ -137,12 +144,12 @@ ifneq ($(CI),)
@echo ::endgroup::
endif

.PHONY: lint-yaml
lint-yaml: ##- Lint YAML files with yamllint
.PHONY: lint-prettier
lint-prettier: install-npm ##- Lint files with prettier
ifneq ($(CI),)
@echo ::group::$@
endif
uv run --extra lint yamllint .
$(PRETTIER) --check $(PRETTIER_FILES)
ifneq ($(CI),)
@echo ::endgroup::
endif
Expand Down Expand Up @@ -238,7 +245,7 @@ ifneq ($(shell which pyright),)
else ifneq ($(shell which snap),)
sudo snap install --classic pyright
else
# Workaround for a bug in npm
# Workaround for a bug in npm
[ -d "$(HOME)/.npm/_cacache" ] && chown -R `id -u`:`id -g` "$(HOME)/.npm" || true
uv tool install pyright
endif
Expand All @@ -263,3 +270,14 @@ else ifneq ($(shell which brew),)
else
$(warning Shellcheck not installed. Please install it yourself.)
endif

.PHONY: install-npm
install-npm:
ifneq ($(shell which npm),)
else ifneq ($(shell which snap),)
sudo snap install --classic node
else ifneq ($(shell which brew),)
brew install node
else
lengau marked this conversation as resolved.
Show resolved Hide resolved
$(error npm not installed. Please install it yourself.)
endif
4 changes: 2 additions & 2 deletions docs/_static/css/custom.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('https://fonts.googleapis.com/css2?family=Ubuntu:ital@0;1&display=swap');
@import url("https://fonts.googleapis.com/css2?family=Ubuntu:ital@0;1&display=swap");

body {
font-family: Ubuntu, "times new roman", times, roman, serif;
Expand All @@ -8,7 +8,7 @@ div .toctree-wrapper {
column-count: 2;
}

div .toctree-wrapper>ul {
div .toctree-wrapper > ul {
margin: 0;
}

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ dev-dependencies = [
"pytest~=8.0",
"pytest-cov~=6.0",
"pytest-mock~=3.12",
"yamllint~=1.34",
"mypy[reports]~=1.13.0",
"pyright==1.1.390",
"types-Pygments",
Expand Down
5 changes: 2 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
env_list = # Environments to run when called with no parameters.
format-{ruff,codespell}
pre-commit
lint-{ruff,mypy,pyright,shellcheck,codespell,docs,yaml}
lint-{ruff,mypy,pyright,shellcheck,codespell,docs}
unit-py3.{10,12}
integration-py3.10
# Integration tests probably take a while, so we're only running them on Python
Expand Down Expand Up @@ -71,7 +71,7 @@ allowlist_externals =
find = git ls-files
filter = file --mime-type -Nnf- | grep shellscript | cut -f1 -d:

[testenv:lint-{ruff,shellcheck,codespell,yaml}]
[testenv:lint-{ruff,shellcheck,codespell}]
description = Lint the source code
base = testenv, lint
labels = lint
Expand All @@ -82,7 +82,6 @@ commands =
ruff: ruff check {posargs:.}
shellcheck: xargs -ra {env_tmp_dir}/shellcheck_files shellcheck
codespell: codespell --toml {tox_root}/pyproject.toml {posargs}
yaml: yamllint {posargs} .

[testenv:lint-{mypy,pyright}]
description = Static type checking
Expand Down
21 changes: 15 additions & 6 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading