Skip to content

Commit 8a12009

Browse files
authored
Add ESLint rule playground (#14609)
* Add ESLint rule playground * Update index.js * Update index.js
1 parent 7ab8a8e commit 8a12009

File tree

8 files changed

+939
-0
lines changed

8 files changed

+939
-0
lines changed

fixtures/eslint/.eslintrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"root": true,
3+
"parserOptions": {
4+
"ecmaVersion": 6,
5+
"sourceType": "module",
6+
"ecmaFeatures": {
7+
"jsx": true
8+
}
9+
},
10+
"plugins": ["react-hooks"],
11+
"rules": {
12+
"react-hooks/rules-of-hooks": 2
13+
}
14+
}

fixtures/eslint/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ESLint Playground Fixture
2+
3+
This is an internal playground for quick iteration on our lint rules inside an IDE like VSCode.
4+
5+
See instructions in `./index.js` in this directory.
6+
7+
![Demo](https://duaw26jehqd4r.cloudfront.net/items/2Z390a31003O0l0o0e3O/Screen%20Recording%202019-01-16%20at%2010.29%20PM.gif?v=d6856125)

fixtures/eslint/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This is a testing playground for our lint rules.
2+
3+
// 1. Run yarn && yarn start
4+
// 2. "File > Add Folder to Workspace" this specific folder in VSCode with ESLint extension
5+
// 3. Changes to the rule source should get picked up without restarting ESLint server
6+
7+
function Foo() {
8+
if (condition) {
9+
useEffect(() => {});
10+
}
11+
}

fixtures/eslint/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"private": true,
3+
"name": "eslint-playground",
4+
"dependencies": {
5+
"eslint": "4.1.0",
6+
"eslint-plugin-react-hooks": "link:./proxy"
7+
},
8+
"scripts": {
9+
"start": "./watch.sh",
10+
"lint": "eslint index.js"
11+
}
12+
}

fixtures/eslint/proxy/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
// This file is a proxy for our rule definition that will
4+
// load the latest built version on every check. This makes
5+
// it convenient to test inside IDEs (which would otherwise
6+
// load a version of our rule once and never restart the server).
7+
// See instructions in ../index.js playground.
8+
9+
let build;
10+
reload();
11+
12+
function reload() {
13+
for (let id in require.cache) {
14+
if (/eslint-plugin-react-hooks/.test(id)) {
15+
delete require.cache[id];
16+
}
17+
}
18+
// Point to the built version.
19+
build = require('../../../build/node_modules/eslint-plugin-react-hooks');
20+
}
21+
22+
let rules = {};
23+
for (let key in build.rules) {
24+
if (build.rules.hasOwnProperty(key)) {
25+
rules[key] = Object.assign({}, build.rules, {
26+
create() {
27+
// Reload changes to the built rule
28+
reload();
29+
return build.rules[key].create.apply(this, arguments);
30+
},
31+
});
32+
}
33+
}
34+
35+
module.exports = {rules};

fixtures/eslint/proxy/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"private": true,
3+
"version": "0.0.0"
4+
}

fixtures/eslint/watch.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
(cd ../.. && yarn build eslint --type=NODE_DEV)
3+
(cd ../.. && watchman-make --make 'yarn build eslint --type=NODE_DEV' -p 'packages/eslint-plugin-*/**/*' -t ignored)

0 commit comments

Comments
 (0)