Skip to content

Commit

Permalink
Add same prettier config as wc dotorg and apply
Browse files Browse the repository at this point in the history
  • Loading branch information
rcantin-w committed Sep 20, 2024
1 parent 447f587 commit c6fd2ed
Show file tree
Hide file tree
Showing 115 changed files with 1,776 additions and 1,774 deletions.
92 changes: 46 additions & 46 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
const sharedPlugins = ["import", "jest", "prettier", "standard"];
const sharedPlugins = ['import', 'jest', 'prettier', 'standard'];

const sharedExtends = [
"standard",
"plugin:jest-playwright/recommended",
"prettier",
"plugin:prettier/recommended", // Should be the last extension https://github.com/prettier/eslint-plugin-prettier#recommended-configuration
'standard',
'plugin:jest-playwright/recommended',
'prettier',
'plugin:prettier/recommended', // Should be the last extension https://github.com/prettier/eslint-plugin-prettier#recommended-configuration
];

const sharedRules = {
"eol-last": "error",
"import/order": [
"warn",
'eol-last': 'error',
'import/order': [
'warn',
{
groups: [
["builtin", "external"],
["internal", "sibling", "parent", "index"],
['builtin', 'external'],
['internal', 'sibling', 'parent', 'index'],
],
pathGroups: [
{
pattern: "@weco/**",
group: "external",
position: "after",
pattern: '@weco/**',
group: 'external',
position: 'after',
},
],
pathGroupsExcludedImportTypes: ["builtin", "object"],
pathGroupsExcludedImportTypes: ['builtin', 'object'],
alphabetize: {
order: "asc",
order: 'asc',
caseInsensitive: true,
},
"newlines-between": "always",
'newlines-between': 'always',
},
],
"no-mixed-operators": "warn",
"no-multi-spaces": "warn",
"no-multi-str": "off",
"no-restricted-imports": [
"error",
{ patterns: ["../*"] }, // Should only import relatively from same directory
'no-mixed-operators': 'warn',
'no-multi-spaces': 'warn',
'no-multi-str': 'off',
'no-restricted-imports': [
'error',
{ patterns: ['../*'] }, // Should only import relatively from same directory
],
"no-restricted-syntax": [
"error",
'no-restricted-syntax': [
'error',
"JSXElement.children > [expression.callee.property.name='stringify']",
],
"no-return-assign": "off",
"prettier/prettier": "error",
"sort-imports": [
"error",
'no-return-assign': 'off',
'prettier/prettier': 'error',
'sort-imports': [
'error',
{
ignoreCase: true,
ignoreDeclarationSort: true,
Expand All @@ -54,10 +54,10 @@ const sharedRules = {
};

module.exports = {
parser: "@babel/eslint-parser",
parser: '@babel/eslint-parser',
plugins: sharedPlugins,
env: {
"jest/globals": true,
'jest/globals': true,
},
extends: sharedExtends,
rules: sharedRules,
Expand All @@ -70,38 +70,38 @@ module.exports = {
},
overrides: [
{
files: ["*.ts", "*.tsx"],
parser: "@typescript-eslint/parser",
plugins: [...sharedPlugins, "@typescript-eslint"],
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
plugins: [...sharedPlugins, '@typescript-eslint'],
extends: [
...sharedExtends,
"plugin:@typescript-eslint/recommended",
"plugin:jest-playwright/recommended",
'plugin:@typescript-eslint/recommended',
'plugin:jest-playwright/recommended',
],
rules: {
...sharedRules,
"no-use-before-define": "off",
"@typescript-eslint/array-type": ["error"],
"@typescript-eslint/no-use-before-define": [
"error",
'no-use-before-define': 'off',
'@typescript-eslint/array-type': ['error'],
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false },
],
"@typescript-eslint/no-unused-vars": [
"error",
'@typescript-eslint/no-unused-vars': [
'error',
{ ignoreRestSiblings: true },
],
"jest/no-standalone-expect": [
"error",
{ additionalTestBlockFunctions: ["each.test"] },
'jest/no-standalone-expect': [
'error',
{ additionalTestBlockFunctions: ['each.test'] },
],
},
},
// Some directories don't have an absolute import equivalent so ignoring
// import rules for them.
{
files: ["webhook/**"],
files: ['webhook/**'],
rules: {
"no-restricted-imports": "off",
'no-restricted-imports': 'off',
},
},
],
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
arrowParens: 'avoid',
endOfLine: 'auto',
singleQuote: true,
trailingComma: 'es5',
};
1 change: 0 additions & 1 deletion .prettierrc.json

This file was deleted.

14 changes: 7 additions & 7 deletions api/config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { URL } from "url";
import { z } from "zod";
import { URL } from 'url';
import { z } from 'zod';

const environmentSchema = z.object({
PUBLIC_ROOT_URL: z
.string()
.url()
.default("https://api.wellcomecollection.org/content/v0"),
.default('https://api.wellcomecollection.org/content/v0'),
});
const environment = environmentSchema.parse(process.env);

// This configuration is exposed via the public healthcheck endpoint,
// so be careful not to expose any secrets here.
const config = {
pipelineDate: "2023-03-24",
articlesIndex: "articles",
eventsIndex: "events",
venuesIndex: "venues",
pipelineDate: '2023-03-24',
articlesIndex: 'articles',
eventsIndex: 'events',
venuesIndex: 'venues',
publicRootUrl: new URL(environment.PUBLIC_ROOT_URL),
};

Expand Down
8 changes: 4 additions & 4 deletions api/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
displayName: "API",
preset: "ts-jest",
testEnvironment: "node",
setupFilesAfterEnv: ["<rootDir>/test/setup.js"],
displayName: 'API',
preset: 'ts-jest',
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/test/setup.js'],
};
18 changes: 9 additions & 9 deletions api/server.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// This must be the first import in the app!
import "@weco/content-common/services/init-apm";
import '@weco/content-common/services/init-apm';

import { getElasticClient } from "@weco/content-common/services/elasticsearch";
import log from "@weco/content-common/services/logging";
import { getElasticClient } from '@weco/content-common/services/elasticsearch';
import log from '@weco/content-common/services/logging';

import { getConfig } from "./config";
import createApp from "./src/app";
import { getConfig } from './config';
import createApp from './src/app';

const config = getConfig();

const isRunningInECS = "ECS_CONTAINER_METADATA_URI_V4" in process.env;
const isRunningInECS = 'ECS_CONTAINER_METADATA_URI_V4' in process.env;

getElasticClient({
serviceName: "api",
serviceName: 'api',
pipelineDate: config.pipelineDate,
hostEndpointAccess: isRunningInECS ? "private" : "public",
}).then(async (elasticClient) => {
hostEndpointAccess: isRunningInECS ? 'private' : 'public',
}).then(async elasticClient => {
const app = createApp({ elastic: elasticClient }, config);
const port = process.env.PORT ?? 3000;
app.listen(port, () => {
Expand Down
26 changes: 13 additions & 13 deletions api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import express from "express";
import morgan from "morgan";
import express from 'express';
import morgan from 'morgan';

import { Config } from "@weco/content-api/config";
import { logStream } from "@weco/content-common/services/logging";
import { Config } from '@weco/content-api/config';
import { logStream } from '@weco/content-common/services/logging';

import {
articleController,
Expand All @@ -12,20 +12,20 @@ import {
eventsController,
healthcheckController,
venuesController,
} from "./controllers";
import { Clients } from "./types";
} from './controllers';
import { Clients } from './types';

const createApp = (clients: Clients, config: Config) => {
const app = express();

app.use(morgan("short", { stream: logStream("http") }));
app.use(morgan('short', { stream: logStream('http') }));

app.get("/articles", articlesController(clients, config));
app.get("/articles/:id", articleController(clients, config));
app.get("/events", eventsController(clients, config));
app.get("/events/:id", eventController(clients, config));
app.get("/venues", venuesController(clients, config));
app.get("/management/healthcheck", healthcheckController(config));
app.get('/articles', articlesController(clients, config));
app.get('/articles/:id', articleController(clients, config));
app.get('/events', eventsController(clients, config));
app.get('/events/:id', eventController(clients, config));
app.get('/venues', venuesController(clients, config));
app.get('/management/healthcheck', healthcheckController(config));

app.use(errorHandler);

Expand Down
18 changes: 9 additions & 9 deletions api/src/controllers/article.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { errors as elasticErrors } from "@elastic/elasticsearch";
import { RequestHandler } from "express";
import asyncHandler from "express-async-handler";
import { errors as elasticErrors } from '@elastic/elasticsearch';
import { RequestHandler } from 'express';
import asyncHandler from 'express-async-handler';

import { Config } from "@weco/content-api/config";
import { Clients, Displayable } from "@weco/content-api/src/types";
import { Config } from '@weco/content-api/config';
import { Clients, Displayable } from '@weco/content-api/src/types';

import { HttpError } from "./error";
import { HttpError } from './error';

type PathParams = { id: string };

const articleController = (
clients: Clients,
config: Config,
config: Config
): RequestHandler<PathParams> => {
const index = config.articlesIndex;

Expand All @@ -21,7 +21,7 @@ const articleController = (
const getResponse = await clients.elastic.get<Displayable>({
index,
id,
_source: ["display"],
_source: ['display'],
});

res.status(200).json(getResponse._source!.display);
Expand All @@ -30,7 +30,7 @@ const articleController = (
if (error.statusCode === 404) {
throw new HttpError({
status: 404,
label: "Not Found",
label: 'Not Found',
description: `Article not found for identifier ${id}`,
});
}
Expand Down
Loading

0 comments on commit c6fd2ed

Please sign in to comment.