Skip to content

Commit

Permalink
Address linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarber623 committed Feb 24, 2024
1 parent 9bad01b commit 66cd7bf
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 51 deletions.
18 changes: 9 additions & 9 deletions eleventy.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import fs from 'node:fs/promises';
import fs from "node:fs/promises";

import postcssPlugin from '@jgarber/eleventy-plugin-postcss';
import postcssPlugin from "@jgarber/eleventy-plugin-postcss";

export default async function(eleventyConfig) {

Check warning on line 5 in eleventy.config.js

View workflow job for this annotation

GitHub Actions / CI / Lint files

Missing JSDoc comment

Check warning on line 5 in eleventy.config.js

View workflow job for this annotation

GitHub Actions / CI / Lint files

Missing JSDoc comment
// Global Data
eleventyConfig.addGlobalData('app', JSON.parse(await fs.readFile('./src/manifest.webmanifest.json')));
eleventyConfig.addGlobalData("app", JSON.parse(await fs.readFile("./src/manifest.webmanifest.json")));

// Passthrough File Copy
eleventyConfig
.addPassthroughCopy('./src/_headers')
.addPassthroughCopy('./src/*.{ico,txt}')
.addPassthroughCopy('./src/assets/images')
.addPassthroughCopy("./src/_headers")
.addPassthroughCopy("./src/*.{ico,txt}")
.addPassthroughCopy("./src/assets/images")
.addPassthroughCopy({
'./src/manifest.webmanifest.json': 'manifest.webmanifest'
"./src/manifest.webmanifest.json": "manifest.webmanifest",
});

// Plugins
eleventyConfig.addPlugin(postcssPlugin);

return {
dir: {
input: './src'
}
input: "./src",
},
};
}
18 changes: 9 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import config from '@jgarber/eslint-config';
import config from "@jgarber/eslint-config";

export default [
...config,
{
files: ['functions/**/*.js'],
files: ["functions/**/*.js"],
rules: {
'jsdoc/no-undefined-types': ['error', { definedTypes: ['EventContext'] }]
}
"jsdoc/no-undefined-types": ["error", { definedTypes: ["EventContext"] }],
},
},
{
files: ['google/**/*.js'],
files: ["google/**/*.js"],
languageOptions: {
globals: {
require: 'readonly'
require: "readonly",
},
sourceType: 'commonjs'
}
}
sourceType: "commonjs",
},
},
];
16 changes: 7 additions & 9 deletions functions/i/[dimensions].js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
* either a single `width` integer or a combined `width` and `height` string
* joined by an `x`.
*
* @see {@link https://developers.cloudflare.com/pages/platform/functions/api-reference/}
*
* @param {EventContext} context An EventContext instance.
*
* @returns {Response} Most likely a 302 redirect.
* @see {@link https://developers.cloudflare.com/pages/platform/functions/api-reference/}
*/
export async function onRequestGet(context) {
let [width, height = width] = context.params.dimensions.split('x');
let [width, height = width] = context.params.dimensions.split("x");

width = Number.parseInt(width, 10);
height = Number.parseInt(height, 10);
Expand All @@ -24,15 +22,15 @@ export async function onRequestGet(context) {
const response = await fetch(context.env.GCP_CLOUD_FUNCTION_URL, {
body: new URLSearchParams({ height, width }),
headers: {
'content-type': 'application/x-www-form-urlencoded'
"content-type": "application/x-www-form-urlencoded",
},
method: 'POST'
method: "POST",
});

return new Response(await response.blob(), {
headers: {
'cache-control': 'public, max-age=3600',
'content-type': 'image/jpeg'
}
"cache-control": "public, max-age=3600",
"content-type": "image/jpeg",
},
});
}
14 changes: 6 additions & 8 deletions functions/i/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@
* content type `application/x-www-form-urlencoded` and include `width` and
* `height` parameters.
*
* @see {@link https://developers.cloudflare.com/pages/platform/functions/api-reference/}
*
* @param {EventContext} context An EventContext instance.
*
* @returns {Response} Most likely a 302 redirect.
* @see {@link https://developers.cloudflare.com/pages/platform/functions/api-reference/}
*/
export async function onRequestPost(context) {
const regexp = /^application\/x-www-form-urlencoded(?:;.+)?$/;

const { request } = context;

console.log('Received request:', request.method, request.url);
console.log("Received request:", request.method, request.url);

if (regexp.test(request.headers.get('content-type'))) {
if (regexp.test(request.headers.get("content-type"))) {
const body = await request.formData();
const { width, height } = Object.fromEntries(body);

if (width && height) {
console.log('Generating response for request with params:', width, height);
console.log("Generating response for request with params:", width, height);

return new Response(null, {
headers: {
location: `/i/${width}x${height}`
location: `/i/${width}x${height}`,
},
status: 302
status: 302,
});
}
}
Expand Down
24 changes: 12 additions & 12 deletions google/cloud-functions/transform-image/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const functions = require('@google-cloud/functions-framework');
const { Storage } = require('@google-cloud/storage');
const functions = require("@google-cloud/functions-framework");
const { Storage } = require("@google-cloud/storage");

const sharp = require('sharp');
const sharp = require("sharp");

const { GCP_BUCKET_NAME } = process.env;

functions.http('transformImage', async (request, response) => {
if (request.method !== 'POST') {
return response.set('allow', 'POST').status(405).end();
functions.http("transformImage", async (request, response) => {
if (request.method !== "POST") {
return response.set("allow", "POST").status(405).end();
}

if (request.get('content-type') !== 'application/x-www-form-urlencoded') {
if (request.get("content-type") !== "application/x-www-form-urlencoded") {
return response.status(415).end();
}

Expand All @@ -23,7 +23,7 @@ functions.http('transformImage', async (request, response) => {
return response.status(400).end();
}

console.log('Generating transform with dimensions:', width, height);
console.log("Generating transform with dimensions:", width, height);

// Retrieve a list of all objects in the bucket
const storage = new Storage();
Expand All @@ -32,7 +32,7 @@ functions.http('transformImage', async (request, response) => {
// Choose a random object
const file = files[Math.floor(Math.random() * files.length)];

console.log('Randomly selected file:', file.name);
console.log("Randomly selected file:", file.name);

// Load that object into memory
//
Expand All @@ -46,14 +46,14 @@ functions.http('transformImage', async (request, response) => {
.resize(width, height)
.jpeg({
progressive: true,
quality: 60
quality: 60,
})
.toBuffer();

response
.set({
'cache-control': 'public, max-age=3600',
'content-type': 'image/jpeg'
"cache-control": "public, max-age=3600",
"content-type": "image/jpeg",
})
.send(data);
});
6 changes: 3 additions & 3 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cssnano from 'cssnano';
import postcssNesting from 'postcss-nesting';
import cssnano from "cssnano";
import postcssNesting from "postcss-nesting";

export default {
plugins: [postcssNesting, cssnano]
plugins: [postcssNesting, cssnano],
};
2 changes: 1 addition & 1 deletion stylelint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
extends: '@jgarber/stylelint-config'
extends: "@jgarber/stylelint-config",
};

0 comments on commit 66cd7bf

Please sign in to comment.