Chore: add a betterer test for undocumented stories (#51444)

* 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>
This commit is contained in:
Ashley Harrison 2022-06-29 12:25:31 +01:00 committed by GitHub
parent 40ce3f3710
commit 688164bbd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 6 deletions

View File

@ -12534,3 +12534,86 @@ exports[`better eslint`] = {
]
}`
};
exports[`no undocumented stories`] = {
value: `{
"packages/grafana-ui/src/components/ButtonCascader/ButtonCascader.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a ButtonCascader.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/ColorPicker/ColorPickerPopover.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a ColorPickerPopover.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/ColorPicker/NamedColorsPalette.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a NamedColorsPalette.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/ColorPicker/SpectrumPalette.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a SpectrumPalette.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/DateTimePickers/RelativeTimeRangePicker/RelativeTimeRangePicker.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a RelativeTimeRangePicker.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/DateTimePickers/TimeOfDayPicker.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a TimeOfDayPicker.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a TimeRangePicker.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/DateTimePickers/TimeZonePicker.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a TimeZonePicker.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/DateTimePickers/WeekStartPicker.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a WeekStartPicker.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/PageLayout/PageToolbar.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a PageToolbar.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/PanelChrome/PanelChrome.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a PanelChrome.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/PluginSignatureBadge/PluginSignatureBadge.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a PluginSignatureBadge.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/QueryField/QueryField.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a QueryField.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/RefreshPicker/RefreshPicker.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a RefreshPicker.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/SecretInput/SecretInput.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a SecretInput.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/SecretTextArea/SecretTextArea.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a SecretTextArea.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/Segment/Segment.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a Segment.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/Segment/SegmentAsync.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a SegmentAsync.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/Segment/SegmentInput.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a SegmentInput.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a StatsPicker.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/Tabs/Tabs.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a Tabs.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/ThemeDemos/ThemeDemo.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a ThemeDemo.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/Typography/Typography.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a Typography.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/VizLayout/VizLayout.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a VizLayout.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/VizLegend/VizLegend.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a VizLegend.mdx with some documentation.", "5381"]
],
"packages/grafana-ui/src/components/VizTooltip/SeriesTable.story.tsx:5381": [
[0, 0, 0, "No undocumented stories are allowed, please add a SeriesTable.mdx with some documentation.", "5381"]
]
}`
};

View File

@ -1,5 +1,6 @@
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.*'),
@ -13,4 +14,27 @@ export default {
},
],
}).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.`
);
}
});
});
}

View File

@ -5,8 +5,6 @@ ERROR_COUNT="0"
ACCESSIBILITY_ERRORS="$(grep -oP '\"errors\":(\d+),' pa11y-ci-results.json | grep -oP '\d+')"
DIRECTIVES="$(grep -r -o directive public/app/ | wc -l)"
CONTROLLERS="$(grep -r -oP 'class .*Ctrl' public/app/ | wc -l)"
STORIES_COUNT="$(find ./packages/grafana-ui/src/components -name "*.story.tsx" | wc -l)"
MDX_COUNT="$(find ./packages/grafana-ui/src/components -name "*.mdx" | wc -l)"
LEGACY_FORMS="$(grep -r -oP 'LegacyForms;' public/app | wc -l)"
TOTAL_BUNDLE="$(du -sk ./public/build | cut -f1)"
@ -22,8 +20,6 @@ echo -e "Typescript errors: $ERROR_COUNT"
echo -e "Accessibility errors: $ACCESSIBILITY_ERRORS"
echo -e "Directives: $DIRECTIVES"
echo -e "Controllers: $CONTROLLERS"
echo -e "Stories: $STORIES_COUNT"
echo -e "Documented stories: $MDX_COUNT"
echo -e "Legacy forms: $LEGACY_FORMS"
echo -e "Total bundle folder size: $TOTAL_BUNDLE"
echo -e "Total outdated dependencies: $OUTDATED_DEPENDENCIES"
@ -45,8 +41,6 @@ echo "Metrics: {
\"grafana.ci-code.accessibilityErrors\": \"${ACCESSIBILITY_ERRORS}\",
\"grafana.ci-code.directives\": \"${DIRECTIVES}\",
\"grafana.ci-code.controllers\": \"${CONTROLLERS}\",
\"grafana.ci-code.grafana-ui.stories\": \"${STORIES_COUNT}\",
\"grafana.ci-code.grafana-ui.mdx\": \"${MDX_COUNT}\",
\"grafana.ci-code.legacyForms\": \"${LEGACY_FORMS}\",
\"grafana.ci-code.bundleFolderSize\": \"${TOTAL_BUNDLE}\",
\"grafana.ci-code.dependencies.outdated\": \"${OUTDATED_DEPENDENCIES}\"