Skip to content

Instantly share code, notes, and snippets.

@mirismaili
Last active November 16, 2023 14:13
Show Gist options
  • Save mirismaili/cb755ed7e2bc6c215cf8a369feb2db19 to your computer and use it in GitHub Desktop.
Save mirismaili/cb755ed7e2bc6c215cf8a369feb2db19 to your computer and use it in GitHub Desktop.
ESLint flat config for next.js. But incomplete yet. See: https://github.com/vercel/next.js/discussions/49337#discussioncomment-7588601
import nextPlugin from '@next/eslint-plugin-next'
import tsPlugin from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import prettierConfig from 'eslint-config-prettier'
import importPlugin from 'eslint-plugin-import'
import prettierPlugin from 'eslint-plugin-prettier'
import reactPlugin from 'eslint-plugin-react'
import hooksPlugin from 'eslint-plugin-react-hooks'
/** @type {import('eslint').Linter.FlatConfig[]} */
const config = [
{
// Put global `ignores` in the first item of config list // https://www.raulmelo.me/en/blog/migration-eslint-to-flat-config#no-more-eslintignore
ignores: ['next-env.d.ts', '.next/**', 'out/**', '**/*.min.js'],
},
{
plugins: {
react: reactPlugin,
},
rules: {
...reactPlugin.configs.recommended.rules,
...reactPlugin.configs['jsx-runtime'].rules,
},
settings: {
react: {
version: 'detect', // Fix: Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration
},
},
},
{
plugins: {
'react-hooks': hooksPlugin,
},
rules: hooksPlugin.configs.recommended.rules,
},
{
plugins: {
'@next/next': nextPlugin,
},
rules: {
...nextPlugin.configs.recommended.rules,
...nextPlugin.configs['core-web-vitals'].rules,
},
},
prettierConfig,
{
plugins: {
'import': importPlugin,
'prettier': prettierPlugin,
'@typescript-eslint': tsPlugin,
},
rules: {
'@typescript-eslint/consistent-type-imports': ['warn', {disallowTypeAnnotations: false}],
'@typescript-eslint/no-inferrable-types': 'warn',
'@typescript-eslint/no-unused-vars': [
'warn',
{
ignoreRestSiblings: true,
destructuredArrayIgnorePattern: '^_',
},
],
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/ban-types': 'warn',
'prefer-const': 'warn',
'no-useless-return': 'warn',
'no-sequences': ['warn', {allowInParentheses: false}],
'quote-props': ['warn', 'consistent-as-needed'],
'dot-notation': 'warn',
'spaced-comment': ['warn', 'always', {block: {balanced: true}}],
'object-shorthand': 'warn',
'no-empty-pattern': 'warn',
'no-console': [
'warn',
{
allow: Object.keys(console).filter((method) => method !== 'log'), // Allow everything except `console.log()`
},
],
'prefer-promise-reject-errors': ['error', {allowEmptyReject: true}],
'react/jsx-filename-extension': ['error', {allow: 'as-needed', extensions: ['.jsx', '.tsx']}],
'react/self-closing-comp': 'warn',
'react/function-component-definition': ['error', {namedComponents: 'function-declaration'}],
'react/jsx-curly-brace-presence': ['warn', {props: 'never', children: 'never'}],
'react/no-unescaped-entities': 'off',
'react/jsx-key': 'warn',
'arrow-body-style': ['warn', 'as-needed'],
'prefer-arrow-callback': ['error', {allowNamedFunctions: true}],
'import/extensions': [
'warn',
'never',
{
css: 'always',
json: 'always',
svg: 'always',
png: 'always',
webp: 'always',
graphql: 'always',
},
],
'import/first': 'warn',
'prettier/prettier': 'warn',
},
},
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: tsParser,
// parserOptions: {
// ecmaFeatures: {modules: true, jsx: true},
// ecmaVersion: 'latest',
// project: './tsconfig.json',
// },
},
},
]
export default config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment