-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce build validation for bulk suppressions.
- Loading branch information
Showing
7 changed files
with
250 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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,88 @@ | ||
const { FileSystem, Executable, Text, Import } = require('@rushstack/node-core-library'); | ||
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-newest', 'eslint-oldest']; | ||
|
||
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} --`; | ||
const endLoggingMessage = '-'.repeat(startLoggingMessage.length); | ||
console.log(startLoggingMessage); | ||
const referenceSuppressionsJsonPath = `${folderPath}/.eslint-bulk-suppressions-${eslintVersion}.json`; | ||
const existingSuppressions = tryLoadSuppressions(referenceSuppressionsJsonPath); | ||
|
||
const executableResult = Executable.spawnSync( | ||
process.argv0, | ||
[eslintBulkStartPath, 'suppress', '--all', 'src'], | ||
{ | ||
currentWorkingDirectory: folderPath, | ||
environment: { | ||
...process.env, | ||
[ESLINT_PACKAGE_NAME_ENV_VAR_NAME]: eslintPackageName | ||
} | ||
} | ||
); | ||
|
||
console.log('STDOUT:'); | ||
console.log(executableResult.stdout.toString()); | ||
|
||
console.log('STDERR:'); | ||
console.log(executableResult.stderr.toString()); | ||
|
||
const newSuppressions = tryLoadSuppressions(suppressionsJsonPath); | ||
if (newSuppressions === existingSuppressions) { | ||
updateFilePaths.delete(referenceSuppressionsJsonPath); | ||
} else { | ||
updateFilePaths.add(referenceSuppressionsJsonPath); | ||
FileSystem.writeFile(referenceSuppressionsJsonPath, newSuppressions); | ||
} | ||
|
||
FileSystem.deleteFile(suppressionsJsonPath); | ||
|
||
console.log(endLoggingMessage); | ||
console.log(); | ||
} | ||
} | ||
|
||
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); | ||
} |
This file contains 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 |
---|---|---|
|
@@ -4,13 +4,18 @@ | |
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"_phase:build": "eslint ." | ||
"_phase:build": "node build.js" | ||
}, | ||
"devDependencies": { | ||
"@rushstack/eslint-bulk": "workspace:*", | ||
"@rushstack/eslint-patch": "workspace:*", | ||
"@rushstack/heft": "workspace:*", | ||
"local-node-rig": "workspace:*", | ||
"@rushstack/node-core-library": "workspace:*", | ||
"@typescript-eslint/parser": "~6.19.0", | ||
"eslint": "~8.7.0", | ||
"eslint-newest": "npm:eslint@~8.23.1", | ||
"eslint-oldest": "npm:[email protected]", | ||
"local-node-rig": "workspace:*", | ||
"typescript": "~5.4.2" | ||
} | ||
} |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. | ||
{ | ||
"pnpmShrinkwrapHash": "552257b9ed51e893210d6bba3f0c10fcddf6a9aa", | ||
"pnpmShrinkwrapHash": "1da0835844b2dddb8f340063ceb13ccf02a65dea", | ||
"preferredVersionsHash": "c3ce06bc821dea3e1fe5dbc73da35b305908795a" | ||
} |
This file contains 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 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