Skip to content

Commit

Permalink
setup eslint with Next 11 more modern architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-burel committed Aug 30, 2021
1 parent 084714d commit c402749
Show file tree
Hide file tree
Showing 12 changed files with 841 additions and 477 deletions.
63 changes: 11 additions & 52 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"extends": ["plugin:cypress/recommended"],
"extends": ["plugin:cypress/recommended", "next"],
"root": true,
"parser": "babel-eslint",
"plugins": ["react", "react-hooks"],
"plugins": [],
"env": {
"browser": true,
"commonjs": true,
Expand All @@ -23,66 +22,25 @@
},
"overrides": [
{ "files": ["**/__tests__/**"], "env": { "jest": true } },
{"files": ["**/*.stories.tsx"],
"rules": {
// stories always have a named default export
"import/no-anonymous-default-export": "off"
}
},
{
"files": ["**/*.ts", "**/*.tsx"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
},
"warnOnUnsupportedTypeScriptVersion": false
},
"plugins": ["@typescript-eslint"],
"rules": {
// Already handled by TS
"no-dupe-class-members": "off",
"no-undef": "off",

// Add TypeScript specific rules (and turn off ESLint equivalents)
"@typescript-eslint/consistent-type-assertions": "warn",
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "warn",
"@typescript-eslint/no-namespace": "error",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": [
"warn",
{
"functions": false,
"classes": false,
"variables": false,
"typedefs": false
}
],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"args": "none",
"ignoreRestSiblings": true
}
],
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": [
"error",
{
"allowShortCircuit": true,
"allowTernary": true,
"allowTaggedTemplates": true
}
],
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "warn"
"no-useless-constructor": "off"
}
},
{
"files": [
"test/**/*",
"examples/**/*",
"packages/create-next-app/templates/**/*"
],
"rules": { "react/react-in-jsx-scope": "off" }
}
],
"rules": {
Expand Down Expand Up @@ -223,6 +181,7 @@
"react/react-in-jsx-scope": "off",
"react/require-render-return": "error",
"react/style-prop-object": "warn",
"react-hooks/rules-of-hooks": "error"
"react-hooks/rules-of-hooks": "error",
"react/no-unescaped-entities": ["error", {"forbid": [">", "}"]}]
}
}
4 changes: 4 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"i18next-http-backend": "^1.0.15",
"lodash": "^4.17.19",
"mongoose": "^5.9.19",
"next": "^10.0.2",
"next": "^11.1.0",
"next-connect": "^0.9.1",
"next-i18next": "^5.1.0",
"next-mdx-remote": "^2.1.3",
Expand All @@ -107,20 +107,15 @@
"@types/react": "^16.9.23",
"@types/react-dom": "^16.9.5",
"@types/shelljs": "^0.8.8",
"@typescript-eslint/eslint-plugin": "^2.21.0",
"@typescript-eslint/parser": "^2.21.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"eslint": "^6.8.0",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^2.5.0",
"eslint": "^7.32.0",
"graphql-voyager": "^1.0.0-rc.31",
"react-is": "^16.13.1",
"source-map-support": "^0.5.19",
"storybook-css-modules-preset": "^1.0.5",
"ts-loader": "^7.0.5",
"ts-node": "^8.10.2",
"typescript": "4.2.2",
"typescript": "^4.3.5",
"yalc": "^1.0.0-pre.53"
},
"optionalDependencies": {
Expand All @@ -145,6 +140,7 @@
"@types/jest": "^25.2.3",
"auto-changelog": "^2.2.1",
"cypress": "4.8.0",
"eslint-config-next": "^11.1.0",
"eslint-plugin-cypress": "2.11.1",
"jest": "^26.0.1",
"jest-transformer-mdx": "^2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@vulcanjs/next-material-ui/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const Link: React.FC<LinkProps> = (props) => {
} = props;

const router = useRouter();
const pathname = typeof href === "string" ? href : href.pathname;
const pathname = typeof href === "string" ? href : (href as URL).pathname;
const className = clsx(classNameProps, {
[activeClassName]: router.pathname === pathname && activeClassName,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/@vulcanjs/next-material-ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"outDir": "./dist",
"lib": ["es6", "dom"]
},
"include": ["*.ts"]
"include": ["**/*.ts", "**/*.tsx"]
}
4 changes: 4 additions & 0 deletions src/components/layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const Header = () => {
</Link>
</li>
<li>
{/* We use a GET request for logging out at the moment
TODO: this should be replaced by an explicit POST request on click,
side-effects with GET is a bad practice leading to all sort of troubles */}
{/* eslint-disable-next-line @next/next/no-html-link-for-pages */}
<a href="/api/logout">Logout</a>
</li>
</>
Expand Down
9 changes: 8 additions & 1 deletion src/components/layout/muiMdComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,12 @@ export const muiMdComponents = {
//hr: Typography,
a: Link,
// TODO: didn't find a way to override image styling...
img: (props) => <img {...props} style={{ maxWidth: "100%" }} />,
img: (props) => (
// eslint-disable-next-line @next/next/no-img-element
<img
alt="Image from markdown content with no alt text"
{...props}
style={{ maxWidth: "100%" }}
/>
),
};
7 changes: 6 additions & 1 deletion src/components/user/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Head from "next/head";
import Link from "next/link";

const Layout = (props) => (
<>
Expand All @@ -16,7 +17,11 @@ const Layout = (props) => (
database.
</p>
<p>
See <a href="/">home README </a> for relevant instructions.
See{" "}
<Link href="/">
<a>home README </a>
</Link>{" "}
for relevant instructions.
</p>
</div>
) : (
Expand Down
4 changes: 3 additions & 1 deletion src/lib/style/colors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
const colors = {
pinkGraphql: "#e10098",
darkBlueApollo: "#15336e",
greenApollo: "#22A699",
Expand All @@ -10,3 +10,5 @@ export default {
darkOrangeVulcan: "#E45729",
white: "#fefefe",
};

export default colors;
4 changes: 2 additions & 2 deletions src/pages/admin/crud/[modelName].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export default function CrudPage({ modelName }) {
<PageLayout>
<Typography variant="h1"> Manage {model.name}</Typography>
<Typography variant="body1">
/!\ This page is an experimental demonstration of using Vulcan "magic"
components (SmartForm) to manage your model
/!&#92; This page is an experimental demonstration of using Vulcan
"magic" components (SmartForm) to manage your model
</Typography>
<hr />
<Typography variant="h2"> Create a new {model.name} </Typography>
Expand Down
8 changes: 7 additions & 1 deletion src/pages/docs/[[...filePath]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { List, ListItem, Link, Typography } from "@material-ui/core";
import matter from "gray-matter";
import { muiMdComponents } from "~/components/layout/muiMdComponents";
import { MdxRemote } from "next-mdx-remote/types";
import Image from "next/image";

// Define components to allow them in your mdx files
// You can also replace HTML tags (components is passed to MDXProvider )
Expand Down Expand Up @@ -52,7 +53,12 @@ function PreviousPageLink(props: { filePath: string }) {
const header = (
<Typography variant="h1">
<Link href="/">
<img src="/img/vns-logo-96.png" style={{ marginRight: "32px" }} />
{/* eslint-disable @next/next/no-img-element */}
<img
src="/img/vns-logo-96.png"
alt="Vulcan Next logo"
style={{ marginRight: "32px" }}
/>
</Link>
VN Live Documentation
</Typography>
Expand Down
Loading

0 comments on commit c402749

Please sign in to comment.