Skip to content

Commit

Permalink
chore(eslint): setup typescript-eslint/recommended (#6577)
Browse files Browse the repository at this point in the history
* chore: remove unused utils/components/packages

* initial eslint/prettier setup

* merge RemoveUnusedCode

* fix(linting errors): single quotes in text

* Remove WhatsNewBanner

* Remove WhatsNewBanner

* fix(linting errors): single quotes in text

* add rule to throw eslint error for react hooks dependencies instead of a warning

* Remove unused InfoPopover

* Remove unused InfoPopover

* fix(linting errors): do not pass children as prop in Block test

* fix(linting errors): fix next img warnings

* fix(linting errors): missing hook dependency GetStartedPopover

* fix(linting error): move handleScroll to its own useEffect w/o dependency array

* fix(linting error): missing hook dependency in MDXCode

* fix(linting error): order of hooks MDXLink

* fix(linting error): missing hook dependency PlatformNavigator

* fix(linting error): convert findRoute to hook, useRouteFinder, move to separate utils file

* fix(lint errors): MenuItem and type update

* fix(lint errors): make 3rd party scripts load async

* fix(linting error): cleanup function in hook useTabKeyDetection

* change 3rd party scripts to defer

* clean up eslint warnings in next.config.mjs

* use next ExportedImage instead of Image

* chore(eslint): setup typescript-eslint/recommended

* remove @typescript-eslint/parser, its already included

* fix unused vars, const/let

* Switch awshome_s_code to async to fix track errors

* Fix unused imports and const/let variables

* use typescript/eslint for unused vars

* add linting to staged files with husky

* update lintstagedrc

* Add prettier to husky precommit

* downgrade lint-staged to v14 to work with node16

* update prettierignore

* ignore mdx files for now

* Remove SidebarLayoutToggle

* remove unified and mdx-prism

* remove comments

* add eslint ignore for 3rd party script we have to load sync

* add comment about prettier coming last
  • Loading branch information
hbuchel authored Dec 5, 2023
1 parent 99d5c62 commit 1dc5709
Show file tree
Hide file tree
Showing 30 changed files with 106 additions and 105 deletions.
14 changes: 11 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"extends": ["next/core-web-vitals", "prettier"],
"plugins": ["prettier"],
"extends": [
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended",
"prettier" // prettier should always come last
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"react-hooks/exhaustive-deps": "error"
"react-hooks/exhaustive-deps": "error",
"@typescript-eslint/no-explicit-any": "warn",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@types/node": "^12.12.9",
"@types/react": "^18.0.0",
"@types/url-parse": "^1.4.3",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"axios": "^1.3.4",
"classnames": "^2.3.2",
"cross-env": "^7.0.3",
Expand Down
8 changes: 4 additions & 4 deletions src/components/Breadcrumbs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ function generateBreadcrumbs(
const breadcrumbs: BreadcrumbItem[] = [];

const pieces = route.split('/').filter((str) => str);
let urls: string[] = [];
const urls: string[] = [];
for (let i = 1; i <= pieces.length; i++) {
urls.push(`/${pieces.slice(0, i).join('/')}`);
}

urls.forEach((url) => {
const directoryEntry = findNode(url);
let href = {
const href = {
pathname: url
};
if (url.includes('[platform]')) {
Expand All @@ -75,8 +75,8 @@ function generateBreadcrumbs(
return breadcrumbs;
}

function BreadcrumbsComponent({ route, platform, isGen2 }: Props) {
const items = generateBreadcrumbs(route, platform, isGen2);
function BreadcrumbsComponent({ route, platform }: Props) {
const items = generateBreadcrumbs(route, platform);
return items.length > 1 ? (
<div className={'breadcrumb__container'}>
<Breadcrumbs.Container>
Expand Down
2 changes: 1 addition & 1 deletion src/components/CliCommands/Command.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CliCommand, CliCommandFlag } from '@/data/cli-commands';
import { Heading, Text, Flex, View } from '@aws-amplify/ui-react';
import { Text, Flex } from '@aws-amplify/ui-react';
import { MDXCode } from '../MDXComponents';
import { CommandHeading, SubCommandHeading } from './CommandHeading';
import { Fragment } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion src/components/ExternalLink/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ExternalLink: React.FC<ExternalLinkProps> = ({
className={className}
rel="noopener noreferrer"
target="_blank"
onClick={(e) => {
onClick={() => {
trackLink(href);
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ExternalLinkButton/ExternalLinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const ExternalLinkButton = ({
as="a"
align-items="center"
className={className}
onClick={(e) => {
onClick={() => {
trackLink(href);
}}
>
Expand Down
3 changes: 0 additions & 3 deletions src/components/FeatureFlags/FeatureFlagValues.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import {
Heading,
Table,
TableCell,
TableBody,
TableHead,
TableRow,
Text,
View
} from '@aws-amplify/ui-react';
import Link from 'next/link';

export type FeatureFlags = Record<string, Section>;

Expand Down
2 changes: 1 addition & 1 deletion src/components/FeatureLists/FeatureLists.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Grid, Heading } from '@aws-amplify/ui-react';
import { Heading } from '@aws-amplify/ui-react';
import { Columns } from '@/components/Columns';

interface FeatureListsProps {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Feedback/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Feedback from '../index';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as trackModule from '../../../utils/track';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import { render, screen } from '@testing-library/react';
import FilterChildren from '../index';
// import * as React from 'react';
// import { render, screen } from '@testing-library/react';
// import FilterChildren from '../index';

let routerMock = {
const routerMock = {
__esModule: true
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { render, screen } from '@testing-library/react';
import FilterContent from '../index';

let routerMock = {
const routerMock = {
__esModule: true
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/Fragments/__tests__/Fragments.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { render, screen } from '@testing-library/react';
import Fragments from '../index';

let routerMock = {
const routerMock = {
__esModule: true,
useRouter: () => {
return {
Expand Down
4 changes: 0 additions & 4 deletions src/components/Fragments/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Fragment } from 'react';
import FilterChildren from '../FilterChildren';

type MdxFrontmatterType = {
lastUpdated: string;
};

export default function Fragments({ fragments }) {
const children: React.ReactNode[] = [];

Expand Down
3 changes: 1 addition & 2 deletions src/components/GetStartedPopover/GetStartedPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect, useRef, useCallback } from 'react';
import { useState, useEffect, useRef } from 'react';
import classNames from 'classnames';
import { Button, Flex, VisuallyHidden, View } from '@aws-amplify/ui-react';
import Link from 'next/link';
Expand All @@ -15,7 +15,6 @@ import {
IconVue
} from '@/components/Icons';
import { useClickOutside } from '@/utils/useClickOutside';
import { DEFAULT_PLATFORM } from '@/data/platforms';
import { useTabKeyDetection } from '@/utils/useTabKeyDetection';

const getStartedHref = '/[platform]/start/getting-started/introduction/';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Icons/IconNext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect, useMemo } from 'react';
import { useState, useEffect } from 'react';
import { Icon } from '@aws-amplify/ui-react';
import { v4 as uuidv4 } from 'uuid';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { render, screen } from '@testing-library/react';
import InlineFilter from '../index';

let routerMock = {
const routerMock = {
__esModule: true,
useRouter: () => {
return {
Expand Down
4 changes: 1 addition & 3 deletions src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ import { LayoutProvider } from '@/components/Layout';
import { TableOfContents } from '@/components/TableOfContents';
import type { HeadingInterface } from '@/components/TableOfContents/TableOfContents';
import { PlatformNavigator } from '@/components/PlatformNavigator';
import directory from 'src/directory/directory.json';
import flatDirectory from 'src/directory/flatDirectory.json';
import { PageNode } from 'src/directory/directory';
import { Breadcrumbs } from '@/components/Breadcrumbs';
import { debounce } from '@/utils/debounce';
import { DocSearch } from '@docsearch/react';
Expand All @@ -65,7 +63,7 @@ export const Layout = ({
url,
useCustomTitle = false
}: {
children: any;
children: React.ReactNode;
hasTOC?: boolean;
pageDescription?: string;
pageTitle?: string;
Expand Down
9 changes: 7 additions & 2 deletions src/components/MDXComponents/MDXLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import ExternalLink from '@/components/ExternalLink';
import { useCurrentPlatform } from '@/utils/useCurrentPlatform';
import { usePathWithoutHash } from '@/utils/usePathWithoutHash';

export const MDXLink = (props) => {
let { href, children, hash } = props;
export const MDXLink = ({
href: hrefFromProps,
children,
hash: hashFromProps
}) => {
let href = hrefFromProps;
let hash = hashFromProps;
const isInternal = href && (href.startsWith('/') || href.startsWith('#'));
const baseURI = usePathWithoutHash();
const platform = useCurrentPlatform();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function MenuItem({
}
};

let pathname = getPathname(pageNode.route, currentPlatform);
const pathname = getPathname(pageNode.route, currentPlatform);

const current = asPathWithoutHash === pathname;

Expand Down
2 changes: 0 additions & 2 deletions src/components/MigrationAlert/MigrationAlert.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useState } from 'react';
import { Callout } from '../Callout';
import Link from 'next/link';
import { useCurrentPlatform } from '@/utils/useCurrentPlatform';
import { Platform } from '@/data/platforms';

type MigrationAlert = {
isLegacy: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/components/NextPrevious/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const NextPrevious = () => {
return { previous, next };
} else if (children && children.length) {
for (let i = 0; i < children.length; i++) {
let child = children[i];
let res = findDirectoryNodes(
const child = children[i];
const res = findDirectoryNodes(
route,
child,
platform,
Expand Down
2 changes: 1 addition & 1 deletion src/components/PlatformNavigator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useRef, useEffect, useCallback } from 'react';
import { useState, useRef, useEffect } from 'react';
import { Button, Flex, Text, View } from '@aws-amplify/ui-react';
import { IconChevron } from '@/components/Icons';
import { frameworks } from '@/constants/frameworks';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function getStaticProps() {

export default function Custom404() {
const basePath = 'https://docs.amplify.aws';
let [href, setHref] = useState(basePath);
const [href, setHref] = useState(basePath);
const path = useRouter().asPath;
useEffect(() => {
setHref(basePath + path);
Expand Down
3 changes: 1 addition & 2 deletions src/pages/[platform]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { FrameworkGrid } from '@/components/FrameworkGrid';
import { IconChevron } from '@/components/Icons';
import { GetStartedPopover } from '@/components/GetStartedPopover';
import { InternalLinkButton } from '@/components/InternalLinkButton';
import { Flex, Heading, Button, Text } from '@aws-amplify/ui-react';
import { Flex, Heading, Text } from '@aws-amplify/ui-react';
import LinkCards from '@/components/LinkCards';
import PlatformFeatureList from '@/components/FeatureLists/PlatformFeatureList';
import Link from 'next/link';

export const meta = {
title: 'Overview',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[platform]/tools/cli/commands.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
import { Flex, Heading, View } from '@aws-amplify/ui-react';
import { Flex } from '@aws-amplify/ui-react';
import { commands } from '@/data/cli-commands.mjs';
import { Command } from '@/components/CliCommands';

Expand Down
4 changes: 2 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Heading, Text, Flex, Button, Grid } from '@aws-amplify/ui-react';
import { Heading, Text, Flex } from '@aws-amplify/ui-react';
import { FrameworkGrid } from '@/components/FrameworkGrid';
import { GetStartedPopover } from '@/components/GetStartedPopover';
import { IconChevron } from '@/components/Icons';
Expand Down Expand Up @@ -28,7 +28,7 @@ export function getStaticProps() {

export default function Page() {
//Default platform is javascript
let defaultPlatform = DEFAULT_PLATFORM;
const defaultPlatform = DEFAULT_PLATFORM;

return (
<Flex className="home-content">
Expand Down
18 changes: 9 additions & 9 deletions src/utils/findDirectoryNode.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import directory from '../directory/directory.json';

export const findDirectoryNode = (route, dir = directory) => {
if(dir.route === route){
return dir
}else if(dir.children && dir.children.length){
for(let i = 0; i < dir.children.length; i++){
let child = dir.children[i];
let res = findDirectoryNode(route, child);
if(res) return res;
}
if (dir.route === route) {
return dir;
} else if (dir.children && dir.children.length) {
for (let i = 0; i < dir.children.length; i++) {
const child = dir.children[i];
const res = findDirectoryNode(route, child);
if (res) return res;
}
}
}
};
2 changes: 1 addition & 1 deletion src/utils/parseLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function parseLocalStorage(key: string, fallback: any): any {
if (typeof localStorage === "undefined") return fallback;
if (typeof localStorage === 'undefined') return fallback;

const result = localStorage.getItem(key);
if (!result) {
Expand Down
47 changes: 1 addition & 46 deletions src/utils/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,6 @@ export enum AnalyticsEventType {
PAGE_DATA_FETCH_EXCEPTION = 'PAGE_DATA_FETCH_EXCEPTION'
}

interface AnalyticsEventPageVisit {
type: AnalyticsEventType.PAGE_VISIT;
attributes: {
url: string;
previousUrl: string;
referrer: string;
};
}

interface AnalyticsEventInternalLinkClick {
type: AnalyticsEventType.INTERNAL_LINK_CLICK;
attributes: {
from: string;
to: string;
};
}

interface AnalyticsEventExternalLinkClick {
type: AnalyticsEventType.EXTERNAL_LINK_CLICK;
attributes: {
from: string;
to: string;
};
}

interface AnalyticsEventPageDataFetchException {
type: AnalyticsEventType.PAGE_DATA_FETCH_EXCEPTION;
attributes: {
url: string;
exception: Error;
};
}

type AnalyticsEvent =
| AnalyticsEventPageVisit
| AnalyticsEventInternalLinkClick
| AnalyticsEventExternalLinkClick
| AnalyticsEventPageDataFetchException;

export const trackPageVisit = (): void => {
if (typeof window !== 'undefined' && typeof s != 'undefined') {
s.pageName = window.location.href;
Expand Down Expand Up @@ -130,13 +91,7 @@ export const setSearchResultCount = (resultCount: number): void => {
}
};

export const trackSearchQuery = (
_input,
_event,
suggestion,
_datasetNumber,
_context
): void => {
export const trackSearchQuery = (_input, _event, suggestion): void => {
if (typeof window !== 'undefined' && typeof s != 'undefined') {
s.linkTrackVars =
'prop39,prop41,prop50,prop61,prop62,eVar26,eVar27,eVar39,eVar41,eVar50,eVar61,eVar62,eVar69,events';
Expand Down
Loading

0 comments on commit 1dc5709

Please sign in to comment.