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

Added a parallel version of lint to speed things up #2

Merged
merged 4 commits into from
Oct 23, 2023
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ Typically, contributions to the SailPoint OpenAPI specification involve creating
sh /path/to/lint.sh
```

Or use the parallel lint script to greatly speed up the linting process:

```sh
sh /path/to/lint-parallel.sh
```

This script uses the git command `git diff --name-only HEAD master` to print the file paths that have changed, and then it loops through each file and applies the appropriate ruleset based on whether the file is a root spec file, path file, or schema file. This script also has the benefit of referencing the rule files directly from this GitHub repository, so it will always apply the latest rules without the user having to download or synchronize any files.

## Understanding the Linter Results
Expand Down
25 changes: 25 additions & 0 deletions lint-parallel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

lint_file () {
LINTER_URL="https://raw.githubusercontent.com/sailpoint-oss/api-linter/main"

if echo $1 | grep "sailpoint-api.*" --quiet
then
# Don't ignore unkown format because we want to know if the root API spec is a valid OpenAPI version
spectral lint $1 --ruleset "${LINTER_URL}/root-ruleset.yaml"
fi

if echo $1 | grep paths --quiet
then
spectral lint $1 --ruleset "${LINTER_URL}/path-ruleset.yaml" --ignore-unknown-format
fi

if echo $1 | grep schemas --quiet
then
spectral lint $1 --ruleset "${LINTER_URL}/schema-ruleset.yaml" --ignore-unknown-format
fi
}

export -f lint_file

git diff --name-only HEAD master | parallel --progress lint_file {}
Loading