-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plugin stats to count number of times eslint-disable is used. (#1…
…21818) * add eslint disable count stats * address code review comments
- Loading branch information
1 parent
0a75d42
commit 4305732
Showing
3 changed files
with
84 additions
and
4 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
25 changes: 25 additions & 0 deletions
25
packages/kbn-docs-utils/src/api_docs/count_eslint_disable.test.ts
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,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 changes: 34 additions & 0 deletions
34
packages/kbn-docs-utils/src/api_docs/count_eslint_disable.ts
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,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 }; | ||
} |