From cd91780cf56dce9b8be392a390e8eb4ad409f70d Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 08:41:35 +0100 Subject: [PATCH 01/13] chore(doc): add contribution guidelines --- CONTRIBUTING.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0b4208a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,52 @@ +# 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. From 31cee0af913c2ced98d1a38f742c3dfb8baddbcc Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 08:41:58 +0100 Subject: [PATCH 02/13] chore(ci): add node version check --- .github/workflows/build.yml | 2 +- checkNodeVersion.js | 16 ++++++++++++++++ package.json | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 checkNodeVersion.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8960e9c..b0452a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - node-version: [12.x] + node-version: [14.17.5] steps: - uses: actions/checkout@v2 diff --git a/checkNodeVersion.js b/checkNodeVersion.js new file mode 100644 index 0000000..ac3d46d --- /dev/null +++ b/checkNodeVersion.js @@ -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) +} diff --git a/package.json b/package.json index ddd7825..02c70e9 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "scripts": { "test": "jest --coverage", "build": "rimraf build && tsc", + "preinstall": "node checkNodeVersion", + "prebuild": "node checkNodeVersion", "prepublishOnly": "cp -r ./build/* . && rm -rf ./build && rm -rf ./src && rm tsconfig.json", "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", From 56020638797f258b3c5b3cf06427ea69018004a2 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 08:46:23 +0100 Subject: [PATCH 03/13] chore(ci): try lts syntax --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b0452a9..3ec5d76 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - node-version: [14.17.5] + node-version: lts/* steps: - uses: actions/checkout@v2 From d204b5bac655a242307a6653b2242abd019c5d28 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 08:49:03 +0100 Subject: [PATCH 04/13] chore(ci): try LTS version --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ec5d76..1af24bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - node-version: lts/* + node-version: [lts/*] steps: - uses: actions/checkout@v2 From acfc559f25f33323e0e501c31507002bbdcdef74 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 08:51:29 +0100 Subject: [PATCH 05/13] chore(ci): use LTS version --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1af24bd..eb3a1ba 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - node-version: [lts/*] + node-version: [lts/fermium] steps: - uses: actions/checkout@v2 From ec95a798b79e574cc973e31136d5ab2f11e6c271 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 08:54:34 +0100 Subject: [PATCH 06/13] chore(ci): use LTS version --- .github/workflows/build.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eb3a1ba..c0e21fe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,16 +11,12 @@ jobs: build: runs-on: ubuntu-latest - strategy: - matrix: - node-version: [lts/fermium] - steps: - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} + - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: ${{ matrix.node-version }} + node-version: lts/fermium - name: Install Dependencies run: npm ci - name: Check Code Style From 39bffd39a40c104c7b071421f00fefa1a5f759df Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 08:56:43 +0100 Subject: [PATCH 07/13] chore(ci): use latest LTS --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0e21fe..e1e0842 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: lts/fermium + node-version: lts/* - name: Install Dependencies run: npm ci - name: Check Code Style From 00dafa5bc0d2239f28445368a2933ab7f03a4c64 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 09:03:41 +0100 Subject: [PATCH 08/13] chore(ci): try LTS version --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e1e0842..f23f4ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: lts/* + node-version: 'lts/*' - name: Install Dependencies run: npm ci - name: Check Code Style From 0dca988438a171b9dd32f3d44ccfd36485fb8819 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 09:05:24 +0100 Subject: [PATCH 09/13] chore(ci): try LTS version --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f23f4ce..c0e21fe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: 'lts/*' + node-version: lts/fermium - name: Install Dependencies run: npm ci - name: Check Code Style From cf5a0700f2aea2d8464bda68f8fe918322228dbf Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 09:06:28 +0100 Subject: [PATCH 10/13] chore(ci): use LTS --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0e21fe..b765b0e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,9 +14,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v2 with: - node-version: lts/fermium + node-version: lts/* - name: Install Dependencies run: npm ci - name: Check Code Style From f6fa20af1c08361276783399aaf284a6271b24bc Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 09:07:43 +0100 Subject: [PATCH 11/13] chore(ci): use LTS version --- .github/workflows/build.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b765b0e..254dd09 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,12 +11,16 @@ jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + node-version: [lts/*] + steps: - uses: actions/checkout@v2 - - name: Set up Node.js + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v2 with: - node-version: lts/* + node-version: ${{ matrix.node-version }} - name: Install Dependencies run: npm ci - name: Check Code Style From 1b15938477a0a9825906e82e0fb069cba4dcd397 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Mon, 13 Sep 2021 09:08:38 +0100 Subject: [PATCH 12/13] chore(ci): cache dependencies --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 254dd09..6c24e62 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,6 +21,7 @@ jobs: uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} + cache: npm - name: Install Dependencies run: npm ci - name: Check Code Style From 49b124e5b80851e6de63db9cc9827230c5ac35c7 Mon Sep 17 00:00:00 2001 From: Allan Bowe <4420615+allanbowe@users.noreply.github.com> Date: Mon, 13 Sep 2021 11:50:01 +0300 Subject: [PATCH 13/13] Update CONTRIBUTING.md --- CONTRIBUTING.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b4208a..a340f2f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,8 +6,10 @@ Please fill in the pull request template and make sure that your code changes ar ## 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 + +* 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.