sasjs lint¶
The sasjs lint
command is used to identify issues such as embedded passwords, trailing spaces, sloppy indentation, missing program headers and more, in your SAS code.
This means developers can spend less time on code reviews and formatting fixes, as well as preventing dangerous code, or code with hard-to-detect bugs from hitting production servers.
Prerequisites¶
Before using this command, you simply need to install the SASjsCLI. It is NOT necessary to configure a sasjsconfig.json file - the sasjs lint
command can be executed from anywhere - including from within a git hook.
The lint settings are described here.
Syntax¶
sasjs lint <action>
sasjs lint¶
Syntax¶
The command works as follows:
sasjs lint
Usage¶
Simply run the command and the list of exceptions (along with line / column numbers) is shown in the console, eg:
sasjs lint fix¶
Syntax¶
The command works as follows:
sasjs lint fix
Usage¶
Simply run the command and the exceptions are fixed! The following rules are supported for 'autofix':
- noTrailingSpaces
- hasDoxygenHeader
- hasMacroNameInMend
- lowerCaseFileNames
Usage in a GIT hook¶
The sasjs lint
command will return a non-zero exit code if any exceptions are found. A great way to prevent questionable code from ever hitting your GIT repo (let alone the production server) is to run the linter as part of a pre-commit hook.
To configure this, there are two steps. First, add the following to the "scripts" section of your package.json
file: "prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true"
Then, add the following to your .git-hooks/pre-commit
file (see example):
#!/bin/bash
# Ensure lint is passing
LINT=`sasjs lint`
if [[ "$LINT" != "✔ All matched files use @sasjs/lint code style!" ]]; then
echo "$LINT"
echo "To commit in spite of these warnings, use the -n parameter."
exit 1
fi
If you run sasjs create SOMEPROJECT -t jobs
you can check out a sample project with this hook already configured. Or, you can just click here.
Sponsorship & Contributions¶
SASjs is an open source framework! Contributions are welcomed. If you would like to see a feature, because it would be useful in your project, but you don't have the requisite (typescript) experience - then how about you engage us on a short project and we build it for you?
Contact Allan Bowe for further details.