Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
add support for shellcheck for shell script static analysis
Browse files Browse the repository at this point in the history
This will help keep bash scripts in check.
  • Loading branch information
ericvw committed Nov 8, 2015
1 parent f5352be commit 4f290b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Expand Up @@ -3,3 +3,10 @@ node_js:
- "0.10"
- "0.12"
- "iojs"

before_install:
- sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' -y
- sudo apt-get update -qq

install:
- sudo apt-get install -y shellcheck
21 changes: 18 additions & 3 deletions Makefile
Expand Up @@ -5,10 +5,12 @@ SRCS_TEST_TS :=
SRCS_TEST_JS :=
SRCS_TSLINT_RULES_TS :=
SRCS_TSLINT_RULES_JS :=
SRCS_SHELL :=

# known directories within the project
TEST_DIR := test
TSLINT_RULES_DIR := tslint-rules
SCRIPTS_DIR = scripts

# glob all source TypeScript files
SRCS_TS += index.ts
Expand All @@ -23,6 +25,9 @@ SRCS_JS += $(patsubst %.ts,%.js,$(SRCS_TS))
SRCS_TEST_JS += $(patsubst %.ts,%.js,$(SRCS_TEST_TS))
SRCS_TSLINT_RULES_JS += $(patsubst %.ts,%.js,$(SRCS_TSLINT_RULES_TS))

# glob scripts
SRCS_SHELL += $(shell find $(SCRIPTS_DIR) -type f -name '*.sh')

# setup variables for program execution
BIN_PREFIX := $(shell npm bin)
ROOT_PREFIX := $(shell npm root)
Expand All @@ -37,6 +42,9 @@ TSLINT_TARGET := .tslint.d
TSLINT_D := $(ROOT_PREFIX)/tslint/lib/tslint.d.ts
TSLINT_TEST_TARGET := $(addprefix $(TEST_DIR)/,.tslint.d)

SHELLCHECK := shellcheck
SHELLCHECK_FAKE_TARGET := $(addprefix $(SCRIPTS_DIR)/,.shellcheck.d)

MOCHA_BIN := $(addprefix $(BIN_PREFIX)/,mocha)
MOCHA_FLAGS := --reporter spec
MOCHA := $(MOCHA_BIN) $(MOCHA_FLAGS)
Expand All @@ -45,16 +53,16 @@ RM ?= rm -f
TOUCH ?= touch

# top-level targets
.PHONY: all build check dependencies tslint test test-mocha clean
.PHONY: all build check dependencies shellcheck tslint test test-mocha clean

all: dependencies build tslint

check: all test
check: all lint test

dependencies:
@npm install

lint: tslint tslint-test
lint: tslint tslint-test shellcheck

test: test-mocha

Expand All @@ -66,6 +74,8 @@ tslint: $(TSLINT_TARGET)

tslint-test: $(TSLINT_TEST_TARGET)

shellcheck: $(SHELLCHECK_FAKE_TARGET)

test-mocha: build build-test tslint-test
@$(MOCHA)

Expand All @@ -77,6 +87,11 @@ clean:
@$(RM) $(SRCS_TSLINT_RULES_JS)


$(SHELLCHECK_FAKE_TARGET): $(SRCS_SHELL)
@$(RM) $(SHELLCHECK_FAKE_TARGET)
@$(SHELLCHECK) $(SRCS_SHELL)
@$(TOUCH) $(SHELLCHECK_FAKE_TARGET)

$(TSLINT_TARGET): $(SRCS_TS) $(TSLINT_CONFIG) $(SRCS_TSLINT_RULES_JS)
@$(RM) $(TSLINT_TARGET)
@$(TSLINT) -r $(TSLINT_RULES_DIR) $(foreach file,$(SRCS_TS),-f $(file))
Expand Down

0 comments on commit 4f290b9

Please sign in to comment.