Skip to content

Commit

Permalink
lint: move eslint configs from frameworks config to eslint config js
Browse files Browse the repository at this point in the history
  • Loading branch information
matschik committed Oct 10, 2024
1 parent 4b108ca commit 30c6768
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 102 deletions.
162 changes: 161 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,169 @@
import FRAMEWORKS from "./frameworks.mjs";

async function importDefault(moduleName) {
const module = await import(moduleName);
return module.default;
}

const getEslintConfigsByFrameworkId = new Map([
[
"svelte4",
async () => {
const js = await importDefault("@eslint/js");
const svelteParser = await importDefault("svelte-eslint-parser");
const globalsBrowser = (await importDefault("globals")).browser;

return [
{
files: ["content/**/svelte4/**/*.svelte"],
languageOptions: {
parser: svelteParser,
},
},
{
files: ["content/**/svelte4/**/*.js"],
rules: js.configs.recommended.rules,
languageOptions: {
globals: {
...globalsBrowser,
},
},
},
];
},
],
[
"lit",
async () => {
const { configs } = await import("eslint-plugin-lit");
const babelParser = await importDefault("@babel/eslint-parser");

return [
{
...configs["flat/recommended"],
files: ["content/**/lit/**.js"],
languageOptions: {
parser: babelParser,
},
},
];
},
],
[
"emberOctane",
async () => {
const filepaths = ["content/**/emberOctane/**/*.js"];
const eslintPluginEmberConfigRecommended = await importDefault(
"eslint-plugin-ember/configs/recommended"
);

return [
{
...eslintPluginEmberConfigRecommended[1],
plugins: eslintPluginEmberConfigRecommended[0].plugins,
files: filepaths,
rules: eslintPluginEmberConfigRecommended[2].rules,
},
];
},
],
[
"svelte5",
async () => {
const js = await importDefault("@eslint/js");
const globalsBrowser = (await importDefault("globals")).browser;
const eslintPluginSvelte = await importDefault("eslint-plugin-svelte");
const svelteParser = await importDefault("svelte-eslint-parser");

const eslintPluginSvelteConfig =
eslintPluginSvelte.configs["flat/recommended"];

return [
{
...eslintPluginSvelteConfig[1],
files: ["content/**/svelte5/**/*.svelte"],
plugins: eslintPluginSvelteConfig[0].plugins,
rules: eslintPluginSvelteConfig[2].rules,
},
{
files: ["content/**/svelte5/**/*.svelte.js"],
languageOptions: {
parser: svelteParser,
},
},
{
files: ["content/**/svelte5/**/*.js"],
rules: js.configs.recommended.rules,
languageOptions: {
globals: {
...globalsBrowser,
},
},
},
];
},
],
[
"svelte5",
async () => {
const js = await importDefault("@eslint/js");
const globalsBrowser = (await importDefault("globals")).browser;
const eslintPluginSvelte = await importDefault("eslint-plugin-svelte");
const svelteParser = await importDefault("svelte-eslint-parser");

const eslintPluginSvelteConfig =
eslintPluginSvelte.configs["flat/recommended"];

return [
{
...eslintPluginSvelteConfig[1],
files: ["content/**/svelte5/**/*.svelte"],
plugins: eslintPluginSvelteConfig[0].plugins,
rules: eslintPluginSvelteConfig[2].rules,
},
{
files: ["content/**/svelte5/**/*.svelte.js"],
languageOptions: {
parser: svelteParser,
},
},
{
files: ["content/**/svelte5/**/*.js"],
rules: js.configs.recommended.rules,
languageOptions: {
globals: {
...globalsBrowser,
},
},
},
];
},
],
[
"emberPolaris",
async () => {
const filepaths = ["content/**/emberPolaris/**/*.{gjs,gts,js}"];
const eslintPluginEmberConfigRecommended = await importDefault(
"eslint-plugin-ember/configs/recommended"
);

return [
{
...eslintPluginEmberConfigRecommended[1],
plugins: eslintPluginEmberConfigRecommended[0].plugins,
files: filepaths,
rules: eslintPluginEmberConfigRecommended[2].rules,
},
];
},
],
]);

/** @type {import('eslint').Linter.Config[]} */
const config = (
await Promise.all(
FRAMEWORKS.map(({ getEslintConfigs }) => {
FRAMEWORKS.map(({ id }) => {
const getEslintConfigs = getEslintConfigsByFrameworkId.get(id);
if (typeof getEslintConfigs === "function") {
return getEslintConfigs();
}
Expand Down
102 changes: 1 addition & 101 deletions frameworks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,6 @@ const frameworks = [
frameworkName: "Svelte",
isCurrentVersion: true,
img: "framework/svelte.svg",
async getEslintConfigs() {
const js = await importDefault("@eslint/js");
const svelteParser = await importDefault("svelte-eslint-parser");
const globalsBrowser = (await importDefault("globals")).browser;

return [
{
files: ["content/**/svelte4/**/*.svelte"],
languageOptions: {
parser: svelteParser,
},
},
{
files: ["content/**/svelte4/**/*.js"],
rules: js.configs.recommended.rules,
languageOptions: {
globals: {
...globalsBrowser,
},
},
},
];
},
playgroundURL: "https://svelte.dev/repl",
documentationURL: "https://svelte.dev/",
filesSorter(files) {
Expand Down Expand Up @@ -161,20 +138,6 @@ const frameworks = [
frameworkName: "Lit",
isCurrentVersion: true,
img: "framework/lit.svg",
async getEslintConfigs() {
const { configs } = await import("eslint-plugin-lit");
const babelParser = await importDefault("@babel/eslint-parser");

return [
{
...configs["flat/recommended"],
files: ["content/**/lit/**.js"],
languageOptions: {
parser: babelParser,
},
},
];
},
playgroundURL: "https://lit.dev/playground",
documentationURL: "https://lit.dev",
filesSorter(files) {
Expand Down Expand Up @@ -211,21 +174,6 @@ const frameworks = [
frameworkName: "Ember",
isCurrentVersion: true,
img: "framework/ember.svg",
async getEslintConfigs() {
const filepaths = ["content/**/emberOctane/**/*.js"];
const eslintPluginEmberConfigRecommended = await importDefault(
"eslint-plugin-ember/configs/recommended"
);

return [
{
...eslintPluginEmberConfigRecommended[1],
plugins: eslintPluginEmberConfigRecommended[0].plugins,
files: filepaths,
rules: eslintPluginEmberConfigRecommended[2].rules,
},
];
},
playgroundURL: "https://ember-twiddle.com",
documentationURL: "https://emberjs.com",
filesSorter(files) {
Expand Down Expand Up @@ -277,39 +225,6 @@ const frameworks = [
frameworkName: "Svelte",
isCurrentVersion: false,
img: "framework/svelte.svg",
async getEslintConfigs() {
const js = await importDefault("@eslint/js");
const globalsBrowser = (await importDefault("globals")).browser;
const eslintPluginSvelte = await importDefault("eslint-plugin-svelte");
const svelteParser = await importDefault("svelte-eslint-parser");

const eslintPluginSvelteConfig =
eslintPluginSvelte.configs["flat/recommended"];

return [
{
...eslintPluginSvelteConfig[1],
files: ["content/**/svelte5/**/*.svelte"],
plugins: eslintPluginSvelteConfig[0].plugins,
rules: eslintPluginSvelteConfig[2].rules,
},
{
files: ["content/**/svelte5/**/*.svelte.js"],
languageOptions: {
parser: svelteParser,
},
},
{
files: ["content/**/svelte5/**/*.js"],
rules: js.configs.recommended.rules,
languageOptions: {
globals: {
...globalsBrowser,
},
},
},
];
},
playgroundURL: "https://svelte-5-preview.vercel.app/",
documentationURL: "https://svelte-5-preview.vercel.app/docs",
filesSorter(files) {
Expand All @@ -324,21 +239,6 @@ const frameworks = [
frameworkName: "Ember",
isCurrentVersion: false,
img: "framework/ember.svg",
async getEslintConfigs() {
const filepaths = ["content/**/emberPolaris/**/*.{gjs,gts,js}"];
const eslintPluginEmberConfigRecommended = await importDefault(
"eslint-plugin-ember/configs/recommended"
);

return [
{
...eslintPluginEmberConfigRecommended[1],
plugins: eslintPluginEmberConfigRecommended[0].plugins,
files: filepaths,
rules: eslintPluginEmberConfigRecommended[2].rules,
},
];
},
playgroundURL: "http://new.emberjs.com",
documentationURL: "https://emberjs.com",
filesSorter(files) {
Expand Down Expand Up @@ -500,7 +400,7 @@ export function matchFrameworkId(id) {
}

async function importDefault(moduleName) {
const module = await import(moduleName);
const module = await import(/* @vite-ignore */ moduleName);
return module.default;
}

Expand Down

0 comments on commit 30c6768

Please sign in to comment.