2022-02-09 06:41:39 -06:00
|
|
|
import { regexp } from '@betterer/regexp';
|
2022-06-23 05:36:20 -05:00
|
|
|
import { eslint } from '@betterer/eslint';
|
2022-06-29 06:25:31 -05:00
|
|
|
import { BettererFileTest } from '@betterer/betterer';
|
2022-02-09 06:41:39 -06:00
|
|
|
|
|
|
|
export default {
|
2022-03-04 03:49:50 -06:00
|
|
|
'no enzyme tests': () => regexp(/from 'enzyme'/g).include('**/*.test.*'),
|
2022-06-25 06:45:38 -05:00
|
|
|
'better eslint': () =>
|
2022-06-23 05:36:20 -05:00
|
|
|
eslint({
|
|
|
|
'@typescript-eslint/no-explicit-any': 'error',
|
2022-06-25 06:45:38 -05:00
|
|
|
'@typescript-eslint/consistent-type-assertions': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
assertionStyle: 'never',
|
|
|
|
},
|
|
|
|
],
|
2022-06-23 05:36:20 -05:00
|
|
|
}).include('**/*.{ts,tsx}'),
|
2022-06-29 06:25:31 -05:00
|
|
|
'no undocumented stories': () => countUndocumentedStories().include('**/*.{story.tsx,mdx}'),
|
2022-02-09 06:41:39 -06:00
|
|
|
};
|
2022-06-29 06:25:31 -05:00
|
|
|
|
|
|
|
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.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|