Chore: Add codemod and betterer config to make barrel imports explicit (#80913)

* chore: add codemod for highlighting barrel imports

* style(frontend): add no-barrel-files plugin to betterer

* chore(betterer): update betterer file

* ci(frontend-metrics): track occurrences of barrel files being imported

* chore: clean up explicit barrel imports codemod script

* chore(codeowners): add explicit barrel imports script

* Add no-barrel-files plugin to betterer configuration

Co-Authored-By: LeventeBalogh <balogh.levente.hu@gmail.com>

---------

Co-authored-by: LeventeBalogh <balogh.levente.hu@gmail.com>
This commit is contained in:
Jack Westbrook
2024-04-15 16:36:19 +02:00
committed by GitHub
parent 453a75b767
commit 1dfd34ee79
8 changed files with 526 additions and 11 deletions

View File

@@ -105,6 +105,16 @@ function countEslintErrors() {
'@typescript-eslint/consistent-type-assertions': ['error', { assertionStyle: 'never' }],
};
const grafanaRules: Partial<Linter.RulesRecord> = {
...nonTestFilesRules,
'no-barrel-files/no-barrel-files': 'error',
};
const testFilesAndGrafanaRules: Partial<Linter.RulesRecord> = {
...baseRules,
'no-barrel-files/no-barrel-files': 'error',
};
// group files by eslint config file
// this will create two file groups for each eslint config file
// one for test files and one for non-test files
@@ -117,10 +127,16 @@ function countEslintErrors() {
filePath.endsWith('.test.ts') ||
filePath.includes('__mocks__') ||
filePath.includes('public/test/');
const isGrafanaFile = filePath.includes('public/app/');
if (isTestFile) {
if (isGrafanaFile && isTestFile) {
configPath += '-test-grafana';
} else if (isGrafanaFile) {
configPath += '-grafana';
} else if (isTestFile) {
configPath += '-test';
}
if (!fileGroups[configPath]) {
fileGroups[configPath] = [];
}
@@ -128,7 +144,16 @@ function countEslintErrors() {
}
for (const configPath of Object.keys(fileGroups)) {
const rules = configPath.endsWith('-test') ? baseRules : nonTestFilesRules;
let rules;
if (configPath.endsWith('-test-grafana')) {
rules = testFilesAndGrafanaRules;
} else if (configPath.endsWith('-test')) {
rules = baseRules;
} else if (configPath.endsWith('-grafana')) {
rules = grafanaRules;
} else {
rules = nonTestFilesRules;
}
// this is by far the slowest part of this code. It takes eslint about 2 seconds just to find the config
const linterOptions = (await cli.calculateConfigForFile(fileGroups[configPath][0])) as Linter.Config;
const runner = new ESLint({