Try to compile with Forget in eslint plugin

Nothing interesting for now, but it does seem to successfully run the compiler
This commit is contained in:
Lauren Tan
2023-06-06 10:56:21 -04:00
parent 359df9e85c
commit 5ebb7f1a8e
5 changed files with 78 additions and 6 deletions
@@ -11,7 +11,13 @@ export {
CompilerErrorDetail,
ErrorSeverity,
} from "./CompilerError";
export { CompilerPipelineValue, compileFn as compile, run } from "./Entrypoint";
export {
CompilerPipelineValue,
compileFn as compile,
compileProgram,
parsePluginOptions,
run,
} from "./Entrypoint";
export { Effect, Hook, ValueKind, printHIR } from "./HIR";
export { printReactiveFunction } from "./ReactiveScopes";
@@ -1,10 +1,39 @@
import BabelESLintParser from "@babel/eslint-parser";
import { RuleTester as ESLintTester } from "eslint";
import ReactForgetDiagnostics from "../src/rules/ReactForgetDiagnostics";
/**
* A string template tag that removes padding from the left side of multi-line strings
* @param {Array} strings array of code strings (only one expected)
*/
function normalizeIndent(strings: TemplateStringsArray): string {
const codeLines = strings[0].split("\n");
const leftPadding = codeLines[1].match(/\s+/)[0];
return codeLines.map((line) => line.slice(leftPadding.length)).join("\n");
}
const tests = {
valid: [{ code: "" }],
valid: [
{
name: "Basic example",
code: normalizeIndent`
function foo(x, y) {
if (x) {
return foo(false, y);
}
return [y * 10];
}
`,
},
],
invalid: [],
};
const eslintTester = new ESLintTester();
const eslintTester = new ESLintTester({
parser: BabelESLintParser,
parserOptions: {
ecmaVersion: 6,
sourceType: "module",
},
});
eslintTester.run("react-forget-diagnostics", ReactForgetDiagnostics, tests);
@@ -17,8 +17,14 @@
"test": "tsc && jest",
"update:eslint-docs": "eslint-doc-generator"
},
"dependencies": {},
"dependencies": {
"@babel/core": "^7.19.1",
"@babel/parser": "^7.19.1",
"@babel/traverse": "^7.19.1",
"babel-plugin-react-forget": "*"
},
"devDependencies": {
"@babel/eslint-parser": "^7.19.1",
"@babel/preset-env": "^7.22.4",
"@babel/preset-typescript": "^7.18.6",
"@types/node": "^20.2.5",
@@ -5,6 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/
import * as parser from "@babel/parser";
import traverse from "@babel/traverse";
import { compileProgram, parsePluginOptions } from "babel-plugin-react-forget";
import type { Rule } from "eslint";
const rule: Rule.RuleModule = {
@@ -15,7 +18,19 @@ const rule: Rule.RuleModule = {
recommended: true,
},
},
create(_context: Rule.RuleContext) {
create(context: Rule.RuleContext) {
const babelAST = parser.parse(context.sourceCode.text);
if (babelAST != null) {
traverse(babelAST, {
Program(prog) {
compileProgram(prog, {
opts: parsePluginOptions(null), // use defaults for now
filename: context.filename,
comments: babelAST.comments ?? [],
});
},
});
}
return {};
},
};
+17 -1
View File
@@ -75,6 +75,15 @@
json5 "^2.2.2"
semver "^6.3.0"
"@babel/eslint-parser@^7.19.1":
version "7.21.8"
resolved "https://registry.yarnpkg.com/@babel/eslint-parser/-/eslint-parser-7.21.8.tgz#59fb6fc4f3b017ab86987c076226ceef7b2b2ef2"
integrity sha512-HLhI+2q+BP3sf78mFUZNCGc10KEmoUqtUT1OCdMZsN+qr4qFeLUod62/zAnF3jNQstwyasDkZnVXwfK2Bml7MQ==
dependencies:
"@nicolo-ribaudo/eslint-scope-5-internals" "5.1.1-v1"
eslint-visitor-keys "^2.1.0"
semver "^6.3.0"
"@babel/generator@7.2.0", "@babel/generator@^7.0.0", "@babel/generator@^7.1.6", "@babel/generator@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.2.0.tgz#eaf3821fa0301d9d4aef88e63d4bcc19b73ba16c"
@@ -2243,6 +2252,13 @@
resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.0.4.tgz#2c3ede793e90d632e1dbdb0e4851f6f32132fba8"
integrity sha512-vXtbo9N1FdtZZRcv4BliU28tTYrkb1EnVpUiiFFe88I6kS9aZVTMY9Z/OtDR52rl1JF1hgs9sL/59D/TQqSATQ==
"@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1":
version "5.1.1-v1"
resolved "https://registry.yarnpkg.com/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz#dbf733a965ca47b1973177dc0bb6c889edcfb129"
integrity sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==
dependencies:
eslint-scope "5.1.1"
"@nodelib/fs.scandir@2.1.5":
version "2.1.5"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
@@ -4806,7 +4822,7 @@ eslint-visitor-keys@^1.1.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==
eslint-visitor-keys@^2.0.0:
eslint-visitor-keys@^2.0.0, eslint-visitor-keys@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==