Skip to content

Commit

Permalink
Add ESLint rule playground (facebook#14609)
Browse files Browse the repository at this point in the history
* Add ESLint rule playground

* Update index.js

* Update index.js
  • Loading branch information
gaearon authored and jetoneza committed Jan 23, 2019
1 parent 8a33238 commit 8d00646
Show file tree
Hide file tree
Showing 8 changed files with 939 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fixtures/eslint/.eslintrc.json
@@ -0,0 +1,14 @@
{
"root": true,
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": ["react-hooks"],
"rules": {
"react-hooks/rules-of-hooks": 2
}
}
7 changes: 7 additions & 0 deletions fixtures/eslint/README.md
@@ -0,0 +1,7 @@
# ESLint Playground Fixture

This is an internal playground for quick iteration on our lint rules inside an IDE like VSCode.

See instructions in `./index.js` in this directory.

![Demo](https://duaw26jehqd4r.cloudfront.net/items/2Z390a31003O0l0o0e3O/Screen%20Recording%202019-01-16%20at%2010.29%20PM.gif?v=d6856125)
11 changes: 11 additions & 0 deletions fixtures/eslint/index.js
@@ -0,0 +1,11 @@
// This is a testing playground for our lint rules.

// 1. Run yarn && yarn start
// 2. "File > Add Folder to Workspace" this specific folder in VSCode with ESLint extension
// 3. Changes to the rule source should get picked up without restarting ESLint server

function Foo() {
if (condition) {
useEffect(() => {});
}
}
12 changes: 12 additions & 0 deletions fixtures/eslint/package.json
@@ -0,0 +1,12 @@
{
"private": true,
"name": "eslint-playground",
"dependencies": {
"eslint": "4.1.0",
"eslint-plugin-react-hooks": "link:./proxy"
},
"scripts": {
"start": "./watch.sh",
"lint": "eslint index.js"
}
}
35 changes: 35 additions & 0 deletions fixtures/eslint/proxy/index.js
@@ -0,0 +1,35 @@
'use strict';

// This file is a proxy for our rule definition that will
// load the latest built version on every check. This makes
// it convenient to test inside IDEs (which would otherwise
// load a version of our rule once and never restart the server).
// See instructions in ../index.js playground.

let build;
reload();

function reload() {
for (let id in require.cache) {
if (/eslint-plugin-react-hooks/.test(id)) {
delete require.cache[id];
}
}
// Point to the built version.
build = require('../../../build/node_modules/eslint-plugin-react-hooks');
}

let rules = {};
for (let key in build.rules) {
if (build.rules.hasOwnProperty(key)) {
rules[key] = Object.assign({}, build.rules, {
create() {
// Reload changes to the built rule
reload();
return build.rules[key].create.apply(this, arguments);
},
});
}
}

module.exports = {rules};
4 changes: 4 additions & 0 deletions fixtures/eslint/proxy/package.json
@@ -0,0 +1,4 @@
{
"private": true,
"version": "0.0.0"
}
3 changes: 3 additions & 0 deletions fixtures/eslint/watch.sh
@@ -0,0 +1,3 @@
#!/bin/bash
(cd ../.. && yarn build eslint --type=NODE_DEV)
(cd ../.. && watchman-make --make 'yarn build eslint --type=NODE_DEV' -p 'packages/eslint-plugin-*/**/*' -t ignored)

0 comments on commit 8d00646

Please sign in to comment.