Skip to content

Commit

Permalink
bug fixes for css eslint rule (vercel#14202)
Browse files Browse the repository at this point in the history
- ignores the link tags which do not have literal href
e.g. `<link rel="stylesheet" href={props.href} />`
  • Loading branch information
prateekbh authored and rokinsky committed Jul 11, 2020
1 parent 1e26f6b commit 49f9c02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/eslint-plugin-next/lib/rules/no-css-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ module.exports = function (context) {
) &&
attributes.find(
(attr) =>
attr.name.name === 'href' && !/^https?/.test(attr.value.value)
attr.name.name === 'href' &&
attr.value.type === 'Literal' &&
!/^https?/.test(attr.value.value)
)
) {
context.report({
Expand Down
12 changes: 12 additions & 0 deletions test/eslint-plugin-next/no-css-tags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ ruleTester.run('no-css-tags', rule, {
);
}
}`,

`import {Head} from 'next/document';
export class Blah extends Head {
render(props) {
return (
<div>
<h1>Hello title</h1>
<link rel="stylesheet" {...props} />
</div>
);
}
}`,
],

invalid: [
Expand Down

0 comments on commit 49f9c02

Please sign in to comment.