diff --git a/src/platform/packages/shared/kbn-cell-actions/.eslintrc.js b/src/platform/packages/shared/kbn-cell-actions/.eslintrc.js index afb13402e4639..46323a73957e8 100644 --- a/src/platform/packages/shared/kbn-cell-actions/.eslintrc.js +++ b/src/platform/packages/shared/kbn-cell-actions/.eslintrc.js @@ -70,19 +70,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -116,7 +122,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -127,7 +133,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/src/platform/packages/shared/kbn-securitysolution-ecs/.eslintrc.js b/src/platform/packages/shared/kbn-securitysolution-ecs/.eslintrc.js index afb13402e4639..cd5b95e098a88 100644 --- a/src/platform/packages/shared/kbn-securitysolution-ecs/.eslintrc.js +++ b/src/platform/packages/shared/kbn-securitysolution-ecs/.eslintrc.js @@ -70,19 +70,24 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -116,7 +121,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -127,7 +132,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/packages/connectors/.eslintrc.js b/x-pack/solutions/security/packages/connectors/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/packages/connectors/.eslintrc.js +++ b/x-pack/solutions/security/packages/connectors/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/packages/ecs-data-quality-dashboard/.eslintrc.js b/x-pack/solutions/security/packages/ecs-data-quality-dashboard/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/packages/ecs-data-quality-dashboard/.eslintrc.js +++ b/x-pack/solutions/security/packages/ecs-data-quality-dashboard/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/packages/features/.eslintrc.js b/x-pack/solutions/security/packages/features/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/packages/features/.eslintrc.js +++ b/x-pack/solutions/security/packages/features/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/packages/navigation/.eslintrc.js b/x-pack/solutions/security/packages/navigation/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/packages/navigation/.eslintrc.js +++ b/x-pack/solutions/security/packages/navigation/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/packages/side-nav/.eslintrc.js b/x-pack/solutions/security/packages/side-nav/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/packages/side-nav/.eslintrc.js +++ b/x-pack/solutions/security/packages/side-nav/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/packages/upselling/.eslintrc.js b/x-pack/solutions/security/packages/upselling/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/packages/upselling/.eslintrc.js +++ b/x-pack/solutions/security/packages/upselling/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/plugins/ecs_data_quality_dashboard/.eslintrc.js b/x-pack/solutions/security/plugins/ecs_data_quality_dashboard/.eslintrc.js index cee2d528612a7..8ea8fb65392c1 100644 --- a/x-pack/solutions/security/plugins/ecs_data_quality_dashboard/.eslintrc.js +++ b/x-pack/solutions/security/plugins/ecs_data_quality_dashboard/.eslintrc.js @@ -68,19 +68,24 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +119,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +130,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/plugins/security_solution/public/cases/.eslintrc.js b/x-pack/solutions/security/plugins/security_solution/public/cases/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/cases/.eslintrc.js +++ b/x-pack/solutions/security/plugins/security_solution/public/cases/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/plugins/security_solution/public/dashboards/.eslintrc.js b/x-pack/solutions/security/plugins/security_solution/public/dashboards/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/dashboards/.eslintrc.js +++ b/x-pack/solutions/security/plugins/security_solution/public/dashboards/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/plugins/security_solution/public/explore/.eslintrc.js b/x-pack/solutions/security/plugins/security_solution/public/explore/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/explore/.eslintrc.js +++ b/x-pack/solutions/security/plugins/security_solution/public/explore/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/plugins/security_solution/public/onboarding/.eslintrc.js b/x-pack/solutions/security/plugins/security_solution/public/onboarding/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/onboarding/.eslintrc.js +++ b/x-pack/solutions/security/plugins/security_solution/public/onboarding/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ]; diff --git a/x-pack/solutions/security/plugins/security_solution/public/overview/.eslintrc.js b/x-pack/solutions/security/plugins/security_solution/public/overview/.eslintrc.js index cee2d528612a7..e8df76cf42c45 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/overview/.eslintrc.js +++ b/x-pack/solutions/security/plugins/security_solution/public/overview/.eslintrc.js @@ -68,19 +68,25 @@ // eslint-disable-next-line import/no-nodejs-modules const path = require('path'); +// eslint-disable-next-line import/no-nodejs-modules +const { execSync } = require('child_process'); + const minimatch = require('minimatch'); /** @type {Array.} */ -const RESTRICTED_IMPORTS = [ +const RESTRICTED_IMPORTS_PATHS = [ { name: 'enzyme', message: 'Please use @testing-library/react instead', }, ]; -// root directory of the project dynamically calculated -const ROOT_DIR = process.cwd(); -const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // e.g. ../../../../.. +const ROOT_DIR = execSync('git rev-parse --show-toplevel', { + encoding: 'utf8', + cwd: __dirname, +}).trim(); + +const ROOT_CLIMB_STRING = path.relative(__dirname, ROOT_DIR); // i.e. '../../..' /** @type {import('eslint').Linter.Config} */ const rootConfig = require(`${ROOT_CLIMB_STRING}/.eslintrc`); // eslint-disable-line import/no-dynamic-require @@ -114,7 +120,7 @@ for (const override of overridesWithNoRestrictedImportRule) { // Dynamic duplicates removal for all restricted imports const existingPaths = modernConfig.paths.filter( (existing) => - !RESTRICTED_IMPORTS.some((restriction) => + !RESTRICTED_IMPORTS_PATHS.some((restriction) => typeof existing === 'string' ? existing === restriction.name : existing.name === restriction.name @@ -125,7 +131,7 @@ for (const override of overridesWithNoRestrictedImportRule) { const newRuleConfig = [ severity, { - paths: [...existingPaths, ...RESTRICTED_IMPORTS], + paths: [...existingPaths, ...RESTRICTED_IMPORTS_PATHS], patterns: modernConfig.patterns, }, ];