-
Notifications
You must be signed in to change notification settings - Fork 631
[eslint-config] Update TypeScript/ESLint Utilities and Refactor Linting #4883
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
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
02e7b02
Bump the version of eslint utils consumed by Rushstack
D4N14L b522dc9
Update lint rules for back compat
D4N14L 87d80a5
Update eslint tests for compatibility
D4N14L 1dddcd4
Bump cyclic versions and rush update
D4N14L 45f5593
Lint fix
D4N14L 707b86d
Refactor and cleanup of linters
D4N14L f70f20c
Bump peer dependency of eslint config package to consume 8.57.0 or gr…
D4N14L c6f9ec3
Rush change
D4N14L 918ff02
Fix install issues
D4N14L 6bba833
Fix install
D4N14L 568b2dc
Fix readme
D4N14L 75402bf
Merge branch 'main' of https://github.com/microsoft/rushstack into us…
D4N14L 82b27fd
Drop Node 16 support
D4N14L 5db6a9d
Add eslint 8.57.0 to legacy
D4N14L c3084f0
Rush update
D4N14L 137a0cd
PR feedback
D4N14L dc47542
Update user-danade-BumpEslintUtils_2024-08-13-00-25.json
D4N14L 30da67a
Empty change to trigger PR check analysis
D4N14L File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
build-tests/eslint-bulk-suppressions-test-legacy/build.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
const { FileSystem, Executable, Text, Import } = require('@rushstack/node-core-library'); | ||
const path = require('path'); | ||
const { | ||
ESLINT_PACKAGE_NAME_ENV_VAR_NAME | ||
} = require('@rushstack/eslint-patch/lib/eslint-bulk-suppressions/constants'); | ||
|
||
const eslintBulkStartPath = Import.resolveModule({ | ||
modulePath: '@rushstack/eslint-bulk/lib/start', | ||
baseFolderPath: __dirname | ||
}); | ||
|
||
function tryLoadSuppressions(suppressionsJsonPath) { | ||
try { | ||
return Text.convertToLf(FileSystem.readFile(suppressionsJsonPath)).trim(); | ||
} catch (e) { | ||
if (FileSystem.isNotExistError(e)) { | ||
return ''; | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
const RUN_FOLDER_PATHS = ['client', 'server']; | ||
const ESLINT_PACKAGE_NAMES = ['eslint', 'eslint-oldest']; | ||
D4N14L marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const updateFilePaths = new Set(); | ||
|
||
for (const runFolderPath of RUN_FOLDER_PATHS) { | ||
const folderPath = `${__dirname}/${runFolderPath}`; | ||
const suppressionsJsonPath = `${folderPath}/.eslint-bulk-suppressions.json`; | ||
|
||
const folderItems = FileSystem.readFolderItems(folderPath); | ||
for (const folderItem of folderItems) { | ||
if (folderItem.isFile() && folderItem.name.match(/^\.eslint\-bulk\-suppressions\-[\d.]+\.json$/)) { | ||
const fullPath = `${folderPath}/${folderItem.name}`; | ||
updateFilePaths.add(fullPath); | ||
} | ||
} | ||
|
||
for (const eslintPackageName of ESLINT_PACKAGE_NAMES) { | ||
const { version: eslintVersion } = require(`${eslintPackageName}/package.json`); | ||
|
||
const startLoggingMessage = `-- Running eslint-bulk-suppressions for eslint@${eslintVersion} in ${runFolderPath} --`; | ||
console.log(startLoggingMessage); | ||
const referenceSuppressionsJsonPath = `${folderPath}/.eslint-bulk-suppressions-${eslintVersion}.json`; | ||
const existingSuppressions = tryLoadSuppressions(referenceSuppressionsJsonPath); | ||
|
||
// The eslint-bulk-suppressions patch expects to find "eslint" in the shell PATH. To ensure deterministic | ||
// test behavior, we need to designate an explicit "node_modules/.bin" folder. | ||
// | ||
// Use the ".bin" folder from @rushstack/eslint-patch as a workaround for this PNPM bug: | ||
// https://github.com/pnpm/pnpm/issues/7833 | ||
const dependencyBinFolder = path.join( | ||
__dirname, | ||
'node_modules', | ||
'@rushstack', | ||
'eslint-patch', | ||
'node_modules', | ||
'.bin' | ||
); | ||
const shellPathWithEslint = `${dependencyBinFolder}${path.delimiter}${process.env['PATH']}`; | ||
|
||
const executableResult = Executable.spawnSync( | ||
process.argv0, | ||
[eslintBulkStartPath, 'suppress', '--all', 'src'], | ||
{ | ||
currentWorkingDirectory: folderPath, | ||
environment: { | ||
...process.env, | ||
PATH: shellPathWithEslint, | ||
[ESLINT_PACKAGE_NAME_ENV_VAR_NAME]: eslintPackageName | ||
} | ||
} | ||
); | ||
|
||
if (executableResult.status !== 0) { | ||
console.error('The eslint-bulk-suppressions command failed.'); | ||
console.error('STDOUT:'); | ||
console.error(executableResult.stdout.toString()); | ||
console.error('STDERR:'); | ||
console.error(executableResult.stderr.toString()); | ||
process.exit(1); | ||
} | ||
|
||
const newSuppressions = tryLoadSuppressions(suppressionsJsonPath); | ||
if (newSuppressions === existingSuppressions) { | ||
updateFilePaths.delete(referenceSuppressionsJsonPath); | ||
} else { | ||
updateFilePaths.add(referenceSuppressionsJsonPath); | ||
FileSystem.writeFile(referenceSuppressionsJsonPath, newSuppressions); | ||
} | ||
|
||
FileSystem.deleteFile(suppressionsJsonPath); | ||
} | ||
} | ||
|
||
if (updateFilePaths.size > 0) { | ||
for (const updateFilePath of updateFilePaths) { | ||
console.log(`The suppressions file "${updateFilePath}" was updated and must be committed to git.`); | ||
} | ||
|
||
process.exit(1); | ||
} |
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
build-tests/eslint-bulk-suppressions-test-legacy/client/.eslintrc.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
|
||
// 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'); | ||
require('local-node-rig/profiles/default/includes/eslint/patch/eslint-bulk-suppressions'); | ||
|
||
module.exports = { | ||
extends: [ | ||
'@rushstack/eslint-config/profile/node-trusted-tool', | ||
'@rushstack/eslint-config/mixins/friendly-locals' | ||
], | ||
ignorePatterns: ['.eslintrc.js'], | ||
|
||
overrides: [ | ||
/** | ||
* Override the parser from @rushstack/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-8-test package. Overriding the parser | ||
* ensures that the these dependencies come from the eslint-8-test package. See: | ||
* https://github.com/microsoft/rushstack/issues/3021 | ||
*/ | ||
{ | ||
files: ['**/*.ts', '**/*.tsx'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { project: '../tsconfig.json', tsconfigRootDir: __dirname } | ||
} | ||
] | ||
}; |
64 changes: 64 additions & 0 deletions
64
build-tests/eslint-bulk-suppressions-test-legacy/client/src/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
|
||
/* Top-level scope code samples */ | ||
// scopeId: '.' | ||
let exampleString: string = 5 + ''; | ||
|
||
const exampleObject = { | ||
exampleString: exampleString | ||
}; | ||
|
||
/* Function scope code samples */ | ||
export function exampleFunction() { | ||
const {}: Object = exampleObject; | ||
|
||
// scopeId: '.exampleFunction' | ||
!!!exampleString as Boolean; | ||
} | ||
|
||
// scope: '.ArrowFunctionExpression', | ||
export const x = () => {}, | ||
// scopeId: '.y' | ||
y = () => {}, | ||
// scopeId: '.z' | ||
z = () => {}; | ||
|
||
/* Class scope code samples */ | ||
export class ExampleClass { | ||
// scopeId: '.ExampleClass' | ||
exampleClassProperty: String = exampleString + '4'; | ||
|
||
exampleMethod() { | ||
// scopeId: '.exampleClass.exampleMethod' | ||
var exampleVar; | ||
return exampleVar; | ||
} | ||
} | ||
|
||
/* Variable and anonymous constructs code samples */ | ||
export const exampleArrowFunction = () => { | ||
const exampleBoolean = true; | ||
if (exampleBoolean) { | ||
} | ||
|
||
exampleObject['exampleString']; | ||
}; | ||
|
||
export const exampleAnonymousClass = class { | ||
exampleClassProperty = 'x' + 'y'; | ||
|
||
// scopeId: '.exampleAnonymousClass.constructor' | ||
constructor() {} | ||
|
||
set exampleSetGet(val: string) { | ||
// scopeId: '.exampleAnonymousClass.exampleSetGet' | ||
let exampleVariable: Number = 1; | ||
this.exampleClassProperty = val + exampleVariable; | ||
} | ||
|
||
get exampleSetGet() { | ||
// scopeId: '.exampleAnonymousClass.exampleSetGet' | ||
return this.exampleClassProperty as String as string; | ||
} | ||
}; |
7 changes: 7 additions & 0 deletions
7
build-tests/eslint-bulk-suppressions-test-legacy/config/rig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
21 changes: 21 additions & 0 deletions
21
build-tests/eslint-bulk-suppressions-test-legacy/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "eslint-bulk-suppressions-test-legacy", | ||
"description": "Sample code to test eslint bulk suppressions for versions of eslint < 8.57.0", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"_phase:build": "node build.js" | ||
}, | ||
"devDependencies": { | ||
"@rushstack/eslint-bulk": "workspace:*", | ||
"@rushstack/eslint-config": "3.7.0", | ||
"@rushstack/eslint-patch": "workspace:*", | ||
"@rushstack/heft": "workspace:*", | ||
"@rushstack/node-core-library": "workspace:*", | ||
"@typescript-eslint/parser": "~6.19.0", | ||
"eslint": "8.23.1", | ||
"eslint-oldest": "npm:eslint@8.6.0", | ||
"local-node-rig": "workspace:*", | ||
"typescript": "~5.4.2" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
build-tests/eslint-bulk-suppressions-test-legacy/server/.eslintrc.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
|
||
// 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'); | ||
require('local-node-rig/profiles/default/includes/eslint/patch/eslint-bulk-suppressions'); | ||
|
||
module.exports = { | ||
extends: [ | ||
'@rushstack/eslint-config/profile/node-trusted-tool', | ||
'@rushstack/eslint-config/mixins/friendly-locals' | ||
], | ||
ignorePatterns: ['.eslintrc.js'], | ||
|
||
overrides: [ | ||
/** | ||
* Override the parser from @rushstack/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-8-test package. Overriding the parser | ||
* ensures that the these dependencies come from the eslint-8-test package. See: | ||
* https://github.com/microsoft/rushstack/issues/3021 | ||
*/ | ||
{ | ||
files: ['**/*.ts', '**/*.tsx'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { project: '../tsconfig.json', tsconfigRootDir: __dirname } | ||
} | ||
] | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.