Monorepo Alpha linting setup is kinda borked #6818
Replies: 2 comments 1 reply
-
FWIW, this was my final – simplified and deduped – setup:
import js from '@eslint/js'
import eslintConfigPrettier from 'eslint-config-prettier'
import onlyWarn from 'eslint-plugin-only-warn'
import turboPlugin from 'eslint-plugin-turbo'
import tseslint from 'typescript-eslint'
/**
* A shared ESLint configuration for the repository.
*
* @type {import('eslint').Linter.Config}
* */
export const baseConfig = [
js.configs.recommended,
eslintConfigPrettier,
...tseslint.configs.recommended,
{
files: [
'**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts}',
'**/.eslintrc.{js,cjs,mjs}',
],
plugins: {
turbo: turboPlugin,
},
rules: {
'turbo/no-undeclared-env-vars': 'warn',
'brace-style': ['warn', 'stroustrup'],
'comma-dangle': ['warn', 'always-multiline'],
'quotes': ['warn', 'single'],
'semi': ['warn', 'never'],
'multiline-ternary': ['error', 'always-multiline'],
},
},
{
plugins: {
onlyWarn,
},
},
{
ignores: [
'dist/**',
],
},
]
import pluginReact from 'eslint-plugin-react'
import pluginReactHooks from 'eslint-plugin-react-hooks'
import pluginNext from '@next/eslint-plugin-next'
import globals from 'globals'
import { baseConfig } from './base.js'
const reactHooksConfig = {
plugins: {
'react-hooks': pluginReactHooks,
},
settings: { react: { version: 'detect' } },
rules: {
...pluginReactHooks.configs.recommended.rules,
// React scope no longer necessary with new JSX transform.
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
},
}
/**
* A custom ESLint configuration for libraries that use React.
* Applies base config, React config, then adds both service worker
* and browser globals, and finally React hooks rules.
*
* @type {import("eslint").Linter.Config}
*/
export const reactConfig = [
...baseConfig,
pluginReact.configs.flat.recommended,
{
languageOptions: {
...pluginReact.configs.flat.recommended.languageOptions,
globals: {
...globals.serviceworker,
...globals.browser,
},
},
},
reactHooksConfig,
]
/**
* A custom ESLint configuration for libraries that use Next.js.
* Applies base config, React config with service worker globals only,
* Next.js specific rules, and React hooks rules.
*
* @type {import("eslint").Linter.Config}
*/
export const nextConfig = [
...baseConfig,
{
...pluginReact.configs.flat.recommended,
languageOptions: {
...pluginReact.configs.flat.recommended.languageOptions,
globals: {
...globals.serviceworker,
},
},
},
{
plugins: {
"@next/next": pluginNext,
},
rules: {
...pluginNext.configs.recommended.rules,
...pluginNext.configs["core-web-vitals"].rules,
},
},
reactHooksConfig,
]
{
"exports": {
"./base": "./src/base.js",
"./react": "./src/react.js"
},
}
import { reactConfig } from '@workspace/eslint-config/react'
/** @type {import("eslint").Linter.Config} */
export default reactConfig
import { nextConfig } from '@workspace/eslint-config/react'
/** @type {import('eslint').Linter.Config} */
export default nextConfig
{
"scripts": {
"lint:fix": "turbo lint -- --fix",
},
} Note For some reason, Improvements welcome (as mentioned, I'm not a react guy!) and I'll probably look to migrate this to Standard JS if possible (it's currently not compatible with ESLint 9). Or, maybe there are better off the shelf (from Next / React) linting setups which could be used here. |
Beta Was this translation helpful? Give feedback.
-
Also, it seems that the workspaces use |
Beta Was this translation helpful? Give feedback.
-
Just some feedback on running the monorepo linting setup:
eslint.rc
format (also, I don't think it needs to be here; Turbo seems to run all the linting)library.js
filebase
file imports therecommended
,prettier
andtseslint
packagesreact
andnext
packages both import and mergebase
, then also import and re-merge the same packages mentioned above (this nukes any user rules you add to the end ofbase
)next
package mainly repeats the same setup in thereact
package (where it could potentially reuse some portions of it?)next
package are the same other than one file, but ordered differently, so you can't tell to start with, which makes it more confusing to maintainpackage.json
sits in the middle (could solve by moving tosrc
especially aspackage.json
has named exportsI'm no React or linting expert (Vue guy jumping into React development) but this does not feel at all like it's had the same TLC as the rest of the framework; in fact, quite the opposite!
Beta Was this translation helpful? Give feedback.
All reactions