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

[eslint-patch] Fix patch compatibility with ESLint >=7.0.0 and <7.12.0 #4374

Merged
merged 7 commits into from
Sep 30, 2023
Merged
Changes from 5 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
27 changes: 27 additions & 0 deletions build-tests/eslint-7-11-test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This is a workaround for https://github.com/eslint/eslint/issues/3458
D4N14L marked this conversation as resolved.
Show resolved Hide resolved
require('local-node-rig/profiles/default/includes/eslint/patch/modern-module-resolution');
// This is a workaround for https://github.com/microsoft/rushstack/issues/3021
require('local-node-rig/profiles/default/includes/eslint/patch/custom-config-package-names');

module.exports = {
extends: [
'local-node-rig/profiles/default/includes/eslint/profile/node-trusted-tool',
'local-node-rig/profiles/default/includes/eslint/mixins/friendly-locals'
],
parserOptions: { tsconfigRootDir: __dirname },

overrides: [
/**
* Override the parser from local-eslint-config. Since the config is coming
* from the workspace instead of the external NPM package, the versions of ESLint
* and TypeScript that the config consumes will be resolved from the devDependencies
* of the config instead of from the eslint-7-test package. Overriding the parser
* ensures that the these dependencies come from the eslint-7-test package. See:
* https://github.com/microsoft/rushstack/issues/3021
*/
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser'
}
]
};
6 changes: 6 additions & 0 deletions build-tests/eslint-7-11-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# eslint-7-11-test

This project folder is one of the **build-tests** for the Rushstack [ESLint configuration](https://www.npmjs.com/package/@rushstack/eslint-config) (and by extension, the [ESLint plugin](https://www.npmjs.com/package/@rushstack/eslint-plugin))
package. This project builds using ESLint v7.11.0 and contains a simple index file to ensure that the build runs ESLint successfully against source code.

Please see the [ESLint Heft task documentation](https://rushstack.io/pages/heft_tasks/eslint/) for documentation and tutorials.
7 changes: 7 additions & 0 deletions build-tests/eslint-7-11-test/config/rig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// The "rig.json" file directs tools to look for their config files in an external package.
// Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",

"rigPackageName": "local-node-rig"
}
20 changes: 20 additions & 0 deletions build-tests/eslint-7-11-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "eslint-7-11-test",
"description": "This project contains a build test to validate ESLint 7.11.0 compatibility with the latest version of @rushstack/eslint-config (and by extension, the ESLint plugin)",
"version": "1.0.0",
"private": true,
"main": "lib/index.js",
"license": "MIT",
"scripts": {
"build": "heft build --clean",
"_phase:build": "heft run --only build -- --clean"
},
"devDependencies": {
"@rushstack/heft": "workspace:*",
"local-node-rig": "workspace:*",
"@types/node": "18.17.15",
"@typescript-eslint/parser": "~5.59.2",
"eslint": "7.11.0",
"typescript": "~5.0.4"
}
}
7 changes: 7 additions & 0 deletions build-tests/eslint-7-11-test/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

export class Foo {
private _bar: string = 'bar';
public baz: string = this._bar;
}
24 changes: 24 additions & 0 deletions build-tests/eslint-7-11-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "http://json.schemastore.org/tsconfig",

"compilerOptions": {
"outDir": "lib",
"rootDir": "src",

"forceConsistentCasingInFileNames": true,
"declaration": true,
"sourceMap": true,
"declarationMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictNullChecks": true,
"noUnusedLocals": true,

"module": "esnext",
"moduleResolution": "node",
"target": "es5",
"lib": ["es5"]
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["node_modules", "lib"]
}
27 changes: 27 additions & 0 deletions build-tests/eslint-7-7-test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('local-node-rig/profiles/default/includes/eslint/patch/modern-module-resolution');
// This is a workaround for https://github.com/microsoft/rushstack/issues/3021
require('local-node-rig/profiles/default/includes/eslint/patch/custom-config-package-names');

module.exports = {
extends: [
'local-node-rig/profiles/default/includes/eslint/profile/node-trusted-tool',
'local-node-rig/profiles/default/includes/eslint/mixins/friendly-locals'
],
parserOptions: { tsconfigRootDir: __dirname },

overrides: [
/**
* Override the parser from local-eslint-config. Since the config is coming
* from the workspace instead of the external NPM package, the versions of ESLint
* and TypeScript that the config consumes will be resolved from the devDependencies
* of the config instead of from the eslint-7-test package. Overriding the parser
* ensures that the these dependencies come from the eslint-7-test package. See:
* https://github.com/microsoft/rushstack/issues/3021
*/
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser'
}
]
};
6 changes: 6 additions & 0 deletions build-tests/eslint-7-7-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# eslint-7-7-test

This project folder is one of the **build-tests** for the Rushstack [ESLint configuration](https://www.npmjs.com/package/@rushstack/eslint-config) (and by extension, the [ESLint plugin](https://www.npmjs.com/package/@rushstack/eslint-plugin))
package. This project builds using ESLint v7.7.0 and contains a simple index file to ensure that the build runs ESLint successfully against source code.

Please see the [ESLint Heft task documentation](https://rushstack.io/pages/heft_tasks/eslint/) for documentation and tutorials.
7 changes: 7 additions & 0 deletions build-tests/eslint-7-7-test/config/rig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// The "rig.json" file directs tools to look for their config files in an external package.
// Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",

"rigPackageName": "local-node-rig"
}
20 changes: 20 additions & 0 deletions build-tests/eslint-7-7-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "eslint-7-7-test",
"description": "This project contains a build test to validate ESLint 7.7.0 compatibility with the latest version of @rushstack/eslint-config (and by extension, the ESLint plugin)",
"version": "1.0.0",
"private": true,
"main": "lib/index.js",
"license": "MIT",
"scripts": {
"build": "heft build --clean",
"_phase:build": "heft run --only build -- --clean"
},
"devDependencies": {
"@rushstack/heft": "workspace:*",
"local-node-rig": "workspace:*",
"@types/node": "18.17.15",
"@typescript-eslint/parser": "~5.59.2",
"eslint": "7.7.0",
"typescript": "~5.0.4"
}
}
7 changes: 7 additions & 0 deletions build-tests/eslint-7-7-test/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

export class Foo {
private _bar: string = 'bar';
public baz: string = this._bar;
}
24 changes: 24 additions & 0 deletions build-tests/eslint-7-7-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "http://json.schemastore.org/tsconfig",

"compilerOptions": {
"outDir": "lib",
"rootDir": "src",

"forceConsistentCasingInFileNames": true,
"declaration": true,
"sourceMap": true,
"declarationMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictNullChecks": true,
"noUnusedLocals": true,

"module": "esnext",
"moduleResolution": "node",
"target": "es5",
"lib": ["es5"]
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["node_modules", "lib"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/eslint-patch",
"comment": "Fix patch compatibility with ESLint 7 for versions matching <7.12.0",
"type": "patch"
}
],
"packageName": "@rushstack/eslint-patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/tree-pattern",
"comment": "",
"type": "none"
}
],
"packageName": "@rushstack/tree-pattern"
}
4 changes: 2 additions & 2 deletions common/config/rush/common-versions.json
Original file line number Diff line number Diff line change
@@ -61,9 +61,9 @@
*/
"allowedAlternativeVersions": {
/**
* Used by build-tests/eslint-7-test
* Used by build-tests/eslint-7-7-test, build-tests/eslint-7-11-test, and build-tests/eslint-7-test
*/
"eslint": ["~7.30.0"],
"eslint": ["7.7.0", "7.11.0", "~7.30.0"],
/**
* For example, allow some projects to use an older TypeScript compiler
* (in addition to whatever "usual" version is being used by other projects in the repo):
436 changes: 250 additions & 186 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/config/rush/repo-state.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "d2f44ef5ae58d7f9cd054dc38f03cce18f09a893",
"pnpmShrinkwrapHash": "8e080c6ec927d3b02d4f9e475bf43f884aa48671",
"preferredVersionsHash": "1926a5b12ac8f4ab41e76503a0d1d0dccc9c0e06"
}
28 changes: 22 additions & 6 deletions eslint/eslint-patch/src/_patch-base.ts
Original file line number Diff line number Diff line change
@@ -92,10 +92,10 @@ for (let currentModule = module; ; ) {
}

if (!eslintFolder) {
// Probe for the ESLint >=7.8.0 layout:
// Probe for the ESLint >=7.12.0 layout:
for (let currentModule = module; ; ) {
if (!configArrayFactoryPath && currentModule.filename.endsWith('config-array-factory.js')) {
// For ESLint >=7.8.0, config-array-factory.js is at this path:
if (!configArrayFactoryPath) {
// For ESLint >=7.12.0, config-array-factory.js is at this path:
// .../@eslint/eslintrc/lib/config-array-factory.js
try {
const eslintrcFolder = path.dirname(
@@ -153,15 +153,31 @@ if (!eslintFolder) {
}

if (!eslintFolder) {
// Probe for the <7.8.0 layout:
// Probe for the <7.12.0 layout:
for (let currentModule = module; ; ) {
// For ESLint <7.8.0, config-array-factory.js was at this path:
// For ESLint <7.12.0, config-array-factory.js was at this path:
// .../eslint/lib/cli-engine/config-array-factory.js
if (/[\\/]eslint[\\/]lib[\\/]cli-engine[\\/]config-array-factory\.js$/i.test(currentModule.filename)) {
eslintFolder = path.join(path.dirname(currentModule.filename), '../..');
configArrayFactoryPath = `${eslintFolder}/lib/cli-engine/config-array-factory`;
moduleResolverPath = `${eslintFolder}/lib/shared/relative-module-resolver`;
namingPath = `${eslintFolder}/lib/shared/naming`;

// The naming module was moved to @eslint/eslintrc in ESLint 7.8.0, which is also when the @eslint/eslintrc
// package was created and added to ESLint, so we need to probe for whether it's in the old or new location.
let eslintrcFolder: string | undefined;
try {
eslintrcFolder = path.dirname(
require.resolve('@eslint/eslintrc/package.json', {
paths: [currentModule.path]
})
);
} catch (ex: unknown) {
if (!isModuleResolutionError(ex)) {
throw ex;
}
}

namingPath = `${eslintrcFolder ?? eslintFolder}/lib/shared/naming`;
break;
}

2 changes: 1 addition & 1 deletion libraries/tree-pattern/package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
"@rushstack/heft-node-rig": "2.3.2",
"@types/heft-jest": "1.0.1",
"@types/node": "18.17.15",
"eslint": "~7.30.0",
"eslint": "~8.7.0",
"typescript": "~5.0.4"
}
}
12 changes: 12 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
@@ -530,6 +530,18 @@
"reviewCategory": "tests",
"shouldPublish": false
},
{
"packageName": "eslint-7-7-test",
"projectFolder": "build-tests/eslint-7-7-test",
"reviewCategory": "tests",
"shouldPublish": false
},
{
"packageName": "eslint-7-11-test",
"projectFolder": "build-tests/eslint-7-11-test",
"reviewCategory": "tests",
"shouldPublish": false
},
{
"packageName": "eslint-7-test",
"projectFolder": "build-tests/eslint-7-test",