Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature ignore pattern #19

Merged
merged 2 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
MATRIX: >-
[
{
"NAME": "jsonlint",
"NAME": "jl",
"VERSION": ["latest", "1.6.0"],
"FLAVOUR": ["alpine", "latest"],
"ARCH": ["linux/amd64", "linux/386", "linux/arm64", "linux/arm/v7", "linux/arm/v6"]
Expand Down
4 changes: 3 additions & 1 deletion Dockerfiles/data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ print_usage() {
>&2 echo " -t CHAR character(s) to use for indentation"
>&2 echo " -i <GLOB-PATTERN> Ignore glob pattern when using the GLOB-PATTERN for file search."
>&2 echo " (e.g.: -i '\.terraform*.json')"
>&2 echo " Multiple ignores can be comma separated:"
>&2 echo " (e.g.: -i '\.terraform*.json,*test.json')"
>&2 echo " <PATH-TO-FILE> Path to file to validate"
>&2 echo " <GLOB-PATTERN> Glob pattern for recursive scanning. (e.g.: *\\.json)"
>&2 echo " Anything that \"find . -name '<GLOB-PATTERN>'\" will take is valid."
Expand Down Expand Up @@ -137,7 +139,7 @@ if [ "${#}" -gt "0" ]; then
if [ -z "${ARG_IGNORE}" ]; then
find_cmd="find . -name \"${1}\" -type f -print0"
else
find_cmd="find . -not \( -path \"${ARG_IGNORE}\" \) -name \"${1}\" -type f -print0"
find_cmd="find . -not \( -path \"${ARG_IGNORE//,/*\" -o -path \"}*\" \) -name \"${1}\" -type f -print0"
fi

echo "${find_cmd}"
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TAG = latest
# Makefile.docker overwrites
NAME = jsonlint
VERSION = latest
IMAGE = cytopia/${NAME}
IMAGE = cytopia/jsonlint
FLAVOUR = latest
FILE = Dockerfile.${FLAVOUR}
DIR = Dockerfiles
Expand Down Expand Up @@ -136,7 +136,11 @@ _test-run:
@echo "------------------------------------------------------------"
@echo "- Testing playbook"
@echo "------------------------------------------------------------"
if ! docker run --rm --platform $(ARCH) -v $(CURRENT_DIR)/tests:/data $(IMAGE):$(DOCKER_TAG) -t ' ' *.json ; then \
if ! docker run --rm --platform $(ARCH) -v $(CURRENT_DIR)/tests:/data $(IMAGE):$(DOCKER_TAG) -t ' ' test.json ; then \
echo "Failed"; \
exit 1; \
fi; \
if ! docker run --rm --platform $(ARCH) -v $(CURRENT_DIR)/tests:/data $(IMAGE):$(DOCKER_TAG) -t ' ' -i '*1.json,*2.json' *.json ; then \
echo "Failed"; \
exit 1; \
fi; \
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Usage: cytopia/jsonlint [-sti] <PATH-TO-FILE>
-t CHAR character(s) to use for indentation
-i <GLOB-PATTERN> Ignore glob pattern when using the GLOB-PATTERN for file search.
(e.g.: -i '\.terraform*.json')
Multiple ignores can be comma separated:
(e.g.: -i '\.terraform*.json,*test.json')
<PATH-TO-FILE> Path to file to validate
<GLOB-PATTERN> Glob pattern for recursive scanning. (e.g.: *\.json)
Anything that "find . -name '<GLOB-PATTERN>'" will take is valid.
Expand Down
4 changes: 4 additions & 0 deletions tests/fail-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"key": "value",
"foo": "bar"a
}
4 changes: 4 additions & 0 deletions tests/fail-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"key": "value",
"foo": "bar"a
}