Skip to content

Commit

Permalink
Update ESLint config and Next
Browse files Browse the repository at this point in the history
  • Loading branch information
morewings committed Jan 29, 2025
1 parent e57164a commit 3427d2b
Show file tree
Hide file tree
Showing 5 changed files with 1,961 additions and 2,127 deletions.
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm lint-staged
pnpm lint:tsc
120 changes: 37 additions & 83 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,62 +1,47 @@
// @ts-check

import eslint from '@eslint/js';
import eslintTS from 'typescript-eslint';
import tsParser from '@typescript-eslint/parser';
import pluginImport from 'eslint-plugin-import';
import pluginSSRFriendly from 'eslint-plugin-ssr-friendly';
import pluginPrettier from 'eslint-plugin-prettier';
import pluginTypescript from '@typescript-eslint/eslint-plugin';
import configReactRecommended from 'eslint-plugin-react/configs/recommended.js';
import configReactJSXRuntime from 'eslint-plugin-react/configs/jsx-runtime.js';
import pluginReactHooks from 'eslint-plugin-react-hooks';
import {fixupPluginRules} from '@eslint/compat';
import configPrettierRecommended from 'eslint-plugin-prettier/recommended';
import {dirname} from 'path';
import {fileURLToPath} from 'url';

import {FlatCompat} from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

// eslint-disable-next-line import/no-anonymous-default-export
export default [
eslint.configs.recommended,
...eslintTS.configs.recommended,
...eslintTS.configs.stylistic,
configReactRecommended,
configReactJSXRuntime,
configPrettierRecommended,
{
files: ['**/*.{js,ts,tsx,cjs}'],
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaFeatures: {modules: true},
ecmaVersion: 'latest',
project: './tsconfig.json',
},
},
settings: {
react: {
version: 'detect',
},
},
plugins: {
import: pluginImport,
prettier: pluginPrettier,
'@typescript-eslint': pluginTypescript,
'react-hooks': fixupPluginRules(pluginReactHooks),
'ssr-friendly': fixupPluginRules(pluginSSRFriendly),
},
...compat.config({
plugins: ['prettier', '@typescript-eslint'],
extends: [
'next/core-web-vitals',
'next/typescript',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/stylistic',
'prettier',
],
rules: {
...pluginReactHooks.configs.recommended.rules,
...pluginSSRFriendly.configs.recommended.rules,
/**
* Allow empty arrow functions `() => {}`, while keeping other empty functions restricted
* @see https://eslint.org/docs/latest/rules/no-empty-function#allow-arrowfunctions
*/
'prettier/prettier': [
'error',
{
semi: true,
singleQuote: true,
jsxSingleQuote: false,
trailingComma: 'es5',
bracketSpacing: false,
jsxBracketSameLine: true,
arrowParens: 'avoid',
},
],
'@typescript-eslint/no-empty-function': [
'error',
{allow: ['arrowFunctions']},
],
'@typescript-eslint/ban-ts-comment': 1,
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'no-const-assign': 'error',
/** Restrict imports from devDependencies since they are not included in library build. peerDependencies are ok */
'import/no-extraneous-dependencies': [
Expand Down Expand Up @@ -95,49 +80,18 @@ export default [
*/
'@typescript-eslint/consistent-type-imports': 'error',
'import/no-cycle': 'error',
'prettier/prettier': [
'error',
{
semi: true,
singleQuote: true,
jsxSingleQuote: false,
trailingComma: 'es5',
bracketSpacing: false,
jsxBracketSameLine: true,
arrowParens: 'avoid',
},
],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
/**
* Allow unused variables with names stating with '_'
* @see https://eslint.org/docs/latest/rules/no-unused-vars
* @see https://typescript-eslint.io/rules/no-unused-vars/
*/
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
args: 'after-used',
},
],
},
},
}),
/* Allow devDependencies imports for tests and config files */
{
files: [
'**/*.spec.*',
'**/testUtils/*.{js,jsx,ts,tsx}',
'*/*.{js,jsx,ts,tsx}',
'**/setupTests.ts',
'*.config.{js,ts}',
'*.config.{js,ts,mjs}',
'**/env/**/*.*',
],
plugins: {
import: pluginImport,
},
rules: {
'import/no-extraneous-dependencies': [
'error',
Expand All @@ -159,7 +113,7 @@ export default [
{
group: ['**/environment/**'],
message:
'Imports from environment directory are forbidden in the library files.',
'Imports from environment directory are forbidden in the library files.',
},
],
},
Expand Down
3 changes: 1 addition & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* Enable bundle analysis. Run `yarn analyze:build` to get report */
/* eslint-disable-next-line import/no-extraneous-dependencies, @typescript-eslint/no-var-requires */
// eslint-disable-next-line @typescript-eslint/no-require-imports
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});

/** @type {import('next').NextConfig} */
module.exports = withBundleAnalyzer({
reactStrictMode: true,
swcMinify: true,
distDir: 'build',
output: process.env.PAGES_BUILD === 'true' ? 'export' : undefined,
cleanDistDir: true,
Expand Down
55 changes: 26 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build": "next build",
"analyze:build": "ANALYZE=true run-s build",
"start": "next start",
"lint:code": "eslint src/** --report-unused-disable-directives",
"lint:code": "next lint",
"fix:code": "run-s 'lint:code --fix'",
"lint:style": "stylelint 'src/**/*.css'",
"fix:style": "stylelint 'src/**/*.css' --fix",
Expand All @@ -29,55 +29,52 @@
"generate:page": "npx generate-react-cli component --type=page"
},
"dependencies": {
"@reduxjs/toolkit": "2.3.0",
"@reduxjs/toolkit": "2.5.1",
"classnames": "2.5.1",
"next": "15.0.2",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-redux": "9.1.2",
"next": "15.1.6",
"react": "19.0.0",
"react-dom": "19.0.0",
"react-redux": "9.2.0",
"redux": "5.0.1",
"uniqid": "5.4.0"
},
"devDependencies": {
"@eslint/compat": "1.2.3",
"@eslint/js": "9.14.0",
"@next/bundle-analyzer": "15.0.2",
"@eslint/eslintrc": "3.2.0",
"@next/bundle-analyzer": "15.1.6",
"@next/eslint-plugin-next": "15.1.6",
"@testing-library/jest-dom": "6.6.3",
"@testing-library/react": "16.0.1",
"@testing-library/react": "16.2.0",
"@testing-library/user-event": "14.6.1",
"@types/jest": "29.5.14",
"@types/lodash": "4.17.13",
"@types/node": "20.17.9",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@types/redux-mock-store": "1.0.6",
"@types/react": "19.0.8",
"@types/react-dom": "19.0.3",
"@types/uniqid": "5.3.4",
"@typescript-eslint/eslint-plugin": "8.13.0",
"@typescript-eslint/parser": "8.13.0",
"eslint": "9.14.0",
"eslint-config-next": "15.0.2",
"eslint-config-prettier": "9.1.0",
"eslint-config-react-app": "7.0.1",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-react": "7.37.2",
"eslint-plugin-react-hooks": "5.0.0",
"eslint-plugin-ssr-friendly": "1.3.0",
"@typescript-eslint/eslint-plugin": "8.22.0",
"@typescript-eslint/parser": "8.22.0",
"alias-hq": "6.2.4",
"eslint": "9.19.0",
"eslint-config-next": "15.1.6",
"eslint-config-prettier": "10.0.1",
"eslint-plugin-prettier": "5.2.3",
"generate-react-cli": "8.4.9",
"husky": "9.1.7",
"is-ci": "3.0.1",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"lint-staged": "15.2.10",
"npm-run-all2": "7.0.1",
"npm-run-all2": "6.2.6",
"postcss": "8.4.49",
"postcss-preset-env": "10.0.9",
"prettier": "3.3.3",
"redux-mock-store": "1.5.5",
"stylelint": "16.10.0",
"stylelint-config-prettier": "9.0.5",
"prettier": "3.4.2",
"stylelint": "16.11.0",
"stylelint-config-standard": "36.0.1",
"stylelint-order": "6.0.4",
"stylelint-prettier": "5.0.2",
"typescript": "5.6.3",
"typescript-eslint": "8.13.0"
"typescript": "5.7.2",
"typescript-eslint": "8.22.0"
}
}
Loading

0 comments on commit 3427d2b

Please sign in to comment.