Skip to content

Commit 2e8bb91

Browse files
Merge pull request #30 from hurrymaplelad/shellcheck
Lint with Shellcheck
2 parents 854b702 + ad951db commit 2e8bb91

File tree

6 files changed

+40
-24
lines changed

6 files changed

+40
-24
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
language: node_js
22
node_js: node
3+
# Lint and test in parallel
4+
script:
5+
- npm run lint
6+
- npm test
7+
# from https://github.com/koalaman/shellcheck#travis-ci-setup
8+
addons:
9+
apt:
10+
sources:
11+
- debian-sid # Grab ShellCheck from the Debian repo
12+
packages:
13+
- shellcheck

bin/plugin_root

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22
#
33
# Writes the full path to the root of this plugin to standard out.
44
# Use to source or run files in libexec/
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
#!/bin/bash
2+
3+
# shellcheck source=libexec/nodenv-package-json-engine
14
source "$(plugin_root)/libexec/nodenv-package-json-engine"
25

36
if ! NODENV_PACKAGE_JSON_VERSION=$(get_version_respecting_precedence); then
47
echo "package-json-engine: no version satisfying \`$(get_expression_respecting_precedence)' installed" >&2
58
exit 1
69
elif [ -n "$NODENV_PACKAGE_JSON_VERSION" ]; then
7-
NODENV_VERSION="${NODENV_PACKAGE_JSON_VERSION}"
10+
export NODENV_VERSION="${NODENV_PACKAGE_JSON_VERSION}"
811
fi
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#!/bin/bash
2+
3+
# shellcheck source=libexec/nodenv-package-json-engine
14
source "$(plugin_root)/libexec/nodenv-package-json-engine"
25

36
ENGINES_EXPRESSION=$(get_expression_respecting_precedence);
47
if [ -n "$ENGINES_EXPRESSION" ]; then
5-
NODENV_VERSION_ORIGIN="package-json-engine matching $ENGINES_EXPRESSION"
8+
export NODENV_VERSION_ORIGIN="package-json-engine matching $ENGINES_EXPRESSION"
69
fi

libexec/nodenv-package-json-engine

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22
#
33
# If a custom Node version is not already defined, we look
44
# for a Node version semver expressing in the current tree's package.json.
@@ -13,32 +13,32 @@
1313
package_json_has_precedence() {
1414
if [[ ( -z "$(nodenv local 2>/dev/null)" )
1515
&& ( -z "$(nodenv sh-shell 2>/dev/null)" ) ]]; then
16-
exit;
16+
return;
1717
else
18-
exit 1;
18+
return 1;
1919
fi
2020
}
2121

2222
find_package_json_path() {
23-
local root="$1"
23+
root="$1"
2424
while [ -n "$root" ]; do
2525
if [ -e "${root}/package.json" ]; then
2626
echo "${root}/package.json"
27-
exit
27+
return
2828
fi
2929
root="${root%/*}"
3030
done
3131
}
3232

3333
extract_version_from_package_json() {
34-
local package_json_path="$1"
35-
local version_regex='"node":[ \t]*"([^"]*)"'
34+
package_json_path="$1"
35+
version_regex='"node":[ \t]*"([^"]*)"'
3636
[[ $(cat "$package_json_path") =~ $version_regex ]]
3737
echo "${BASH_REMATCH[1]}"
3838
}
3939

4040
find_installed_verion_matching_expression() {
41-
local version_expression="$1"
41+
version_expression="$1"
4242
local -a installed_versions
4343
while IFS= read -r v; do
4444
installed_versions+=( "$v" )
@@ -52,32 +52,30 @@ find_installed_verion_matching_expression() {
5252
SEMVER="$(plugin_root)/node_modules/sh-semver/semver.sh"
5353

5454
get_version_respecting_precedence() {
55-
if ! $(package_json_has_precedence); then
56-
exit
57-
fi
55+
if ! package_json_has_precedence; then return; fi
5856

59-
local package_json_path=$(find_package_json_path "$PWD")
60-
if [ ! -e "$package_json_path" ]; then exit; fi
57+
package_json_path=$(find_package_json_path "$PWD")
58+
if [ ! -e "$package_json_path" ]; then return; fi
6159

62-
local version_expression=$(
60+
version_expression=$(
6361
extract_version_from_package_json "$package_json_path"
6462
)
65-
if [ -z "$version_expression" ]; then exit; fi
63+
if [ -z "$version_expression" ]; then return; fi
6664

67-
local version=$(
65+
version=$(
6866
find_installed_verion_matching_expression "$version_expression"
6967
)
70-
if [ -z "$version" ]; then exit 1; fi
68+
if [ -z "$version" ]; then return 1; fi
7169
echo "$version"
7270
}
7371

7472
get_expression_respecting_precedence() {
75-
if ! $(package_json_has_precedence); then exit; fi
73+
if ! package_json_has_precedence; then return; fi
7674

77-
local package_json_path=$(find_package_json_path "$PWD")
78-
if [ ! -e "$package_json_path" ]; then exit; fi
75+
package_json_path=$(find_package_json_path "$PWD")
76+
if [ ! -e "$package_json_path" ]; then return; fi
7977

80-
local version_expression=$(
78+
version_expression=$(
8179
extract_version_from_package_json "$package_json_path"
8280
)
8381
echo "$version_expression"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"test": "test"
2323
},
2424
"scripts": {
25+
"lint": "git ls-files bin etc libexec | xargs shellcheck",
2526
"pretest": "[ -d $npm_package_directories_testnodenv ] || git clone --quiet --depth 1 https://github.com/nodenv/nodenv $npm_package_directories_testnodenv",
2627
"test": "PATH=$PWD/$npm_package_directories_testnodenv/bin:$PATH bats ${CI:+--tap} test",
2728
"publish:brew": "brew-publish $npm_package_name v$npm_package_version",

0 commit comments

Comments
 (0)