Skip to content

[code-infra] Bring eslint configuration from core and bump to v9 #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
65af21f
[code-infra] Bring eslint configuration from core
May 30, 2025
50ba1d1
Update local usage of the eslint config
May 30, 2025
177341c
run and fix eslint issues in the codebase
May 30, 2025
e9a38f1
Remove redundant package
May 30, 2025
6c37967
Rename package to @mui/infra
Jun 2, 2025
5c6c6a7
Remove nested paths
Jun 2, 2025
cbed7a0
Revert to eslint-plugin-import from import-x package
Jun 3, 2025
8e38a0c
Sync with changes in core
Jun 3, 2025
2c927bb
Make all config exports as factory functions
Jun 3, 2025
dec1337
Bump versions
Jun 3, 2025
0995a43
Rename package
Jun 10, 2025
02f377b
tests + typescript
Janpot Jun 18, 2025
8325712
prettier update
Janpot Jun 18, 2025
ecc1732
typescript
Janpot Jun 18, 2025
411a3e5
Merge branch 'master' into configs-package
Janpot Jun 23, 2025
91558b2
fix tsconfig
Janpot Jun 23, 2025
f809e3e
Add composite
Janpot Jun 23, 2025
1ed5382
fixes
Janpot Jun 23, 2025
8ebc51c
Fixes to types
Janpot Jun 23, 2025
fc981ad
Update eslint.config.mjs
Janpot Jun 23, 2025
1951e21
Fix return types
Janpot Jun 24, 2025
0e81f96
revert a few things
Janpot Jun 24, 2025
166e6ba
Update moduleResolution and use single ts project
Jun 24, 2025
25602c5
Rename code infra package folder
Jun 24, 2025
3184c51
Add more general rules to the config
Jun 24, 2025
ce9fc86
Move no-direct-state-access rule from mui-x
Jun 24, 2025
662ac60
Fix CI issue
Jun 24, 2025
87a8b6e
Test airbnb config with FlatCompat
Jun 24, 2025
9ecb7aa
Move docs config to the main index
Jun 24, 2025
25e0ca8
Add estree-jsx types
Jun 25, 2025
2abae5e
Dedupe
Jun 25, 2025
80e0f7a
Remove no-hardcode-labels rule
Jun 25, 2025
3459f4b
More typescript fixes
Jun 26, 2025
17df0d4
Pending ts fixes
Jun 26, 2025
0d01b02
Add custom typings files to the top-level tsconfig
Jun 26, 2025
6c49f14
Add build script
Jun 26, 2025
9f1eda1
Less verbose
Jun 26, 2025
0195e3c
Fix tests
Jun 26, 2025
097bbf0
Fix tests, but still 4 failing ones
Janpot Jun 26, 2025
3951914
fix types
Janpot Jun 26, 2025
2f85ab7
fix rules-of-use-theme-variants
Janpot Jun 26, 2025
639e12f
skip failing tests
Janpot Jun 26, 2025
60b8151
Update setupVitest.ts
Janpot Jun 26, 2025
d506e27
Update no-direct-state-access.mjs
Janpot Jun 26, 2025
3d86cb1
Update package.json
Janpot Jun 26, 2025
44868b5
reset tests
Janpot Jun 26, 2025
c13e40a
Update no-direct-state-access.mjs
Janpot Jun 26, 2025
535cd45
f it
Janpot Jun 26, 2025
e909514
Remove mui-x specific rule
Jun 27, 2025
03067f8
Refactor imports
Jun 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/scripts/prs/checkTargetBranchLabel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
const vBranchRegex = /^v\d{1,3}\.x$/;
const transferLabels = ['cherry-pick'];
// const transferLabels = ['cherry-pick'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just remove? Or does this have a function?

Suggested change
// const transferLabels = ['cherry-pick'];
// const transferLabels = ['cherry-pick'];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a leftover. 🙈

Suggested change
// const transferLabels = ['cherry-pick'];


/**
* @param {Object} params
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/scripts/prs/checkTypeLabel.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// @ts-check
const createEnumerationFromArray = (stringArray) =>
stringArray.length > 1
? stringArray
? `${stringArray
.slice(0, -1)
.map((s) => `\`${s}\``)
.join(', ') +
' or ' +
`\`${stringArray.slice(-1)}\``
.join(', ')} or \`${stringArray.slice(-1)}\``
: stringArray.map((s) => `\`${s}\``).join('');

const typeLabels = [
Expand Down Expand Up @@ -48,7 +46,7 @@ module.exports = async ({ core, context, github }) => {
?.map((label) => label.name)
.filter((labelName) => labelRegex.test(labelName));

const { data: prComments } = await github.rest.issues.listComments({
await github.rest.issues.listComments({
owner,
repo,
issue_number: pullNumber,
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint.useFlatConfig": true
}
1 change: 0 additions & 1 deletion apps/code-infra-dashboard/functions/circle-ci-artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import type { Handler } from '@netlify/functions';
import zlib from 'zlib';
import util from 'util';
Expand Down
1 change: 0 additions & 1 deletion apps/tools-public/toolpad/resources/bundleSizeQueries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import axios from 'axios';

function getMainBundleLabel(bundleId: string): string {
Expand Down
1 change: 0 additions & 1 deletion apps/tools-public/toolpad/resources/queryAbout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
function flip(data) {
return Object.fromEntries(Object.entries(data).map(([key, value]) => [value, key]));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import { rawRequest } from 'graphql-request';

export async function queryGitHubSearchAPI(queryInput = '', type = 'ISSUE') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import { formatDatePart, getDateString, getMonthKey } from './queryHeadlessLibrariesDownloads';

const prepareData = (inData) => {
Expand Down
1 change: 0 additions & 1 deletion apps/tools-public/toolpad/resources/queryLabelsActivity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import { request } from 'graphql-request';

interface LabelTimelineItem {
Expand Down
1 change: 0 additions & 1 deletion apps/tools-public/toolpad/resources/queryPRs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import { request } from 'graphql-request';

interface PullRequest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import { request } from 'graphql-request';

export async function queryPRswithoutReviewer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/prefer-default-export */
import dayjs from 'dayjs';
import { sheets } from '@googleapis/sheets';
import { JWT } from 'google-auth-library';
Expand Down
63 changes: 63 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { includeIgnoreFile } from '@eslint/compat';
import { defineConfig } from 'eslint/config';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import {
createBaseConfig,
createTestConfig,
EXTENSION_TEST_FILE,
} from '@mui/internal-code-infra/eslint';

const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);

export default defineConfig(
includeIgnoreFile(path.join(dirname, '.gitignore')),
includeIgnoreFile(path.join(dirname, '.eslintignore')),
{
name: 'Base config',
extends: createBaseConfig({
baseDirectory: dirname,
}),
rules: {
// No time for this
'react/prop-types': 'off',
'jsx-a11y/control-has-associated-label': 'off',
'jsx-a11y/no-autofocus': 'off',
},
settings: {
'import/resolver': {
typescript: {
project: ['tsconfig.json'],
},
},
},
},
{
files: [
// matching the pattern of the test runner
`**/*${EXTENSION_TEST_FILE}`,
],
extends: createTestConfig(),
},
{
files: ['apps/**/*'],
rules: {
'react/jsx-one-expression-per-line': 'off',
},
},
{
files: ['packages/bundle-size-checker/**/*'],
rules: {
// Allow .js file extensions in import statements for ESM compatibility
'import/extensions': [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to make the default so that in .mjs/.mts files extensions are required?

'error',
'ignorePackages',
{
js: 'always',
mjs: 'always',
},
],
},
},
);
43 changes: 20 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,37 @@
"release:publish": "tsx scripts/publish.mjs",
"pkg-pr-new-packages": "pnpm ls -r --parseable --depth -1 -F \"./packages/**\""
},
"devDependencies": {
"pnpm": {
"packageExtensions": {
"@eslint/config-helpers@*": {
"peerDependencies": {
"eslint": "*"
},
"peerDependenciesMeta": {
"eslint": {
"optional": true
}
}
}
}
},
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@eslint/compat": "^1.3.0",
"@mui/internal-bundle-size-checker": "workspace:*",
"@mui/monorepo": "https://github.com/mui/material-ui.git#010de4505361345951824d905d1508d6f258ba67",
"@mui/internal-code-infra": "workspace:*",
"@tsconfig/node22": "^22.0.2",
"@types/node": "^24.0.3",
"@types/semver": "^7.7.0",
"@typescript-eslint/eslint-plugin": "7.12.0",
"@typescript-eslint/parser": "7.12.0",
"eslint": "8.57.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "18.0.0",
"eslint-config-prettier": "9.1.0",
"eslint-import-resolver-typescript": "^4.3.4",
"eslint-plugin-filenames": "1.3.2",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-material-ui": "workspace:*",
"eslint-plugin-mocha": "10.4.3",
"eslint-plugin-react": "7.34.2",
"eslint-plugin-react-compiler": "latest",
"eslint-plugin-react-hooks": "4.6.2",
"eslint-plugin-testing-library": "^6.2.2",
"eslint-plugin-typescript-enum": "2.1.0",
"eslint": "^9.29.0",
"lerna": "^8.2.2",
"prettier": "^3.3.3",
"pretty-quick": "^4.0.0",
"prettier": "^3.5.3",
"pretty-quick": "^4.2.2",
"tsx": "^4.20.3",
"typescript": "^5.8.3",
"vitest": "^3.1.3"
},
"dependencies": {
"@next/eslint-plugin-next": "^14.2.4",
"execa": "^7.2.0",
"semver": "^7.7.2",
"vitest": "^3.1.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
rules: {
// keeps test simple
'no-unreachable': 'off',
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-minify-errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@types/babel__core": "^7.20.5",
"@types/babel__helper-module-imports": "^7.18.3",
"@types/find-package-json": "^1.2.6",
"babel-plugin-tester": "^11.0.4",
"babel-plugin-tester": "^12.0.0",
"chai": "^4.5.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-resolve-imports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/chai": "^4.3.20",
"@types/node": "^20.17.46",
"@types/resolve": "^1.20.6",
"babel-plugin-tester": "^11.0.4",
"babel-plugin-tester": "^12.0.0",
"chai": "^4.5.0"
},
"peerDependencies": {
Expand Down
14 changes: 0 additions & 14 deletions packages/bundle-size-checker/.eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion packages/bundle-size-checker/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import os from 'os';
import fs from 'fs/promises';
import yargs from 'yargs';
import Piscina from 'piscina';
import { Piscina } from 'piscina';
import micromatch from 'micromatch';
import { loadConfig } from './configLoader.js';
import { uploadSnapshot } from './uploadSnapshot.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable testing-library/render-result-naming-convention */
import { vi, describe, it, expect, beforeEach } from 'vitest';
import { renderMarkdownReport } from './renderMarkdownReport.js';
import * as fetchSnapshotModule from './fetchSnapshot.js';
Expand Down
3 changes: 3 additions & 0 deletions packages/code-infra/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__fixtures__
*.tsbuildinfo
*.test.mjs
3 changes: 3 additions & 0 deletions packages/code-infra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @mui/internal-code-infra

Build scripts and configs to be used across MUI repos.
76 changes: 76 additions & 0 deletions packages/code-infra/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@mui/internal-code-infra",
"version": "0.0.1",
"description": "Infra scripts and configs to be used across MUI repos.",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/mui/mui-public.git",
"directory": "packages/mui-internal-code-infra"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"directory": "packages/mui-internal-code-infra"
"directory": "packages/code-infra"

},
"sideEffects": false,
"exports": {
"./package.json": "./package.json",
"./prettier": {
"default": "./src/prettier.mjs"
},
"./eslint": {
"default": "./src/eslint/index.mjs"
}
},
"scripts": {
"typescript": "tsc -p tsconfig.json",
"test": "pnpm -w test --project @mui/internal-code-infra"
},
"dependencies": {
"@eslint/eslintrc": "^3.3.1",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^10.1.5",
"eslint-import-resolver-typescript": "^4.4.3",
"eslint-module-utils": "^2.12.1",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-mocha": "^11.1.0",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-compiler": "^19.1.0-rc.2",
"eslint-plugin-react-hooks": "^6.0.0-rc.1",
"eslint-plugin-testing-library": "^7.5.3",
"@next/eslint-plugin-next": "^15.0.0",
"globals": "^16.2.0",
"minimatch": "^10.0.3",
"typescript-eslint": "^8.35.0"
},
"peerDependencies": {
"eslint": "^9.0.0",
"prettier": "^3.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that typescript-eslint should also be the peer dependency, shouldn't it? 🤔
P.S. Is there point in having only eslint and prettier as optional peer deps, but we still have a bunch of other direct dependencies related to eslint..? 🙈 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not needed because in the repo, you don't directly import it or try to use it in some way. It is already configured for you.
Agree about the optional peer dep. Removing it since you anyways need to install these two explicitly to access the CLI command.

},
"peerDependenciesMeta": {
"eslint": {
"optional": true
},
"prettier": {
"optional": true
}
},
"devDependencies": {
"@next/eslint-plugin-next": "^15.3.3",
"@types/eslint-plugin-jsx-a11y": "^6.10.0",
"@types/estree": "^1.0.8",
"@types/estree-jsx": "^1.0.5",
"@typescript-eslint/parser": "^8.35.0",
"@typescript-eslint/rule-tester": "^8.35.0",
"eslint": "^9.29.0",
"prettier": "^3.5.3",
"typescript-eslint": "^8.35.0"
},
"files": [
"build",
"src",
"README.md",
"LICENSE"
],
"publishConfig": {
"access": "public"
}
}
18 changes: 18 additions & 0 deletions packages/code-infra/src/eslint/airbnb/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FlatCompat } from '@eslint/eslintrc';
import * as tseslint from 'typescript-eslint';

/**
* @param {Object} options - Configuration options.
* @param {string} [options.baseDirectory] - The base directory for the configuration.
* @returns {import('eslint').Linter.Config[]}
*/
export function createAirbnbConfig({ baseDirectory } = {}) {
if (!baseDirectory) {
throw new Error('"baseDirectory" option is required for Airbnb configuration.');
}
const compat = new FlatCompat({
baseDirectory,
});
const airbnbConfig = compat.extends('eslint-config-airbnb');
return /** @type {import('eslint').Linter.Config[]} */ (tseslint.config(airbnbConfig));
}
Loading