Skip to content

Commit

Permalink
format code and add astro
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianwd committed Nov 21, 2024
1 parent f13bf62 commit f04705b
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-birds-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'swd-eslint-config': patch
---

add astro support and format code
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@next/eslint-plugin-next": "^15.0.2",
"eslint-config-expo": "^8.0.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-astro": "^1.3.1",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
Expand Down
95 changes: 95 additions & 0 deletions pnpm-lock.yaml

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

10 changes: 10 additions & 0 deletions prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import("prettier").Config} */
export default {
endOfLine: 'lf',
semi: false,
singleQuote: true,
jsxSingleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
lineWidth: 120,
}
50 changes: 25 additions & 25 deletions src/flat-base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import tseslint from "typescript-eslint";
import eslint from "@eslint/js";
import pluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import type { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
import tseslint from 'typescript-eslint'
import eslint from '@eslint/js'
import pluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import simpleImportSort from 'eslint-plugin-simple-import-sort'
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'

export const base = tseslint.config({
files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"],
files: ['**/*.{js,mjs,cjs,ts,jsx,tsx}'],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
Expand All @@ -14,35 +14,35 @@ export const base = tseslint.config({
languageOptions: {
parser: tseslint.parser,
parserOptions: {
extraFileExtensions: [".json", ".d.ts"],
extraFileExtensions: ['.json', '.d.ts'],
},
},
plugins: {
"simple-import-sort": simpleImportSort,
'simple-import-sort': simpleImportSort,
},
rules: {
"simple-import-sort/imports": "warn",
"simple-import-sort/exports": "warn",
"@typescript-eslint/no-empty-object-type": "warn",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-misused-promises": [
"warn",
'simple-import-sort/imports': 'warn',
'simple-import-sort/exports': 'warn',
'@typescript-eslint/no-empty-object-type': 'warn',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-misused-promises': [
'warn',
{
checksVoidReturn: false,
},
],
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
},
}) satisfies FlatConfig.ConfigArray;
}) satisfies FlatConfig.ConfigArray
64 changes: 33 additions & 31 deletions src/flat-react.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import type { FlatConfig } from "@typescript-eslint/utils/ts-eslint";
import pluginReact from "eslint-plugin-react";
import jsxA11y from "eslint-plugin-jsx-a11y";
import tseslint from "typescript-eslint";
import nextPlugin from "@next/eslint-plugin-next";
import pluginTailwindcss from "eslint-plugin-tailwindcss";
import { FlatCompat } from "@eslint/eslintrc";
import reactHooks from "eslint-plugin-react-hooks";
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'
import pluginReact from 'eslint-plugin-react'
import jsxA11y from 'eslint-plugin-jsx-a11y'
import tseslint from 'typescript-eslint'
import nextPlugin from '@next/eslint-plugin-next'
import pluginTailwindcss from 'eslint-plugin-tailwindcss'
import { FlatCompat } from '@eslint/eslintrc'
import reactHooks from 'eslint-plugin-react-hooks'
import eslintPluginAstro from 'eslint-plugin-astro'

const compat = new FlatCompat();
const compat = new FlatCompat()

export interface ReactPluginOptions {
framework?: "next" | "expo";
framework?: 'next' | 'expo' | 'astro'
}

const eslintNext = compat.config(nextPlugin.configs["core-web-vitals"]);
const eslintTailwind = pluginTailwindcss.configs["flat/recommended"];
const eslintNext = compat.config(nextPlugin.configs['core-web-vitals'])
const eslintExpo = compat.extends('eslint-config-expo')
const eslintAstro = eslintPluginAstro.configs.recommended

const eslintExpo = compat.extends("eslint-config-expo");
const eslintTailwind = pluginTailwindcss.configs['flat/recommended']

export const react = ({ framework }: ReactPluginOptions) =>
tseslint.config(
{
files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"],
files: ['**/*.{js,mjs,cjs,ts,jsx,tsx}'],
extends: [
// @ts-expect-error - Types are broken in eslint-plugin-react https://github.com/jsx-eslint/eslint-plugin-react/issues/3838
pluginReact.configs.flat.recommended,
// @ts-expect-error - See above
pluginReact.configs.flat["jsx-runtime"],
pluginReact.configs.flat['jsx-runtime'],
...compat.config(reactHooks.configs.recommended),
...pluginTailwindcss.configs["flat/recommended"],
...(framework === "expo" ? eslintExpo : eslintTailwind),
...(framework === "next" ? eslintNext : []),
...(framework === 'expo' ? eslintExpo : eslintTailwind),
...(framework === 'next' ? eslintNext : []),
...(framework === 'astro' ? eslintAstro : []),
],
languageOptions: {
parserOptions: {
Expand All @@ -41,29 +43,29 @@ export const react = ({ framework }: ReactPluginOptions) =>
},
settings: {
react: {
version: "detect",
version: 'detect',
},
},
rules: {
"react/prop-types": "off",
"react/display-name": "warn",
"react/button-has-type": "warn",
"tailwindcss/no-custom-classname": [
"warn",
'react/prop-types': 'off',
'react/display-name': 'warn',
'react/button-has-type': 'warn',
'tailwindcss/no-custom-classname': [
'warn',
{
callees: ["classnames", "clsx", "cva", "twMerge", "cn"],
ignoredKeys: ["color", "variant", "size", "defaultVariants"],
callees: ['classnames', 'clsx', 'cva', 'twMerge', 'cn'],
ignoredKeys: ['color', 'variant', 'size', 'defaultVariants'],
},
],
},
},
{
files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"],
files: ['**/*.{js,mjs,cjs,ts,jsx,tsx}'],
ignores: [
"**/*.stories.@(ts|tsx|js|jsx|mjs|cjs)",
"**/*.test.@(ts|tsx|js|jsx|mjs|cjs)",
"**/*.spec.@(ts|tsx|js|jsx|mjs|cjs)",
'**/*.stories.@(ts|tsx|js|jsx|mjs|cjs)',
'**/*.test.@(ts|tsx|js|jsx|mjs|cjs)',
'**/*.spec.@(ts|tsx|js|jsx|mjs|cjs)',
],
extends: [jsxA11y.flatConfigs.recommended],
}
) satisfies FlatConfig.ConfigArray;
) satisfies FlatConfig.ConfigArray
Loading

0 comments on commit f04705b

Please sign in to comment.