Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 2749120

Browse files
authored
chore: implements eslint #2 (#21)
1 parent 2e4f20b commit 2749120

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3369
-2420
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@payloadcms'],
4+
}

.prettierrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
printWidth: 100,
3+
parser: "typescript",
4+
semi: false,
5+
singleQuote: true,
6+
trailingComma: "all",
7+
arrowParens: "avoid",
8+
};

package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
1313
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
1414
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
15-
"generate:graphQLSchema": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema"
15+
"generate:graphQLSchema": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema",
16+
"lint": "eslint src",
17+
"lint:fix": "eslint --fix --ext .ts,.tsx src"
1618
},
1719
"dependencies": {
1820
"@aws-sdk/client-s3": "^3.192.0",
@@ -27,10 +29,24 @@
2729
"payload": "^1.6.4"
2830
},
2931
"devDependencies": {
32+
"@types/node": "18.11.3",
33+
"@types/react": "18.0.21",
3034
"@types/express": "^4.17.9",
35+
"@typescript-eslint/eslint-plugin": "^5.51.0",
36+
"@typescript-eslint/parser": "^5.51.0",
37+
"@payloadcms/eslint-config": "^0.0.1",
3138
"copyfiles": "^2.4.1",
39+
"cross-env": "^7.0.3",
40+
"eslint": "^8.19.0",
41+
"eslint-config-prettier": "^8.5.0",
42+
"eslint-plugin-filenames": "^1.3.2",
43+
"eslint-plugin-import": "2.25.4",
44+
"eslint-plugin-prettier": "^4.0.0",
45+
"eslint-plugin-react-hooks": "^4.6.0",
46+
"eslint-plugin-simple-import-sort": "^10.0.0",
3247
"nodemon": "^2.0.6",
48+
"prettier": "^2.7.1",
3349
"ts-node": "^9.1.1",
34-
"typescript": "^4.1.3"
50+
"typescript": "^4.8.4"
3551
}
3652
}

src/access/isAdmin.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import { Access, FieldAccess } from "payload/types";
2-
import { User } from "../payload-types";
1+
import type { Access, FieldAccess } from 'payload/types'
32

4-
export const isAdmin: Access<any, User> = ({ req: { user } }) => {
3+
import type { User } from '../payload-types'
4+
5+
export const isAdmin: Access<
6+
any, // eslint-disable-line @typescript-eslint/no-explicit-any
7+
User
8+
> = ({ req: { user } }) => {
59
// Return true or false based on if the user has an admin role
6-
return Boolean(user?.roles?.includes('admin'));
10+
return Boolean(user?.roles?.includes('admin'))
711
}
812

9-
export const isAdminFieldLevel: FieldAccess<{ id: string }, unknown, User> = ({ req: { user } }) => {
13+
export const isAdminFieldLevel: FieldAccess<{ id: string }, unknown, User> = ({
14+
req: { user },
15+
}) => {
1016
// Return true or false based on if the user has an admin role
11-
return Boolean(user?.roles?.includes('admin'));
12-
}
17+
return Boolean(user?.roles?.includes('admin'))
18+
}

src/access/isAdminOrSelf.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import { Access } from "payload/config";
2-
import { FieldAccess } from "payload/types";
3-
import { User } from "../payload-types";
1+
import type { Access } from 'payload/config'
2+
import type { FieldAccess } from 'payload/types'
3+
4+
import type { User } from '../payload-types'
45

56
export const isAdminOrSelf: Access = ({ req: { user } }) => {
67
// Need to be logged in
78
if (user) {
89
// If user has role of 'admin'
9-
if (user.roles?.includes("admin")) {
10-
return true;
10+
if (user.roles?.includes('admin')) {
11+
return true
1112
}
1213

1314
// If any other type of user, only provide access to themselves
1415
return {
1516
id: {
1617
equals: user.id,
1718
},
18-
};
19+
}
1920
}
2021

2122
// Reject everyone else
22-
return false;
23-
};
23+
return false
24+
}
2425

25-
export const isAdminOrSelfFieldLevel: FieldAccess<
26-
{ id: string },
27-
unknown,
28-
User
29-
> = ({ req: { user }, id }) => {
26+
export const isAdminOrSelfFieldLevel: FieldAccess<{ id: string }, unknown, User> = ({
27+
req: { user },
28+
id,
29+
}) => {
3030
// Return true or false based on if the user has an admin role
31-
if (user?.roles?.includes("admin")) return true;
32-
if (user?.id === id) return true;
33-
return false;
34-
};
31+
if (user?.roles?.includes('admin')) return true
32+
if (user?.id === id) return true
33+
return false
34+
}

src/access/publishedOnly.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Access } from "payload/config";
1+
import type { Access } from 'payload/config'
22

33
export const publishedOnly: Access = ({ req: { user } }) => {
44
if (user?.roles?.includes('admin')) {
@@ -7,7 +7,7 @@ export const publishedOnly: Access = ({ req: { user } }) => {
77

88
return {
99
_status: {
10-
equals: 'published'
10+
equals: 'published',
1111
},
1212
}
13-
}
13+
}

src/blocks/Banner/index.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Block } from "payload/types";
2-
import { blockFields } from "../../fields/blockFields";
1+
import type { Block } from 'payload/types'
2+
3+
import { blockFields } from '../../fields/blockFields'
34

45
export const Banner: Block = {
56
slug: 'banner',
@@ -34,7 +35,7 @@ export const Banner: Block = {
3435
],
3536
admin: {
3637
width: '50%',
37-
}
38+
},
3839
},
3940
{
4041
name: 'addCheckmark',
@@ -43,22 +44,20 @@ export const Banner: Block = {
4344
width: '50%',
4445
style: {
4546
alignSelf: 'center',
46-
}
47-
}
47+
},
48+
},
4849
},
49-
]
50+
],
5051
},
5152
{
5253
name: 'content',
5354
type: 'richText',
5455
required: true,
5556
admin: {
56-
elements: [
57-
'link',
58-
],
59-
}
60-
}
61-
]
57+
elements: ['link'],
58+
},
59+
},
60+
],
6261
}),
63-
]
64-
}
62+
],
63+
}

src/blocks/BlogContent/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { Block } from "payload/types";
2-
import { blockFields } from "../../fields/blockFields";
3-
import richText from "../../fields/richText";
1+
import type { Block } from 'payload/types'
2+
3+
import { blockFields } from '../../fields/blockFields'
4+
import richText from '../../fields/richText'
45

56
export const BlogContent: Block = {
6-
slug: "blogContent",
7+
slug: 'blogContent',
78
fields: [
89
blockFields({
9-
name: "blogContentFields",
10-
fields: [richText({}, { elements: ["ul"] })],
10+
name: 'blogContentFields',
11+
fields: [richText({}, { elements: ['ul'] })],
1112
}),
1213
],
13-
};
14+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export const validate = (value: string) => {
1+
export const validate = (value: string): true | string => {
22
if (typeof value !== 'string' || value?.length === 0) {
3-
return 'This field is required.';
3+
return 'This field is required.'
44
}
55

6-
return true;
7-
};
6+
return true
7+
}

src/blocks/BlogMarkdown/index.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
import { Block } from "payload/types";
2-
import { blockFields } from "../../fields/blockFields";
3-
import { BlogMarkdownField } from "./Field";
1+
import type { Block } from 'payload/types'
2+
3+
import { blockFields } from '../../fields/blockFields'
4+
import { BlogMarkdownField } from './Field'
45

56
export const BlogMarkdown: Block = {
6-
slug: "blogMarkdown",
7+
slug: 'blogMarkdown',
78
labels: {
89
singular: 'Markdown',
910
plural: 'Markdown Blocks',
1011
},
1112
fields: [
1213
blockFields({
13-
name: "blogMarkdownFields",
14+
name: 'blogMarkdownFields',
1415
fields: [
1516
{
1617
name: 'markdown',
1718
type: 'text',
1819
required: true,
1920
admin: {
2021
components: {
21-
Field: BlogMarkdownField
22-
}
23-
}
24-
}
22+
Field: BlogMarkdownField,
23+
},
24+
},
25+
},
2526
],
2627
}),
2728
],
28-
};
29+
}

src/blocks/CallToAction/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Block } from "payload/types";
2-
import { blockFields } from "../../fields/blockFields";
3-
import linkGroup from "../../fields/linkGroup";
4-
import richText from "../../fields/richText";
1+
import type { Block } from 'payload/types'
2+
3+
import { blockFields } from '../../fields/blockFields'
4+
import linkGroup from '../../fields/linkGroup'
5+
import richText from '../../fields/richText'
56

67
export const CallToAction: Block = {
78
slug: 'cta',
@@ -28,12 +29,12 @@ export const CallToAction: Block = {
2829
label: 'Create Payload App',
2930
value: 'cpa',
3031
},
31-
]
32+
],
3233
},
3334
linkGroup({
3435
appearances: false,
3536
}),
36-
]
37-
})
38-
]
39-
}
37+
],
38+
}),
39+
],
40+
}

src/blocks/CardGrid/index.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Block } from "payload/types";
2-
import { blockFields } from "../../fields/blockFields";
3-
import link from "../../fields/link";
4-
import linkGroup from "../../fields/linkGroup";
5-
import richText from "../../fields/richText";
1+
import type { Block } from 'payload/types'
2+
3+
import { blockFields } from '../../fields/blockFields'
4+
import link from '../../fields/link'
5+
import linkGroup from '../../fields/linkGroup'
6+
import richText from '../../fields/richText'
67

78
export const CardGrid: Block = {
89
slug: 'cardGrid',
@@ -15,9 +16,9 @@ export const CardGrid: Block = {
1516
appearances: false,
1617
overrides: {
1718
admin: {
18-
description: 'These links will be placed above the card grid as calls-to-action.'
19-
}
20-
}
19+
description: 'These links will be placed above the card grid as calls-to-action.',
20+
},
21+
},
2122
}),
2223
{
2324
name: 'cards',
@@ -41,13 +42,13 @@ export const CardGrid: Block = {
4142
appearances: false,
4243
overrides: {
4344
admin: {
44-
condition: (_, { enableLink }) => enableLink ,
45-
}
46-
}
45+
condition: (_, { enableLink }) => enableLink,
46+
},
47+
},
4748
}),
48-
]
49+
],
4950
},
50-
]
51-
})
52-
]
53-
}
51+
],
52+
}),
53+
],
54+
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Block } from "payload/types";
2-
import { blockFields } from "../../fields/blockFields";
3-
import richText from "../../fields/richText";
1+
import type { Block } from 'payload/types'
2+
3+
import { blockFields } from '../../fields/blockFields'
4+
import richText from '../../fields/richText'
45

56
export const CaseStudiesHighlight: Block = {
67
slug: 'caseStudiesHighlight',
@@ -15,8 +16,8 @@ export const CaseStudiesHighlight: Block = {
1516
relationTo: 'case-studies',
1617
hasMany: true,
1718
required: true,
18-
}
19-
]
20-
})
21-
]
22-
}
19+
},
20+
],
21+
}),
22+
],
23+
}

0 commit comments

Comments
 (0)