mirror of
https://github.com/sasjs/lint.git
synced 2025-12-10 17:34:36 +00:00
Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9623828fc8 | ||
| debeff7929 | |||
| c210699954 | |||
|
|
cee30d0030 | ||
|
|
66bcfb2962 | ||
| a3bade0a5a | |||
|
|
1d821db934 | ||
|
|
f3858d33fc | ||
|
|
0d9e17f072 | ||
|
|
421513850c | ||
|
|
5ce33ab66c | ||
| 5290339c9e | |||
| 4772aa70c6 | |||
| 623d4df79d | |||
| 40aea383b7 | |||
| e1bcf5b06b | |||
|
|
51c6dd7c1a | ||
|
|
6e0f1c4167 | ||
|
|
5f905c88d9 | ||
|
|
ac95546910 | ||
|
|
7a00cc5f2d | ||
|
|
8950c97f84 | ||
|
|
49b124e5b8 | ||
|
|
1b15938477 | ||
|
|
f6fa20af1c | ||
|
|
cf5a0700f2 | ||
|
|
0dca988438 | ||
|
|
00dafa5bc0 | ||
|
|
39bffd39a4 | ||
|
|
ec95a798b7 | ||
|
|
acfc559f25 | ||
|
|
d204b5bac6 | ||
|
|
5602063879 | ||
|
|
31cee0af91 | ||
|
|
cd91780cf5 | ||
|
|
108bbfbaa5 | ||
|
|
f2edf1176a | ||
|
|
b5d446adc9 | ||
|
|
cc221bccc3 | ||
|
|
f38bcec582 | ||
|
|
75ab01cccf | ||
|
|
7ccb122744 | ||
|
|
884480d3df | ||
|
|
1b940497aa | ||
|
|
94d9d246eb | ||
|
|
95502647e8 | ||
|
|
be9d5b8e68 | ||
|
|
c2d368327b | ||
|
|
94a693e57d | ||
|
|
fec3372f92 | ||
|
|
d5b38373d4 | ||
|
|
21114e0a6f | ||
|
|
b52b3ac42f | ||
|
|
7f4c389468 | ||
|
|
1fd4cd7ddc |
113
.all-contributorsrc
Normal file
113
.all-contributorsrc
Normal 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
54
.github/CONTRIBUTING.md
vendored
Normal 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.
|
||||||
10
.github/dependabot.yml
vendored
10
.github/dependabot.yml
vendored
@@ -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
|
||||||
|
|||||||
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@@ -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
8
.gitpod.yml
Normal 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
|
||||||
|
|
||||||
|
|
||||||
91
README.md
91
README.md
@@ -1,4 +1,9 @@
|
|||||||
[](https://dependabot.com)
|
[](/LICENSE)
|
||||||
|

|
||||||
|
[](https://github.com/sasjs/lint/issues?q=is%3Aissue+is%3Aclosed)
|
||||||
|
[](https://github.com/sasjs/lint/issues)
|
||||||
|

|
||||||
|
[](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.
|
||||||
@@ -44,7 +74,7 @@ The SASjs framework recommends the use of Doxygen headers for describing all typ
|
|||||||
* Severity: WARNING
|
* Severity: WARNING
|
||||||
|
|
||||||
#### hasMacroNameInMend
|
#### hasMacroNameInMend
|
||||||
The addition of the macro name in the `%mend` statement is optional, but can approve readability in large programs. A discussion on this topic can be found [here](https://www.linkedin.com/posts/allanbowe_sas-sasapps-sasjs-activity-6783413360781266945-1-7m). The default setting will be the result of a popular vote by around 300 people.
|
The addition of the macro name in the `%mend` statement is optional, but can approve readability in large programs. A discussion on this topic can be found [here](https://www.linkedin.com/posts/allanbowe_sas-sasapps-sasjs-activity-6783413360781266945-1-7m). The default setting was the result of a poll with over 300 votes.
|
||||||
|
|
||||||
* Default: true
|
* Default: true
|
||||||
* Severity: WARNING
|
* Severity: WARNING
|
||||||
@@ -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.
|
||||||
|
|
||||||
@@ -72,13 +105,13 @@ Code becomes far more readable when line lengths are short. The most compelling
|
|||||||
|
|
||||||
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.
|
||||||
|
|
||||||
For this reason we strongly recommend a line length limit, and we 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.
|
||||||
|
|
||||||
* Default: 80
|
* Default: 80
|
||||||
* Severity: WARNING
|
* Severity: WARNING
|
||||||
|
|
||||||
#### noNestedMacros
|
#### noNestedMacros
|
||||||
Where macros are defined inside other macros, they are recompiled every time the outer maro 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
|
||||||
@@ -95,7 +128,7 @@ In addition, when such files are used in URLs, they are often padded with a mess
|
|||||||
* Severity: WARNING
|
* Severity: WARNING
|
||||||
|
|
||||||
#### noTabIndentation
|
#### noTabIndentation
|
||||||
Whilst there are some arguments for using tabs to indent (such as the ability to set your own indentation width, and to save on characters) there are many, many, many developers who think otherwise. We're in that camp. Sorry (not sorry).
|
Whilst there are some arguments for using tabs to indent (such as the ability to set your own indentation width, and to reduce character count) there are many, many, many developers who think otherwise. We're in that camp. Sorry (not sorry).
|
||||||
|
|
||||||
* Default: true
|
* Default: true
|
||||||
* Severity: WARNING
|
* Severity: WARNING
|
||||||
@@ -116,14 +149,19 @@ This will highlight lines with trailing spaces. Trailing spaces serve no useful
|
|||||||
|
|
||||||
A formatter will automatically apply rules when you hit SAVE, which can save a LOT of time.
|
A formatter will automatically apply rules when you hit SAVE, which can save a LOT of time.
|
||||||
|
|
||||||
We're looking to implement the following rules:
|
We've already implemented the following rules:
|
||||||
|
|
||||||
* Remove trailing spaces
|
|
||||||
* Change tabs to spaces
|
|
||||||
* 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
|
||||||
|
|
||||||
Later we will investigate some harder stuff, such as automatic indentation and code layout
|
We're looking to implement the following rules:
|
||||||
|
|
||||||
|
* Change tabs to spaces
|
||||||
|
* zap gremlins
|
||||||
|
* fix line endings
|
||||||
|
|
||||||
|
We are also investigating some harder stuff, such as automatic indentation and code layout
|
||||||
|
|
||||||
## Sponsorship & Contributions
|
## Sponsorship & Contributions
|
||||||
|
|
||||||
@@ -133,10 +171,41 @@ Contact [Allan Bowe](https://www.linkedin.com/in/allanbowe/) for further details
|
|||||||
|
|
||||||
## SAS 9 Health check
|
## SAS 9 Health check
|
||||||
|
|
||||||
The SASjs Linter (and formatter) is a great way to de-risk and accelerate the delivery of SAS code into production environments. However, code is just one part of a SAS estate. If you are running SAS 9, you may be interested to know what 'gremlins' are lurking in your system. Maybe you are preparing for a migration. Maybe you are preparing to hand over the control of your environment. Either way, an assessment of your existing system would put minds at rest and pro-actively identify trouble spots.
|
The SASjs Linter (and formatter) is a great way to de-risk and accelerate the delivery of SAS code into production environments. However, code is just one part of a SAS estate. If you are running SAS 9, you may be interested to know what 'gremlins' are lurking in your SAS 9 system. Maybe you are preparing for a migration. Maybe you are preparing to hand over the control of your environment. Either way, an assessment of your existing system would put minds at rest and pro-actively identify trouble spots.
|
||||||
|
|
||||||
The SAS 9 Health Check is a 'plug & play' product, that uses the [SAS 9 REST API](https://sas9api.io) to run hundreds of metadata and system checks to identify common problems. The checks are non-invasive, and becuase it is a client app, there is NOTHING TO INSTALL on your SAS server. We offer this assessment for a low fixed fee, and if you engage our (competitively priced) services to address the issues we highlight, then the assessment is free.
|
The SAS 9 Health Check is a 'plug & play' product, that uses the [SAS 9 REST API](https://sas9api.io) to run hundreds of metadata and system checks to identify common problems. The checks are non-invasive, and becuase it is a client app, there is NOTHING TO INSTALL on your SAS server. We offer this assessment for a low fixed fee, and if you engage our (competitively priced) services to address the issues we highlight, then the assessment is free.
|
||||||
|
|
||||||
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 -->
|
||||||
|
[](#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
16
checkNodeVersion.js
Normal 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)
|
||||||
|
}
|
||||||
7000
package-lock.json
generated
7000
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@@ -4,12 +4,14 @@
|
|||||||
"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}\"",
|
||||||
"postinstall": "[ -d .git ] && git config core.hooksPath ./.git-hooks || true"
|
"prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
@@ -38,13 +40,15 @@
|
|||||||
"homepage": "https://github.com/sasjs/lint#readme",
|
"homepage": "https://github.com/sasjs/lint#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.23",
|
"@types/jest": "^26.0.23",
|
||||||
"@types/node": "^15.0.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.2.4"
|
"typescript": "^4.3.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/utils": "^2.12.0"
|
"@sasjs/utils": "^2.19.0",
|
||||||
|
"ignore": "^5.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,32 @@ describe('hasDoxygenHeader - test', () => {
|
|||||||
expect(hasDoxygenHeader.test(content)).toEqual([])
|
expect(hasDoxygenHeader.test(content)).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should return an empty array when the file starts with a doxygen header', () => {
|
||||||
|
const content = `
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
@file
|
||||||
|
@brief Returns an unused libref
|
||||||
|
*/
|
||||||
|
|
||||||
|
%macro mf_getuniquelibref(prefix=mclib,maxtries=1000);
|
||||||
|
%local x libref;
|
||||||
|
%let x={SAS002};
|
||||||
|
%do x=0 %to &maxtries;`
|
||||||
|
|
||||||
|
expect(hasDoxygenHeader.test(content)).toEqual([
|
||||||
|
{
|
||||||
|
message:
|
||||||
|
'File not following Doxygen header style, use double asterisks',
|
||||||
|
lineNumber: 4,
|
||||||
|
startColumnNumber: 1,
|
||||||
|
endColumnNumber: 1,
|
||||||
|
severity: Severity.Warning
|
||||||
|
}
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
it('should return an array with a single diagnostic when the file has no header', () => {
|
it('should return an array with a single diagnostic when the file has no header', () => {
|
||||||
const content = `
|
const content = `
|
||||||
%macro mf_getuniquelibref(prefix=mclib,maxtries=1000);
|
%macro mf_getuniquelibref(prefix=mclib,maxtries=1000);
|
||||||
@@ -86,7 +112,33 @@ describe('hasDoxygenHeader - fix', () => {
|
|||||||
expect(hasDoxygenHeader.fix!(content)).toEqual(content)
|
expect(hasDoxygenHeader.fix!(content)).toEqual(content)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should should add a doxygen header if not present', () => {
|
it('should update single asterisks to double if a doxygen header is already present', () => {
|
||||||
|
const contentOriginal = `
|
||||||
|
/*
|
||||||
|
@file
|
||||||
|
@brief Returns an unused libref
|
||||||
|
*/
|
||||||
|
|
||||||
|
%macro mf_getuniquelibref(prefix=mclib,maxtries=1000);
|
||||||
|
%local x libref;
|
||||||
|
%let x={SAS002};
|
||||||
|
%do x=0 %to &maxtries;`
|
||||||
|
|
||||||
|
const contentExpected = `
|
||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Returns an unused libref
|
||||||
|
*/
|
||||||
|
|
||||||
|
%macro mf_getuniquelibref(prefix=mclib,maxtries=1000);
|
||||||
|
%local x libref;
|
||||||
|
%let x={SAS002};
|
||||||
|
%do x=0 %to &maxtries;`
|
||||||
|
|
||||||
|
expect(hasDoxygenHeader.fix!(contentOriginal)).toEqual(contentExpected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should add a doxygen header if not present', () => {
|
||||||
const content = `%macro mf_getuniquelibref(prefix=mclib,maxtries=1000);
|
const content = `%macro mf_getuniquelibref(prefix=mclib,maxtries=1000);
|
||||||
%local x libref;
|
%local x libref;
|
||||||
%let x={SAS002};
|
%let x={SAS002};
|
||||||
|
|||||||
@@ -3,17 +3,34 @@ 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 =
|
||||||
'Enforce the presence of a Doxygen header at the start of each file.'
|
'Enforce the presence of a Doxygen header at the start of each file.'
|
||||||
const message = 'File missing Doxygen header'
|
const message = 'File missing Doxygen header'
|
||||||
const test = (value: string) => {
|
const messageForSingleAsterisk =
|
||||||
|
'File not following Doxygen header style, use double asterisks'
|
||||||
|
const test = (value: string, config?: LintConfig) => {
|
||||||
|
const lineEnding = config?.lineEndings === LineEndings.CRLF ? '\r\n' : '\n'
|
||||||
try {
|
try {
|
||||||
const hasFileHeader = value.trimStart().startsWith('/*')
|
const hasFileHeader = value.trimStart().startsWith('/**')
|
||||||
if (hasFileHeader) return []
|
if (hasFileHeader) return []
|
||||||
|
|
||||||
|
const hasFileHeaderWithSingleAsterisk = value.trimStart().startsWith('/*')
|
||||||
|
if (hasFileHeaderWithSingleAsterisk)
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
message: messageForSingleAsterisk,
|
||||||
|
lineNumber:
|
||||||
|
(value.split('/*')![0]!.match(new RegExp(lineEnding, 'g')) ?? [])
|
||||||
|
.length + 1,
|
||||||
|
startColumnNumber: 1,
|
||||||
|
endColumnNumber: 1,
|
||||||
|
severity: Severity.Warning
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
message,
|
message,
|
||||||
@@ -37,13 +54,17 @@ const test = (value: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fix = (value: string, config?: LintConfig): string => {
|
const fix = (value: string, config?: LintConfig): string => {
|
||||||
if (test(value).length === 0) {
|
const result = test(value, config)
|
||||||
|
if (result.length === 0) {
|
||||||
return value
|
return value
|
||||||
}
|
} else if (result[0].message == messageForSingleAsterisk)
|
||||||
|
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}`
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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
119
src/utils/isIgnored.spec.ts
Normal 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
34
src/utils/isIgnored.ts
Normal 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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user