Skip to content

Commit

Permalink
ci: fold style (CSS) linting support into utils/lint.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-pierre committed Jul 23, 2024
1 parent e004158 commit 50e67d7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 22 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,32 @@ concurrency:
cancel-in-progress: true

jobs:

linux:

name: Static linting
runs-on: ubuntu-24.04
env:
CLICOLOR_FORCE: "1"

steps:

- name: Checkout
uses: actions/checkout@v4
with:
clean: false
show-progress: false

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'latest'
# No cache, there are complaints about lockfiles that we don't want otherwise. See <https://github.com/actions/setup-node/issues/928>.
# cache: 'npm'

- name: Install prerequisites
run: |
set -ex
packages=(
clang-tidy
cppcheck
Expand All @@ -33,26 +50,9 @@ jobs:
# We need a more recent version of libunibreak for `lb_get_char_class` support.
wget http://ftp.debian.org/debian/pool/main/libu/libunibreak/libunibreak{6,-dev}_6.1-2_amd64.deb
sudo dpkg -i *.deb
- name: Checkout
uses: actions/checkout@v4
with:
clean: false
show-progress: false
# Install stylelint.
npm init --yes
npm install stylelint stylelint-config-standard
- name: Lint
run: ./utils/lint.sh 2>&1

# NPM tests

- name: Uses Node.js
uses: actions/setup-node@v4
with:
node-version: 'latest'
# No cache, there are complaints about lockfiles that we don't want otherwise. See <https://github.com/actions/setup-node/issues/928>.
# cache: 'npm'

- run: npm init --yes && npm install stylelint stylelint-config-standard

- name: Check CSS syntax (only epub.css, html5.css and fb2.css)
run: npx stylelint cr3gui/data/epub.css cr3gui/data/html5.css cr3gui/data/fb2.css
34 changes: 32 additions & 2 deletions utils/lint.mk
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ endef

# }}}

# CSS files. {{{

define CSS_FILES
cr3gui/data/epub.css
cr3gui/data/html5.css
cr3gui/data/fb2.css
endef

# }}}

# Hyphenation patterns. {{{

HYPH_DIR := cr3gui/data/hyph
Expand Down Expand Up @@ -281,6 +291,19 @@ endef

# }}}

# Stylelint. {{{

define STYLELINT_FLAGS
$(if $(CLICOLOR_FORCE),--color)
--formatter=$(if $(GITHUB_ACTIONS),github,unix)
endef

define stylelint_rule
$(call lint_rule,stylelint,$1,$(ci_time) npx stylelint $(strip $(STYLELINT_FLAGS) $1))
endef

# }}}

# XmlLint. {{{

define xmllint_rule
Expand All @@ -290,17 +313,20 @@ endef
# }}}

CPPFILES := $(filter %.c %.cpp,$(sort $(CPPFILES) $(filter-out cppcheck-% clang-tidy-%,$(MAKECMDGOALS))))
CSS_FILES := $(filter %.css, $(sort $(CSS_FILES) $(filter-out stylelint-%,$(MAKECMDGOALS))))
HYPH_PATTERNS := $(filter %.pattern,$(sort $(HYPH_PATTERNS) $(filter-out xmllint-%,$(MAKECMDGOALS))))

lint: $(CPPFILES) $(HYPH_LANGUAGES) $(HYPH_PATTERNS)
lint: $(CPPFILES) $(CSS_FILES) $(HYPH_LANGUAGES) $(HYPH_PATTERNS)

cpp: $(CPPFILES)

hyph: $(HYPH_LANGUAGES) $(HYPH_PATTERNS)

style: $(CSS_FILES)

# Avoid "Nothing to be done for '…'"
# or "'…' is up to date messages".
$(CPPFILES) $(HYPH_PATTERNS):
$(CPPFILES) $(CSS_FILES) $(HYPH_PATTERNS):
@:

.PHONY: $(HYPH_LANGUAGES)
Expand All @@ -310,6 +336,10 @@ $(foreach f,$(CPPFILES),\
$(eval $(call cppcheck_rule,$f))\
)

$(foreach f,$(CSS_FILES),\
$(eval $(call stylelint_rule,$f))\
)

$(eval $(call lint_rule,check,$(HYPH_LANGUAGES),$(check_languages.json)))

$(foreach f,$(HYPH_PATTERNS),\
Expand Down

0 comments on commit 50e67d7

Please sign in to comment.