mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -06:00
688164bbd6
* add a betterer test for undocumented stories * update results * Update .betterer.ts Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com> * update results * prettier * slightly nicer regexp Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { regexp } from '@betterer/regexp';
|
|
import { eslint } from '@betterer/eslint';
|
|
import { BettererFileTest } from '@betterer/betterer';
|
|
|
|
export default {
|
|
'no enzyme tests': () => regexp(/from 'enzyme'/g).include('**/*.test.*'),
|
|
'better eslint': () =>
|
|
eslint({
|
|
'@typescript-eslint/no-explicit-any': 'error',
|
|
'@typescript-eslint/consistent-type-assertions': [
|
|
'error',
|
|
{
|
|
assertionStyle: 'never',
|
|
},
|
|
],
|
|
}).include('**/*.{ts,tsx}'),
|
|
'no undocumented stories': () => countUndocumentedStories().include('**/*.{story.tsx,mdx}'),
|
|
};
|
|
|
|
function countUndocumentedStories() {
|
|
return new BettererFileTest(async (filePaths, fileTestResult) => {
|
|
const storyFilePaths = filePaths.filter((filePath) => filePath.endsWith('story.tsx'));
|
|
const mdxFilePaths = filePaths.filter((filePath) => filePath.endsWith('mdx'));
|
|
storyFilePaths.forEach((filePath) => {
|
|
if (!mdxFilePaths.includes(filePath.replace(/\.story.tsx$/, '.mdx'))) {
|
|
// In this case the file contents don't matter:
|
|
const file = fileTestResult.addFile(filePath, '');
|
|
// Add the issue to the first character of the file:
|
|
file.addIssue(
|
|
0,
|
|
0,
|
|
`No undocumented stories are allowed, please add a ${filePath.replace(
|
|
/^(.*\/)(\w+)\.story\.tsx$/,
|
|
'$2.mdx'
|
|
)} with some documentation.`
|
|
);
|
|
}
|
|
});
|
|
});
|
|
}
|