-
Notifications
You must be signed in to change notification settings - Fork 1
/
oxlint.sh
executable file
·75 lines (57 loc) · 2.24 KB
/
oxlint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -e -o pipefail
# config
if [ -n "$OXLINT_CONFIG" ]; then
# check if config file exists
if [ ! -f "$OXLINT_CONFIG" ]; then
echo "::error file={$OXLINT_CONFIG}::Config file not found: $OXLINT_CONFIG"
exit 1
# check if the config file is js, which is not supported
elif [ "${OXLINT_CONFIG##*.}" = "js" ]; then
echo "::error file={$OXLINT_CONFIG}::Oxlint only supports JSON files. Please convert your config file to JSON."
exit 1
fi
config="--config $OXLINT_CONFIG"
fi
OXLINT_ARGS="$config"
# Build plugin args
# map whitespace-separated `name` to `--name-plugin`
if [ -n "$OXLINT_PLUGINS" ]; then
plugins="$(echo "$OXLINT_PLUGINS" | xargs | sed -e 's/ /-plugin --/g' -e 's/^/--/')-plugin"
fi
# build disable plugin args
# map whitespace-separated `name` to `--disable-name-plugin`
if [ -n "$OXLINT_PLUGINS_DISABLE" ]; then
disable_plugins="$(echo "$OXLINT_PLUGINS_DISABLE" | xargs | sed -e 's/ /-plugin --disable-/g' -e 's/^/--disable-/')-plugin"
fi
OXLINT_ARGS="$OXLINT_ARGS $plugins $disable_plugins"
# build allow, warn, and deny lists
# map `rule-name` to `-[A/W/D] rule-name`
if [ -n "$OXLINT_ALLOW" ]; then
allow_list="$(echo "$OXLINT_ALLOW" | xargs | sed -e 's/ / -A /g' -e 's/^/-A /')"
fi
if [ -n "$OXLINT_WARN" ]; then
warn_list="$(echo "$OXLINT_WARN" | xargs | sed -e 's/ / -W /g' -e 's/^/-W /')"
else
warn_list="-W correctness"
fi
if [ -n "$OXLINT_DENY" ]; then
deny_list="$(echo "$OXLINT_DENY" | xargs | sed -e 's/ / -D /g' -e 's/^/-D /')"
fi
# order is important. We want consumers to be able to deny a category, and then
# allow single rules as needed.
OXLINT_ARGS="$OXLINT_ARGS $warn_list $deny_list $allow_list"
# build deny warnings and max warnings args
if [ -n "$OXLINT_MAX_WARNINGS" ]; then
OXLINT_ARGS="$OXLINT_ARGS --max-warnings $OXLINT_MAX_WARNINGS"
fi
if [ "$OXLINT_DENY_WARNINGS" = "true" ]; then
OXLINT_ARGS="$OXLINT_ARGS --deny-warnings"
fi
# use github output format
OXLINT_ARGS="$OXLINT_ARGS --format github"
echo "::debug::Args: $OXLINT_ARGS"
# Files to lint are passed as arguments. For non-prs, no arguments are passed,
# which defaults to all VCS files.
# shellcheck disable=SC2068,SC2086
npx oxlint@$OXLINT_VERSION $OXLINT_ARGS ${@:1}