Skip to content

Commit

Permalink
Updated standalone and its tests to flat config.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwilsonvu committed Apr 27, 2024
1 parent 7b81ba5 commit 6dda5b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
38 changes: 15 additions & 23 deletions standalone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, 0 | 1 | 2> 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];
}
}
});
Expand Down
16 changes: 9 additions & 7 deletions standalone/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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');
Expand All @@ -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 = <div className="red" />'), [
{
assert.deepStrictEqual(
verify('let el = <div className="red" />', { '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,
Expand All @@ -57,8 +59,8 @@ assert.deepStrictEqual(verify('let el = <div className="red" />'), [
endLine: 1,
endColumn: 30,
fix: { range: [14, 23], text: "class" },
},
]);
}],
);
assert.deepStrictEqual(verifyAndFix('let el = <div className="red" />'), {
fixed: true,
messages: [],
Expand Down

0 comments on commit 6dda5b1

Please sign in to comment.