1 line
17 KiB
Plaintext
1 line
17 KiB
Plaintext
{"version":3,"file":"bulk-suppressions-patch.js","sourceRoot":"","sources":["../../src/eslint-bulk-suppressions/bulk-suppressions-patch.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG3D,4CAAoB;AAEpB,qDAAuC;AAEvC,gDAA8C;AAC9C,2CAIqB;AACrB,qEAOkC;AAElC,MAAM,kBAAkB,GAAa;IACnC,cAAc;IACd,eAAe;IACf,uGAAuG;IACvG,sDAAsD;CACvD,CAAC;AACF,MAAM,kBAAkB,GAAkB,MAAM,CAAC,aAAa,CAAC,CAAC;AAChE,MAAM,kCAAkC,GAAuB,OAAO,CAAC,GAAG,CAAC,6CAAiC,CAAC,CAAC;AAC9G,MAAM,kBAAkB,GAAY,kCAAkC,KAAK,GAAG,CAAC;AAC/E,MAAM,iBAAiB,GAA4B,kCAAkC;IACnF,CAAC,CAAC,IAAI,GAAG,CAAC,kCAAkC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC,CAAC,SAAS,CAAC;AAUd,SAAS,WAAW,CAAC,IAAmB;IACtC,IAAI,MAAM,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;IACtB,CAAC;SAAM,IAAI,MAAM,CAAC,6BAA6B,CAAC,IAAI,CAAC,EAAE,CAAC;QACtD,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;IACtB,CAAC;SAAM,IAAI,MAAM,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;QAClD,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;IACtB,CAAC;SAAM,IAAI,MAAM,CAAC,4BAA4B,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;IACtB,CAAC;SAAM,IAAI,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C/B,IAAI,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAAC;oBAChC,MAAM,EACJ,qBAAqB,EACrB,WAAW,EACX,MAAM,EAAE,EACN,yBAAyB,EACzB,UAAU,EAAE,EAAE,YAAY,EAAE,EAC5B,aAAa,EAAE,EAAE,YAAY,EAAE,eAAe,EAAE,EACjD,EACF,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;oBAChC,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,qBAAqB,CAAC,EAAE,CAAC;wBAC1D,yBAAyB,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;wBACrD,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;wBAClC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;oBACjC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC;AA5BD,oDA4BC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { TSESTree } from '@typescript-eslint/types';\nimport fs from 'fs';\n\nimport * as Guards from './ast-guards';\n\nimport { eslintFolder } from '../_patch-base';\nimport {\n ESLINT_BULK_ENABLE_ENV_VAR_NAME,\n ESLINT_BULK_PRUNE_ENV_VAR_NAME,\n ESLINT_BULK_SUPPRESS_ENV_VAR_NAME\n} from './constants';\nimport {\n getSuppressionsConfigForEslintrcFolderPath,\n serializeSuppression,\n type IBulkSuppressionsConfig,\n type ISuppression,\n writeSuppressionsJsonToFile,\n getAllBulkSuppressionsConfigsByEslintrcFolderPath\n} from './bulk-suppressions-file';\n\nconst ESLINTRC_FILENAMES: string[] = [\n '.eslintrc.js',\n '.eslintrc.cjs'\n // Several other filenames are allowed, but this patch requires that it be loaded via a JS config file,\n // so we only need to check for the JS-based filenames\n];\nconst SUPPRESSION_SYMBOL: unique symbol = Symbol('suppression');\nconst ESLINT_BULK_SUPPRESS_ENV_VAR_VALUE: string | undefined = process.env[ESLINT_BULK_SUPPRESS_ENV_VAR_NAME];\nconst SUPPRESS_ALL_RULES: boolean = ESLINT_BULK_SUPPRESS_ENV_VAR_VALUE === '*';\nconst RULES_TO_SUPPRESS: Set<string> | undefined = ESLINT_BULK_SUPPRESS_ENV_VAR_VALUE\n ? new Set(ESLINT_BULK_SUPPRESS_ENV_VAR_VALUE.split(','))\n : undefined;\n\ninterface IProblem {\n [SUPPRESSION_SYMBOL]?: {\n config: IBulkSuppressionsConfig;\n suppression: ISuppression;\n serializedSuppression: string;\n };\n}\n\nfunction getNodeName(node: TSESTree.Node): string | undefined {\n if (Guards.isClassDeclarationWithName(node)) {\n return node.id.name;\n } else if (Guards.isFunctionDeclarationWithName(node)) {\n return node.id.name;\n } else if (Guards.isClassExpressionWithName(node)) {\n return node.id.name;\n } else if (Guards.isFunctionExpressionWithName(node)) {\n return node.id.name;\n } else if (Guards.isNormalVariableDeclaratorWithAnonymousExpressionAssigned(node)) {\n return node.id.name;\n } else if (Guards.isNormalObjectPropertyWithAnonymousExpressionAssigned(node)) {\n return node.key.name;\n } else if (Guards.isNormalClassPropertyDefinitionWithAnonymousExpressionAssigned(node)) {\n return node.key.name;\n } else if (Guards.isNormalAssignmentPatternWithAnonymousExpressionAssigned(node)) {\n return node.left.name;\n } else if (Guards.isNormalMethodDefinition(node)) {\n return node.key.name;\n } else if (Guards.isTSEnumDeclaration(node)) {\n return node.id.name;\n } else if (Guards.isTSInterfaceDeclaration(node)) {\n return node.id.name;\n } else if (Guards.isTSTypeAliasDeclaration(node)) {\n return node.id.name;\n }\n}\n\ntype NodeWithParent = TSESTree.Node & { parent?: TSESTree.Node };\n\nfunction calculateScopeId(node: NodeWithParent | undefined): string {\n const scopeIds: string[] = [];\n for (let current: NodeWithParent | undefined = node; current; current = current.parent) {\n const scopeIdForASTNode: string | undefined = getNodeName(current);\n if (scopeIdForASTNode !== undefined) {\n scopeIds.unshift(scopeIdForASTNode);\n }\n }\n\n if (scopeIds.length === 0) {\n return '.';\n } else {\n return '.' + scopeIds.join('.');\n }\n}\n\nconst eslintrcPathByFileOrFolderPath: Map<string, string> = new Map();\n\nfunction findEslintrcFolderPathForNormalizedFileAbsolutePath(normalizedFilePath: string): string {\n const cachedFolderPathForFilePath: string | undefined =\n eslintrcPathByFileOrFolderPath.get(normalizedFilePath);\n if (cachedFolderPathForFilePath) {\n return cachedFolderPathForFilePath;\n }\n const normalizedFileFolderPath: string = normalizedFilePath.substring(\n 0,\n normalizedFilePath.lastIndexOf('/')\n );\n\n const pathsToCache: string[] = [normalizedFilePath];\n let eslintrcFolderPath: string | undefined;\n findEslintrcFileLoop: for (\n let currentFolder: string = normalizedFileFolderPath;\n currentFolder; // 'something'.substring(0, -1) is ''\n currentFolder = currentFolder.substring(0, currentFolder.lastIndexOf('/'))\n ) {\n const cachedEslintrcFolderPath: string | undefined = eslintrcPathByFileOrFolderPath.get(currentFolder);\n if (cachedEslintrcFolderPath) {\n return cachedEslintrcFolderPath;\n }\n\n pathsToCache.push(currentFolder);\n for (const eslintrcFilename of ESLINTRC_FILENAMES) {\n if (fs.existsSync(`${currentFolder}/${eslintrcFilename}`)) {\n eslintrcFolderPath = currentFolder;\n break findEslintrcFileLoop;\n }\n }\n }\n\n if (eslintrcFolderPath) {\n for (const checkedFolder of pathsToCache) {\n eslintrcPathByFileOrFolderPath.set(checkedFolder, eslintrcFolderPath);\n }\n\n return eslintrcFolderPath;\n } else {\n throw new Error(`Cannot locate an ESLint configuration file for ${normalizedFilePath}`);\n }\n}\n\n// One-line insert into the ruleContext report method to prematurely exit if the ESLint problem has been suppressed\nexport function shouldBulkSuppress(params: {\n filename: string;\n currentNode: TSESTree.Node;\n ruleId: string;\n problem: IProblem;\n}): boolean {\n // Use this ENV variable to turn off eslint-bulk-suppressions functionality, default behavior is on\n if (process.env[ESLINT_BULK_ENABLE_ENV_VAR_NAME] === 'false') {\n return false;\n }\n\n const { filename: fileAbsolutePath, currentNode, ruleId: rule, problem } = params;\n const normalizedFileAbsolutePath: string = fileAbsolutePath.replace(/\\\\/g, '/');\n const eslintrcDirectory: string =\n findEslintrcFolderPathForNormalizedFileAbsolutePath(normalizedFileAbsolutePath);\n const fileRelativePath: string = normalizedFileAbsolutePath.substring(eslintrcDirectory.length + 1);\n const scopeId: string = calculateScopeId(currentNode);\n const suppression: ISuppression = { file: fileRelativePath, scopeId, rule };\n\n const config: IBulkSuppressionsConfig = getSuppressionsConfigForEslintrcFolderPath(eslintrcDirectory);\n const serializedSuppression: string = serializeSuppression(suppression);\n const currentNodeIsSuppressed: boolean = config.serializedSuppressions.has(serializedSuppression);\n\n if (currentNodeIsSuppressed || SUPPRESS_ALL_RULES || RULES_TO_SUPPRESS?.has(suppression.rule)) {\n problem[SUPPRESSION_SYMBOL] = {\n suppression,\n serializedSuppression,\n config\n };\n }\n\n return process.env[ESLINT_BULK_PRUNE_ENV_VAR_NAME] !== '1' && currentNodeIsSuppressed;\n}\n\nexport function prune(): void {\n for (const [\n eslintrcFolderPath,\n suppressionsConfig\n ] of getAllBulkSuppressionsConfigsByEslintrcFolderPath()) {\n if (suppressionsConfig) {\n const { newSerializedSuppressions, newJsonObject } = suppressionsConfig;\n const newSuppressionsConfig: IBulkSuppressionsConfig = {\n serializedSuppressions: newSerializedSuppressions,\n jsonObject: newJsonObject,\n newSerializedSuppressions: new Set(),\n newJsonObject: { suppressions: [] }\n };\n\n writeSuppressionsJsonToFile(eslintrcFolderPath, newSuppressionsConfig);\n }\n }\n}\n\nexport function write(): void {\n for (const [\n eslintrcFolderPath,\n suppressionsConfig\n ] of getAllBulkSuppressionsConfigsByEslintrcFolderPath()) {\n if (suppressionsConfig) {\n writeSuppressionsJsonToFile(eslintrcFolderPath, suppressionsConfig);\n }\n }\n}\n\n// utility function for linter-patch.js to make require statements that use relative paths in linter.js work in linter-patch.js\nexport function requireFromPathToLinterJS(importPath: string): import('eslint').Linter {\n if (!eslintFolder) {\n return require(importPath);\n }\n\n const pathToLinterFolder: string = `${eslintFolder}/lib/linter`;\n const moduleAbsolutePath: string = require.resolve(importPath, { paths: [pathToLinterFolder] });\n return require(moduleAbsolutePath);\n}\n\nexport function patchClass<T, U extends T>(originalClass: new () => T, patchedClass: new () => U): void {\n // Get all the property names of the patched class prototype\n const patchedProperties: string[] = Object.getOwnPropertyNames(patchedClass.prototype);\n\n // Loop through all the properties\n for (const prop of patchedProperties) {\n // Override the property in the original class\n originalClass.prototype[prop] = patchedClass.prototype[prop];\n }\n\n // Handle getters and setters\n for (const [prop, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(patchedClass.prototype))) {\n if (descriptor.get || descriptor.set) {\n Object.defineProperty(originalClass.prototype, prop, descriptor);\n }\n }\n}\n\n/**\n * This returns a wrapped version of the \"verify\" function from ESLint's Linter class\n * that postprocesses rule violations that weren't suppressed by comments. This postprocessing\n * records suppressions that weren't otherwise suppressed by comments to be used\n * by the \"suppress\" and \"prune\" commands.\n */\nexport function extendVerifyFunction(\n originalFn: (this: unknown, ...args: unknown[]) => IProblem[] | undefined\n): (this: unknown, ...args: unknown[]) => IProblem[] | undefined {\n return function (this: unknown, ...args: unknown[]): IProblem[] | undefined {\n const problems: IProblem[] | undefined = originalFn.apply(this, args);\n if (problems) {\n for (const problem of problems) {\n if (problem[SUPPRESSION_SYMBOL]) {\n const {\n serializedSuppression,\n suppression,\n config: {\n newSerializedSuppressions,\n jsonObject: { suppressions },\n newJsonObject: { suppressions: newSuppressions }\n }\n } = problem[SUPPRESSION_SYMBOL];\n if (!newSerializedSuppressions.has(serializedSuppression)) {\n newSerializedSuppressions.add(serializedSuppression);\n newSuppressions.push(suppression);\n suppressions.push(suppression);\n }\n }\n }\n }\n\n return problems;\n };\n}\n"]} |