mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Add plugin stats to count number of times eslint-disable is used. (#121818)
* add eslint disable count stats * address code review comments
This commit is contained in:
parent
0a75d426b9
commit
4305732a45
3 changed files with 84 additions and 4 deletions
|
@ -22,6 +22,7 @@ import { writeDeprecationDocByApi } from './mdx/write_deprecations_doc_by_api';
|
|||
import { writeDeprecationDocByPlugin } from './mdx/write_deprecations_doc_by_plugin';
|
||||
import { writePluginDirectoryDoc } from './mdx/write_plugin_directory_doc';
|
||||
import { collectApiStatsForPlugin } from './stats';
|
||||
import { countEslintDisableLine, EslintDisableCounts } from './count_eslint_disable';
|
||||
|
||||
function isStringArray(arr: unknown | string[]): arr is string[] {
|
||||
return Array.isArray(arr) && arr.every((p) => typeof p === 'string');
|
||||
|
@ -78,17 +79,19 @@ export function runBuildApiDocsCli() {
|
|||
|
||||
const reporter = CiStatsReporter.fromEnv(log);
|
||||
|
||||
const allPluginStats = plugins.reduce((acc, plugin) => {
|
||||
const allPluginStats: { [key: string]: PluginMetaInfo & ApiStats & EslintDisableCounts } = {};
|
||||
for (const plugin of plugins) {
|
||||
const id = plugin.manifest.id;
|
||||
const pluginApi = pluginApiMap[id];
|
||||
acc[id] = {
|
||||
|
||||
allPluginStats[id] = {
|
||||
...(await countEslintDisableLine(plugin.directory)),
|
||||
...collectApiStatsForPlugin(pluginApi, missingApiItems, referencedDeprecations),
|
||||
owner: plugin.manifest.owner,
|
||||
description: plugin.manifest.description,
|
||||
isPlugin: plugin.isPlugin,
|
||||
};
|
||||
return acc;
|
||||
}, {} as { [key: string]: PluginMetaInfo & ApiStats });
|
||||
}
|
||||
|
||||
writePluginDirectoryDoc(outputFolder, pluginApiMap, allPluginStats, log);
|
||||
|
||||
|
@ -142,6 +145,24 @@ export function runBuildApiDocsCli() {
|
|||
group: 'References to deprecated APIs',
|
||||
value: pluginStats.deprecatedAPIsReferencedCount,
|
||||
},
|
||||
{
|
||||
id,
|
||||
meta: { pluginTeam },
|
||||
group: 'ESLint disabled line counts',
|
||||
value: pluginStats.eslintDisableLineCount,
|
||||
},
|
||||
{
|
||||
id,
|
||||
meta: { pluginTeam },
|
||||
group: 'ESLint disabled in files',
|
||||
value: pluginStats.eslintDisableFileCount,
|
||||
},
|
||||
{
|
||||
id,
|
||||
meta: { pluginTeam },
|
||||
group: 'Total ESLint disabled count',
|
||||
value: pluginStats.eslintDisableFileCount + pluginStats.eslintDisableLineCount,
|
||||
},
|
||||
]);
|
||||
|
||||
const getLink = (d: ApiDeclaration) =>
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { countEslintDisableLine } from './count_eslint_disable';
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
it('countEsLintDisableLine', async () => {
|
||||
console.log('This is a test');
|
||||
|
||||
// eslint-disable-next-line prefer-const
|
||||
let test: string = '';
|
||||
|
||||
const counts = await countEslintDisableLine(__filename);
|
||||
expect(counts.eslintDisableLineCount).toBe(1);
|
||||
expect(counts.eslintDisableFileCount).toBe(1);
|
||||
|
||||
// To avoid unused warning.
|
||||
return test;
|
||||
});
|
34
packages/kbn-docs-utils/src/api_docs/count_eslint_disable.ts
Normal file
34
packages/kbn-docs-utils/src/api_docs/count_eslint_disable.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
export interface EslintDisableCounts {
|
||||
eslintDisableLineCount: number;
|
||||
eslintDisableFileCount: number;
|
||||
}
|
||||
|
||||
export async function countEslintDisableLine(path: string): Promise<EslintDisableCounts> {
|
||||
const disableCountOutputs = await Promise.all([
|
||||
execSync(`grep -rE 'eslint-disable-next-line|eslint-disable-line' ${path} | wc -l`),
|
||||
execSync(`grep -rE 'eslint-disable ' ${path} | wc -l`),
|
||||
]);
|
||||
const eslintDisableLineCount = Number.parseInt(disableCountOutputs[0].toString(), 10);
|
||||
|
||||
if (eslintDisableLineCount === undefined || isNaN(eslintDisableLineCount)) {
|
||||
throw new Error(`Parsing ${disableCountOutputs[0]} failed to product a valid number`);
|
||||
}
|
||||
|
||||
const eslintDisableFileCount = Number.parseInt(disableCountOutputs[1].toString(), 10);
|
||||
|
||||
if (eslintDisableFileCount === undefined || isNaN(eslintDisableFileCount)) {
|
||||
throw new Error(`Parsing ${disableCountOutputs[1]} failed to product a valid number`);
|
||||
}
|
||||
|
||||
return { eslintDisableFileCount, eslintDisableLineCount };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue