73b473991c
Follow-up on https://github.com/vercel/next.js/pull/38534#pullrequestreview-1035020450 This lets us use modern JS/TS syntax in ESLint rules and avoid issues like #38530 and #36693 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
130 lines
3.1 KiB
TypeScript
130 lines
3.1 KiB
TypeScript
import rule from '@next/eslint-plugin-next/dist/rules/no-typos'
|
|
import { RuleTester } from 'eslint'
|
|
;(RuleTester as any).setDefaultConfig({
|
|
parserOptions: {
|
|
ecmaVersion: 2018,
|
|
sourceType: 'module',
|
|
ecmaFeatures: {
|
|
modules: true,
|
|
jsx: true,
|
|
},
|
|
},
|
|
})
|
|
|
|
const ruleTester = new RuleTester()
|
|
|
|
ruleTester.run('no-typos', rule, {
|
|
valid: [
|
|
`
|
|
export default function Page() {
|
|
return <div></div>;
|
|
}
|
|
export const getStaticPaths = async () => {};
|
|
export const getStaticProps = async () => {};
|
|
`,
|
|
`
|
|
export default function Page() {
|
|
return <div></div>;
|
|
}
|
|
export const getServerSideProps = async () => {};
|
|
`,
|
|
`
|
|
export default function Page() {
|
|
return <div></div>;
|
|
}
|
|
export async function getStaticPaths() {};
|
|
export async function getStaticProps() {};
|
|
`,
|
|
`
|
|
export default function Page() {
|
|
return <div></div>;
|
|
}
|
|
export async function getServerSideProps() {};
|
|
`,
|
|
// detect only typo that is one operation away from the correct one
|
|
`
|
|
export default function Page() {
|
|
return <div></div>;
|
|
}
|
|
export async function getServerSidePropsss() {};
|
|
`,
|
|
`
|
|
export default function Page() {
|
|
return <div></div>;
|
|
}
|
|
export async function getstatisPath() {};
|
|
`,
|
|
],
|
|
invalid: [
|
|
{
|
|
code: `
|
|
export default function Page() {
|
|
return <div></div>;
|
|
}
|
|
export const getStaticpaths = async () => {};
|
|
export const getStaticProps = async () => {};
|
|
`,
|
|
filename: 'pages/index.js',
|
|
errors: [
|
|
{
|
|
message: 'getStaticpaths may be a typo. Did you mean getStaticPaths?',
|
|
type: 'ExportNamedDeclaration',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
export default function Page() {
|
|
return <div></div>;
|
|
}
|
|
export async function getStaticPathss(){};
|
|
export async function getStaticPropss(){};
|
|
`,
|
|
filename: 'pages/index.js',
|
|
errors: [
|
|
{
|
|
message:
|
|
'getStaticPathss may be a typo. Did you mean getStaticPaths?',
|
|
type: 'ExportNamedDeclaration',
|
|
},
|
|
{
|
|
message:
|
|
'getStaticPropss may be a typo. Did you mean getStaticProps?',
|
|
type: 'ExportNamedDeclaration',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
export default function Page() {
|
|
return <div></div>;
|
|
}
|
|
export async function getServurSideProps(){};
|
|
`,
|
|
filename: 'pages/index.js',
|
|
errors: [
|
|
{
|
|
message:
|
|
'getServurSideProps may be a typo. Did you mean getServerSideProps?',
|
|
type: 'ExportNamedDeclaration',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
export default function Page() {
|
|
return <div></div>;
|
|
}
|
|
export const getServurSideProps = () => {};
|
|
`,
|
|
filename: 'pages/index.js',
|
|
errors: [
|
|
{
|
|
message:
|
|
'getServurSideProps may be a typo. Did you mean getServerSideProps?',
|
|
type: 'ExportNamedDeclaration',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|