Skip to content

Commit

Permalink
Change condition to check for string attribute in lint rules utility …
Browse files Browse the repository at this point in the history
…function (#42625)

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

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)
  • Loading branch information
mrkldshv committed Nov 10, 2022
1 parent eed63e1 commit 2b85da7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/eslint-plugin-next/src/utils/node-attributes.ts
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions test/unit/eslint-plugin-next/google-font-display.test.ts
Expand Up @@ -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 (
<Html>
<Head>
<link
href="https://fonts.googleapis.com/css?family=Krona+One&display=swap"
rel="stylesheet"
crossOrigin=""
/>
</Head>
</Html>
);
}
}
export default MyDocument;
`,
],

invalid: [
Expand Down

0 comments on commit 2b85da7

Please sign in to comment.