From 6dda5b1127fe175444f8c6a40814d4dd08de5ab7 Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Sat, 27 Apr 2024 18:07:38 -0400 Subject: [PATCH] Updated standalone and its tests to flat config. --- standalone/index.js | 38 +++++++++++++++----------------------- standalone/test.mjs | 16 +++++++++------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/standalone/index.js b/standalone/index.js index d1dcb59..84c9fa4 100644 --- a/standalone/index.js +++ b/standalone/index.js @@ -7,36 +7,28 @@ import memoizeOne from "memoize-one"; // Create linter instance const linter = new Linter(); -// Define all rules from `eslint-plugin-solid` -Object.keys(plugin.rules).forEach((key) => { - linter.defineRule(`solid/${key}`, plugin.rules[key]); -}); - -// Define TS parser -linter.defineParser("@typescript-eslint/parser", parser); - const getConfig = memoizeOne((ruleSeverityOverrides) => { - const config = { - parser: "@typescript-eslint/parser", - parserOptions: { - ecmaFeatures: { - jsx: true, + const config = [ + { + languageOptions: { + parser, + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, }, + ...plugin.configs["flat/typescript"], }, - env: { - browser: true, - es6: true, - }, - rules: plugin.configs.typescript.rules, - }; + ]; if (ruleSeverityOverrides) { // change severity levels of rules based on rules: Record arg Object.keys(ruleSeverityOverrides).forEach((key) => { - if (Object.prototype.hasOwnProperty.call(config.rules, key)) { - if (Array.isArray(config.rules[key])) { - config.rules[key] = [ruleSeverityOverrides[key], ...config.rules[key].slice(1)]; + if (Object.prototype.hasOwnProperty.call(config[0].rules, key)) { + if (Array.isArray(config[0].rules[key])) { + config[0].rules[key] = [ruleSeverityOverrides[key], ...config[0].rules[key].slice(1)]; } else { - config.rules[key] = ruleSeverityOverrides[key]; + config[0].rules[key] = ruleSeverityOverrides[key]; } } }); diff --git a/standalone/test.mjs b/standalone/test.mjs index c6523f0..fea9619 100644 --- a/standalone/test.mjs +++ b/standalone/test.mjs @@ -12,7 +12,8 @@ import typescript from "typescript"; // inject assert and a hidden _TYPESCRIPT_GLOBAL into global scope const context = vm.createContext({ - assert: assert, + assert, + structuredClone, _TYPESCRIPT_GLOBAL: typescript, }); @@ -32,7 +33,7 @@ const test = new vm.SourceTextModule( import { plugin, pluginVersion, eslintVersion, verify, verifyAndFix } from "dist.js"; // check no Node APIs are present, except injected 'assert' and '_TYPESCRIPT_GLOBAL' -assert.equal(Object.keys(globalThis).length, 2); +assert.equal(Object.keys(globalThis).length, 3); assert.equal(typeof assert, 'function'); assert.equal(typeof process, 'undefined'); assert.equal(typeof __dirname, 'undefined'); @@ -45,10 +46,11 @@ assert.equal(typeof verify, "function"); assert.equal(typeof verifyAndFix, "function"); // ensure that the standalone runs without crashing and returns results -assert.deepStrictEqual(verify('let el =
'), [ - { +assert.deepStrictEqual( + verify('let el =
', { 'solid/no-react-specific-props': 2 }), + [{ ruleId: "solid/no-react-specific-props", - severity: 1, + severity: 2, message: "Prefer the \`class\` prop over the deprecated \`className\` prop.", line: 1, column: 15, @@ -57,8 +59,8 @@ assert.deepStrictEqual(verify('let el =
'), [ endLine: 1, endColumn: 30, fix: { range: [14, 23], text: "class" }, - }, -]); + }], +); assert.deepStrictEqual(verifyAndFix('let el =
'), { fixed: true, messages: [],