1
0
mirror of https://github.com/sasjs/lint.git synced 2025-12-10 17:34:36 +00:00

Compare commits

...

41 Commits

Author SHA1 Message Date
Allan Bowe
9623828fc8 Merge pull request #180 from sasjs/quick-fix
feat: add configuration as an optional argument for formatText
2022-11-08 14:48:44 +00:00
debeff7929 fix: updated sasjslint-schema.json 2022-11-08 19:43:18 +05:00
c210699954 feat: add configuration as an optional argument for formatText 2022-11-08 19:33:21 +05:00
Allan Bowe
cee30d0030 Merge pull request #179 from sasjs/issue-178
feat: customise the defaultHeader
2022-11-07 13:41:03 +00:00
Allan Bowe
66bcfb2962 fix: README 2022-11-07 12:30:31 +00:00
a3bade0a5a feat: customise the defaultHeader 2022-11-07 16:50:35 +05:00
Allan Bowe
1d821db934 Update sasjslint-schema.json 2022-08-16 00:13:15 +01:00
Allan Bowe
f3858d33fc Merge pull request #169 from sasjs/allanbowe/vs-code-error-when-adding-168
chore: updating docs for ignoreList
2022-08-16 00:10:28 +01:00
Allan Bowe
0d9e17f072 chore: moving github docs to github folder 2022-08-15 23:07:05 +00:00
Allan Bowe
421513850c chore: updating docs for ignoreList 2022-08-15 23:04:33 +00:00
Allan Bowe
5ce33ab66c Merge pull request #167 from sasjs/issue-166
feat: honour .gitignore when linting filesystems
2022-08-15 18:27:01 +01:00
5290339c9e chore: spec fixes 2022-08-15 21:57:18 +05:00
4772aa70c6 chore: update jsdoc header 2022-08-12 15:59:58 +05:00
623d4df79d chore: fixed vulnerabilities by npm audit fix 2022-08-12 15:50:58 +05:00
40aea383b7 feat: honour .gitignore and ignoreList from config when linting filesystem 2022-08-12 15:49:28 +05:00
e1bcf5b06b feat: add a new attribute ignoreList to .sasjslint (LintConfig) 2022-08-12 15:48:35 +05:00
Allan Bowe
51c6dd7c1a Update README.md 2022-03-09 15:35:15 +00:00
Allan Bowe
6e0f1c4167 Merge pull request #128 from sasjs/all-contributors
docs: add all-contributors dependence to package.json, and modify README.md file
2021-09-30 10:27:33 +01:00
Vladislav Parhomchik
5f905c88d9 docs: add all-contributors dependence to package.json, and modify README.md file 2021-09-30 11:06:43 +03:00
Yury Shkoda
ac95546910 Merge pull request #127 from sasjs/dependabot-upd
chore(dependabot): change schedule interval
2021-09-16 14:31:29 +03:00
Yury Shkoda
7a00cc5f2d chore(dependabot): change schedule interval 2021-09-16 14:27:50 +03:00
Krishna Acondy
8950c97f84 Merge pull request #125 from sasjs/improve-docs-ci
chore(*): add contribution guidelines, add node version check
2021-09-13 09:57:39 +01:00
Allan Bowe
49b124e5b8 Update CONTRIBUTING.md 2021-09-13 11:50:01 +03:00
Krishna Acondy
1b15938477 chore(ci): cache dependencies 2021-09-13 09:08:38 +01:00
Krishna Acondy
f6fa20af1c chore(ci): use LTS version 2021-09-13 09:07:43 +01:00
Krishna Acondy
cf5a0700f2 chore(ci): use LTS 2021-09-13 09:06:28 +01:00
Krishna Acondy
0dca988438 chore(ci): try LTS version 2021-09-13 09:05:24 +01:00
Krishna Acondy
00dafa5bc0 chore(ci): try LTS version 2021-09-13 09:03:41 +01:00
Krishna Acondy
39bffd39a4 chore(ci): use latest LTS 2021-09-13 08:56:43 +01:00
Krishna Acondy
ec95a798b7 chore(ci): use LTS version 2021-09-13 08:54:34 +01:00
Krishna Acondy
acfc559f25 chore(ci): use LTS version 2021-09-13 08:51:29 +01:00
Krishna Acondy
d204b5bac6 chore(ci): try LTS version 2021-09-13 08:49:03 +01:00
Krishna Acondy
5602063879 chore(ci): try lts syntax 2021-09-13 08:46:23 +01:00
Krishna Acondy
31cee0af91 chore(ci): add node version check 2021-09-13 08:41:58 +01:00
Krishna Acondy
cd91780cf5 chore(doc): add contribution guidelines 2021-09-13 08:41:35 +01:00
Yury Shkoda
108bbfbaa5 Merge pull request #113 from sasjs/lint-fix
chore(lint): fix file path for prettier
2021-08-26 14:56:57 +03:00
Yury Shkoda
f2edf1176a chore(lint): fix file path for prettier 2021-08-26 14:54:20 +03:00
Allan Bowe
b5d446adc9 Merge pull request #96 from sasjs/all-contributors/add-Carus11
docs: add Carus11 as a contributor for ideas
2021-07-26 20:31:45 +03:00
Allan Bowe
cc221bccc3 Update README.md 2021-07-23 10:03:19 +03:00
allcontributors[bot]
f38bcec582 docs: create .all-contributorsrc [skip ci] 2021-07-23 07:02:28 +00:00
allcontributors[bot]
75ab01cccf docs: update README.md [skip ci] 2021-07-23 07:02:27 +00:00
21 changed files with 7386 additions and 93 deletions

113
.all-contributorsrc Normal file
View File

@@ -0,0 +1,113 @@
{
"files": [
"README.md"
],
"imageSize": 100,
"commit": false,
"contributors": [
{
"login": "Carus11",
"name": "Carus Kyle",
"avatar_url": "https://avatars.githubusercontent.com/u/4925828?v=4",
"profile": "https://github.com/Carus11",
"contributions": [
"ideas"
]
},
{
"login": "allanbowe",
"name": "Allan Bowe",
"avatar_url": "https://avatars.githubusercontent.com/u/4420615?v=4",
"profile": "https://github.com/allanbowe",
"contributions": [
"code",
"test",
"review",
"video",
"doc"
]
},
{
"login": "YuryShkoda",
"name": "Yury Shkoda",
"avatar_url": "https://avatars.githubusercontent.com/u/25773492?v=4",
"profile": "https://www.erudicat.com/",
"contributions": [
"code",
"test",
"projectManagement",
"video",
"doc"
]
},
{
"login": "krishna-acondy",
"name": "Krishna Acondy",
"avatar_url": "https://avatars.githubusercontent.com/u/2980428?v=4",
"profile": "https://krishna-acondy.io/",
"contributions": [
"code",
"test",
"review",
"infra",
"platform",
"maintenance",
"content"
]
},
{
"login": "saadjutt01",
"name": "Muhammad Saad ",
"avatar_url": "https://avatars.githubusercontent.com/u/8914650?v=4",
"profile": "https://github.com/saadjutt01",
"contributions": [
"code",
"test",
"review",
"mentoring",
"doc"
]
},
{
"login": "sabhas",
"name": "Sabir Hassan",
"avatar_url": "https://avatars.githubusercontent.com/u/82647447?v=4",
"profile": "https://github.com/sabhas",
"contributions": [
"code",
"test",
"review",
"ideas"
]
},
{
"login": "medjedovicm",
"name": "Mihajlo Medjedovic",
"avatar_url": "https://avatars.githubusercontent.com/u/18329105?v=4",
"profile": "https://github.com/medjedovicm",
"contributions": [
"code",
"test",
"review",
"infra"
]
},
{
"login": "VladislavParhomchik",
"name": "Vladislav Parhomchik",
"avatar_url": "https://avatars.githubusercontent.com/u/83717836?v=4",
"profile": "https://github.com/VladislavParhomchik",
"contributions": [
"test",
"review"
]
}
],
"contributorsPerLine": 7,
"projectName": "lint",
"projectOwner": "sasjs",
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true,
"commitConvention": "none"
}

54
.github/CONTRIBUTING.md vendored Normal file
View File

@@ -0,0 +1,54 @@
# Contributing
Contributions to `@sasjs/lint` are very welcome!
Please fill in the pull request template and make sure that your code changes are adequately covered with tests when making a PR.
## Architecture
This project implements a number of rules for SAS projects and code. There are three types of rules:
* File rules - rules applied at the file level
* Line rules - rules applied to each line of a file
* Path rules - rules applied to paths and file names
When implementing a new rule, place it in the appropriate folder for its type.
Please also make sure to export it from the `index.ts` file in that folder.
The file for each rule typically exports an object that conforms to the `LintRule` interface.
This means it will have a `type`, `name`, `description` and `message` at a minimum.
File, line and path lint rules also have a `test` property.
This is a function that will run a piece of logic against the supplied item and produce an array of `Diagnostic` objects.
These objects can be used in the consuming application to display the problems in the code.
With some lint rules, we can also write logic that can automatically fix the issues found.
These rules will also have a `fix` property, which is a function that takes the original content -
either a line or the entire contents of a file, and returns the transformed content with the fix applied.
## Testing
Testing is one of the most important steps when developing a new lint rule.
It helps us ensure that our lint rules do what they are intended to do.
We use `jest` for testing, and since most of the code is based on pure functions, there is little mocking to do.
This makes `@sasjs/lint` very easy to unit test, and so there is no excuse for not testing a new rule. :)
When adding a new rule, please make sure that all positive and negative scenarios are tested in separate test cases.
When modifying an existing rule, ensure that your changes haven't affected existing functionality by running the tests on your machine.
You can run the tests using `npm test`.
## Code Style
This repository uses `Prettier` to ensure a uniform code style.
If you are using VS Code for development, you can automatically fix your code to match the style as follows:
- Install the `Prettier` extension for VS Code.
- Open your `settings.json` file by choosing 'Preferences: Open Settings (JSON)' from the command palette.
- Add the following items to the JSON.
```
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
```
If you are using another editor, or are unable to install the extension, you can run `npm run lint:fix` to fix the formatting after you've made your changes.

View File

@@ -1,7 +1,7 @@
version: 2 version: 2
updates: updates:
- package-ecosystem: npm - package-ecosystem: npm
directory: "/" directory: '/'
schedule: schedule:
interval: daily interval: monthly
open-pull-requests-limit: 10 open-pull-requests-limit: 10

View File

@@ -13,14 +13,15 @@ jobs:
strategy: strategy:
matrix: matrix:
node-version: [12.x] node-version: [lts/*]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1 uses: actions/setup-node@v2
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
cache: npm
- name: Install Dependencies - name: Install Dependencies
run: npm ci run: npm ci
- name: Check Code Style - name: Check Code Style

8
.gitpod.yml Normal file
View File

@@ -0,0 +1,8 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
# and commit this file to your remote git repository to share the goodness with others.
tasks:
- init: npm install && npm run build

View File

@@ -1,4 +1,9 @@
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=sasjs/lint)](https://dependabot.com) [![License](https://img.shields.io/apm/l/atomic-design-ui.svg)](/LICENSE)
![GitHub top language](https://img.shields.io/github/languages/top/sasjs/lint)
[![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/sasjs/lint)](https://github.com/sasjs/lint/issues?q=is%3Aissue+is%3Aclosed)
[![GitHub issues](https://img.shields.io/github/issues-raw/sasjs/lint)](https://github.com/sasjs/lint/issues)
![total lines](https://tokei.rs/b1/github/sasjs/lint)
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-908a85?logo=gitpod)](https://gitpod.io/#https://github.com/sasjs/lint)
# SAS Code linting and formatting # SAS Code linting and formatting
@@ -18,18 +23,43 @@ Configuration is via a `.sasjslint` file with the following structure (these are
"hasDoxygenHeader": true, "hasDoxygenHeader": true,
"hasMacroNameInMend": true, "hasMacroNameInMend": true,
"hasMacroParentheses": true, "hasMacroParentheses": true,
"ignoreList": [
"sajsbuild/",
"sasjsresults/"
],
"indentationMultiple": 2, "indentationMultiple": 2,
"lowerCaseFileNames": true, "lowerCaseFileNames": true,
"maxLineLength": 80, "maxLineLength": 80,
"noNestedMacros": true, "noNestedMacros": true,
"noSpacesInFileNames": true, "noSpacesInFileNames": true,
"noTabIndentation": true, "noTabIndentation": true,
"noTrailingSpaces": true "noTrailingSpaces": true,
"defaultHeader": "/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/"
} }
``` ```
### SAS Lint Settings ### SAS Lint Settings
#### defaultHeader
This sets the default program header - applies when a SAS program does NOT begin with `/**`. The default header is as follows:
```sas
/**
@file
@brief <Your brief here>
<h4> SAS Macros </h4>
**/
```
The default header is automatically applied when running `sasjs lint fix` in the SASjs CLI, or by hitting "save" when using the SASjs VS Code extension. If creating a new value, use `{lineEnding}` instead of `\n`, eg as follows:
```json
{
"defaultHeader": "/**{lineEnding} @file{lineEnding} @brief Our Company Brief{lineEnding}**/"
}
```
#### noEncodedPasswords #### noEncodedPasswords
This will highlight any rows that contain a `{sas00X}` type password, or `{sasenc}`. These passwords (especially 001 and 002) are NOT secure, and should NEVER be pushed to source control or saved to the filesystem without special permissions applied. This will highlight any rows that contain a `{sas00X}` type password, or `{sasenc}`. These passwords (especially 001 and 002) are NOT secure, and should NEVER be pushed to source control or saved to the filesystem without special permissions applied.
@@ -55,6 +85,9 @@ As per the example [here](https://github.com/sasjs/lint/issues/20), macros defin
* Default: true * Default: true
* Severity: WARNING * Severity: WARNING
#### ignoreList
There may be specific files (or folders) that are not good candidates for linting. Simply list them in this array and they will be ignored. In addition, any files in the project `.gitignore` file will also be ignored.
#### indentationMultiple #### indentationMultiple
This will check each line to ensure that the count of leading spaces can be divided cleanly by this multiple. This will check each line to ensure that the count of leading spaces can be divided cleanly by this multiple.
@@ -70,7 +103,7 @@ On *nix systems, it is imperative that autocall macros are in lowercase. When s
#### maxLineLength #### maxLineLength
Code becomes far more readable when line lengths are short. The most compelling reason for short line lengths is to avoid the need to scroll when performing a side-by-side 'compare' between two files (eg as part of a GIT feature branch review). A longer discussion on optimal code line length can be found [here](https://stackoverflow.com/questions/578059/studies-on-optimal-code-width) Code becomes far more readable when line lengths are short. The most compelling reason for short line lengths is to avoid the need to scroll when performing a side-by-side 'compare' between two files (eg as part of a GIT feature branch review). A longer discussion on optimal code line length can be found [here](https://stackoverflow.com/questions/578059/studies-on-optimal-code-width)
In batch mode, long SAS code lines may also be truncated, causing hard-to-detect errors. In batch mode, long SAS code lines may also be truncated, causing hard-to-detect errors.
We strongly recommend a line length limit, and set the bar at 80. To turn this feature off, set the value to 0. We strongly recommend a line length limit, and set the bar at 80. To turn this feature off, set the value to 0.
@@ -78,7 +111,7 @@ We strongly recommend a line length limit, and set the bar at 80. To turn this
* Severity: WARNING * Severity: WARNING
#### noNestedMacros #### noNestedMacros
Where macros are defined inside other macros, they are recompiled every time the outer macro is invoked. Hence, it is widely considered inefficient, and bad practice, to nest macro definitions. Where macros are defined inside other macros, they are recompiled every time the outer macro is invoked. Hence, it is widely considered inefficient, and bad practice, to nest macro definitions.
* Default: true * Default: true
* Severity: WARNING * Severity: WARNING
@@ -108,7 +141,7 @@ This will highlight lines with trailing spaces. Trailing spaces serve no useful
### Upcoming Linting Rules: ### Upcoming Linting Rules:
* `noTabs` -> does what it says on the tin * `noTabs` -> does what it says on the tin
* `noGremlins` -> identifies all invisible characters, other than spaces / tabs / line endings. If you really need that bell character, use a hex literal! * `noGremlins` -> identifies all invisible characters, other than spaces / tabs / line endings. If you really need that bell character, use a hex literal!
* `lineEndings` -> set a standard line ending, such as LF or CRLF * `lineEndings` -> set a standard line ending, such as LF or CRLF
@@ -118,13 +151,13 @@ A formatter will automatically apply rules when you hit SAVE, which can save a L
We've already implemented the following rules: We've already implemented the following rules:
* Add the macro name to the %mend statement * Add the macro name to the %mend statement
* Add a doxygen header template if none exists * Add a doxygen header template if none exists
* Remove trailing spaces * Remove trailing spaces
We're looking to implement the following rules: We're looking to implement the following rules:
* Change tabs to spaces * Change tabs to spaces
* zap gremlins * zap gremlins
* fix line endings * fix line endings
@@ -145,3 +178,34 @@ The SAS 9 Health Check is a 'plug & play' product, that uses the [SAS 9 REST API
Contact [Allan Bowe](https://www.linkedin.com/in/allanbowe/) for further details. Contact [Allan Bowe](https://www.linkedin.com/in/allanbowe/) for further details.
## Contributors ✨
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/Carus11"><img src="https://avatars.githubusercontent.com/u/4925828?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Carus Kyle</b></sub></a><br /><a href="#ideas-Carus11" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/allanbowe"><img src="https://avatars.githubusercontent.com/u/4420615?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Allan Bowe</b></sub></a><br /><a href="https://github.com/sasjs/lint/commits?author=allanbowe" title="Code">💻</a> <a href="https://github.com/sasjs/lint/commits?author=allanbowe" title="Tests">⚠️</a> <a href="https://github.com/sasjs/lint/pulls?q=is%3Apr+reviewed-by%3Aallanbowe" title="Reviewed Pull Requests">👀</a> <a href="#video-allanbowe" title="Videos">📹</a> <a href="https://github.com/sasjs/lint/commits?author=allanbowe" title="Documentation">📖</a></td>
<td align="center"><a href="https://www.erudicat.com/"><img src="https://avatars.githubusercontent.com/u/25773492?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yury Shkoda</b></sub></a><br /><a href="https://github.com/sasjs/lint/commits?author=YuryShkoda" title="Code">💻</a> <a href="https://github.com/sasjs/lint/commits?author=YuryShkoda" title="Tests">⚠️</a> <a href="#projectManagement-YuryShkoda" title="Project Management">📆</a> <a href="#video-YuryShkoda" title="Videos">📹</a> <a href="https://github.com/sasjs/lint/commits?author=YuryShkoda" title="Documentation">📖</a></td>
<td align="center"><a href="https://krishna-acondy.io/"><img src="https://avatars.githubusercontent.com/u/2980428?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Krishna Acondy</b></sub></a><br /><a href="https://github.com/sasjs/lint/commits?author=krishna-acondy" title="Code">💻</a> <a href="https://github.com/sasjs/lint/commits?author=krishna-acondy" title="Tests">⚠️</a> <a href="https://github.com/sasjs/lint/pulls?q=is%3Apr+reviewed-by%3Akrishna-acondy" title="Reviewed Pull Requests">👀</a> <a href="#infra-krishna-acondy" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#platform-krishna-acondy" title="Packaging/porting to new platform">📦</a> <a href="#maintenance-krishna-acondy" title="Maintenance">🚧</a> <a href="#content-krishna-acondy" title="Content">🖋</a></td>
<td align="center"><a href="https://github.com/saadjutt01"><img src="https://avatars.githubusercontent.com/u/8914650?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Muhammad Saad </b></sub></a><br /><a href="https://github.com/sasjs/lint/commits?author=saadjutt01" title="Code">💻</a> <a href="https://github.com/sasjs/lint/commits?author=saadjutt01" title="Tests">⚠️</a> <a href="https://github.com/sasjs/lint/pulls?q=is%3Apr+reviewed-by%3Asaadjutt01" title="Reviewed Pull Requests">👀</a> <a href="#mentoring-saadjutt01" title="Mentoring">🧑‍🏫</a> <a href="https://github.com/sasjs/lint/commits?author=saadjutt01" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/sabhas"><img src="https://avatars.githubusercontent.com/u/82647447?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sabir Hassan</b></sub></a><br /><a href="https://github.com/sasjs/lint/commits?author=sabhas" title="Code">💻</a> <a href="https://github.com/sasjs/lint/commits?author=sabhas" title="Tests">⚠️</a> <a href="https://github.com/sasjs/lint/pulls?q=is%3Apr+reviewed-by%3Asabhas" title="Reviewed Pull Requests">👀</a> <a href="#ideas-sabhas" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/medjedovicm"><img src="https://avatars.githubusercontent.com/u/18329105?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mihajlo Medjedovic</b></sub></a><br /><a href="https://github.com/sasjs/lint/commits?author=medjedovicm" title="Code">💻</a> <a href="https://github.com/sasjs/lint/commits?author=medjedovicm" title="Tests">⚠️</a> <a href="https://github.com/sasjs/lint/pulls?q=is%3Apr+reviewed-by%3Amedjedovicm" title="Reviewed Pull Requests">👀</a> <a href="#infra-medjedovicm" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/VladislavParhomchik"><img src="https://avatars.githubusercontent.com/u/83717836?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vladislav Parhomchik</b></sub></a><br /><a href="https://github.com/sasjs/lint/commits?author=VladislavParhomchik" title="Tests">⚠️</a> <a href="https://github.com/sasjs/lint/pulls?q=is%3Apr+reviewed-by%3AVladislavParhomchik" title="Reviewed Pull Requests">👀</a></td>
</tr>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

16
checkNodeVersion.js Normal file
View File

@@ -0,0 +1,16 @@
const result = process.versions
if (result && result.node) {
if (parseInt(result.node) < 14) {
console.log(
'\x1b[31m%s\x1b[0m',
`❌ Process failed due to Node Version,\nPlease install and use Node Version >= 14\nYour current Node Version is: ${result.node}`
)
process.exit(1)
}
} else {
console.log(
'\x1b[31m%s\x1b[0m',
'Something went wrong while checking Node version'
)
process.exit(1)
}

6935
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,11 +4,13 @@
"scripts": { "scripts": {
"test": "jest --coverage", "test": "jest --coverage",
"build": "rimraf build && tsc", "build": "rimraf build && tsc",
"preinstall": "node checkNodeVersion",
"prebuild": "node checkNodeVersion",
"prepublishOnly": "cp -r ./build/* . && rm -rf ./build && rm -rf ./src && rm tsconfig.json", "prepublishOnly": "cp -r ./build/* . && rm -rf ./build && rm -rf ./src && rm tsconfig.json",
"postpublish": "git clean -fd", "postpublish": "git clean -fd",
"package:lib": "npm run build && cp ./package.json build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack", "package:lib": "npm run build && cp ./package.json ./checkNodeVersion.js build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack",
"lint:fix": "npx prettier --write '{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}'", "lint:fix": "npx prettier --write \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
"lint": "npx prettier --check '{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}'", "lint": "npx prettier --check \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,json,yml,md,graphql}\"",
"prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true" "prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true"
}, },
"publishConfig": { "publishConfig": {
@@ -39,12 +41,14 @@
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.23", "@types/jest": "^26.0.23",
"@types/node": "^15.12.2", "@types/node": "^15.12.2",
"all-contributors-cli": "^6.20.0",
"jest": "^26.6.3", "jest": "^26.6.3",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"ts-jest": "^26.5.6", "ts-jest": "^26.5.6",
"typescript": "^4.3.2" "typescript": "^4.3.2"
}, },
"dependencies": { "dependencies": {
"@sasjs/utils": "^2.19.0" "@sasjs/utils": "^2.19.0",
"ignore": "^5.2.0"
} }
} }

View File

@@ -7,6 +7,7 @@
"default": { "default": {
"noEncodedPasswords": true, "noEncodedPasswords": true,
"hasDoxygenHeader": true, "hasDoxygenHeader": true,
"defaultHeader": "/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/",
"hasMacroNameInMend": false, "hasMacroNameInMend": false,
"hasMacroParentheses": true, "hasMacroParentheses": true,
"indentationMultiple": 2, "indentationMultiple": 2,
@@ -17,7 +18,8 @@
"noTabIndentation": true, "noTabIndentation": true,
"noTrailingSpaces": true, "noTrailingSpaces": true,
"lineEndings": "lf", "lineEndings": "lf",
"strictMacroDefinition": true "strictMacroDefinition": true,
"ignoreList": ["sajsbuild", "sasjsresults"]
}, },
"examples": [ "examples": [
{ {
@@ -33,7 +35,8 @@
"noNestedMacros": true, "noNestedMacros": true,
"hasMacroParentheses": true, "hasMacroParentheses": true,
"lineEndings": "crlf", "lineEndings": "crlf",
"strictMacroDefinition": true "strictMacroDefinition": true,
"ignoreList": ["sajsbuild", "sasjsresults"]
} }
], ],
"properties": { "properties": {
@@ -53,6 +56,14 @@
"default": true, "default": true,
"examples": [true, false] "examples": [true, false]
}, },
"defaultHeader": {
"$id": "#/properties/defaultHeader",
"type": "boolean",
"title": "defaultHeader",
"description": "This sets the default program header - applies when a SAS program does NOT begin with `/**`.",
"default": "/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/",
"examples": []
},
"hasMacroNameInMend": { "hasMacroNameInMend": {
"$id": "#/properties/hasMacroNameInMend", "$id": "#/properties/hasMacroNameInMend",
"type": "boolean", "type": "boolean",
@@ -140,6 +151,14 @@
"description": "Enforces Macro Definition syntax. Shows a warning when incorrect syntax is used.", "description": "Enforces Macro Definition syntax. Shows a warning when incorrect syntax is used.",
"default": true, "default": true,
"examples": [true, false] "examples": [true, false]
},
"ignoreList": {
"$id": "#/properties/ignoreList",
"type": "array",
"title": "ignoreList",
"description": "An array of paths or path patterns to ignore when linting. Any files or matching patterns in the .gitignore file will also be ignored.",
"default": ["sasjsbuild/", "sasjsresults/"],
"examples": ["sasjs/tests", "tmp/scratch.sas"]
} }
} }
} }

View File

@@ -1,7 +1,8 @@
import { LintConfig } from '../types'
import { getLintConfig } from '../utils' import { getLintConfig } from '../utils'
import { processText } from './shared' import { processText } from './shared'
export const formatText = async (text: string) => { export const formatText = async (text: string, configuration?: LintConfig) => {
const config = await getLintConfig() const config = configuration || (await getLintConfig())
return processText(text, config) return processText(text, config)
} }

View File

@@ -19,7 +19,7 @@ const processContent = (config: LintConfig, content: string): string => {
config.fileLintRules config.fileLintRules
.filter((r) => !!r.fix) .filter((r) => !!r.fix)
.forEach((rule) => { .forEach((rule) => {
processedContent = rule.fix!(processedContent) processedContent = rule.fix!(processedContent, config)
}) })
return processedContent return processedContent
@@ -30,7 +30,7 @@ export const processLine = (config: LintConfig, line: string): string => {
config.lineLintRules config.lineLintRules
.filter((r) => !!r.fix) .filter((r) => !!r.fix)
.forEach((rule) => { .forEach((rule) => {
processedLine = rule.fix!(line) processedLine = rule.fix!(line, config)
}) })
return processedLine return processedLine

View File

@@ -1,18 +1,20 @@
import { readFile } from '@sasjs/utils/file' import { readFile } from '@sasjs/utils/file'
import { LintConfig } from '../types/LintConfig' import { Diagnostic, LintConfig } from '../types'
import { getLintConfig } from '../utils/getLintConfig' import { getLintConfig, isIgnored } from '../utils'
import { processFile, processText } from './shared' import { processFile, processText } from './shared'
/** /**
* Analyses and produces a set of diagnostics for the file at the given path. * Analyses and produces a set of diagnostics for the file at the given path.
* @param {string} filePath - the path to the file to be linted. * @param {string} filePath - the path to the file to be linted.
* @param {LintConfig} configuration - an optional configuration. When not passed in, this is read from the .sasjslint file. * @param {LintConfig} configuration - an optional configuration. When not passed in, this is read from the .sasjslint file.
* @returns {Diagnostic[]} array of diagnostic objects, each containing a warning, line number and column number. * @returns {Promise<Diagnostic[]>} array of diagnostic objects, each containing a warning, line number and column number.
*/ */
export const lintFile = async ( export const lintFile = async (
filePath: string, filePath: string,
configuration?: LintConfig configuration?: LintConfig
) => { ): Promise<Diagnostic[]> => {
if (await isIgnored(filePath)) return []
const config = configuration || (await getLintConfig()) const config = configuration || (await getLintConfig())
const text = await readFile(filePath) const text = await readFile(filePath)

View File

@@ -1,10 +1,7 @@
import { listSubFoldersInFolder } from '@sasjs/utils/file' import { listSubFoldersInFolder } from '@sasjs/utils/file'
import path from 'path' import path from 'path'
import { Diagnostic } from '../types/Diagnostic' import { Diagnostic, LintConfig } from '../types'
import { LintConfig } from '../types/LintConfig' import { asyncForEach, getLintConfig, isIgnored, listSasFiles } from '../utils'
import { asyncForEach } from '../utils/asyncForEach'
import { getLintConfig } from '../utils/getLintConfig'
import { listSasFiles } from '../utils/listSasFiles'
import { lintFile } from './lintFile' import { lintFile } from './lintFile'
const excludeFolders = [ const excludeFolders = [
@@ -28,6 +25,9 @@ export const lintFolder = async (
) => { ) => {
const config = configuration || (await getLintConfig()) const config = configuration || (await getLintConfig())
let diagnostics: Map<string, Diagnostic[]> = new Map<string, Diagnostic[]>() let diagnostics: Map<string, Diagnostic[]> = new Map<string, Diagnostic[]>()
if (await isIgnored(folderPath)) return diagnostics
const fileNames = await listSasFiles(folderPath) const fileNames = await listSasFiles(folderPath)
await asyncForEach(fileNames, async (fileName) => { await asyncForEach(fileNames, async (fileName) => {
const filePath = path.join(folderPath, fileName) const filePath = path.join(folderPath, fileName)
@@ -39,10 +39,8 @@ export const lintFolder = async (
) )
await asyncForEach(subFolders, async (subFolder) => { await asyncForEach(subFolders, async (subFolder) => {
const subFolderDiagnostics = await lintFolder( const subFolderPath = path.join(folderPath, subFolder)
path.join(folderPath, subFolder), const subFolderDiagnostics = await lintFolder(subFolderPath, config)
config
)
diagnostics = new Map([...diagnostics, ...subFolderDiagnostics]) diagnostics = new Map([...diagnostics, ...subFolderDiagnostics])
}) })

View File

@@ -3,8 +3,7 @@ import { LineEndings } from '../../types/LineEndings'
import { FileLintRule } from '../../types/LintRule' import { FileLintRule } from '../../types/LintRule'
import { LintRuleType } from '../../types/LintRuleType' import { LintRuleType } from '../../types/LintRuleType'
import { Severity } from '../../types/Severity' import { Severity } from '../../types/Severity'
import { DefaultLintConfiguration } from '../../utils/getLintConfig'
const DoxygenHeader = `/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/`
const name = 'hasDoxygenHeader' const name = 'hasDoxygenHeader'
const description = const description =
@@ -61,10 +60,11 @@ const fix = (value: string, config?: LintConfig): string => {
} else if (result[0].message == messageForSingleAsterisk) } else if (result[0].message == messageForSingleAsterisk)
return value.replace('/*', '/**') return value.replace('/*', '/**')
config = config || new LintConfig(DefaultLintConfiguration)
const lineEndingConfig = config?.lineEndings || LineEndings.LF const lineEndingConfig = config?.lineEndings || LineEndings.LF
const lineEnding = lineEndingConfig === LineEndings.LF ? '\n' : '\r\n' const lineEnding = lineEndingConfig === LineEndings.LF ? '\n' : '\r\n'
return `${DoxygenHeader.replace( return `${config?.defaultHeader.replace(
/{lineEnding}/g, /{lineEnding}/g,
lineEnding lineEnding
)}${lineEnding}${value}` )}${lineEnding}${value}`

View File

@@ -16,6 +16,7 @@ import {
import { lowerCaseFileNames, noSpacesInFileNames } from '../rules/path' import { lowerCaseFileNames, noSpacesInFileNames } from '../rules/path'
import { LineEndings } from './LineEndings' import { LineEndings } from './LineEndings'
import { FileLintRule, LineLintRule, PathLintRule } from './LintRule' import { FileLintRule, LineLintRule, PathLintRule } from './LintRule'
import { getDefaultHeader } from '../utils'
/** /**
* LintConfig is the logical representation of the .sasjslint file. * LintConfig is the logical representation of the .sasjslint file.
@@ -25,14 +26,30 @@ import { FileLintRule, LineLintRule, PathLintRule } from './LintRule'
* More types of rules, when available, will be added here. * More types of rules, when available, will be added here.
*/ */
export class LintConfig { export class LintConfig {
readonly ignoreList: string[] = []
readonly lineLintRules: LineLintRule[] = [] readonly lineLintRules: LineLintRule[] = []
readonly fileLintRules: FileLintRule[] = [] readonly fileLintRules: FileLintRule[] = []
readonly pathLintRules: PathLintRule[] = [] readonly pathLintRules: PathLintRule[] = []
readonly maxLineLength: number = 80 readonly maxLineLength: number = 80
readonly indentationMultiple: number = 2 readonly indentationMultiple: number = 2
readonly lineEndings: LineEndings = LineEndings.LF readonly lineEndings: LineEndings = LineEndings.LF
readonly defaultHeader: string = getDefaultHeader()
constructor(json?: any) { constructor(json?: any) {
if (json?.ignoreList) {
if (Array.isArray(json.ignoreList)) {
json.ignoreList.forEach((item: any) => {
if (typeof item === 'string') this.ignoreList.push(item)
else
throw new Error(
`Property "ignoreList" has invalid type of values. It can contain only strings.`
)
})
} else {
throw new Error(`Property "ignoreList" can only be an array of strings`)
}
}
if (json?.noTrailingSpaces) { if (json?.noTrailingSpaces) {
this.lineLintRules.push(noTrailingSpaces) this.lineLintRules.push(noTrailingSpaces)
} }
@@ -72,6 +89,10 @@ export class LintConfig {
this.fileLintRules.push(hasDoxygenHeader) this.fileLintRules.push(hasDoxygenHeader)
} }
if (json?.defaultHeader) {
this.defaultHeader = json.defaultHeader
}
if (json?.noSpacesInFileNames) { if (json?.noSpacesInFileNames) {
this.pathLintRules.push(noSpacesInFileNames) this.pathLintRules.push(noSpacesInFileNames)
} }

View File

@@ -3,6 +3,9 @@ import { LintConfig } from '../types/LintConfig'
import { readFile } from '@sasjs/utils/file' import { readFile } from '@sasjs/utils/file'
import { getProjectRoot } from './getProjectRoot' import { getProjectRoot } from './getProjectRoot'
export const getDefaultHeader = () =>
`/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/`
/** /**
* Default configuration that is used when a .sasjslint file is not found * Default configuration that is used when a .sasjslint file is not found
*/ */
@@ -18,7 +21,8 @@ export const DefaultLintConfiguration = {
hasMacroNameInMend: true, hasMacroNameInMend: true,
noNestedMacros: true, noNestedMacros: true,
hasMacroParentheses: true, hasMacroParentheses: true,
strictMacroDefinition: true strictMacroDefinition: true,
defaultHeader: getDefaultHeader()
} }
/** /**

View File

@@ -1,4 +1,6 @@
export * from './asyncForEach'
export * from './getLintConfig' export * from './getLintConfig'
export * from './getProjectRoot' export * from './getProjectRoot'
export * from './isIgnored'
export * from './listSasFiles' export * from './listSasFiles'
export * from './splitText' export * from './splitText'

119
src/utils/isIgnored.spec.ts Normal file
View File

@@ -0,0 +1,119 @@
import path from 'path'
import * as fileModule from '@sasjs/utils/file'
import * as getLintConfigModule from './getLintConfig'
import { getProjectRoot, DefaultLintConfiguration, isIgnored } from '.'
import { LintConfig } from '../types'
describe('isIgnored', () => {
it('should return true if provided path matches the patterns from .gitignore', async () => {
jest
.spyOn(getLintConfigModule, 'getLintConfig')
.mockImplementationOnce(
async () => new LintConfig(DefaultLintConfiguration)
)
jest
.spyOn(fileModule, 'fileExists')
.mockImplementationOnce(async () => true)
jest
.spyOn(fileModule, 'readFile')
.mockImplementationOnce(async () => 'sasjs')
const projectRoot = await getProjectRoot()
const pathToTest = path.join(projectRoot, 'sasjs')
const ignored = await isIgnored(pathToTest)
expect(ignored).toBeTruthy()
})
it('should return true if top level path of provided path is in .gitignore', async () => {
jest
.spyOn(getLintConfigModule, 'getLintConfig')
.mockImplementationOnce(
async () => new LintConfig(DefaultLintConfiguration)
)
jest
.spyOn(fileModule, 'fileExists')
.mockImplementationOnce(async () => true)
jest
.spyOn(fileModule, 'readFile')
.mockImplementationOnce(async () => 'sasjs/common')
const projectRoot = await getProjectRoot()
const pathToTest = path.join(projectRoot, 'sasjs/common/init/init.sas')
const ignored = await isIgnored(pathToTest)
expect(ignored).toBeTruthy()
})
it('should return true if provided path matches any pattern from ignoreList (.sasjslint)', async () => {
jest
.spyOn(fileModule, 'fileExists')
.mockImplementationOnce(async () => false)
const projectRoot = await getProjectRoot()
const pathToTest = path.join(projectRoot, 'sasjs')
const ignored = await isIgnored(
pathToTest,
new LintConfig({
...DefaultLintConfiguration,
ignoreList: ['sasjs']
})
)
expect(ignored).toBeTruthy()
})
it('should return true if top level path of provided path is in ignoreList (.sasjslint)', async () => {
jest
.spyOn(fileModule, 'fileExists')
.mockImplementationOnce(async () => false)
const projectRoot = await getProjectRoot()
const pathToTest = path.join(projectRoot, 'sasjs/common/init/init.sas')
const ignored = await isIgnored(
pathToTest,
new LintConfig({
...DefaultLintConfiguration,
ignoreList: ['sasjs']
})
)
expect(ignored).toBeTruthy()
})
it('should return false if provided path does not matches any pattern from .gitignore and ignoreList (.sasjslint)', async () => {
jest
.spyOn(fileModule, 'fileExists')
.mockImplementationOnce(async () => true)
jest.spyOn(fileModule, 'readFile').mockImplementationOnce(async () => '')
const projectRoot = await getProjectRoot()
const pathToTest = path.join(projectRoot, 'sasjs')
const ignored = await isIgnored(
pathToTest,
new LintConfig(DefaultLintConfiguration)
)
expect(ignored).toBeFalsy()
})
it('should return false if provided path is equal to projectRoot', async () => {
const projectRoot = await getProjectRoot()
const pathToTest = path.join(projectRoot, '')
const ignored = await isIgnored(
pathToTest,
new LintConfig(DefaultLintConfiguration)
)
expect(ignored).toBeFalsy()
})
})

34
src/utils/isIgnored.ts Normal file
View File

@@ -0,0 +1,34 @@
import { fileExists, readFile } from '@sasjs/utils'
import path from 'path'
import ignore from 'ignore'
import { getLintConfig, getProjectRoot } from '.'
import { LintConfig } from '../types'
/**
* A function to check if file/folder path matches any pattern from .gitignore or ignoreList (.sasjsLint)
*
* @param {string} fPath - absolute path of file or folder
* @returns {Promise<boolean>} true if path matches the patterns from .gitignore file otherwise false
*/
export const isIgnored = async (
fPath: string,
configuration?: LintConfig
): Promise<boolean> => {
const config = configuration || (await getLintConfig())
const projectRoot = await getProjectRoot()
const gitIgnoreFilePath = path.join(projectRoot, '.gitignore')
const rootPath = projectRoot + path.sep
const relativePath = fPath.replace(rootPath, '')
if (fPath === projectRoot) return false
let gitIgnoreFileContent = ''
if (await fileExists(gitIgnoreFilePath))
gitIgnoreFileContent = await readFile(gitIgnoreFilePath)
return ignore()
.add(gitIgnoreFileContent)
.add(config.ignoreList)
.ignores(relativePath)
}