rsnext/packages/eslint-plugin-next/lib/rules/google-font-preconnect.js
JJ Kasper 9a0fc42d56
Fix ie11 support with webpack 5 (#25014)
This fixes ie11 compatibility that broke in https://github.com/vercel/next.js/pull/24656 from the polyfills not being loaded first, our existing ie11 test caught this but was failing, this ensures the test is passing again. This also updates the `hrefValue` optional chaining in the eslint plugin as these files aren't transpiled and related tests were failing in azure 

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
2021-05-12 12:24:42 +00:00

41 lines
1 KiB
JavaScript

const NodeAttributes = require('../utils/nodeAttributes.js')
module.exports = {
meta: {
docs: {
description: 'Ensure preconnect is used with Google Fonts',
recommended: true,
},
},
create: function (context) {
return {
JSXOpeningElement(node) {
if (node.name.name !== 'link') {
return
}
const attributes = new NodeAttributes(node)
if (!attributes.has('href') || !attributes.hasValue('href')) {
return
}
const hrefValue = attributes.value('href')
const preconnectMissing =
!attributes.has('rel') ||
!attributes.hasValue('rel') ||
attributes.value('rel') !== 'preconnect'
if (
typeof hrefValue === 'string' &&
hrefValue.startsWith('https://fonts.gstatic.com') &&
preconnectMissing
) {
context.report({
node,
message: `Preconnect is missing. See https://nextjs.org/docs/messages/google-font-preconnect.`,
})
}
},
}
},
}