Skip to content

Commit

Permalink
feat(preset-web): upgrade to flat eslint config
Browse files Browse the repository at this point in the history
Note: ESLint v9 is deprecating the legacy
.eslintrc.json configuration file, so it has been
converted to the new flat TypeScript configuration
format
  • Loading branch information
alvis committed Nov 5, 2024
1 parent 3819692 commit 6f66f94
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 7 deletions.
4 changes: 0 additions & 4 deletions packages/preset-web/configs/eslint.yaml

This file was deleted.

14 changes: 13 additions & 1 deletion packages/preset-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"type": "module",
"exports": {
".": {
"default": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"./eslint.config": {
"default": "./lib/eslint.config.js",
"types": "./lib/eslint.config.d.ts"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/alvis/presetter.git"
Expand All @@ -35,12 +45,14 @@
"autoprefixer": "^10.0.0",
"eslint-plugin-tailwindcss": "^3.0.0",
"eslint-plugin-testing-library": "^6.0.0",
"globals": "^15.0.0",
"postcss": "^8.0.0",
"presetter": "workspace:*",
"tailwindcss": "^3.0.0"
},
"devDependencies": {
"presetter": "workspace:*"
"presetter": "workspace:*",
"presetter-preset-esm": "workspace:*"
},
"dependencies": {
"presetter-types": "workspace:*"
Expand Down
20 changes: 20 additions & 0 deletions packages/preset-web/source/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import globals from 'globals';

import presetESMConfig from 'presetter-preset-esm/eslint.config';

import tailwind from 'eslint-plugin-tailwindcss';
import testing from 'eslint-plugin-testing-library';

import type { Linter } from 'eslint';

export default [
...presetESMConfig,
...tailwind.configs['flat/recommended'],
testing.configs['flat/dom'],
{
name: 'presetter-preset-web',
languageOptions: {
globals: globals.browser,
},
},
] as Linter.Config[];
8 changes: 6 additions & 2 deletions packages/preset-web/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import type { PresetAsset } from 'presetter-types';

const DIR = fileURLToPath(dirname(import.meta.url));

// paths to the template directory
// paths to the template directories
const CONFIGS = resolve(DIR, '..', 'configs');
const TEMPLATES = resolve(DIR, '..', 'templates');

/**
* get the list of templates provided by this preset
* @returns list of preset templates
*/
export default async function (): Promise<PresetAsset> {
return {
extends: ['presetter-preset-esm'],
supplementaryConfig: {
eslint: resolve(CONFIGS, 'eslint.yaml'),
tsconfig: resolve(CONFIGS, 'tsconfig.yaml'),
},
template: {
'eslint.config.ts': resolve(TEMPLATES, 'eslint.config.ts'),
},
};
}
8 changes: 8 additions & 0 deletions packages/preset-web/templates/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import presetConfig from 'presetter-preset-web/eslint.config';

export default [
...presetConfig,
{
ignores: ['{test}/**', 'types/**', 'generated/**', '{output}/**'],
},
];
21 changes: 21 additions & 0 deletions packages/preset-web/types/eslint-plugin-tailwindcss/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { ESLint, Linter } from 'eslint';

export default declare as ESLint.Plugin & {
configs: {
'flat/recommended': [
{
plugins: Linter.PluginsRecord;
languageOptions: Linter.LanguageOptions;
},
{
rules: Linter.RulesRecord;
},
];
'recommended': {
plugins: string[];
languageOptions: Linter.LanguageOptions;
rules: Linter.RulesRecord;
};
};
rules: Linter.RulesRecord;
};
23 changes: 23 additions & 0 deletions packages/preset-web/types/eslint-plugin-testing-library/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { ESLint, Linter } from 'eslint';

export default declare as ESLint.Plugin & {
configs: {
'flat/dom': {
plugins: Linter.PluginsRecord;
rules: Linter.RulesRecord;
};
'flat/react': {
plugins: Linter.PluginsRecord;
rules: Linter.RulesRecord;
};
'dom': {
plugins: string[];
rules: Linter.RulesRecord;
};
'react': {
plugins: string[];
rules: Linter.RulesRecord;
};
};
rules: Linter.RulesRecord;
};
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f66f94

Please sign in to comment.