diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cf03e17a..9f7c18fc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,27 +1,41 @@ -name: Lint Web Embeds +name: Lint Web Packages on: push: + branches: + - main paths: - 'web-embeds/**' + - 'packages/web-shared/**' + - '.github/workflows/lint.yml' + - 'package.json' + - 'yarn.lock' pull_request: paths: - 'web-embeds/**' + - 'packages/web-shared/**' + - '.github/workflows/lint.yml' + - 'package.json' + - 'yarn.lock' jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: - node-version: '>=18.17.0' + node-version: '18' + cache: 'yarn' - - name: Install Dependencies - run: cd web-embeds && yarn install + - name: Install dependencies + run: yarn install --frozen-lockfile - - name: Run Lint - run: cd web-embeds && yarn lint + - name: Lint web embeds + run: yarn workspace @apollosproject/apollos-embeds lint + + - name: Lint web shared + run: yarn workspace @apollosproject/web-shared lint diff --git a/packages/web-shared/.eslintrc.js b/packages/web-shared/.eslintrc.js new file mode 100644 index 00000000..3692f4ed --- /dev/null +++ b/packages/web-shared/.eslintrc.js @@ -0,0 +1,44 @@ +module.exports = { + extends: ['react-app', 'plugin:prettier/recommended'], + plugins: ['simple-import-sort', 'import'], + rules: { + 'import/first': 'error', + 'import/newline-after-import': 'error', + 'import/no-duplicates': 'error', + 'import/order': [ + 'error', + { + groups: [['external', 'builtin'], 'internal', ['sibling', 'parent'], 'index'], + pathGroups: [ + { + pattern: '@(react|react-native)', + group: 'external', + position: 'before', + }, + { + pattern: '@src/**', + group: 'internal', + }, + ], + pathGroupsExcludedImportTypes: ['internal', 'react'], + 'newlines-between': 'always', + alphabetize: { + order: 'asc', + caseInsensitive: true, + }, + }, + ], + 'lines-around-comment': [ + 'error', + { + allowArrayStart: true, + allowBlockStart: true, + allowClassStart: true, + allowObjectStart: true, + beforeBlockComment: true, + beforeLineComment: true, + }, + ], + 'spaced-comment': ['error', 'always'], + }, +}; diff --git a/packages/web-shared/analytics/segment.js b/packages/web-shared/analytics/segment.js index 34cd0135..3d0becd4 100644 --- a/packages/web-shared/analytics/segment.js +++ b/packages/web-shared/analytics/segment.js @@ -1,4 +1,5 @@ import { AnalyticsBrowser } from '@segment/analytics-next'; + const clientFactory = (writeKey, clientManaged = false) => { if (!writeKey) { return null; diff --git a/packages/web-shared/client/apolloClient.js b/packages/web-shared/client/apolloClient.js index 01c42833..ab11bcd5 100644 --- a/packages/web-shared/client/apolloClient.js +++ b/packages/web-shared/client/apolloClient.js @@ -1,11 +1,11 @@ import { ApolloClient, ApolloLink } from '@apollo/client'; -import { AUTH_TOKEN_KEY, AUTH_REFRESH_TOKEN_KEY } from '../config/keys'; import apollosApiLink from './apollosApiLink'; import authLink from './authLink'; +import buildErrorLink from './buildErrorLink'; import httpLink from './httpLink'; import initCache from './initCache'; -import buildErrorLink from './buildErrorLink'; +import { AUTH_TOKEN_KEY, AUTH_REFRESH_TOKEN_KEY } from '../config/keys'; const client = async (church_slug) => { let storeIsResetting = false; diff --git a/packages/web-shared/client/authLink.js b/packages/web-shared/client/authLink.js index dd0794d8..b8262552 100644 --- a/packages/web-shared/client/authLink.js +++ b/packages/web-shared/client/authLink.js @@ -1,4 +1,5 @@ import { setContext } from '@apollo/client/link/context'; + import { AUTH_TOKEN_KEY } from '../config/keys'; export default setContext(async (request, { headers }) => { diff --git a/packages/web-shared/client/httpLink.js b/packages/web-shared/client/httpLink.js index 705343a9..e083a92a 100644 --- a/packages/web-shared/client/httpLink.js +++ b/packages/web-shared/client/httpLink.js @@ -1,6 +1,6 @@ -import { createUploadLink } from 'apollo-upload-client'; import { split, createHttpLink } from '@apollo/client'; import { getMainDefinition } from '@apollo/client/utilities'; +import { createUploadLink } from 'apollo-upload-client'; export const uri = process.env.NEXT_PUBLIC_DATA_URL || process.env.REACT_APP_DATA_URL || 'https://cdn.apollos.app'; diff --git a/packages/web-shared/client/initCache.js b/packages/web-shared/client/initCache.js index 74bccfbe..d80fed76 100644 --- a/packages/web-shared/client/initCache.js +++ b/packages/web-shared/client/initCache.js @@ -1,5 +1,6 @@ import { InMemoryCache } from '@apollo/client/core'; import { persistCache } from 'apollo3-cache-persist'; + import { uri } from './httpLink'; const initCache = async (initialState, { church }) => { diff --git a/packages/web-shared/client/introspectionToPossibleTypes.js b/packages/web-shared/client/introspectionToPossibleTypes.js index c7bd03a0..aa77213d 100644 --- a/packages/web-shared/client/introspectionToPossibleTypes.js +++ b/packages/web-shared/client/introspectionToPossibleTypes.js @@ -3,9 +3,7 @@ function introspectionToPossibleTypes(introspectionQueryResultData) { introspectionQueryResultData.__schema.types.forEach((supertype) => { if (supertype.possibleTypes) { - possibleTypes[supertype.name] = [ - ...supertype.possibleTypes.map((subtype) => subtype.name), - ]; + possibleTypes[supertype.name] = [...supertype.possibleTypes.map((subtype) => subtype.name)]; } }); diff --git a/packages/web-shared/components/AddToCalendar/AddToCalendar.js b/packages/web-shared/components/AddToCalendar/AddToCalendar.js index 7fbef21a..9b541171 100644 --- a/packages/web-shared/components/AddToCalendar/AddToCalendar.js +++ b/packages/web-shared/components/AddToCalendar/AddToCalendar.js @@ -1,4 +1,5 @@ import React from 'react'; + import { Menu } from '@headlessui/react'; import { CalendarPlus, @@ -7,9 +8,10 @@ import { MicrosoftOutlookLogo, FileArrowDown, } from '@phosphor-icons/react'; -import { ActionIcon, List, MenuLink } from './AddToCalendar.styles'; import { addSeconds, parseISO } from 'date-fns'; +import { ActionIcon, List, MenuLink } from './AddToCalendar.styles'; + function convertToGoogleLink({ start, duration, location, allDay, title }) { const startDate = parseISO(start); const endDate = addSeconds(startDate, duration); diff --git a/packages/web-shared/components/AddToCalendar/AddToCalendar.styles.js b/packages/web-shared/components/AddToCalendar/AddToCalendar.styles.js index e9de00f0..f3e7b043 100644 --- a/packages/web-shared/components/AddToCalendar/AddToCalendar.styles.js +++ b/packages/web-shared/components/AddToCalendar/AddToCalendar.styles.js @@ -1,10 +1,10 @@ import React from 'react'; + import { Menu } from '@headlessui/react'; -import styled from 'styled-components'; -import { withTheme } from 'styled-components'; +import { themeGet } from '@styled-system/theme-get'; import { rgba } from 'polished'; +import styled, { withTheme } from 'styled-components'; -import { themeGet } from '@styled-system/theme-get'; import { system } from '../../ui-kit/_lib/system'; export const ActionIcon = withTheme(styled(Menu.Button)` diff --git a/packages/web-shared/components/AddToCalendar/index.js b/packages/web-shared/components/AddToCalendar/index.js index ad0a8ee8..87cf1a92 100644 --- a/packages/web-shared/components/AddToCalendar/index.js +++ b/packages/web-shared/components/AddToCalendar/index.js @@ -1,2 +1,3 @@ import AddToCalendar from './AddToCalendar'; + export default AddToCalendar; diff --git a/packages/web-shared/components/AppHeader/AppHeader.js b/packages/web-shared/components/AppHeader/AppHeader.js index 850577a2..013d61f3 100644 --- a/packages/web-shared/components/AppHeader/AppHeader.js +++ b/packages/web-shared/components/AppHeader/AppHeader.js @@ -1,11 +1,10 @@ -import Wordmark from '../Wordmark'; -import { useCurrentChurch } from '../../hooks'; -import { Box, Avatar } from '../../ui-kit'; import { User } from '@phosphor-icons/react'; -import SearchStyles from '../Searchbar/Search.styles'; - +import { useCurrentChurch } from '../../hooks'; +import { Box } from '../../ui-kit'; import ProfileButton from '../Profile/ProfileButton'; +import SearchStyles from '../Searchbar/Search.styles'; +import Wordmark from '../Wordmark'; function ChurchLogo(props) { const { currentChurch } = useCurrentChurch(); diff --git a/packages/web-shared/components/Auth/AuthConfirm.js b/packages/web-shared/components/Auth/AuthConfirm.js index 444bc485..da73b888 100644 --- a/packages/web-shared/components/Auth/AuthConfirm.js +++ b/packages/web-shared/components/Auth/AuthConfirm.js @@ -1,15 +1,13 @@ import React, { useEffect, useState } from 'react'; -import isEmpty from 'lodash/isEmpty'; -import { useValidateLogin, useValidateRegister } from '../../hooks'; -// import amplitude from '../../libs/amplitude'; -import { update as updateAuth, useAuth } from '../../providers/AuthProvider'; +import isEmpty from 'lodash/isEmpty'; -import { Box, Button, Input } from '../../ui-kit'; import AuthLayout from './AuthLayout'; - import authSteps from './authSteps'; +import { useValidateLogin, useValidateRegister } from '../../hooks'; import { useAnalytics } from '../../providers/AnalyticsProvider'; +import { update as updateAuth, useAuth } from '../../providers/AuthProvider'; +import { Box, Button, Input } from '../../ui-kit'; const AuthConfirm = (props) => { const [status, setStatus] = useState('IDLE'); @@ -146,11 +144,7 @@ const AuthConfirm = (props) => { error={error?.passcode} /> -