-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experimental: New ESLint Plugin #11986
Changes from 6 commits
edabb95
c147099
63b04ca
14ae8c3
07dd2bb
5a1a989
3b52bfc
7891cca
7e090a4
3eb1999
0baa620
22007a7
0517bff
0bae2f1
b02a0a3
d6923b0
e679d66
72d65e0
4679168
86c7be3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"modules": true, | ||
"jsx": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
rules: { | ||
'no-css-tags': require('./rules/no-css-tags'), | ||
'sync-scripts': require('./rules/sync-scripts'), | ||
}, | ||
configs: { | ||
recommended: { | ||
rules: { | ||
'@next/next/no-css-tags': 2, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets start with |
||
'@next/next/sync-scripts': 2, | ||
}, | ||
}, | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = function(context) { | ||
return { | ||
JSXOpeningElement(node) { | ||
if (node.name.name !== 'link') { | ||
return | ||
} | ||
if (node.attributes.length === 0) { | ||
return | ||
} | ||
|
||
if ( | ||
janicklas-ralph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
node.attributes.find( | ||
attr => attr.name.name === 'rel' && attr.value.value === 'stylesheet' | ||
) | ||
) { | ||
context.report({ | ||
node, | ||
message: | ||
'In order to use external stylesheets use @import in the root stylesheet compiled with NextJS. This ensures proper priority to CSS when loading a webpage.', | ||
}) | ||
} | ||
}, | ||
} | ||
} | ||
|
||
module.exports.schema = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module.exports = function(context) { | ||
return { | ||
JSXOpeningElement(node) { | ||
if (node.name.name !== 'script') { | ||
return | ||
} | ||
if (node.attributes.length === 0) { | ||
return | ||
} | ||
|
||
if ( | ||
node.attributes.find(attr => attr.name.name === 'src') && | ||
!node.attributes.find( | ||
attr => attr.name.name === 'async' || attr.name.name === 'defer' | ||
) | ||
) { | ||
context.report({ | ||
node, | ||
message: | ||
"A synchronous script tag in head, can impact your webpage's performance", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are no more looking in |
||
}) | ||
} | ||
}, | ||
} | ||
} | ||
|
||
module.exports.schema = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@next/eslint-plugin-next", | ||
"version": "0.0.0", | ||
"description": "ESLint plugin for NextJS.", | ||
"main": "lib/index.js", | ||
"license": "MIT", | ||
"repository": { | ||
"url": "zeit/next.js", | ||
"directory": "packages/next-plugin-eslint" | ||
}, | ||
"scripts": { | ||
"test": "mocha tests --recursive" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we'll want to use jest or our global test suite instead of having it inside the package |
||
}, | ||
"devDependencies": { | ||
"mocha": "^3.1.2" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const rule = require('../../../lib/rules/no-css-tags') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
RuleTester.setDefaultConfig({ | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
modules: true, | ||
jsx: true, | ||
}, | ||
}, | ||
}) | ||
|
||
var ruleTester = new RuleTester() | ||
ruleTester.run('no-css-tags', rule, { | ||
valid: [ | ||
`import {Head} from 'next/document'; | ||
|
||
export class Blah extends Head { | ||
render() { | ||
return ( | ||
<div> | ||
<h1>Hello title</h1> | ||
</div> | ||
); | ||
} | ||
}`, | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: ` | ||
import {Head} from 'next/document'; | ||
|
||
export class Blah extends Head { | ||
render() { | ||
return ( | ||
<div> | ||
<h1>Hello title</h1> | ||
<link href="/_next/static/css/styles.css" rel="stylesheet" /> | ||
</div> | ||
); | ||
} | ||
}`, | ||
errors: [ | ||
{ | ||
message: | ||
'In order to use external stylesheets use @import in the root stylesheet compiled with NextJS. This ensures proper priority to CSS when loading a webpage.', | ||
type: 'JSXOpeningElement', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
<div> | ||
<link href="/_next/static/css/styles.css" rel="stylesheet" /> | ||
</div>`, | ||
errors: [ | ||
{ | ||
message: | ||
'In order to use external stylesheets use @import in the root stylesheet compiled with NextJS. This ensures proper priority to CSS when loading a webpage.', | ||
type: 'JSXOpeningElement', | ||
}, | ||
], | ||
}, | ||
], | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const rule = require('../../../lib/rules/sync-scripts') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
RuleTester.setDefaultConfig({ | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
ecmaFeatures: { | ||
modules: true, | ||
jsx: true, | ||
}, | ||
}, | ||
}) | ||
|
||
var ruleTester = new RuleTester() | ||
ruleTester.run('sync-scripts', rule, { | ||
valid: [ | ||
`import {Head} from 'next/document'; | ||
|
||
export class Blah extends Head { | ||
render() { | ||
return ( | ||
<div> | ||
<h1>Hello title</h1> | ||
<script src='https://blah.com' async></script> | ||
</div> | ||
); | ||
} | ||
}`, | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: ` | ||
import {Head} from 'next/document'; | ||
|
||
export class Blah extends Head { | ||
render() { | ||
return ( | ||
<div> | ||
<h1>Hello title</h1> | ||
<script src='https://blah.com'></script> | ||
</div> | ||
); | ||
} | ||
}`, | ||
errors: [ | ||
{ | ||
message: | ||
"A synchronous script tag in head, can impact your webpage's performance", | ||
type: 'JSXOpeningElement', | ||
}, | ||
], | ||
}, | ||
], | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit(just for convention sake):
no-sync-scripts