1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-09-19 20:02:10 +00:00

Streamline lint configuration

- Add lint using local installation of the Nu HTML Validator and some
  jq-based filtering of false positives
- Move linter configs to directory, to de-clutter the repo
This commit is contained in:
Rohan Kumar 2022-05-11 10:01:22 -07:00
parent b5bf54ff45
commit 7a3aee1539
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479
10 changed files with 36 additions and 80 deletions

View file

@ -1,65 +0,0 @@
---
ci:
assert:
preset: lighthouse:recommended
assertions:
performance-budget: "error"
render-blocking-resources:
- warn
# the CSS file.
# My site doesn't use JS so it doesn't use the recommended async hack
- maxLength: 1
timing-budget: "off" # buggy; manually use the below assertions instead
# https://seirdy.one/2020/11/23/website-best-practices.html#about-lazy-loading
speed-index:
- warn
- maxNumericValue: 2000
largest-contentful-paint:
- warn
- maxNumericValue: 2000
first-contentful-paint:
- warn
- maxNumericValue: 2000
first-meaningful-paint:
- warn
- maxNumericValue: 2000
total-blocking-time:
- warn
- maxNumericValue: 0
cumulative-layout-shift:
- warn
- maxNumericValue: 0
canonical: "off" # staging site has no rel=canonical
service-worker: "off" # not a PWA
works-offline: "off" # not a PWA
installable-manifest: "off" # not a PWA
splash-screen: "off" # not a PWA
themed-omnibox: "off" # not a PWA
offline-start-url: "off" # not a pwa
offscreen-images: "off" # antipattern: see my article on best practices for textual websites
collect:
method: node
settings:
budgetPath: budget.json
chromeFlags: "--disable-gpu --no-sandbox --disable-extensions --no-first-run --headless"
skipAudits:
- canonical
- service-worker
- works-offline
- installable-manifest
- splash-screen
- themed-omnibox
- offline-start-url
- offscreen-images
throttling:
cpuSlowdownMultiplier: 1
throttlingMethod: devtools
url:
- https://seirdy.one/
- https://seirdy.one/about.html
- https://seirdy.one/2020/11/23/website-best-practices.html
numberOfRuns: 3
upload:
outputDir: lighthouse-reports
reportFilenamePattern: lighthouse-report-%%PATHNAME%%.%%EXTENSION%%
target: filesystem

View file

@ -1,4 +0,0 @@
public/
public_*/
hint-report/
themes/etch-custom/exampleSite

View file

@ -18,6 +18,8 @@ RSYNCFLAGS += --skip-compress=gz/br/zst/png/webp/jpg/avif/jxl/mp4/mkv/webm/opus/
# compression gets slow for extreme levels like the old "70109"
ECT_LEVEL=9
VNU ?= vnu
.PHONY: hugo
hugo: clean
hugo -b $(HUGO_BASEURL) $(HUGO_FLAGS)
@ -25,10 +27,10 @@ hugo: clean
# .hintrc-local for linting local files
# same as regular .hintrc but with a different connector.
.hintrc-local: .hintrc
jq --tab '.connector .name = "local" | del(.connector .options)' <.hintrc >.hintrc-local
jq --tab '.connector .name = "local" | del(.connector .options)' <linter-configs/hintrc >.hintrc-local
.hintrc-devserver: .hintrc
jq --tab '.extends = ["development"] | .hints["http-compression","https-only","ssllabs","sri"] = "off"' <.hintrc >.hintrc-devserver
jq --tab '.extends = ["development"] | .hints["http-compression","https-only","ssllabs","sri"] = "off"' <linter-configs/hintrc >.hintrc-devserver
.PHONY: clean
clean:
@ -36,8 +38,12 @@ clean:
.PHONY: lint-css
lint-css:
pnpx stylelint --di --rd --rdd $(CSS_DIR)/main.css $(CSS_DIR)/dark.css $(CSS_DIR)/print.css
csslint --quiet $(CSS_DIR)
pnpm -s dlx stylelint --config linter-configs/stylelintrc.json --di --rd --rdd $(CSS_DIR)/main.css $(CSS_DIR)/dark.css $(CSS_DIR)/print.css
@#csslint --quiet $(CSS_DIR)
.PHONY: lint-html
lint-html: hugo
$(VNU) --stdout --format json --skip-non-html --also-check-svg public | jq --from-file linter-configs/vnu_filter.jq
.PHONY: hint
hint: hugo .hintrc-local
@ -45,7 +51,7 @@ hint: hugo .hintrc-local
rm .hintrc-local
.PHONY: lint-local
lint-local: lint-css hint
lint-local: lint-css lint-html
# dev server
.PHONY: serve
@ -79,7 +85,7 @@ endif
mentions.json: hugo
# gather old version of the site
# rsync $(RSYNCFLAGS) --exclude '*.gz' --exclude '*.br' --exclude '*.png' --exclude-from .rsyncignore $(WWW_RSYNC_DEST)/ old
static-webmentions -f mentions.json.unfiltered find
static-webmentions -f mentions.json.unfiltered find
# filter the webmentions a bit; jq offers more flexibility than config.toml
jq '[ .[] | select(.Dest|test("https://(git.sr.ht/~seirdy/seirdy.one/log/master|seirdy.one|web.archive.org|archive.is|en.wikipedia.org|matrix.to|([a-z]*.)?reddit.com|github.com)") | not) ]' <mentions.json.unfiltered >mentions.json
rm mentions.json.unfiltered

View file

@ -6,14 +6,14 @@ SCHEME=https://
URL = $(SCHEME)$(DOMAIN)$(PAGE_PATH)
# latest bleeding-edge chromium snapshot
CHROME_PATH = /home/rkumar/Downloads/chromium/thorium/latest/chrome
CHROME_PROFILE = /tmp/chrome-lighthouse
CHROME_PROFILE ?= /tmp/chrome-lighthouse
JS_FLAGS=''
CHROME_FLAGS += --disable-extensions --no-default-browser-check --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-device-discovery-notifications --disable-domain-reliability --disable-background-timer-throttling --disable-breakpad --enable-blink-features=LayoutInstabilityAPI --no-first-run --disable-component-update --disable-background-networking --user-data-dir=$(CHROME_PROFILE) --enable-quic --origin-to-force-quic-on=seirdy.one:443
CPU_SLOWDOWN=2.9
LIGHTHOUSE_ARGS += --budget-path budget.json --output html --output json --output-file lighthouse-results --throttling.cpuSlowdownMultiplier=$(CPU_SLOWDOWN) --chrome-flags="$(CHROME_FLAGS)"
CHROME_FLAGS += --disable-extensions --no-default-browser-check --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-device-discovery-notifications --disable-domain-reliability --disable-background-timer-throttling --disable-breakpad --enable-blink-features=LayoutInstabilityAPI --no-first-run --disable-component-update --disable-background-networking --user-data-dir=$(CHROME_PROFILE) --enable-quic --origin-to-force-quic-on=$(DOMAIN):443
CPU_SLOWDOWN=2.8
LIGHTHOUSE_ARGS += --budget-path linter-configs/budget.json --output html --output json --output-file lighthouse-results --throttling.cpuSlowdownMultiplier=$(CPU_SLOWDOWN) --chrome-flags="$(CHROME_FLAGS)"
hint-online:
pnpx hint --config .hintrc -f codeframe $(URL)
hint --config linter-configs/hintrc -f codeframe $(URL)
lighthouse:
mkdir -p $(CHROME_PROFILE)
CHROME_PATH=$(CHROME_PATH) CHROME_PROFILE=$(CHROME_PROFILE) JS_FLAGS='' lighthouse $(URL) $(LIGHTHOUSE_ARGS)

View file

@ -0,0 +1,19 @@
# Filter false positives from the .messages entry of Nu Validator output
.messages |= map(
. | select(
.type == "error" and
(
( # See https://github.com/w3c/css-validator/issues/361
.message == "CSS: Parse Error."
and .extract == "){outline:none}}:focus-visible"
and .hiliteLength == 1
)
or
( # See https://github.com/validator/validator/issues/1166
.message == "Attribute “media” not allowed on element “meta” at this point."
and .firstColumn == 1
and (.extract | test(" name=\"theme-color\""))
)
) | not
)
)