Skip to content

Commit 49ad977

Browse files
authored
Benchmark improvement fix (#6)
* chore(benchmark): improve and fix benchmark * docs(benchmark): update result * fix(core): add `shellcheck` support
1 parent 710007d commit 49ad977

File tree

8 files changed

+127
-36
lines changed

8 files changed

+127
-36
lines changed

benchmark/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ commitlint-*
77
# Lockfile
88
bun.lockb
99
yarn.lock
10+
package-lock.json
1011

1112
# Logfile
1213
*.log

benchmark/.lintstagedrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export default {
22
"*.{js,jsx,ts,tsx}": "biome check --diagnostic-level=warn",
3-
"*.{json,yaml}": "spectral lint --ignore-unknown-format",
3+
"*.json": "jsona fmt --option trailing_newline=true --check",
4+
"*.yaml": "spectral lint --ignore-unknown-format",
45
"*.{js,jsx,ts,tsx,json,yaml,md}": "prettier -c",
56
};

benchmark/benchmark.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,19 @@ set -eu
55
export PATH="./node_modules/.bin:$PATH"
66

77
prepare() {
8-
rm -rf tmp.json
98
echo '{ "foo": "bar" }' >>tmp.json
109
git init
1110
git add -A tmp.json
1211
git commit -m "initial commit"
1312
git add -Af package.json result.md
1413
}
1514

16-
run() {
17-
hyperfine --runs 10 --warmup 3 '../lint-staged.sh' 'lint-staged' 'lefthook run pre-commit' --export-markdown "result.md"
18-
}
19-
2015
cleanup() {
2116
git rm -f result.md --cached
2217
rm -rf .git tmp.json
2318
}
2419

25-
prepare
26-
run
27-
cleanup
20+
export -f prepare
21+
export -f cleanup
22+
23+
hyperfine --runs 10 --warmup 3 '../lint-staged.sh' 'lint-staged' 'lefthook run pre-commit' --export-markdown "result.md" --setup prepare --cleanup cleanup

benchmark/biome.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
3+
"formatter": {
4+
"enabled": true,
5+
"formatWithErrors": false,
6+
"lineWidth": 80,
7+
"indentStyle": "space",
8+
"indentWidth": 2,
9+
"lineEnding": "lf"
10+
},
11+
"linter": {
12+
"enabled": false
13+
},
14+
"javascript": {
15+
"formatter": {
16+
"enabled": true,
17+
"quoteStyle": "single",
18+
"trailingComma": "none",
19+
"arrowParentheses": "always",
20+
"bracketSpacing": true,
21+
"bracketSameLine": true
22+
}
23+
},
24+
"json": {
25+
"parser": {
26+
"allowComments": true,
27+
"allowTrailingCommas": false
28+
},
29+
"formatter": {
30+
"enabled": true
31+
}
32+
}
33+
}

benchmark/lefthook.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ pre-commit:
77
exclude: 'node_modules'
88
run: ./node_modules/.bin/biome check --diagnostic-level=warn {staged_files}
99
spectral-linter:
10-
glob: '*.{json,yaml}'
10+
glob: '*.yaml'
1111
exclude: 'node_modules'
1212
run: ./node_modules/.bin/spectral lint --ignore-unknown-format {staged_files}
13+
jsona-linter:
14+
glob: '*.json'
15+
exclude: 'node_modules'
16+
run: ./node_modules/.bin/jsona fmt --option trailing_newline=true --check {staged_files}
1317
prettier-formatter:
1418
glob: '*.{js,jsx,ts,tsx,json,yaml,md}'
1519
exclude: 'node_modules'

benchmark/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"devDependencies": {
77
"@biomejs/biome": "1.6.3",
88
"@stoplight/spectral-cli": "^6.11.0",
9+
"jsona-rs-npm": "^0.6.0",
910
"lefthook": "^1.6.7",
1011
"lint-staged": "^15.2.2",
1112
"prettier": "^3.2.5"

docs/BENCHMARK.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ List of contents:
2020

2121
| Command | Mean \[ms\] | Min \[ms\] | Max \[ms\] | Relative |
2222
| :------------------------ | ----------: | ---------: | ---------: | ----------: |
23-
| `../lint-staged.sh` | 97.5 ± 1.1 | 96.4 | 99.4 | 1.00 |
24-
| `lint-staged` | 270.7 ± 7.7 | 263.5 | 286.3 | 2.78 ± 0.08 |
25-
| `lefthook run pre-commit` | 205.6 ± 9.4 | 197.8 | 230.1 | 2.11 ± 0.10 |
23+
| `../lint-staged.sh` | 133.8 ± 7.0 | 126.7 | 146.9 | 1.00 |
24+
| `lint-staged` | 275.3 ± 6.7 | 271.4 | 294.1 | 2.06 ± 0.12 |
25+
| `lefthook run pre-commit` | 185.0 ± 4.9 | 181.1 | 193.8 | 1.38 ± 0.08 |

lint-staged.sh

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,30 @@ log() {
1212
echo "$CLI_PREFIX $1"
1313
}
1414

15+
SH_FILES=""
1516
MARKDOWN_FILES=""
1617
TJSX_FILES=""
17-
JSON_YML_FILES=""
18+
JSON_FILES=""
19+
YAML_FILES=""
1820
HTML_FILES=""
1921
CSS_FILES=""
2022

2123
for file in $(git diff --name-only --cached --diff-filter=ACMR); do
2224
case "$file" in
25+
*.sh | *.bash)
26+
SH_FILES="$SH_FILES $file"
27+
;;
2328
*.md)
2429
MARKDOWN_FILES="$MARKDOWN_FILES $file"
2530
;;
2631
*.js | *.jsx | *.ts | *.tsx)
2732
TJSX_FILES="$TJSX_FILES $file"
2833
;;
29-
*.json | *.yml | *.yaml)
30-
JSON_YML_FILES="$JSON_YML_FILES $file"
34+
*.json)
35+
JSON_FILES="$JSON_FILES $file"
36+
;;
37+
*.yml | *.yaml)
38+
YAML_FILES="$YAML_FILES $file"
3139
;;
3240
*.html)
3341
HTML_FILES="$HTML_FILES $file"
@@ -38,24 +46,43 @@ for file in $(git diff --name-only --cached --diff-filter=ACMR); do
3846
esac
3947
done
4048

49+
SH_FILES=$(echo "$SH_FILES" | awk '{$1=$1}1')
4150
MARKDOWN_FILES=$(echo "$MARKDOWN_FILES" | awk '{$1=$1}1')
4251
TJSX_FILES=$(echo "$TJSX_FILES" | awk '{$1=$1}1')
52+
JSON_FILES=$(echo "$JSON_FILES" | awk '{$1=$1}1')
53+
YAML_FILES=$(echo "$YAML_FILES" | awk '{$1=$1}1')
4354
HTML_FILES=$(echo "$HTML_FILES" | awk '{$1=$1}1')
4455
CSS_FILES=$(echo "$CSS_FILES" | awk '{$1=$1}1')
4556

57+
# Shell files
58+
if [ ${#SH_FILES} -gt 1 ]; then
59+
log "Shell linting started"
60+
if [ "$(command -v shellcheck)" ]; then
61+
log "Markdown [dprint] linting..."
62+
# shellcheck disable=SC2086
63+
shellcheck ${SH_FILES}
64+
log "Markdown [dprint] linting done"
65+
else
66+
log "dprint binary and/or configuration are not installed"
67+
fi
68+
log "Markdown linting done\n"
69+
fi
70+
4671
# Markdown files
4772
if [ ${#MARKDOWN_FILES} -gt 1 ]; then
4873
log "Markdown linting started"
4974
if [ "$(command -v dprint)" ] && [ -f "./dprint.json" ]; then
5075
log "Markdown [dprint] linting..."
51-
dprint check --log-level=warn "${MARKDOWN_FILES}"
76+
# shellcheck disable=SC2086
77+
dprint check --log-level=warn ${MARKDOWN_FILES}
5278
log "Markdown [dprint] linting done"
5379
else
5480
log "dprint binary and/or configuration are not installed"
5581
fi
5682
if [ "$(command -v markdownlint)" ]; then
5783
log "Markdown [markdownlint] linting..."
58-
markdownlint "${MARKDOWN_FILES}"
84+
# shellcheck disable=SC2086
85+
markdownlint ${MARKDOWN_FILES}
5986
log "Markdown [markdownlint] done..."
6087
else
6188
log "markdownlint binary is not installed"
@@ -68,38 +95,63 @@ if [ ${#TJSX_FILES} -gt 1 ]; then
6895
log "JS(X)/TS(X) linting started"
6996
if [ "$(command -v biome)" ] && [ -f "./biome.json" ]; then
7097
log "JS(X)/TS(X) [biome] linting..."
71-
biome check --diagnostic-level=warn "${TJSX_FILES}"
98+
# shellcheck disable=SC2086
99+
biome check --diagnostic-level=warn ${TJSX_FILES}
72100
log "JS(X)/TS(X) [biome] linting done"
73101
else
74102
log "biome binary and/or configuration are not installed"
75103
fi
76104
log "JS(X)/TS(X) linting done\n"
77105
fi
78106

79-
# json/yaml
80-
if [ ${#JSON_YML_FILES} -gt 1 ]; then
81-
log "JSON/YAML linting started"
107+
# json
108+
if [ ${#JSON_FILES} -gt 1 ]; then
109+
log "JSON linting started"
110+
if [ "$(command -v jsona)" ]; then
111+
log "JSON [jsona] linting..."
112+
# shellcheck disable=SC2086
113+
jsona fmt --option trailing_newline=true --check ${JSON_FILES}
114+
log "JSON [jsona] linting done"
115+
elif [ "$(command -v spectral)" ]; then
116+
if [ -f "./.spectral.yaml" ] || [ -f "./.spectral.yml" ]; then
117+
log "JSON [spectral] linting..."
118+
# shellcheck disable=SC2086
119+
spectral lint --ignore-unknown-format ${JSON_FILES}
120+
log "JSON [spectral] linting done"
121+
else
122+
log "JSON [spectral] config not found"
123+
fi
124+
else
125+
log "spectral-lint binary is not installed"
126+
fi
127+
log "JSON linting done\n"
128+
fi
129+
130+
# yaml
131+
if [ ${#YAML_FILES} -gt 1 ]; then
132+
log "YAML linting started"
82133
if [ "$(command -v spectral)" ]; then
83-
log "JSON/YAML [spectral] linting..."
84-
spectral lint --ignore-unknown-format "${JSON_YML_FILES}"
85-
log "JSON/YAML [spectral] linting done"
86-
elif [ "$(command -v jsonymllint)" ]; then
87-
log "JSON/YAML [jsonyamllint] linting..."
88-
log "spectral-lint binary is not installed, but we use jsonymllint"
89-
jsonymllint "${JSON_YML_FILES}"
90-
log "JSON/YAML [jsonyamllint] linting done"
134+
if [ -f "./.spectral.yaml" ] || [ -f "./.spectral.yml" ]; then
135+
log "YAML [spectral] linting..."
136+
# shellcheck disable=SC2086
137+
spectral lint --ignore-unknown-format ${YAML_FILES}
138+
log "YAML [spectral] linting done"
139+
else
140+
log "YAML [spectral] config not found"
141+
fi
91142
else
92-
log "spectral-lint and jsonymllint binaries is not installed"
143+
log "spectral-lint binary is not installed"
93144
fi
94-
log "JSON/YAML linting done\n"
145+
log "YAML linting done\n"
95146
fi
96147

97148
# html
98149
if [ ${#HTML_FILES} -gt 1 ]; then
99150
log "HTML linting started"
100151
if [ "$(command -v htmllint)" ]; then
101152
log "HTML [htmllint] linting..."
102-
htmllint "${HTML_FILES}"
153+
# shellcheck disable=SC2086
154+
htmllint ${HTML_FILES}
103155
log "HTML [htmllint] linting done"
104156
else
105157
log "htmlhint binary is not installed"
@@ -112,20 +164,23 @@ if [ ${#CSS_FILES} -gt 1 ]; then
112164
log "CSS linting..."
113165
if [ "$(command -v stylelint)" ]; then
114166
log "CSS [stylelint] linting..."
115-
stylelint --color "${CSS_FILES}"
167+
# shellcheck disable=SC2086
168+
stylelint --color ${CSS_FILES}
116169
log "CSS [stylelint] linting done"
117170
else
118171
log "stylelint binary is not installed"
119172
fi
120173
log "CSS linting done\n"
121174
fi
122175

123-
PRETTIER_FILES=$(echo "${MARKDOWN_FILES} ${TJSX_FILES} ${JSON_YML_FILES} ${HTML_FILES} ${CSS_FILES}" | awk '{$1=$1}1')
176+
PRETTIER_FILES=$(echo "${MARKDOWN_FILES} ${TJSX_FILES} ${JSON_FILES} ${YAML_FILES} ${HTML_FILES} ${CSS_FILES}" | awk '{$1=$1}1')
177+
124178
if [ ${#PRETTIER_FILES} -gt 4 ]; then
125179
log "Prettier overall linting..."
126180
if [ "$(command -v prettier)" ]; then
127181
log "Prettier overall linting started"
128-
prettier -c "${PRETTIER_FILES}"
182+
# shellcheck disable=SC2086
183+
prettier -c ${PRETTIER_FILES}
129184
log "Prettier overall linting done\n"
130185
fi
131186
fi

0 commit comments

Comments
 (0)