Skip to content

Commit

Permalink
chore: Upgrade to ESLint 9 and use Prettier separately (#1400)
Browse files Browse the repository at this point in the history
Fixes #1349
  • Loading branch information
amannn authored Oct 17, 2024
1 parent a4d0408 commit ff195c8
Show file tree
Hide file tree
Showing 166 changed files with 1,304 additions and 2,450 deletions.
25 changes: 8 additions & 17 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,24 @@ Now, you're all set and you can work on individual packages.
### Tests

There are currently two test setups:

1. Packages use [Vitest](https://vitest.dev/)
2. Examples use [Playwright](https://playwright.dev/)

In either case, you can focus individual tests during development via `it.only`.

### Code formatting (ESLint & Prettier)

This project uses ESLint both for detecting issues in code, as well as for formatting.
### Linting & formatting

Prettier is integrated via an autofixable ESLint rule, therefore it's recommended to autofix all ESLint issues on save in your editor:

```js
// settings.json (VSCode)
{
"[typescriptreact]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.formatOnSave": true
}
}
```
This project uses ESLint for detecting issues in code, as well as Prettier for formatting.

For ESLint to work correctly, you should open individual packages you work on as the workspace root (e.g. `./packages/next-intl`).
It's recommended to use [an editor integration](https://github.com/molindo/eslint-config-molindo?tab=readme-ov-file#editor-integration) for both, so that autofixable issues are automatically resolved. For editor plugins to work correctly, you should open individual packages you work on as the workspace root (e.g. `next-intl/packages/next-intl` instead of `next-intl`).

Alternatively, you can run ESLint via the command line:
Alternatively, you can run ESLint and Prettier via the command line:

```sh
cd packages/next-intl
pnpm eslint src --fix
pnpm prettier src --write
```

### Pull requests
Expand Down Expand Up @@ -93,7 +84,7 @@ Due to this, it's important to clean up commit messages of merged PRs since the

Note that the exclamation mark syntax (`!`) for indicating breaking changes is currently [not supported by Lerna](https://github.com/lerna/lerna/issues/2668#issuecomment-1467902595). Instead, a block like `BREAKING CHANGE: Dropped support for Node.js 12` should be added to the body of the commit message.

Other prefixes that are allowed and will *not* create a release are the following:
Other prefixes that are allowed and will _not_ create a release are the following:

1. `docs`: Documentation-only changes
2. `test`: Missing tests were added or existing ones corrected
Expand Down
16 changes: 0 additions & 16 deletions docs/.eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/components/AlgoliaSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
import {DocSearch} from '@docsearch/react';
import Router from 'next/router';
import {TITLE_TEMPLATE_SUFFIX} from 'theme.config';
Expand Down
3 changes: 0 additions & 3 deletions docs/components/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export default function CopyToClipboard({

const handleClick = useCallback(async () => {
setCopied(true);
if (!navigator?.clipboard) {
console.error('Access to clipboard rejected!');
}
try {
await navigator.clipboard.writeText(getValue());
} catch {
Expand Down
2 changes: 1 addition & 1 deletion docs/components/Details.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import useLocationHash from 'hooks/useLocationHash';
import {useMDXComponents} from 'nextra/mdx';
import {ComponentProps, useEffect, useReducer} from 'react';
import useLocationHash from 'hooks/useLocationHash';

type Props = ComponentProps<'details'>;

Expand Down
2 changes: 1 addition & 1 deletion docs/components/Example.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {clsx} from 'clsx';
import useLocationHash from 'hooks/useLocationHash';
import Image from 'next/image';
import useLocationHash from 'hooks/useLocationHash';

type Props = {
demoLink?: string;
Expand Down
2 changes: 1 addition & 1 deletion docs/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from 'config';
import {useRouter} from 'next/router';
import config from 'config';
import FooterLink from './FooterLink';
import FooterSeparator from './FooterSeparator';

Expand Down
3 changes: 3 additions & 0 deletions docs/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {getPresets} from 'eslint-config-molindo';

export default await getPresets('typescript', 'react', 'tailwind');
10 changes: 5 additions & 5 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"dev": "next dev",
"lint": "eslint pages components",
"lint": "eslint pages components && tsc && prettier pages components --check",
"test": "echo 'No tests yet'",
"build": "next build",
"sitemap": "next-sitemap",
Expand Down Expand Up @@ -32,11 +32,11 @@
"@types/node": "^20.14.5",
"@types/react": "^18.3.3",
"autoprefixer": "^10.4.19",
"eslint": "^8.56.0",
"eslint-config-molindo": "^7.0.0",
"eslint-config-next": "^14.2.4",
"eslint": "^9.11.1",
"eslint-config-molindo": "^8.0.0",
"next-sitemap": "^4.2.3",
"prettier": "^3.3.3",
"typescript": "^5.5.3"
},
"prettier": "../.prettierrc.json"
"prettier": "eslint-config-molindo/.prettierrc.json"
}
2 changes: 1 addition & 1 deletion docs/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {SpeedInsights} from '@vercel/speed-insights/next';
import Analytics from 'components/Analytics';
import {AppProps} from 'next/app';
import {Inter} from 'next/font/google';
import {ReactNode} from 'react';
import Analytics from 'components/Analytics';
import 'nextra-theme-docs/style.css';
import '../styles.css';

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Html, Head, Main, NextScript} from 'next/document';
import {Head, Html, Main, NextScript} from 'next/document';
import {SkipNavLink} from 'nextra-theme-docs';
import React from 'react';

Expand Down
5 changes: 4 additions & 1 deletion docs/pages/blog/next-intl-3-0.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ Typically, you'll want to call this factory function in a central place in your
These changes bring the existing APIs in line with the new [`createLocalizedPathnamesNavigation` API](/docs/routing/navigation) that allows you to localize pathnames:

```tsx filename="navigation.ts"
import {createLocalizedPathnamesNavigation, Pathnames} from 'next-intl/navigation';
import {
createLocalizedPathnamesNavigation,
Pathnames
} from 'next-intl/navigation';

export const locales = ['en', 'de'] as const;

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/workflows/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default getRequestConfig(async ({locale}) => {

return {
formats
}
};
});
```

Expand Down
17 changes: 3 additions & 14 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"extends": "eslint-config-molindo/tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
Expand All @@ -25,13 +21,6 @@
],
"strict": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
13 changes: 0 additions & 13 deletions examples/example-app-router-migration/.eslintrc.js

This file was deleted.

3 changes: 3 additions & 0 deletions examples/example-app-router-migration/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {getPresets} from 'eslint-config-molindo';

export default await getPresets('typescript', 'react');
11 changes: 6 additions & 5 deletions examples/example-app-router-migration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"dev": "next dev",
"lint": "eslint src && tsc",
"lint": "eslint src && tsc && prettier src --check",
"test": "echo 'No tests yet'",
"build": "next build",
"start": "next start"
Expand All @@ -18,9 +18,10 @@
"@types/lodash": "^4.17.5",
"@types/node": "^20.14.5",
"@types/react": "^18.3.3",
"eslint": "^8.56.0",
"eslint-config-molindo": "^7.0.0",
"eslint-config-next": "^14.2.4",
"eslint": "^9.11.1",
"eslint-config-molindo": "^8.0.0",
"prettier": "^3.3.3",
"typescript": "^5.5.3"
}
},
"prettier": "eslint-config-molindo/.prettierrc.json"
}
2 changes: 1 addition & 1 deletion examples/example-app-router-migration/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = AppProps & {
function App({Component, pageProps, router}: Props) {
return (
<NextIntlClientProvider
locale={(router.query?.locale as string) ?? 'en'}
locale={(router.query.locale as string) || 'en'}
messages={pageProps.messages}
timeZone="Europe/Vienna"
>
Expand Down
21 changes: 4 additions & 17 deletions examples/example-app-router-migration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"extends": "eslint-config-molindo/tsconfig.json",
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"noEmit": true,
Expand All @@ -23,19 +19,10 @@
}
],
"paths": {
"@/*": [
"./src/*"
]
"@/*": ["./src/*"]
},
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
11 changes: 0 additions & 11 deletions examples/example-app-router-mixed-routing/.eslintrc.js

This file was deleted.

2 changes: 2 additions & 0 deletions examples/example-app-router-mixed-routing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
An example of how to achieve locale prefixes on public routes while reading the locale from user settings on pages for logged-in users.

**Relevant docs:**

1. [Setting up `next-intl` with i18n routing](https://next-intl-docs.vercel.app/docs/getting-started/app-router/with-i18n-routing)
2. [Setting up `next-intl` without i18n routing](https://next-intl-docs.vercel.app/docs/getting-started/app-router/without-i18n-routing)

**Relevant parts in app code:**

1. `src/middleware.ts`: Add a hint if it's a non-public route that we can read in `i18n.ts`.
2. `src/i18n.ts`: Uses the locale from the pathname segment for public routes or returns a locale from the user profile for internal app routes.
3. `src/navigation.public.ts`: Navigation APIs that automatically consider the `[locale]` segment for public routes. For internal app routes, the navigation APIs from Next.js should be used directly (see `PublicNavigation.tsx` vs `AppNavigation.tsx`).
Expand Down
3 changes: 3 additions & 0 deletions examples/example-app-router-mixed-routing/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {getPresets} from 'eslint-config-molindo';

export default await getPresets('typescript', 'react', 'tailwind');
2 changes: 1 addition & 1 deletion examples/example-app-router-mixed-routing/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"Profile": {
"title": "Profil"
}
}
}
2 changes: 1 addition & 1 deletion examples/example-app-router-mixed-routing/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"Profile": {
"title": "Profile"
}
}
}
11 changes: 6 additions & 5 deletions examples/example-app-router-mixed-routing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"dev": "next dev",
"lint": "eslint src && tsc",
"lint": "eslint src && tsc && prettier src --check",
"test": "playwright test",
"build": "next build",
"start": "next start"
Expand All @@ -20,10 +20,11 @@
"@types/node": "^20.14.5",
"@types/react": "^18.3.3",
"autoprefixer": "^10.4.19",
"eslint": "^8.56.0",
"eslint-config-molindo": "^7.0.0",
"eslint-config-next": "^14.2.4",
"eslint": "^9.11.1",
"eslint-config-molindo": "^8.0.0",
"postcss": "^8.4.38",
"prettier": "^3.3.3",
"typescript": "^5.5.3"
}
},
"prettier": "eslint-config-molindo/.prettierrc.json"
}
6 changes: 3 additions & 3 deletions examples/example-app-router-mixed-routing/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
autoprefixer: {}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {Metadata} from 'next';
import {NextIntlClientProvider} from 'next-intl';
import {getMessages} from 'next-intl/server';
import {ReactNode} from 'react';
import Document from '@/components/Document';
import PublicNavigation from './PublicNavigation';
import PublicNavigationLocaleSwitcher from './PublicNavigationLocaleSwitcher';
import Document from '@/components/Document';

type Props = {
children: ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import {useRouter} from 'next/navigation';
import {useLocale} from 'next-intl';
import updateLocale from './updateLocale';
import {Locale} from '@/config';
import updateLocale from './updateLocale';

export default function AppNavigationLocaleSwitcher() {
const router = useRouter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {Metadata} from 'next';
import {NextIntlClientProvider} from 'next-intl';
import {getLocale, getMessages} from 'next-intl/server';
import {ReactNode} from 'react';
import Document from '@/components/Document';
import AppNavigation from './AppNavigation';
import AppNavigationLocaleSwitcher from './AppNavigationLocaleSwitcher';
import Logout from './Logout';
import Document from '@/components/Document';

type Props = {
children: ReactNode;
Expand Down
Loading

0 comments on commit ff195c8

Please sign in to comment.