Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

feat: update eslint, prettier and typescript #912

Merged
merged 2 commits into from
Oct 4, 2023
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
1 change: 0 additions & 1 deletion packages/app/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ module.exports = {
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-function-return-type': [0],
'@typescript-eslint/explicit-module-boundary-types': [0],
'@typescript-eslint/no-duplicate-imports': 'error',
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false, classes: true, variables: true },
Expand Down
25 changes: 12 additions & 13 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"last 2 Safari versions"
],
"dependencies": {
"@babel/eslint-parser": "7.21.3",
"@babel/eslint-parser": "7.22.15",
"@babel/runtime": "7.21.0",
"@emotion/babel-preset-css-prop": "11.10.0",
"@staticcms/core": "^3.3.4",
Expand All @@ -60,13 +60,13 @@
"@babel/preset-env": "7.21.4",
"@babel/preset-react": "7.18.6",
"@babel/preset-typescript": "7.21.4",
"@emotion/eslint-plugin": "11.10.0",
"@emotion/eslint-plugin": "11.11.0",
"@emotion/jest": "11.10.5",
"@types/node": "18.16.14",
"@types/react": "18.2.0",
"@types/react-dom": "18.2.1",
"@typescript-eslint/eslint-plugin": "5.59.1",
"@typescript-eslint/parser": "5.59.1",
"@typescript-eslint/eslint-plugin": "6.7.4",
"@typescript-eslint/parser": "6.7.4",
"autoprefixer": "10.4.14",
"babel-core": "7.0.0-bridge.0",
"babel-loader": "9.1.2",
Expand All @@ -81,24 +81,23 @@
"cross-env": "7.0.3",
"css-loader": "6.7.3",
"dotenv": "16.0.3",
"eslint": "8.39.0",
"eslint-import-resolver-typescript": "3.5.5",
"eslint-plugin-cypress": "2.13.3",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-react": "7.32.2",
"eslint": "8.50.0",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-cypress": "2.15.1",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-unicorn": "46.0.1",
"eslint-plugin-unicorn": "48.0.1",
"mini-css-extract-plugin": "2.7.5",
"npm-run-all": "4.1.5",
"postcss": "8.4.23",
"postcss-scss": "4.0.6",
"prettier": "2.8.8",
"prettier": "3.0.3",
"source-map-loader": "4.0.1",
"style-loader": "3.3.2",
"to-string-loader": "1.2.0",
"tsconfig-paths-webpack-plugin": "4.0.1",
"typescript": "5.0.4",
"typescript": "5.2.2",
"webpack": "5.80.0",
"webpack-cli": "5.0.2"
},
Expand Down
1 change: 0 additions & 1 deletion packages/core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ module.exports = {
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-function-return-type': [0],
'@typescript-eslint/explicit-module-boundary-types': [0],
'@typescript-eslint/no-duplicate-imports': 'error',
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false, classes: true, variables: true },
Expand Down
28 changes: 14 additions & 14 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"last 2 Safari versions"
],
"dependencies": {
"@babel/eslint-parser": "7.21.3",
"@babel/eslint-parser": "7.22.15",
"@babel/runtime": "7.21.0",
"@codemirror/autocomplete": "6.5.1",
"@codemirror/commands": "6.2.3",
Expand Down Expand Up @@ -102,7 +102,7 @@
"deepmerge": "4.3.1",
"diacritics": "1.3.0",
"escape-html": "1.0.3",
"eslint-config-prettier": "8.8.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-babel": "5.3.1",
"fuzzy": "0.1.3",
"globby": "13.1.4",
Expand Down Expand Up @@ -189,7 +189,7 @@
"@babel/preset-env": "7.21.4",
"@babel/preset-react": "7.18.6",
"@babel/preset-typescript": "7.21.4",
"@emotion/eslint-plugin": "11.10.0",
"@emotion/eslint-plugin": "11.11.0",
"@emotion/jest": "11.10.5",
"@iarna/toml": "2.2.5",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
Expand Down Expand Up @@ -217,8 +217,8 @@
"@types/styled-components": "5.1.26",
"@types/url-join": "4.0.1",
"@types/uuid": "9.0.1",
"@typescript-eslint/eslint-plugin": "5.59.1",
"@typescript-eslint/parser": "5.59.1",
"@typescript-eslint/eslint-plugin": "6.7.4",
"@typescript-eslint/parser": "6.7.4",
"autoprefixer": "10.4.14",
"axios": "1.3.6",
"babel-core": "7.0.0-bridge.0",
Expand All @@ -237,14 +237,14 @@
"cross-env": "7.0.3",
"css-loader": "6.7.3",
"dotenv": "16.0.3",
"eslint": "8.39.0",
"eslint-import-resolver-typescript": "3.5.5",
"eslint-plugin-cypress": "2.13.3",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-react": "7.32.2",
"eslint": "8.50.0",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-cypress": "2.15.1",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-unicorn": "46.0.1",
"eslint-plugin-unicorn": "48.0.1",
"execa": "7.1.1",
"fs-extra": "11.1.1",
"gitlab": "14.2.2",
Expand All @@ -260,7 +260,7 @@
"npm-run-all": "4.1.5",
"postcss": "8.4.23",
"postcss-loader": "7.2.4",
"prettier": "2.8.8",
"prettier": "3.0.3",
"process": "0.11.10",
"react-refresh": "0.14.0",
"react-svg-loader": "3.0.3",
Expand All @@ -273,7 +273,7 @@
"ts-jest": "29.1.0",
"ts-node": "10.9.1",
"tsconfig-paths-webpack-plugin": "4.0.1",
"typescript": "5.0.4",
"typescript": "5.2.2",
"webpack": "5.80.0",
"webpack-cli": "5.0.2",
"webpack-dev-server": "4.13.3"
Expand Down
62 changes: 34 additions & 28 deletions packages/core/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,22 @@ export function expandSearchEntries(
field: string;
})[] {
// expand the entries for the purpose of the search
const expandedEntries = entries.reduce((acc, e) => {
const expandedFields = searchFields.reduce((acc, f) => {
const fields = expandPath({ data: e.data, path: f });
acc.push(...fields);
return acc;
}, [] as string[]);
const expandedEntries = entries.reduce(
(acc, e) => {
const expandedFields = searchFields.reduce((acc, f) => {
const fields = expandPath({ data: e.data, path: f });
acc.push(...fields);
return acc;
}, [] as string[]);

for (let i = 0; i < expandedFields.length; i++) {
acc.push({ ...e, field: expandedFields[i] });
}
for (let i = 0; i < expandedFields.length; i++) {
acc.push({ ...e, field: expandedFields[i] });
}

return acc;
}, [] as (Entry & { field: string })[]);
return acc;
},
[] as (Entry & { field: string })[],
);

return expandedEntries;
}
Expand All @@ -212,27 +215,30 @@ export function mergeExpandedEntries(entries: (Entry & { field: string })[]): En
const fields = entries.map(f => f.field);
const arrayPaths: Record<string, Set<string>> = {};

const merged = entries.reduce((acc, e) => {
if (!acc[e.slug]) {
const { field: _field, ...rest } = e;
acc[e.slug] = rest;
arrayPaths[e.slug] = new Set();
}
const merged = entries.reduce(
(acc, e) => {
if (!acc[e.slug]) {
const { field: _field, ...rest } = e;
acc[e.slug] = rest;
arrayPaths[e.slug] = new Set();
}

const nestedFields = e.field.split('.');
let value: ValueOrNestedValue = acc[e.slug].data;
for (let i = 0; i < nestedFields.length; i++) {
if (isNotNullish(value)) {
value = value[nestedFields[i]];
if (Array.isArray(value)) {
const path = nestedFields.slice(0, i + 1).join('.');
arrayPaths[e.slug] = arrayPaths[e.slug].add(path);
const nestedFields = e.field.split('.');
let value: ValueOrNestedValue = acc[e.slug].data;
for (let i = 0; i < nestedFields.length; i++) {
if (isNotNullish(value)) {
value = value[nestedFields[i]];
if (Array.isArray(value)) {
const path = nestedFields.slice(0, i + 1).join('.');
arrayPaths[e.slug] = arrayPaths[e.slug].add(path);
}
}
}
}

return acc;
}, {} as Record<string, Entry>);
return acc;
},
{} as Record<string, Entry>,
);

// this keeps the search score sorting order designated by the order in entries
// and filters non matching items
Expand Down
33 changes: 18 additions & 15 deletions packages/core/src/backends/github/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,24 @@ function withCmsLabel(pr: GitHubPull, cmsLabelPrefix: string) {
}

function getTreeFiles(files: GitHubCompareFiles) {
const treeFiles = files.reduce((arr, file) => {
if (file.status === 'removed') {
// delete the file
arr.push({ sha: null, path: file.filename });
} else if (file.status === 'renamed') {
// delete the previous file
arr.push({ sha: null, path: file.previous_filename as string });
// add the renamed file
arr.push({ sha: file.sha, path: file.filename });
} else {
// add the file
arr.push({ sha: file.sha, path: file.filename });
}
return arr;
}, [] as { sha: string | null; path: string }[]);
const treeFiles = files.reduce(
(arr, file) => {
if (file.status === 'removed') {
// delete the file
arr.push({ sha: null, path: file.filename });
} else if (file.status === 'renamed') {
// delete the previous file
arr.push({ sha: null, path: file.previous_filename as string });
// add the renamed file
arr.push({ sha: file.sha, path: file.filename });
} else {
// add the file
arr.push({ sha: file.sha, path: file.filename });
}
return arr;
},
[] as { sha: string | null; path: string }[],
);

return treeFiles;
}
Expand Down
13 changes: 8 additions & 5 deletions packages/core/src/backends/gitlab/__tests__/gitlab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,14 @@ describe('gitlab backend', () => {
if (!query) {
return {};
}
return query.split('&').reduce((acc, q) => {
const [key, value] = q.split('=');
acc[key] = value;
return acc;
}, {} as Record<string, string>);
return query.split('&').reduce(
(acc, q) => {
const [key, value] = q.split('=');
acc[key] = value;
return acc;
},
{} as Record<string, string>,
);
}

interface CreateHeadersOptions {
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/components/collections/CollectionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ const CollectionHeader: FC<CollectionHeaderProps> = ({ collection }) => {

const pluralLabel = useMemo(() => {
if ('nested' in collection && collection.nested?.path && filterTerm) {
const entriesByPath = entries.reduce((acc, entry) => {
acc[entry.path] = entry;
return acc;
}, {} as Record<string, Entry>);
const entriesByPath = entries.reduce(
(acc, entry) => {
acc[entry.path] = entry;
return acc;
},
{} as Record<string, Entry>,
);

if (isNotEmpty(filterTerm)) {
const extension = selectFolderEntryExtension(collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ const EntryListing: FC<EntryListingProps> = ({
}

const fieldNames = otherProps.collection.summary_fields;
const collectionFields = selectFields(otherProps.collection).reduce((acc, f) => {
acc[f.name] = f;
return acc;
}, {} as Record<string, Field>);
const collectionFields = selectFields(otherProps.collection).reduce(
(acc, f) => {
acc[f.name] = f;
return acc;
},
{} as Record<string, Field>,
);

return fieldNames.map(summaryField => {
const field = collectionFields[summaryField];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ const Autocomplete: FC<AutocompleteProps> = ({
const finalOptions = useMemo(() => options.map(getOptionLabelAndValue), [options]);
const optionsByValue = useMemo(
() =>
finalOptions.reduce((acc, option) => {
acc[option.value] = option;
finalOptions.reduce(
(acc, option) => {
acc[option.value] = option;

return acc;
}, {} as Record<string, Option>),
return acc;
},
{} as Record<string, Option>,
),
[finalOptions],
);

Expand Down
Loading