From 2b85da7735a12f8b7c46de2b45b714607d67c134 Mon Sep 17 00:00:00 2001 From: Mark Ladyshau <47859603+mrkldshv@users.noreply.github.com> Date: Thu, 10 Nov 2022 04:54:38 +0100 Subject: [PATCH] Change condition to check for string attribute in lint rules utility function (#42625) Fixes #42604. ## Bug - [x] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a 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 a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) --- .../src/utils/node-attributes.ts | 11 +++++----- .../google-font-display.test.ts | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin-next/src/utils/node-attributes.ts b/packages/eslint-plugin-next/src/utils/node-attributes.ts index 4ad4667fa8b7..e5d0878f3686 100644 --- a/packages/eslint-plugin-next/src/utils/node-attributes.ts +++ b/packages/eslint-plugin-next/src/utils/node-attributes.ts @@ -32,11 +32,12 @@ export default class NodeAttributes { if (!!attribute.value) { // hasValue - const value = attribute.value.value - ? attribute.value.value - : typeof attribute.value.expression.value !== 'undefined' - ? attribute.value.expression.value - : attribute.value.expression.properties + const value = + typeof attribute.value.value === 'string' + ? attribute.value.value + : typeof attribute.value.expression.value !== 'undefined' + ? attribute.value.expression.value + : attribute.value.expression.properties this.attributes[attribute.name.name] = { hasValue: true, diff --git a/test/unit/eslint-plugin-next/google-font-display.test.ts b/test/unit/eslint-plugin-next/google-font-display.test.ts index d52ec9a831d7..45ae4b0b70c7 100644 --- a/test/unit/eslint-plugin-next/google-font-display.test.ts +++ b/test/unit/eslint-plugin-next/google-font-display.test.ts @@ -56,6 +56,27 @@ ruleTester.run('google-font-display', rule, { export default MyDocument; `, + + `import Document, { Html, Head } from "next/document"; + + class MyDocument extends Document { + render() { + return ( + + + + + + ); + } + } + + export default MyDocument; + `, ], invalid: [