mirror of
https://github.com/sasjs/lint.git
synced 2026-01-17 17:20:05 +00:00
Merge pull request #125 from sasjs/improve-docs-ci
chore(*): add contribution guidelines, add node version check
This commit is contained in:
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
|
||||||
|
|||||||
54
CONTRIBUTING.md
Normal file
54
CONTRIBUTING.md
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.
|
||||||
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)
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
"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 build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack",
|
||||||
|
|||||||
Reference in New Issue
Block a user