Skip to content

Commit

Permalink
ci: setup ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed Sep 6, 2021
1 parent f89a21d commit fa99038
Show file tree
Hide file tree
Showing 128 changed files with 1,443 additions and 159 deletions.
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Opt into dotfile linting
!.*

# Compiled sources
.github
.yarn
node_modules
27 changes: 27 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
env: {
es2021: true,
mocha: true,
node: true,
},
extends: ['@fuelrats/eslint-config'],
rules: {
// Core
indent: ['error', 'tab'],
'new-parens': ['error', 'never'],
'no-param-reassign': ['error', {
props: false,
}],

// Import
'import/extensions': ['error', 'ignorePackages'],
},
overrides: [
{
files: ['tests/**/*.js'],
env: {
jest: true,
},
},
],
}
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: GH Actions - Lint
on: [push]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
cache: 'yarn'

- name: Install dependencies
run: yarn install

- name: Test
run: yarn lint
31 changes: 17 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: GH Actions - Release
on:
workflow_run:
workflows: ['GH Actions - Test']
workflows:
- 'GH Actions - Lint'
- 'GH Actions - Test'
branches:
- 'main'
- 'v*.x.x'
Expand All @@ -14,19 +16,20 @@ jobs:
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v1
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 16
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
cache: 'yarn'

- name: Install dependencies
run: yarn install
- name: Install dependencies
run: yarn install

- name: Release
run: yarn semantic-release
env:
GITHUB_TOKEN: ${{ secrets.PORYGON_Y_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Release
run: yarn semantic-release
env:
GITHUB_TOKEN: ${{ secrets.PORYGON_Y_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
15 changes: 2 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@ jobs:
- uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
cache: 'yarn'

- name: Install dependencies
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .mocharc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
parallel: true,
recursive: true,
require: ['test/setup.js']
require: ['test/setup.js'],
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@
},
"scripts": {
"dev": "nodemon ./src/index.js",
"lint": "eslint --ext js,cjs,mjs .",
"start": "node ./src/index.js",
"semantic-release": "semantic-release",
"test": "nyc mocha --experimental-loader=@istanbuljs/esm-loader-hook"
},
"devDependencies": {
"@babel/eslint-parser": "^7.15.4",
"@babel/eslint-plugin": "^7.14.5",
"@fuelrats/eslint-config": "^2.3.0",
"@fuelrats/eslint-plugin": "^2.3.0",
"@istanbuljs/esm-loader-hook": "^0.1.2",
"@semantic-release/changelog": "^5.0.1",
"chai": "^4.3.4",
"chai-http": "^4.3.0",
"coveralls": "^3.1.1",
"eslint": "^7.32.0",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jsdoc": "^36.0.8",
"mocha": "^9.1.1",
"nodemon": "^2.0.12",
"nyc": "^15.1.0",
Expand Down
1 change: 1 addition & 0 deletions scripts/normalizeDataFromUniteDB.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
// Module imports
import fetch from 'node-fetch'
import fs from 'fs/promises'
Expand Down
72 changes: 39 additions & 33 deletions src/helpers/bodyBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,57 @@ import { getVersion } from './getVersion.js'



export async function bodyBuilder(context, next) {
const meta = {
start_ms: Date.now()
}
let body = {}
/**
* Middleware that constructs a valid JSON:API body
*
* @param {*} context
* @param {*} next
*/
export async function bodyBuilder (context, next) {
const meta = {
start_ms: Date.now(),
}
let body = {}

context.errors = []
context.errors = []

await next()

if (context.errors.length) {
body.errors = context.errors.map(error => {
if (error instanceof Error) {
return error.message
}

return error
})
} else if (context.data) {
body = {
...body,
data: context.data,
jsonapi: {
version: '1.0',
},
meta: context.data.meta || {},
if (context.errors.length) {
body.errors = context.errors.map((error) => {
if (error instanceof Error) {
return error.message
}

return error
})
} else if (context.data) {
body = {
...body,
data: context.data,
jsonapi: {
version: '1.0',
},
meta: context.data.meta || {},
}

if (context.included) {
body.included = context.included
}

if (Array.isArray(body.data)) {
body.meta.count = body.data.length
}
}
if (Array.isArray(body.data)) {
body.meta.count = body.data.length
}
}

meta.version = await getVersion()
meta.end_ms = Date.now()
meta.response_ms = (meta.end_ms - meta.start_ms)
meta.version = await getVersion()
meta.end_ms = Date.now()
meta.response_ms = (meta.end_ms - meta.start_ms)

body.meta = {
...meta,
...body.meta,
body.meta = {
...meta,
...body.meta,
}

context.body = body
context.body = body
}
7 changes: 6 additions & 1 deletion src/helpers/getVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import path from 'path'



export async function getVersion() {
/**
* Gets the current version set in `package.json`.
*
* @returns {string}
*/
export async function getVersion () {
const packagePath = path.resolve(process.cwd(), 'package.json')
const packageData = await fs.readFile(packagePath, 'utf8')
const packageJSON = JSON.parse(packageData)
Expand Down
112 changes: 112 additions & 0 deletions src/helpers/httpStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* eslint-disable no-magic-numbers */
const HttpStatus = {
// Informational
CONTINUE: 100,
SWITCHING_PROTOCOLS: 101,
PROCESSING: 102,

// Success
OK: 200,
CREATED: 201,
ACCEPTED: 202,
NON_AUTHORITATIVE_INFORMATION: 203,
NO_CONTENT: 204,
RESET_CONTENT: 205,
PARTIAL_CONTENT: 206,
MULTI_STATUS: 207,
ALREADY_REPORTED: 208,
IM_USED: 226,

// Redirection
MULTIPLE_CHOICES: 300,
MOVED_PERMANENTLY: 301,
FOUND: 302,
SEE_OTHER: 303,
NOT_MODIFIED: 304,
USE_PROXY: 305,
TEMPORARY_REDIRECT: 307,
PERMANENT_REDIRECT: 308,

// Client Error
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
PAYMENT_REQUIRED: 402,
FORBIDDEN: 403,
NOT_FOUND: 404,
METHOD_NOT_ALLOWED: 405,
NOT_ACCEPTABLE: 406,
PROXY_AUTHENTICATION_REQUIRED: 407,
REQUEST_TIMEOUT: 408,
CONFLICT: 409,
GONE: 410,
LENGTH_REQUIRED: 411,
PRECONDITION_FAILED: 412,
PAYLOAD_TOO_LARGE: 413,
URI_TOO_LONG: 414,
UNSUPPORTED_MEDIA_TYPE: 415,
RANGE_NOT_SATISFIABLE: 416,
EXPECTATION_FAILED: 417,
IM_A_TEAPOT: 418,
MISDIRECTED_REQUEST: 421,
UNPROCESSABLE_ENTITY: 422,
LOCKED: 423,
FAILED_DEPENDENCY: 424,
UPGRADE_REQUIRED: 426,
PRECONDITION_REQUIRED: 428,
TOO_MANY_REQUESTS: 429,
HEADER_FIELDS_TOO_LARGE: 431,
CLOSED_WITHOUT_RESPONSE: 444,
UNAVAILABLE_FOR_LEGAL_REASONS: 451,
CLIENT_CLOSED_REQUEST: 499,

// Server Error
INTERNAL_SERVER_ERROR: 500,
NOT_IMPLEMENTED: 501,
BAD_GATEWAY: 502,
SERVICE_UNAVAILABLE: 503,
GATEWAY_TIMEOUT: 504,
HTTP_VERSION_NOT_SUPPORTED: 505,
VARIANT_ALSO_NEGOTIATES: 506,
INSUFFICIENT_STORAGE: 507,
LOOP_DETECTED: 508,
NOT_EXTENDED: 510,
NETWORK_AUTHENTICATION_REQUIRED: 511,
NETWORK_CONNECTION_TIMEOUT_ERROR: 599,

// Helper Functions
isInformational: (code) => {
return code >= 100 && code < 200
},

isSuccess: (code) => {
return code >= 200 && code < 300
},

isRedirection: (code) => {
return code >= 300 && code < 400
},

isError: (code) => {
return code >= 400 && code < 600
},

isClientError: (code) => {
return code >= 400 && code < 500
},

isServerError: (code) => {
return code >= 500 && code < 600
},
}





Object.freeze(HttpStatus)





export default HttpStatus
Loading

0 comments on commit fa99038

Please sign in to comment.