Skip to content

Commit

Permalink
feat: improve eslint implementation and refactor for new rules
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstals committed Sep 4, 2024
1 parent 42abfe9 commit 1e2defa
Show file tree
Hide file tree
Showing 34 changed files with 1,520 additions and 506 deletions.
89 changes: 89 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module.exports = {
root: true,
env: {
node: true,
es6: true,
},
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
ignorePatterns: ['node_modules/*', 'public/mockServiceWorker.js', 'generators/*'],
extends: ['eslint:recommended', 'next/core-web-vitals'],
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
settings: {
react: { version: 'detect' },
'import/resolver': {
typescript: {},
},
},
env: {
browser: true,
node: true,
es6: true,
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
'plugin:prettier/recommended',
'plugin:testing-library/react',
'plugin:jest-dom/recommended',
'plugin:tailwindcss/recommended',
'plugin:vitest/legacy-recommended',
],
rules: {
'@next/next/no-img-element': 'off',
'import/no-cycle': 'error',
'linebreak-style': ['error', 'unix'],
'react/prop-types': 'off',
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object'],
'newlines-between': 'always',
alphabetize: { order: 'asc', caseInsensitive: true },
},
],
'import/default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-named-as-default': 'off',
'react/react-in-jsx-scope': 'off',
'jsx-a11y/anchor-is-valid': 'off',
'@typescript-eslint/no-unused-vars': ['error'],
'@typescript-eslint/explicit-function-return-type': ['off'],
'@typescript-eslint/explicit-module-boundary-types': ['off'],
'@typescript-eslint/no-empty-function': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
},
},
{
plugins: ['check-file'],
files: ['src/**/*'],
rules: {
'check-file/filename-naming-convention': [
'error',
{
'**/*.{ts,tsx}': 'KEBAB_CASE',
},
{
ignoreMiddleExtensions: true,
},
],
'check-file/folder-naming-convention': [
'error',
{
'!(src/app)/**/*': 'KEBAB_CASE',
'!(**/__tests__)/**/*': 'KEBAB_CASE',
},
],
},
},
],
};
3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ yarn-error.log*

# typescript
*.tsbuildinfo
next-env.d.ts
next-env.d.ts
Empty file added .husky/pre-commit
Empty file.
14 changes: 14 additions & 0 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import path from 'path';

const buildEslintCommand = (filenames) => {
return `next lint --fix --file ${filenames
.filter((f) => f.includes('/src/'))
.map((f) => path.relative(process.cwd(), f))
.join(' --file ')}`;
};

const config = {
'*.{ts,tsx}': [buildEslintCommand, "bash -c 'yarn check-types'"],
};

export default config;
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
webpack: (config) => {
config.resolve.alias.canvas = false;

Expand Down
23 changes: 22 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
"name": "daniel-ai",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"check-types": "tsc --project tsconfig.json --pretty --noEmit",
"generate": "npx ts-node ./scripts/generate.ts",
"generate-upstash": "npx ts-node ./scripts/generate-upstash.ts"
"generate-upstash": "npx ts-node ./scripts/generate-upstash.ts",
"prepare": "husky"
},
"dependencies": {
"@ai-sdk/openai": "^0.0.49",
Expand Down Expand Up @@ -47,13 +50,31 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.4.0",
"@typescript-eslint/parser": "^8.4.0",
"dotenv": "^16.4.5",
"eslint": "^8",
"eslint-config-next": "14.2.5",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-check-file": "^2.8.0",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-jest-dom": "^5.4.0",
"eslint-plugin-jsx-a11y": "^6.10.0",
"eslint-plugin-playwright": "^1.6.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.35.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-tailwindcss": "^3.17.4",
"eslint-plugin-testing-library": "^6.3.0",
"eslint-plugin-vitest": "^0.5.4",
"husky": "^9.1.5",
"lint-staged": "^15.2.10",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"ts-node": "^10.9.2",
Expand Down
Loading

0 comments on commit 1e2defa

Please sign in to comment.