import { RuleTester as ESLintTesterV8 } from 'eslint-v8'
import { RuleTester as ESLintTesterV9 } from 'eslint'
import { rules } from '@next/eslint-plugin-next'
const NextESLintRule = rules['no-img-element']
const message =
'Using `` could result in slower LCP and higher bandwidth. Consider using `
)
);
}
`,
filename: `src/app/icon.js`,
},
{
code: `\
import { ImageResponse } from "next/og";
export default function Image() {
return new ImageResponse(
(
)
);
}
`,
filename: `app/opengraph-image.tsx`,
},
],
invalid: [
{
code: `
export class MyComponent {
render() {
return (
);
}
}`,
errors: [{ message, type: 'JSXOpeningElement' }],
},
{
code: `\
import { ImageResponse } from "next/og";
export default function Image() {
return new ImageResponse(
(
)
);
}
`,
filename: `some/non-metadata-route-image.tsx`,
errors: [{ message, type: 'JSXOpeningElement' }],
},
],
}
describe('no-img-element', () => {
new ESLintTesterV8({
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
modules: true,
jsx: true,
},
},
}).run('eslint-v8', NextESLintRule, tests)
new ESLintTesterV9({
languageOptions: {
ecmaVersion: 2018,
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
modules: true,
jsx: true,
},
},
},
}).run('eslint-v9', NextESLintRule, tests)
})