From 4cd8191bbabb205e7ce91e1b4cde010ab0248d25 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 8 May 2024 14:42:28 -0700 Subject: [PATCH] Release v1.0.7 (#21) - update lint dep - populate [files] in package.json. - dep: eslint-plugin-haraka -> @haraka/eslint-config - doc(CONTRIBUTORS): added - prettier --- .codeclimate.yml | 13 ++-- .eslintrc.yaml | 8 +-- .github/dependabot.yml | 6 +- .github/workflows/ci.yml | 31 ++------ .github/workflows/codeql.yml | 4 +- .github/workflows/publish.yml | 2 +- .prettierrc | 2 + .release | 2 +- CHANGELOG.md | 11 +++ CONTRIBUTORS.md | 8 +++ README.md | 10 ++- index.js | 98 +++++++++++++------------- package.json | 20 ++++-- test/index.js | 129 +++++++++++++++++----------------- 14 files changed, 176 insertions(+), 168 deletions(-) create mode 100644 .prettierrc create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTORS.md diff --git a/.codeclimate.yml b/.codeclimate.yml index 0e443ca..4518db5 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,10 +1,15 @@ engines: eslint: enabled: true - channel: "eslint-8" + channel: 'eslint-8' config: - config: ".eslintrc.yaml" + config: '.eslintrc.yaml' ratings: - paths: - - "**.js" + paths: + - '**.js' + +checks: + method-complexity: + config: + threshold: 10 \ No newline at end of file diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 0587dec..035a400 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -2,10 +2,6 @@ env: node: true es6: true mocha: true - es2020: true + es2022: true - -plugins: - - haraka - -extends: [ "eslint:recommended", "plugin:haraka/recommended" ] +extends: ['@haraka'] diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0449e4a..d450132 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,9 +2,9 @@ version: 2 updates: - - package-ecosystem: "npm" - directory: "/" + - package-ecosystem: 'npm' + directory: '/' schedule: - interval: "weekly" + interval: 'weekly' allow: - dependency-type: production diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae87d28..77e274d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,11 @@ name: CI -on: [ push, pull_request ] +on: [push, pull_request] env: CI: true jobs: - lint: uses: haraka/.github/.github/workflows/lint.yml@master @@ -15,27 +14,9 @@ jobs: secrets: inherit test: - needs: [ lint, get-lts ] - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ ubuntu-latest, windows-latest ] - node-version: ${{ fromJson(needs.get-lts.outputs.active) }} - fail-fast: false - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - name: Node ${{ matrix.node-version }} on ${{ matrix.os }} - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm test + needs: [lint] + uses: haraka/.github/.github/workflows/ubuntu.yml@master - get-lts: - runs-on: ubuntu-latest - steps: - - id: get - uses: msimerson/node-lts-versions@v1 - outputs: - active: ${{ steps.get.outputs.active }} - lts: ${{ steps.get.outputs.lts }} + windows: + needs: [lint] + uses: haraka/.github/.github/workflows/windows.yml@master diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 3627451..8314a66 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,10 +2,10 @@ name: CodeQL on: push: - branches: [ master ] + branches: [master] pull_request: # The branches below must be a subset of the branches above - branches: [ master ] + branches: [master] schedule: - cron: '18 7 * * 4' diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d489fbd..e81c15f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,4 +13,4 @@ env: jobs: publish: uses: haraka/.github/.github/workflows/publish.yml@master - secrets: inherit \ No newline at end of file + secrets: inherit diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..8ded5e0 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,2 @@ +singleQuote: true +semi: false diff --git a/.release b/.release index 9be2b27..afb1db8 160000 --- a/.release +++ b/.release @@ -1 +1 @@ -Subproject commit 9be2b270ef836bcfefda085674bf62e2a91defe8 +Subproject commit afb1db801607dda5e859f39b600f0dd0111e4651 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f7031f7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +The format is based on [Keep a Changelog](https://keepachangelog.com/). + +### [1.0.7] 2024-05-08 + +- populate [files] in package.json. +- dep: eslint-plugin-haraka -> @haraka/eslint-config + +[1.0.6]: https://github.com/haraka/haraka-constants/releases/tag/v1.0.6 +[1.0.7]: https://github.com/haraka/haraka-constants/releases/tag/v1.0.7 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 0000000..69a03c7 --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,8 @@ +# Contributors + +This handcrafted artisinal software is brought to you by: + +|
msimerson (21) |
PSSGCSim (1) | +| :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | + +this file is maintained by [.release](https://github.com/msimerson/.release) diff --git a/README.md b/README.md index efbba39..4b02512 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ Haraka constants. Exports the following constants used throughout Haraka: Populates an object with the constants. ```js -const constants = require('haraka-constants'); -const myObj = {}; -constants.import(myObj); +const constants = require('haraka-constants') +const myObj = {} +constants.import(myObj) // myObj.cont === 900 ``` @@ -38,11 +38,10 @@ constants.import(myObj); Converts a numeric constant to its string representation. ```js -const constants = require('haraka-constants'); +const constants = require('haraka-constants') // 'CONT' === constants.translate(900); ``` - [ci-img]: https://github.com/haraka/haraka-constants/actions/workflows/ci.yml/badge.svg [ci-url]: https://github.com/haraka/haraka-constants/actions/workflows/ci.yml [cov-img]: https://codecov.io/github/haraka/haraka-constants/coverage.svg @@ -51,4 +50,3 @@ const constants = require('haraka-constants'); [clim-url]: https://codeclimate.com/github/haraka/haraka-constants [npm-img]: https://nodei.co/npm/haraka-constants.png [npm-url]: https://www.npmjs.com/package/haraka-constants - diff --git a/index.js b/index.js index 755c71f..c0e79b3 100644 --- a/index.js +++ b/index.js @@ -1,63 +1,63 @@ -'use strict'; +'use strict' // node.js class -const node_const = require('constants'); - -const translationTable = {}; - -exports.cont = 900; -exports.stop = 901; -exports.deny = 902; -exports.denysoft = 903; -exports.denydisconnect = 904; -exports.disconnect = 905; -exports.ok = 906; -exports.next_hook = 907; -exports.delay = 908; -exports.denysoftdisconnect = 909; -exports.write_excl = node_const.O_CREAT | node_const.O_TRUNC | node_const.O_WRONLY | node_const.O_EXCL; +const node_const = require('node:constants') + +const translationTable = {} + +exports.cont = 900 +exports.stop = 901 +exports.deny = 902 +exports.denysoft = 903 +exports.denydisconnect = 904 +exports.disconnect = 905 +exports.ok = 906 +exports.next_hook = 907 +exports.delay = 908 +exports.denysoftdisconnect = 909 +exports.write_excl = + node_const.O_CREAT | + node_const.O_TRUNC | + node_const.O_WRONLY | + node_const.O_EXCL exports.import = function (object) { - for (const k in exports) { - if (k === 'import') continue; - if (k === 'translate') continue; - if (k === 'connection') continue; - if (Object.prototype.hasOwnProperty.call(exports, k)) { - object[k.toUpperCase()] = exports[k]; - } + for (const k in exports) { + if (['import', 'translate', 'connection'].includes(k)) continue + if (Object.prototype.hasOwnProperty.call(exports, k)) { + object[k.toUpperCase()] = exports[k] } -}; + } +} exports.translate = function (value) { - - // cache the translationTable object - if (Object.keys(translationTable).length === 0) { - for (const k in exports) { - if (typeof exports[k] === 'number') { - translationTable[exports[k]] = k.toUpperCase(); - } - } + // cache the translationTable object + if (Object.keys(translationTable).length === 0) { + for (const k in exports) { + if (typeof exports[k] === 'number') { + translationTable[exports[k]] = k.toUpperCase() + } } + } - if (translationTable[value]) return translationTable[value]; - return 'UNKNOWN'; -}; + return translationTable[value] || 'UNKNOWN' +} -exports.import(exports); +exports.import(exports) exports.connection = { - state: { - CMD: 1, - LOOP: 2, - DATA: 3, - PAUSE: 4, - PAUSE_SMTP: 5, - PAUSE_DATA: 6, - DISCONNECTING: 99, - DISCONNECTED: 100, - } + state: { + CMD: 1, + LOOP: 2, + DATA: 3, + PAUSE: 4, + PAUSE_SMTP: 5, + PAUSE_DATA: 6, + DISCONNECTING: 99, + DISCONNECTED: 100, + }, } -Object.keys(exports.connection.state).forEach((state) => { - exports.connection.state[`STATE_${state}`] = exports.connection.state[state]; -}) +for (const state of Object.keys(exports.connection.state)) { + exports.connection.state[`STATE_${state}`] = exports.connection.state[state] +} diff --git a/package.json b/package.json index 2c00b4f..82b2292 100644 --- a/package.json +++ b/package.json @@ -3,30 +3,36 @@ "name": "haraka-constants", "license": "MIT", "description": "Haraka constants", - "version": "1.0.6", + "version": "1.0.7", "homepage": "http://haraka.github.io", "repository": { "type": "git", "url": "git@github.com:haraka/haraka-constants.git" }, "main": "index.js", + "files": [ + "CHANGELOG.md" + ], "engines": { "node": ">= 6" }, "dependencies": {}, "optionalDependencies": {}, "devDependencies": { - "eslint": ">=8", - "eslint-plugin-haraka": ">=1.0.10", - "mocha": "*" + "@haraka/eslint-config": "^1.1.5" }, "bugs": { "mail": "helpme@gmail.com", "url": "https://github.com/haraka/haraka-constants/issues" }, "scripts": { - "lint": "npx eslint *.js test", - "lintfix": "npx eslint --fix *.js test", - "test": "npx mocha" + "format": "npm run prettier:fix && npm run lint:fix", + "lint": "npx eslint@^8 *.js test", + "lint:fix": "npx eslint@^8 *.js test --fix", + "prettier": "npx prettier . --check", + "prettier:fix": "npx prettier . --write --log-level=warn", + "test": "npx mocha@10", + "versions": "npx dependency-version-checker check", + "versions:fix": "npx dependency-version-checker update && npm run prettier:fix" } } diff --git a/test/index.js b/test/index.js index 98e297c..4565a99 100644 --- a/test/index.js +++ b/test/index.js @@ -1,79 +1,80 @@ - const assert = require('assert') -const node_const = require('constants'); +const node_const = require('constants') -const constants = require('../index'); -const write_excl_val = node_const.O_CREAT | node_const.O_TRUNC | node_const.O_WRONLY | node_const.O_EXCL; +const constants = require('../index') +const write_excl_val = + node_const.O_CREAT | + node_const.O_TRUNC | + node_const.O_WRONLY | + node_const.O_EXCL describe('constants', function () { - it('cont', function () { - assert.equal(constants.cont, 900); - }) - it('CONT', function () { - assert.equal(constants.CONT, 900); - }) - it('stop', function () { - assert.equal(constants.stop, 901); - }) - it('deny', function () { - assert.equal(constants.deny, 902); - }) - it('DENY', function () { - assert.equal(constants.DENY, 902); - }) - it('WRITE_EXCL', function () { - assert.equal(constants.WRITE_EXCL, write_excl_val); - }) + it('cont', function () { + assert.equal(constants.cont, 900) + }) + it('CONT', function () { + assert.equal(constants.CONT, 900) + }) + it('stop', function () { + assert.equal(constants.stop, 901) + }) + it('deny', function () { + assert.equal(constants.deny, 902) + }) + it('DENY', function () { + assert.equal(constants.DENY, 902) + }) + it('WRITE_EXCL', function () { + assert.equal(constants.WRITE_EXCL, write_excl_val) + }) }) describe('import', function () { - it('exists as function', function () { - assert.equal(typeof constants.import, 'function'); - }) - it('populates an object', function () { - const newObj = {}; - constants.import(newObj); - delete newObj.connection; - assert.deepEqual(newObj, - { - CONT: 900, - STOP: 901, - DENY: 902, - DENYSOFT: 903, - DENYDISCONNECT: 904, - DISCONNECT: 905, - OK: 906, - NEXT_HOOK: 907, - DELAY: 908, - DENYSOFTDISCONNECT: 909, - WRITE_EXCL: write_excl_val - } - ); + it('exists as function', function () { + assert.equal(typeof constants.import, 'function') + }) + it('populates an object', function () { + const newObj = {} + constants.import(newObj) + delete newObj.connection + assert.deepEqual(newObj, { + CONT: 900, + STOP: 901, + DENY: 902, + DENYSOFT: 903, + DENYDISCONNECT: 904, + DISCONNECT: 905, + OK: 906, + NEXT_HOOK: 907, + DELAY: 908, + DENYSOFTDISCONNECT: 909, + WRITE_EXCL: write_excl_val, }) + }) }) describe('translate', function () { - it('converts num to str', function () { - assert.equal('CONT', constants.translate(900)); - assert.equal('DENY', constants.translate(902)); - }) - it('UNKNOWN', function () { - assert.equal('UNKNOWN', constants.translate(800)); - }) + it('converts num to str', function () { + assert.equal('CONT', constants.translate(900)) + assert.equal('DENY', constants.translate(902)) + }) + it('UNKNOWN', function () { + assert.equal('UNKNOWN', constants.translate(800)) + }) }) describe('connection', function () { - it('has connection state CMD', function () { - assert.equal(constants.connection.state.CMD, 1); - }) - it('has connection state STATE_CMD', function () { - assert.equal(constants.connection.state.STATE_CMD, 1); - }) - it('has connection state DISCONNECTED', function () { - assert.equal(constants.connection.state.DISCONNECTED, 100); - }) - it('has connection state STATE_DISCONNECTED', function () { - assert.equal(constants.connection.state.STATE_DISCONNECTED, 100); - }) -}) \ No newline at end of file + it('has connection state CMD', function () { + assert.equal(constants.connection.state.CMD, 1) + }) + it('has connection state STATE_CMD', function () { + assert.equal(constants.connection.state.STATE_CMD, 1) + }) + it('has connection state DISCONNECTED', function () { + assert.equal(constants.connection.state.DISCONNECTED, 100) + }) + it('has connection state STATE_DISCONNECTED', function () { + assert.equal(constants.connection.state.STATE_DISCONNECTED, 100) + }) +})