Skip to content

Commit

Permalink
feat(eslint): upgrade to v9 and flat config
Browse files Browse the repository at this point in the history
- Various packages were majorly or minorly upgraded.
- Configuration for ESlint and various plugins was overhauled.
  • Loading branch information
RubenSibon committed Dec 11, 2024
1 parent f8e89c1 commit 2c0c370
Show file tree
Hide file tree
Showing 10 changed files with 556 additions and 421 deletions.
12 changes: 0 additions & 12 deletions .eslintignore

This file was deleted.

72 changes: 0 additions & 72 deletions .eslintrc.json

This file was deleted.

1 change: 0 additions & 1 deletion .eslintrc.ts.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"rules": {
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"array-callback-return": ["error", { "checkForEach": false }],
"block-scoped-var": "error",
"consistent-return": "error",
Expand Down
3 changes: 1 addition & 2 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"composer.json": "composer validate",
"package.json": "npmPkgJsonLint --allowEmptyTargets",
"*.md": ["markdownlint", "prettier --check"],
"*.{js,json,jsx,mdx,ts,tsx}": ["eslint --no-error-on-unmatched-pattern", "prettier --check"],
"*.{md,js,json,jsx,mdx,ts,tsx}": ["eslint --no-error-on-unmatched-pattern", "prettier --check"],
"*.{css,scss}": ["stylelint --allow-empty-input", "prettier --check"]
}
5 changes: 0 additions & 5 deletions .markdownlint.json

This file was deleted.

6 changes: 0 additions & 6 deletions .markdownlintignore

This file was deleted.

109 changes: 109 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import _import from 'eslint-plugin-import'
import { fileURLToPath } from 'node:url'
import { fixupPluginRules } from '@eslint/compat'
import { FlatCompat } from '@eslint/eslintrc'
import eslint from '@eslint/js'
import globals from 'globals'
import jest from 'eslint-plugin-jest'
import json from '@eslint/json'
import markdown from '@eslint/markdown'
import mdx from 'eslint-plugin-mdx'
import path from 'node:path'
import react from 'eslint-plugin-react'
import tseslint from 'typescript-eslint'
import tsParser from '@typescript-eslint/parser'
import tsPlugin from '@typescript-eslint/eslint-plugin'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: eslint.configs.recommended,
allConfig: eslint.configs.all,
})

export default tseslint.config(
// Global
{
ignores: [
'**/node_modules/',
'**/vendor/',
'**/build/',
'**/coverage/',
'**/dist/',
'**/tmp/',
'proprietary/react-icons',
],
},
{
languageOptions: {
globals: { ...globals.browser, ...globals.es6, ...globals.jest },
},
},
...compat.extends('eslint-config-prettier'),

// JSON
{
files: ['**/*.json'],
plugins: { json },
language: 'json/json',
...json.configs.recommended,
},

// Markdown
{
plugins: { markdown },
},
{
files: ['**/*.md'],
ignores: ['dist/**/*.md', 'CHANGELOG.md'],
processor: 'markdown/markdown',
rules: {
...markdown.configs.recommended.rules,
'markdown/line-length': 'off',
'markdown/no-inline-html': 'off',
},
},

// MDX
{
...mdx.flat,
files: ['**/*.mdx'],
processor: mdx.createRemarkProcessor({
lintCodeBlocks: true,
}),
},
...compat.extends('plugin:mdx/overrides').map((config) => ({
...config,
...mdx.flatCodeBlocks,
rules: {
...mdx.flatCodeBlocks.rules,
'react/jsx-no-undef': 'off',
},
})),

// JavaScript, TypeScript & React
...compat.extends('plugin:react/recommended', './.eslintrc.ts.json', './.eslintrc.react.json').map(() => ({
files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'],
plugins: {
'@typescript-eslint': tsPlugin,
import: fixupPluginRules(_import),
jest,
react,
},
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaFeatures: { jsx: true },
},
},
settings: {
'import/resolver': {
node: {
extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
},
},
react: { version: '18' },
},
})),
)
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,24 @@
"./storybook"
],
"devDependencies": {
"@eslint/compat": "1.2.4",
"@eslint/eslintrc": "3.2.0",
"@eslint/js": "9.16.0",
"@eslint/json": "0.8.0",
"@eslint/markdown": "6.2.1",
"@types/node": "22.10.1",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"@typescript-eslint/eslint-plugin": "8.18.0",
"@typescript-eslint/parser": "8.18.0",
"conventional-changelog-conventionalcommits": "8.0.0",
"eslint": "8.57.1",
"eslint": "9.16.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jest": "28.9.0",
"eslint-plugin-json": "3.1.0",
"eslint-plugin-json": "4.0.1",
"eslint-plugin-markdown": "5.1.0",
"eslint-plugin-mdx": "3.1.5",
"eslint-plugin-react": "7.37.2",
"globals": "15.13.0",
"html-validate": "8.27.0",
"husky": "9.1.7",
"lint-staged": "15.2.10",
Expand All @@ -54,20 +61,21 @@
"stylelint-order": "6.0.4",
"stylelint-use-logical": "2.1.2",
"typescript": "5.7.2",
"typescript-eslint": "8.18.0",
"wait-on": "8.0.1"
},
"scripts": {
"build": "pnpm -r build",
"clean": "pnpm -r clean",
"lint": "npm-run-all --continue-on-error lint:** lint-workspaces",
"lint:css": "stylelint --allow-empty-input '**/*.{css,scss}'",
"lint:js": "eslint . --ext .js,.json,.jsx,.mdx,.ts,.tsx --report-unused-disable-directives",
"lint:js": "eslint .",
"lint:md": "markdownlint **/*.md --ignore node_modules",
"lint:package-json": "npmPkgJsonLint **/package.json",
"lint:package-lock": "pnpm ls --recursive",
"lint-fix": "npm-run-all --continue-on-error lint-fix:** prettier",
"lint-fix:css": "stylelint --fix '**/*.{css,scss}'",
"lint-fix:js": "eslint . --ext .js,.json,.jsx,.mdx,.ts,.tsx --fix --report-unused-disable-directives",
"lint-fix:js": "eslint . --fix",
"lint-fix:md": "markdownlint --fix **/*.md",
"lint-workspaces": "pnpm -r --no-bail lint",
"plop": "plop",
Expand Down
Loading

0 comments on commit 2c0c370

Please sign in to comment.