Skip to content

Commit

Permalink
feat: ✨ sort everything naturally with perfectionist
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Oct 31, 2024
1 parent 7268b1c commit b39a47d
Show file tree
Hide file tree
Showing 25 changed files with 1,046 additions and 170 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
"eslint-plugin-jest-dom": "^5.4.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-node-import": "^1.0.4",
"eslint-plugin-perfectionist": "^3.9.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "0.4.14",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-testing-library": "7.0.0-beta.4",
"globals": "^15.11.0",
"local-pkg": "0.5.0",
Expand Down
52 changes: 40 additions & 12 deletions pnpm-lock.yaml

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

18 changes: 9 additions & 9 deletions src/configs/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ export const astroConfig = () => {
return [
{
files,
name: "jimmy.codes/astro",
plugins: {
"astro": pluginAstro,
"jsx-a11y": jsxA11y,
},
languageOptions: {
globals: {
...globals.node,
Astro: false,
Fragment: false,
},
parser: parserAstro,
sourceType: "module",
parserOptions: {
parser: parserTs,
extraFileExtensions: [".astro"],
parser: parserTs,
},
sourceType: "module",
},
name: "jimmy.codes/astro",
plugins: {
"astro": pluginAstro,
"jsx-a11y": jsxA11y,
},
processor: "astro/client-side-ts",
rules: {
Expand All @@ -39,9 +39,9 @@ export const astroConfig = () => {
"astro/no-deprecated-astro-fetchcontent": "error",
"astro/no-deprecated-astro-resolve": "error",
"astro/no-deprecated-getentrybyslug": "error",
"astro/no-exports-from-components": "off",
"astro/no-unused-define-vars-in-style": "error",
"astro/valid-compile": "error",
"astro/no-exports-from-components": "off",
},
},
{
Expand All @@ -50,10 +50,10 @@ export const astroConfig = () => {
name: "jimmy.codes/astro/disable-type-checked",
},
{
name: "jimmy.codes/astro/imports",
settings: {
"import-x/core-modules": ["astro:content"],
},
name: "jimmy.codes/astro/imports",
},
];
};
2 changes: 1 addition & 1 deletion src/configs/commonjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { type TypedConfigItem } from "../types";
export const commonjsConfig = () => {
return [
{
name: "jimmy.codes/commonjs",
files: [GLOB_CJS],
languageOptions: {
globals: globals.commonjs,
},
name: "jimmy.codes/commonjs",
},
] satisfies TypedConfigItem[];
};
10 changes: 5 additions & 5 deletions src/configs/imports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ describe("importsConfig", () => {

expect(imports).toStrictEqual(
expect.objectContaining({
settings: {
"import-x/parsers": {
espree: [".js", ".cjs", ".mjs", ".jsx"],
},
},
languageOptions: {
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
},
settings: {
"import-x/parsers": {
espree: [".js", ".cjs", ".mjs", ".jsx"],
},
},
}),
);
});
Expand Down
18 changes: 8 additions & 10 deletions src/configs/imports.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { type ESLint, type Linter } from "eslint";
import importX from "eslint-plugin-import-x";
import nodeImport from "eslint-plugin-node-import";
import simpleImportSort from "eslint-plugin-simple-import-sort";

import { importsRules } from "../rules/imports";
import { type TypescriptOptions } from "../types";

const typescriptImports = {
name: "jimmy.codes/imports/typescript",
rules: importX.configs.typescript.rules,
settings: {
...importX.configs.typescript.settings,
"import-x/resolver": {
...importX.configs.typescript.settings["import-x/resolver"],
typescript: true,
},
},
rules: importX.configs.typescript.rules,
};

interface ImportsConfigOptions {
Expand All @@ -25,26 +24,25 @@ interface ImportsConfigOptions {
const importsConfig = ({ typescript = false }: ImportsConfigOptions = {}) => {
return [
{
languageOptions: {
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
},
name: "jimmy.codes/imports",
plugins: {
// TODO: remove unknown conversion
"import-x": importX as unknown as ESLint.Plugin,
"simple-import-sort": simpleImportSort,
"node-import": nodeImport,
},
rules: importsRules,
// https://github.com/import-js/eslint-plugin-import/issues/2556#issuecomment-1419518561
settings: {
"import-x/parsers": {
espree: [".js", ".cjs", ".mjs", ".jsx"],
},
},
languageOptions: {
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
},
rules: importsRules,
},
...(typescript ? [typescriptImports] : []),
] satisfies Linter.Config[];
Expand Down
20 changes: 20 additions & 0 deletions src/configs/perfectionist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { type ESLint } from "eslint";
import perfectionist from "eslint-plugin-perfectionist";

import { perfectionistRules } from "../rules/perfectionist";
import { type TypedConfigItem } from "../types";

const perfectionistConfig = () => {
return [
{
name: "jimmy.codes/perfectionist",
plugins: {
// TODO: remove unknown conversion
perfectionist: perfectionist as unknown as ESLint.Plugin,
},
rules: perfectionistRules,
},
] satisfies TypedConfigItem[];
};

export default perfectionistConfig;
27 changes: 14 additions & 13 deletions src/configs/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,39 @@ const reactConfig = (

return [
{
name: "jimmy.codes/react",
files: [GLOB_JSX, GLOB_TSX],
plugins: {
react,
"react-hooks": reactHooks,
"jsx-a11y": jsxA11y,
"react-refresh": reactRefresh,
},
languageOptions: {
globals: {
...globals.browser,
},
parserOptions: {
jsxPragma: null,
ecmaFeatures: {
jsx: true,
},
},
globals: {
...globals.browser,
jsxPragma: null,
},
},
name: "jimmy.codes/react",
plugins: {
"jsx-a11y": jsxA11y,
react,
"react-hooks": reactHooks,
"react-refresh": reactRefresh,
},
rules: reactRules,
settings: {
react: {
version: "detect",
},
},
rules: reactRules,
},
...(includeReactQuery
? [
{
name: "jimmy.codes/react/query",
files: [GLOB_JSX, GLOB_TSX],
name: "jimmy.codes/react/query",
plugins: {
// TODO: remove unknown conversion
"@tanstack/query": queryPlugin as unknown as ESLint.Plugin,
},
rules: {
Expand Down
6 changes: 3 additions & 3 deletions src/configs/testing-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import { type TypedConfigItem } from "../types";
const testingLibraryConfig = () => {
return [
{
name: "jimmy.codes/testing/testing-library",
files: GLOB_TESTS,
name: "jimmy.codes/testing/testing-library",
plugins: {
"testing-library": testingLibrary,
"jest-dom": jestDom,
"testing-library": testingLibrary,
},
rules: {
...testingLibrary.configs.react.rules,
...jestDom.configs["flat/recommended"].rules,
},
},
{
name: "jimmy.codes/testing/testing-library/disabled",
files: GLOB_E2E,
name: "jimmy.codes/testing/testing-library/disabled",
rules: {
"testing-library/prefer-screen-queries": "off",
},
Expand Down
Loading

0 comments on commit b39a47d

Please sign in to comment.