Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Arc lint rules #731

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bin/binary-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let os = process.platform
let config = {
name: 'sandbox-binary',
bin: {
cli: 'binary-entry.js'
cli: 'binary-entry.js',
},
pkg: {
// Don't manually include runtimes/deno.js in scripts, as it fails on pkg#997
Expand All @@ -26,8 +26,8 @@ let config = {
'../src/tables/_aws-lite-dynamodb-vendor.js',
],
targets: [],
outputPath: 'bin'
}
outputPath: 'bin',
},
}

let nodeVer = `node18`
Expand All @@ -51,7 +51,7 @@ else {
config.pkg.targets = [
p('linux'),
p('darwin'),
p('win32')
p('win32'),
].filter(Boolean)
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"ws": "~8.16.0"
},
"devDependencies": {
"@architect/eslint-config": "~2.1.2",
"@architect/eslint-config": "~3.0.0-RC.0",
"@architect/functions": "~8.1.0",
"@architect/req-res-fixtures": "git+https://github.com/architect/req-res-fixtures.git",
"@aws-lite/apigatewaymanagementapi": "~0.0.8",
Expand Down
4 changes: 2 additions & 2 deletions src/arc/_runtime-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function runtimeAPI ({ body }, params, req, res) {
`[${requestID}] Incoming runtime API request`,
`URL: ${url}`,
`Headers: ${JSON.stringify(req.headers)}`,
`Body: ${body ? `'${body}'` : '[no body]'} ${body ? `(${Buffer.byteLength(body)}b)` : ''}`
`Body: ${body ? `'${body}'` : '[no body]'} ${body ? `(${Buffer.byteLength(body)}b)` : ''}`,
)

// Don't respond to unknown request ID roots
Expand Down Expand Up @@ -80,7 +80,7 @@ function runtimeAPI ({ body }, params, req, res) {
update.debug.status(`[${requestID}] Missing request ID in /response request`)
return res.end()
}
invocations[requestID].response = body && JSON.parse(body) || undefined
invocations[requestID].response = (body && JSON.parse(body)) || undefined
res.statusCode = accepted
res.end()
update.debug.status(`[${requestID}] Received /response request`)
Expand Down
2 changes: 1 addition & 1 deletion src/arc/_ssm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = function _ssm ({ body, services }, params, req, res) {
Type: 'String',
Value,
Version: 1,
ARN: 'Architect Sandbox'
ARN: 'Architect Sandbox',
})

// ssm.getParametersByPath()
Expand Down
6 changes: 3 additions & 3 deletions src/cli/_stdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ module.exports = function handleStdin (params) {
rehydrate({
timer: 'rehydrateAll',
msg: 'Rehydrating all shared files...',
force: true
force: true,
})
}
if (input === 'S') {
rehydrate({
timer: 'rehydrateShared',
only: 'shared',
msg: 'Rehydrating src/shared...',
force: true
force: true,
})
}
if (input === 'V') {
rehydrate({
timer: 'rehydrateViews',
only: 'views',
msg: 'Rehydrating src/views...',
force: true
force: true,
})
}
if (key.sequence === '\u0003' || key.sequence === '\u0004') {
Expand Down
10 changes: 5 additions & 5 deletions src/cli/_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ module.exports = function runWatcher (args, params) {
* Watch for pertinent filesystem changes
*/
watcher.on('all', function (event, filename) {
if (ignoredEvents.includes(event)){
if (ignoredEvents.includes(event)) {
update.debug.status(`Watcher: ignored '${event}' on ${filename}`)
return
}
if (pluginsRunning || paused && existsSync(pauseFile)) {
if (pluginsRunning || (paused && existsSync(pauseFile))) {
return
}
if (!paused && existsSync(pauseFile)) {
Expand All @@ -124,7 +124,7 @@ module.exports = function runWatcher (args, params) {
rehydrate({
timer: 'rehydrateAll',
msg: 'Restoring shared file symlinks...',
force: true
force: true,
}, liveReloadClients)
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ module.exports = function runWatcher (args, params) {
rehydrate({
timer: 'rehydrateShared',
only: 'shared',
msg: 'Shared file changed, rehydrating functions...'
msg: 'Shared file changed, rehydrating functions...',
}, liveReloadClients)
}

Expand All @@ -211,7 +211,7 @@ module.exports = function runWatcher (args, params) {
rehydrate({
timer: 'rehydrateViews',
only: 'views',
msg: 'Views file changed, rehydrating views...'
msg: 'Views file changed, rehydrating views...',
}, liveReloadClients)
}

Expand Down
4 changes: 2 additions & 2 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ update({ pkg, shouldNotifyInNpmScript: true })
align: 'center',
borderColor: 'green',
borderStyle: 'round',
dimBorder: true
}
dimBorder: true,
},
})

// Hit it
Expand Down
2 changes: 1 addition & 1 deletion src/events/_listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = function eventBusListener (params, req, res) {
if (err?.message === 'lambda_not_found') {
update.warn(
`@${arcType} ${name} missing Lambda handler file\n` +
`Please create a handler file, or run [npx] arc init, or add 'autocreate true' to your project preferences file's '@create' pragma`
`Please create a handler file, or run [npx] arc init, or add 'autocreate true' to your project preferences file's '@create' pragma`,
)
}
else if (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function start (params, callback) {
let httpPort = params.ports.http
// Node.js 17+ changed DNS lookup behavior for host binding; prefer host to be undefined unless manually specified
httpServer.listen(httpPort, host, callback)
}
},
], callback)
}

Expand Down
4 changes: 2 additions & 2 deletions src/http/invoke-http/http/_req-fmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function requestFormatter ({ method, path, req }) {

// Here we go!
let request = {
version: '2.0'
version: '2.0',
}

// Resource may be manually supplied via ASAP
Expand Down Expand Up @@ -73,7 +73,7 @@ module.exports = function requestFormatter ({ method, path, req }) {
},
// requestId // TODO add me maybe
routeKey,
timeEpoch: Math.floor(Date.now() / 1000)
timeEpoch: Math.floor(Date.now() / 1000),
}

// Path parameters
Expand Down
2 changes: 1 addition & 1 deletion src/http/invoke-http/http/_res-header-fmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function responseHeaderFormatter (normalizedHeaders) {
'content-length',
'date',
'upgrade',
'transfer-encoding'
'transfer-encoding',
]

for (let [ key, value ] of Object.entries(normalizedHeaders)) {
Expand Down
4 changes: 2 additions & 2 deletions src/http/invoke-http/rest/_req-fmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ module.exports = function requestFormatter ({ method, path, req }, httpApi) {
protocol: `HTTP/${req.httpVersion}`,
identity: {
sourceIp,
userAgent: headers['User-Agent'] || headers['user-agent'] || null
userAgent: headers['User-Agent'] || headers['user-agent'] || null,
},
}
},
}

// Base64 encoding status set by binary handler middleware
Expand Down
2 changes: 1 addition & 1 deletion src/http/invoke-http/rest/_res-header-fmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function responseHeaderFormatter (normalizedHeaders, httpApi) {
let headers = {}
let drops = [
'upgrade', // Technically not dropped, but header is validated by APIG and impl can cause HTTP issues, so we'll sidestep in Sandbox
'transfer-encoding'
'transfer-encoding',
]

if (httpApi) {
Expand Down
2 changes: 1 addition & 1 deletion src/http/invoke-http/rest/_res-validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function responseValidator ({ res, result }, httpApi) {
'body',
'headers',
'multiValueHeaders',
'isBase64Encoded'
'isBase64Encoded',
]

// Malformed returns – must be an object
Expand Down
2 changes: 1 addition & 1 deletion src/http/invoke-http/utils/livereload.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function compressor (direction, type, body) {
let exec = {
gzip: compress ? gzipSync : gunzipSync,
br: compress ? brotliCompressSync : brotliDecompressSync,
deflate: compress ? deflateSync : inflateSync
deflate: compress ? deflateSync : inflateSync,
}
if (!exec[type]) return body

Expand Down
6 changes: 3 additions & 3 deletions src/http/invoke-http/utils/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ autocreate true
other: (title, body) => `${head}<h1>${title}</h1>
<p>${body}<p>`,
chonky: size => `<h1>Invalid payload size</h1>
<p>Responses must be 6MB or less; this response is ${size}</p>`
<p>Responses must be 6MB or less; this response is ${size}</p>`,
}

function invalid (res, body) {
Expand All @@ -36,12 +36,12 @@ function invalid (res, body) {
res.setHeader('cache-control', 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0')
return {
valid: false,
body
body,
}
}

module.exports = {
isBuffer,
errors,
invalid
invalid,
}
2 changes: 1 addition & 1 deletion src/http/invoke-ws/_req-fmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function requestFormatter (params) {
stage: process.env.ARC_ENV || 'testing',
identity: { sourceIp },
},
isBase64Encoded: false
isBase64Encoded: false,
}

if (name === 'disconnect') {
Expand Down
2 changes: 1 addition & 1 deletion src/http/register-websocket/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function connection (params, connectionId, ws) {
pool.register(connectionId, ws)

const respondToError = (err, response) => {
if (err || response && response.statusCode >= 400) {
if (err || (response && response.statusCode >= 400)) {
ws.send(JSON.stringify({ 'message': 'Internal server error', connectionId, 'requestId': 'xxxxxx=' }), noop)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/http/register-websocket/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ let pool = {
register (connectionId, ws) {
pool.connections[connectionId] = {
ws,
connectedAt: Date.now()
connectedAt: Date.now(),
}
},
delete (connectionId) {
delete pool.connections[connectionId]
},
reset () {
pool.connections = {}
}
},
}

module.exports = pool
2 changes: 1 addition & 1 deletion src/http/register-websocket/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function upgrade (wss, params) {
socket.destroy()
return
}
else if (statusCode >= 200 && statusCode <= 208 || statusCode === 226) {
else if ((statusCode >= 200 && statusCode <= 208) || statusCode === 226) {
wss.handleUpgrade(req, socket, head, (ws) => {
wss.emit('connection', connectionId, ws)
})
Expand Down
2 changes: 1 addition & 1 deletion src/invoke-lambda/_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = async function _invoke (params, options) {
let msg = `Plugin invoke: @${pragma} ${name} missing Lambda handler file`
update.warn(
`${msg}\n` +
`Please create a handler file, or run [npx] arc init, or add 'autocreate true' to your project preferences file's '@create' pragma`
`Please create a handler file, or run [npx] arc init, or add 'autocreate true' to your project preferences file's '@create' pragma`,
)
err.message = msg
return rej(err)
Expand Down
2 changes: 1 addition & 1 deletion src/invoke-lambda/exec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function exec (lambda, params, callback) {
// `sandboxPath` named differently because `staticPath` was too vague within ASAP
sandboxPath: context.staticPath,
// Pick up SPA setting (which may be overridden by process ARC_STATIC_SPA within ASAP)
spa: context.inventory.inv?.static?.spa
spa: context.inventory.inv?.static?.spa,
})
asap(invocations[requestID].request)
.then(result => {
Expand Down
2 changes: 1 addition & 1 deletion src/invoke-lambda/exec/runtimes/deno.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint semi: [ 'error', 'always' ] */
/* eslint @stylistic/js/semi: [ 'error', 'always' ] */
/* global Deno */
const { __ARC_CONFIG__, __ARC_CONTEXT__, AWS_LAMBDA_RUNTIME_API: runtimeAPI } = Deno.env.toObject();
const url = p => runtimeAPI + '/2018-06-01/runtime/' + p;
Expand Down
8 changes: 4 additions & 4 deletions src/invoke-lambda/exec/runtimes/node-esm.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint semi: [ 'error', 'always' ] */
/* eslint @stylistic/js/semi: [ 'error', 'always' ] */
let { __ARC_CONFIG__, __ARC_CONTEXT__, AWS_LAMBDA_RUNTIME_API: runtimeAPI } = process.env;
let url = p => runtimeAPI + '/2018-06-01/runtime/' + p;

Expand All @@ -17,7 +17,7 @@ function client (method, params) {
body = JSON.stringify(params.body);
headers['content-length'] = Buffer.byteLength(body);
}
let req = http.request(params.url, { method, headers, }, res => {
let req = http.request(params.url, { method, headers }, res => {
let { statusCode } = res;
if (statusCode < 200 || statusCode > 202) {
return reject(Error('Runtime API error:', statusCode));
Expand All @@ -30,7 +30,7 @@ function client (method, params) {
try {
resolve({
headers: res.headers,
body: JSON.parse(body)
body: JSON.parse(body),
});
}
catch (err) {
Expand Down Expand Up @@ -58,7 +58,7 @@ function client (method, params) {

let isPromise = obj => obj && typeof obj.then === 'function';

async function run (){
async function run () {
let next = url('invocation/next');
let invocation = await get({ url: next });
let { headers, body: event } = invocation;
Expand Down
6 changes: 3 additions & 3 deletions src/invoke-lambda/exec/runtimes/node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint semi: [ 'error', 'always' ] */
/* eslint @stylistic/js/semi: [ 'error', 'always' ] */
let { __ARC_CONFIG__, __ARC_CONTEXT__, AWS_LAMBDA_RUNTIME_API: runtimeAPI } = process.env;
let url = p => runtimeAPI + '/2018-06-01/runtime/' + p;

Expand All @@ -17,7 +17,7 @@ function client (method, params) {
body = JSON.stringify(params.body);
headers['content-length'] = Buffer.byteLength(body);
}
let req = http.request(params.url, { method, headers, }, res => {
let req = http.request(params.url, { method, headers }, res => {
let { statusCode } = res;
if (statusCode < 200 || statusCode > 202) {
return reject(Error('Runtime API error:', statusCode));
Expand All @@ -30,7 +30,7 @@ function client (method, params) {
try {
resolve({
headers: res.headers,
body: JSON.parse(body)
body: JSON.parse(body),
});
}
catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/invoke-lambda/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module.exports = function invokeLambda (params, callback) {
// Next check payload size is within limits
let maxSize = 1000 * 6000
let { body, Records } = event
let bodySize = body && JSON.stringify(body).length || 0
let payloadSize = Records && JSON.stringify(Records).length || 0
let bodySize = (body && JSON.stringify(body).length) || 0
let payloadSize = (Records && JSON.stringify(Records).length) || 0
if (bodySize > maxSize || payloadSize > maxSize) {
let err = Error('Maximum event body exceeded: Lambda allows up to 6MB payloads (base64-encoded)')
return callback(err)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let template = require('./template')
let { head } = template
let headers = {
'content-type': 'text/html; charset=utf8;',
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0'
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0',
}

module.exports = function errors ({ lambdaError, lambda, type = 'error' }) {
Expand Down
Loading
Loading