Skip to content
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

Enhance ESLint config #6357

Merged
merged 8 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
804 changes: 750 additions & 54 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/ws-npm-8.16.0-46943f6199-7c511c59e9.zip
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions .yarn/versions/a712705e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
"@yarnpkg/eslint-config": minor
59 changes: 39 additions & 20 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,61 @@ import eslintConfig from '@yarnpkg/eslint-config';

// eslint-disable-next-line arca/no-default-export
export default [
...eslintConfig,
...reactEslintConfig,

{
ignores: [
`*.json`,
`**/coverage/**`,
`**/__snapshots__/**`,
`.yarn`,
`.pnp.cjs`,
`.pnp.loader.mjs`,

`packages/docusaurus/.docusaurus`,

`packages/yarnpkg-pnp/sources/hook.js`,
`packages/yarnpkg-pnp/sources/esm-loader/built-loader.js`,
// Pre-compiled binaries
`packages/*/lib`,
`packages/*/bin`,
`packages/*/build`,
`packages/*/bundles`,

`packages/yarnpkg-libzip/sources/libzipAsync.js`,
`packages/yarnpkg-libzip/sources/libzipSync.js`,
// Test fixtures
`packages/**/*fixtures*`,

// The parsers are auto-generated
`packages/yarnpkg-parsers/sources/grammars/*.js`,
// Generated files for website
`packages/docusaurus/.docusaurus`,

// Generated compressed worker
`packages/yarnpkg-core/sources/worker-zip/index.js`,
`packages/yarnpkg-cli/bundles/yarn.js`,

`packages/*/lib`,
`packages/*/bin`,
`packages/*/build`,
`packages/**/*fixtures*`,
// Build output for libui
`packages/yarnpkg-libui/sources/**/*.js`,
`packages/yarnpkg-libui/sources/**/*.d.ts`,

// Pre-compiled from C sources
`packages/yarnpkg-libzip/sources/libzipAsync.js`,
`packages/yarnpkg-libzip/sources/libzipSync.js`,
// The C sources themselves
`packages/yarnpkg-libzip/artifacts`,
`packages/plugin-compat/extra/fsevents/fsevents-*.js`,

// Minimize the diff with upstream`,
// Generated compressed hooks
`packages/yarnpkg-pnp/sources/hook.js`,
`packages/yarnpkg-pnp/sources/esm-loader/built-loader.js`,
// Minimize the diff with upstream
`packages/yarnpkg-pnp/sources/node`,
`packages/yarnpkg-pnp/sources/loader/node-options*`,

// Generated PEG.js grammars
`packages/yarnpkg-parsers/sources/grammars/*.js`,

// Patched fsevents
`packages/plugin-compat/extra/fsevents/fsevents-*.js`,
],
},

...eslintConfig,
...reactEslintConfig,

{
files: [`!packages/*/sources/{index,Plugin}.ts`],
name: `berry/naming-convention`,
files: [`**/*.ts`, `**/*.cts`, `**/*.mts`, `**/*.tsx`],
ignores: [`packages/*/sources/{index,Plugin}.ts`],
rules: {
'@typescript-eslint/naming-convention': [`error`, {
selector: `typeLike`,
Expand All @@ -54,6 +71,7 @@ export default [
},

{
name: `berry/env/acceptance-tests`,
files: [`packages/acceptance-tests/pkg-tests-specs/**/*.test.{js,ts}`],
languageOptions: {
globals: {
Expand All @@ -64,6 +82,7 @@ export default [
},

{
name: `berry/rules`,
rules: {
'no-restricted-properties': [2,
{
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
],
"devDependencies": {
"@arcanis/sherlock": "^2.0.3",
"@eslint/config-inspector": "^0.5.0",
"@types/jest": "^28.1.6",
"@types/micromatch": "^4.0.1",
"@types/node": "^18.17.15",
Expand Down Expand Up @@ -54,7 +55,7 @@
"build:plugin-workspace-tools": "yarn node -r ./scripts/setup-ts-execution ./scripts/create-mock-plugin.ts workspace-tools",
"build:plugin-commands": "node ./scripts/gen-plugin-commands.js > packages/yarnpkg-cli/sources/pluginCommands.ts",
"build:compile": "rm -rf \"$0\"/lib && mkdir -p \"$0\"/lib && rsync -a --include '*.d.ts' --exclude '*.ts' --exclude '*.tsx' \"$0\"/sources/ \"$0\"/lib/ && node scripts/compile \"$@\"",
"test:lint": "eslint --max-warnings 0 \"./**/*.@(tsx|ts|js|mjs)\"",
"test:lint": "eslint --max-warnings 0 .",
"test:unit": "jest",
"typecheck:all": "tsc -p ."
},
Expand Down
6 changes: 0 additions & 6 deletions packages/acceptance-tests/.eslintrc.js

This file was deleted.

19 changes: 13 additions & 6 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,35 @@ import typescript from './rules/typescript.js';

// eslint-disable-next-line arca/no-default-export
export default [
...bestPractices,
...errors,
...style,
...typescript,

{
name: `@yarnpkg/setup`,
languageOptions: {
parser: tsParser,
sourceType: `module`,
},
},
{
name: `@yarnpkg/env`,
languageOptions: {
globals: {
...globals.node,
...globals.es2021,
},
},
},

{
name: `@yarnpkg/env/tests`,
files: [`**/*.test.*`],
ignores: [`**/__snapshots__/**`],
languageOptions: {
globals: {
...globals.jest,
},
},
},

...bestPractices,
...errors,
...style,
...typescript,
];
2 changes: 2 additions & 0 deletions packages/eslint-config/rules/best-practices.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import arcaEslint from 'eslint-plugin-arca';
// eslint-disable-next-line arca/no-default-export
export default [
{
name: `@yarnpkg/configs/best-practices`,

plugins: {
[`arca`]: arcaEslint,
[`@typescript-eslint`]: typescriptEslint,
Expand Down
8 changes: 2 additions & 6 deletions packages/eslint-config/rules/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import arcaEslint from 'eslint-plugin-arca';
// eslint-disable-next-line arca/no-default-export
export default [
{
name: `@yarnpkg/configs/errors`,

plugins: {
[`arca`]: arcaEslint,
[`@typescript-eslint`]: typescriptEslint,
Expand Down Expand Up @@ -73,10 +75,4 @@ export default [
'valid-typeof': 2,
},
},
{
files: [`*.test.{js,ts}`],
env: {
jest: true,
},
},
];
2 changes: 2 additions & 0 deletions packages/eslint-config/rules/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import reactEslint from 'eslint-plugin-react';
// eslint-disable-next-line arca/no-default-export
export default [
{
name: `@yarnpkg/configs/react`,

plugins: {
[`arca`]: arcaEslint,
[`react`]: reactEslint,
Expand Down
12 changes: 2 additions & 10 deletions packages/eslint-config/rules/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import arcaEslint from 'eslint-plugin-arca';
// eslint-disable-next-line arca/no-default-export
export default [
{
name: `@yarnpkg/configs/style`,

plugins: {
[`arca`]: arcaEslint,
[`@typescript-eslint`]: typescriptEslint,
Expand All @@ -22,16 +24,6 @@ export default [

'@typescript-eslint/comma-spacing': 2,

'@typescript-eslint/naming-convention': [`error`, {
selector: `default`,
format: [`camelCase`, `UPPER_CASE`, `PascalCase`],
filter: {
regex: `^(__.*|__non_webpack_require__|npm(_[a-z]+)+)$`,
match: false,
},
leadingUnderscore: `allow`,
}],

'@typescript-eslint/func-call-spacing': 2,

'@typescript-eslint/indent': [`error`, 2, {
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-config/rules/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import typescriptEslint from '@typescript-eslint/eslint-plugin';
// eslint-disable-next-line arca/no-default-export
export default [
{
files: [`**/*.{ts,tsx}`],
name: `@yarnpkg/configs/typescript`,

files: [`**/*.ts`, `**/*.cts`, `**/*.mts`, `**/*.tsx`],

plugins: {
[`@typescript-eslint`]: typescriptEslint,
Expand Down
Loading
Loading