Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(eslint): setup typescript-eslint/recommended #6577

Merged
merged 49 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a8804e1
chore: remove unused utils/components/packages
hbuchel Nov 28, 2023
dda4881
initial eslint/prettier setup
hbuchel Nov 29, 2023
a66fa1e
merge RemoveUnusedCode
hbuchel Nov 28, 2023
5568a92
fix(linting errors): single quotes in text
hbuchel Nov 29, 2023
4746062
Remove WhatsNewBanner
hbuchel Nov 29, 2023
e6ec6f1
Remove WhatsNewBanner
hbuchel Nov 29, 2023
eabaab7
fix(linting errors): single quotes in text
hbuchel Nov 29, 2023
ef26faa
add rule to throw eslint error for react hooks dependencies instead o…
hbuchel Nov 29, 2023
1e125b5
Remove unused InfoPopover
hbuchel Nov 29, 2023
7eee674
Remove unused InfoPopover
hbuchel Nov 29, 2023
f65bcf5
fix(linting errors): do not pass children as prop in Block test
hbuchel Nov 29, 2023
9d9c6fb
fix(linting errors): fix next img warnings
hbuchel Nov 29, 2023
f1a1dff
fix(linting errors): missing hook dependency GetStartedPopover
hbuchel Nov 29, 2023
48d96dc
fix(linting error): move handleScroll to its own useEffect w/o depend…
hbuchel Nov 29, 2023
e9ecf32
fix(linting error): missing hook dependency in MDXCode
hbuchel Nov 29, 2023
4538920
fix(linting error): order of hooks MDXLink
hbuchel Nov 29, 2023
6c59a53
fix(linting error): missing hook dependency PlatformNavigator
hbuchel Nov 29, 2023
792a44d
fix(linting error): convert findRoute to hook, useRouteFinder, move t…
hbuchel Nov 29, 2023
c0056a6
fix(lint errors): MenuItem and type update
hbuchel Nov 29, 2023
370898d
fix(lint errors): make 3rd party scripts load async
hbuchel Nov 29, 2023
490d66f
Merge branch 'main' into SetupESLint
hbuchel Nov 29, 2023
a630015
fix(linting error): cleanup function in hook useTabKeyDetection
hbuchel Nov 29, 2023
a8570ee
change 3rd party scripts to defer
hbuchel Nov 29, 2023
2b2485d
clean up eslint warnings in next.config.mjs
hbuchel Nov 29, 2023
fa0623e
use next ExportedImage instead of Image
hbuchel Nov 29, 2023
1890ae7
chore(eslint): setup typescript-eslint/recommended
hbuchel Nov 29, 2023
cb261cd
remove @typescript-eslint/parser, its already included
hbuchel Nov 29, 2023
c35d62c
fix unused vars, const/let
hbuchel Nov 29, 2023
9fb98f9
Switch awshome_s_code to async to fix track errors
hbuchel Nov 29, 2023
81972ab
Merge branch 'SetupESLint' into ESLintWithTypescript
hbuchel Nov 29, 2023
e57c2d7
Fix unused imports and const/let variables
hbuchel Nov 30, 2023
118c048
use typescript/eslint for unused vars
hbuchel Nov 30, 2023
fa89987
add linting to staged files with husky
hbuchel Nov 30, 2023
6428534
update lintstagedrc
hbuchel Nov 30, 2023
b6050d1
Add prettier to husky precommit
hbuchel Nov 30, 2023
5ca25f0
downgrade lint-staged to v14 to work with node16
hbuchel Nov 30, 2023
6ae6057
update prettierignore
hbuchel Nov 30, 2023
700c84f
ignore mdx files for now
hbuchel Nov 30, 2023
a0ee4c4
Remove SidebarLayoutToggle
hbuchel Nov 30, 2023
38c473b
merge RemoveUnusedCode
hbuchel Nov 30, 2023
39798c2
Merge branch 'SetupESLint' into ESLintWithTypescript
hbuchel Nov 30, 2023
f520a5b
remove unified and mdx-prism
hbuchel Dec 1, 2023
4074610
Merge branch 'RemoveUnusedCode' into SetupESLint
hbuchel Dec 1, 2023
a7d7ddd
remove comments
hbuchel Dec 1, 2023
7b41842
add eslint ignore for 3rd party script we have to load sync
hbuchel Dec 1, 2023
859c383
merge main
hbuchel Dec 4, 2023
2c24c62
Merge branch 'SetupESLint' into ESLintWithTypescript
hbuchel Dec 4, 2023
285bb6b
merge main
hbuchel Dec 5, 2023
6bfb587
add comment about prettier coming last
hbuchel Dec 5, 2023
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
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
Loading